Skip to content

Commit

Permalink
partially revert changes of issue #2858 and add IsEqual method
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Jan 22, 2017
1 parent db0fe5b commit 66b91b1
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/Base/Tools2D.h
Expand Up @@ -56,6 +56,8 @@ class BaseExport Vector2d

// methods
inline double Length (void) const;
inline double Distance(const Vector2d&) const;
inline bool IsEqual(const Vector2d&, double tolerance) const;

// operators
inline Vector2d& operator= (const Vector2d &rclVct);
Expand Down Expand Up @@ -86,6 +88,7 @@ class BaseExport BoundBox2d
inline BoundBox2d (const BoundBox2d &rclBB);
inline BoundBox2d (double fX1, double fY1, double fX2, double fY2);
inline bool IsValid (void);
inline bool IsEqual(const BoundBox2d&, double tolerance) const;

// operators
inline BoundBox2d& operator= (const BoundBox2d& rclBB);
Expand Down Expand Up @@ -190,6 +193,18 @@ inline double Vector2d::Length (void) const
return sqrt ((x * x) + (y * y));
}

inline double Vector2d::Distance(const Vector2d& v) const
{
double dx = (x - v.x);
double dy = (y - v.y);
return sqrt(dx*dx + dy*dy);
}

inline bool Vector2d::IsEqual(const Vector2d& v, double tolerance) const
{
return Distance (v) <= tolerance;
}

inline Vector2d& Vector2d::operator= (const Vector2d &rclVct)
{
x = rclVct.x;
Expand All @@ -199,8 +214,7 @@ inline Vector2d& Vector2d::operator= (const Vector2d &rclVct)

inline bool Vector2d::operator== (const Vector2d &rclVct) const
{
return (fabs (x - rclVct.x) <= DBL_EPSILON) &&
(fabs (y - rclVct.y) <= DBL_EPSILON);
return (x == rclVct.x) && (y == rclVct.y);
}

inline Vector2d Vector2d::operator+ (const Vector2d &rclVct) const
Expand Down Expand Up @@ -355,6 +369,12 @@ inline bool BoundBox2d::IsValid (void)
return (MaxX >= MinX) && (MaxY >= MinY);
}

inline bool BoundBox2d::IsEqual(const BoundBox2d& b, double tolerance) const
{
return Vector2d(MinX,MinY).IsEqual(Vector2d(b.MinX,b.MinY), tolerance) &&
Vector2d(MaxX,MaxY).IsEqual(Vector2d(b.MaxX,b.MaxY), tolerance);
}

inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB)
{
MinX = rclBB.MinX;
Expand All @@ -366,10 +386,10 @@ inline BoundBox2d& BoundBox2d::operator= (const BoundBox2d& rclBB)

inline bool BoundBox2d::operator== (const BoundBox2d& rclBB) const
{
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);
return (MinX == rclBB.MinX) &&
(MinY == rclBB.MinY) &&
(MaxX == rclBB.MaxX) &&
(MaxY == rclBB.MaxY);
}

inline void BoundBox2d::Add(const Vector2d &rclVct)
Expand Down

0 comments on commit 66b91b1

Please sign in to comment.