fixes #0002858: Vector2d Equality Incorrect

This commit is contained in:
wmayer 2017-01-15 16:34:14 +01:00
parent cd6c918f5a
commit 6e7c4915a3
2 changed files with 8 additions and 7 deletions

View File

@ -27,6 +27,7 @@
#include <algorithm>
#include <cmath>
#include <cfloat>
#include <stdio.h>
#include <list>
#include <vector>
@ -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)

View File

@ -69,7 +69,7 @@ template <>
struct float_traits<double> {
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; }
};