mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-18 07:53:12 +00:00
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
svn-id: r39911
This commit is contained in:
parent
c473fa849d
commit
a1dc2ecc63
@ -127,14 +127,14 @@ struct Rect {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,24 @@ class RectTestSuite : public CxxTest::TestSuite
|
||||
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 @@ class RectTestSuite : public CxxTest::TestSuite
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user