[Scummvm-cvs-logs] SF.net SVN: scummvm: [24370] scummvm/trunk/common/rect.h

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Oct 18 16:48:56 CEST 2006


Revision: 24370
          http://svn.sourceforge.net/scummvm/?rev=24370&view=rev
Author:   fingolfin
Date:     2006-10-18 07:48:51 -0700 (Wed, 18 Oct 2006)

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

Modified Paths:
--------------
    scummvm/trunk/common/rect.h

Modified: scummvm/trunk/common/rect.h
===================================================================
--- scummvm/trunk/common/rect.h	2006-10-18 14:30:29 UTC (rev 24369)
+++ scummvm/trunk/common/rect.h	2006-10-18 14:48:51 UTC (rev 24370)
@@ -42,6 +42,24 @@
 	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.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list