Added Point::sqrDist method to (safely) compute the square of the distance between two points

svn-id: r24370
This commit is contained in:
Max Horn 2006-10-18 14:48:51 +00:00
parent 74c5d457e4
commit 1a086279b2

View file

@ -42,6 +42,24 @@ struct Point {
Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; };
bool operator==(const Point & p) const { return x == p.x && y == p.y; };
bool operator!=(const Point & p) const { return x != p.x || y != p.y; };
/**
* Return the square of the distance between this point and the point p.
*
* @param p the other point
* @return the distance between this and p
*/
uint sqrDist(const Point & p) const {
int diffx = ABS(p.x - x);
if (diffx >= 0x1000)
return 0xFFFFFF;
int diffy = ABS(p.y - y);
if (diffy >= 0x1000)
return 0xFFFFFF;
return diffx*diffx + diffy*diffy;
}
};
/*! @brief simple class for handling a rectangular zone.