From 6e7c4915a3a11c32b1c82c128b6b6c0d8799c744 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 15 Jan 2017 16:34:14 +0100 Subject: [PATCH] fixes #0002858: Vector2d Equality Incorrect --- src/Base/Tools2D.h | 13 +++++++------ src/Base/Vector3D.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index dc148d672..c2881f2c2 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -198,7 +199,8 @@ inline Vector2d& Vector2d::operator= (const Vector2d &rclVct) inline bool Vector2d::operator== (const Vector2d &rclVct) const { - return (x == rclVct.x) && (y == rclVct.y); + return (fabs (x - rclVct.x) <= DBL_EPSILON) && + (fabs (y - rclVct.y) <= DBL_EPSILON); } inline Vector2d Vector2d::operator+ (const Vector2d &rclVct) const @@ -364,11 +366,10 @@ inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB) inline bool BoundBox2d::operator== (const BoundBox2d& rclBB) const { - return - (MinX == rclBB.MinX) && - (MinY == rclBB.MinY) && - (MaxX == rclBB.MaxX) && - (MaxY == rclBB.MaxY); + return (fabs (MinX - rclBB.MinX) <= DBL_EPSILON) && + (fabs (MinY - rclBB.MinY) <= DBL_EPSILON) && + (fabs (MaxX - rclBB.MaxX) <= DBL_EPSILON) && + (fabs (MaxY - rclBB.MaxY) <= DBL_EPSILON); } inline void BoundBox2d::Add(const Vector2d &rclVct) diff --git a/src/Base/Vector3D.h b/src/Base/Vector3D.h index f6816cc5d..52ffd4786 100644 --- a/src/Base/Vector3D.h +++ b/src/Base/Vector3D.h @@ -69,7 +69,7 @@ template <> struct float_traits { typedef double float_type; static inline float_type pi() { return D_PI; } - static inline float_type epsilon() { return FLT_EPSILON; } + static inline float_type epsilon() { return DBL_EPSILON; } static inline float_type maximum() { return DBL_MAX; } };