[Scummvm-cvs-logs] SF.net SVN: scummvm:[39911] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Thu Apr 9 19:08:09 CEST 2009


Revision: 39911
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39911&view=rev
Author:   fingolfin
Date:     2009-04-09 17:08:09 +0000 (Thu, 09 Apr 2009)

Log Message:
-----------
Rewrote Common::Rect::contains(Rect) to do what the name suggests (check whether one rect contains the other). Previously, foo.contains(foo) would return false. Added/enabled unit tets for this

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

Modified: scummvm/trunk/common/rect.h
===================================================================
--- scummvm/trunk/common/rect.h	2009-04-09 17:07:53 UTC (rev 39910)
+++ scummvm/trunk/common/rect.h	2009-04-09 17:08:09 UTC (rev 39911)
@@ -127,14 +127,14 @@
 	}
 
 	/**
-	 * Check if the given rect is _fully_ contained inside this rectangle.
+	 * Check if the given rect is contained inside this rectangle.
 	 *
 	 * @param r The rectangle to check
 	 *
 	 * @return true if the given rect is inside, false otherwise
 	 */
 	bool contains(const Rect &r) const {
-		return (left < r.left) && (right > r.right) && (top < r.top) && (bottom > r.bottom);
+		return (left <= r.left) && (r.right <= right) && (top <= r.top) && (r.bottom <= bottom);
 	}
 
 	/**

Modified: scummvm/trunk/test/common/rect.h
===================================================================
--- scummvm/trunk/test/common/rect.h	2009-04-09 17:07:53 UTC (rev 39910)
+++ scummvm/trunk/test/common/rect.h	2009-04-09 17:08:09 UTC (rev 39911)
@@ -26,6 +26,24 @@
 		TS_ASSERT( !Common::Rect(0, 0, 1, 1).intersects(Common::Rect(1, 1, 2, 2)) );
 	}
 
+	void test_contains( void )
+	{
+		Common::Rect r0;
+		Common::Rect r1(0, 0, 1, 1);
+		Common::Rect r2(0, 0, 2, 2);
+		TS_ASSERT( !r0.contains(r1) );
+		TS_ASSERT( !r0.contains(r2) );
+		TS_ASSERT( !r1.contains(r2) );
+		TS_ASSERT( r0.contains(r0) );
+
+		TS_ASSERT( r1.contains(r0) );
+		TS_ASSERT( r1.contains(r1) );
+
+		TS_ASSERT( r2.contains(r0) );
+		TS_ASSERT( r2.contains(r1) );
+		TS_ASSERT( r2.contains(r2) );
+	}
+
 	void test_extend( void )
 	{
 		Common::Rect r0;
@@ -33,7 +51,7 @@
 		Common::Rect r2(0, 0, 2, 2);
 		TS_ASSERT( !r0.contains(r1) );
 		r0.extend(r1);
-//		TS_ASSERT( r0.contains(r1) );
+		TS_ASSERT( r0.contains(r1) );
 		TS_ASSERT_EQUALS(r0.top,    0);
 		TS_ASSERT_EQUALS(r0.left,   0);
 		TS_ASSERT_EQUALS(r0.bottom, 1);


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