diff options
author | Max Horn | 2006-10-18 14:48:51 +0000 |
---|---|---|
committer | Max Horn | 2006-10-18 14:48:51 +0000 |
commit | 1a086279b25b802f5b4c905afdd4fec4509002cd (patch) | |
tree | 9ffd20eeefe5d2ef9a45ea30c0238ffa5a73f626 | |
parent | 74c5d457e4e602ecf82d4c836e991fc288c3b6fa (diff) | |
download | scummvm-rg350-1a086279b25b802f5b4c905afdd4fec4509002cd.tar.gz scummvm-rg350-1a086279b25b802f5b4c905afdd4fec4509002cd.tar.bz2 scummvm-rg350-1a086279b25b802f5b4c905afdd4fec4509002cd.zip |
Added Point::sqrDist method to (safely) compute the square of the distance between two points
svn-id: r24370
-rw-r--r-- | common/rect.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/rect.h b/common/rect.h index 20be29cc39..1e37733af0 100644 --- a/common/rect.h +++ b/common/rect.h @@ -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. |