mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Implement Rect::Contains(Rect), add corresponding test
This commit is contained in:
parent
518f9fff35
commit
7506b05a77
@ -129,6 +129,10 @@ bool Rect::Contains(const Point& point) const {
|
||||
return !(point.x < x || point.y < y || point.x > GetX2() || point.y > GetY2());
|
||||
}
|
||||
|
||||
bool Rect::Contains(const Rect& rect) const {
|
||||
return rect.x >= x && rect.y >= y && rect.GetX2() <= GetX2() && rect.GetY2() <= GetY2();
|
||||
}
|
||||
|
||||
Rect Rect::operator+(const Point& offset) const {
|
||||
return Rect(x + offset.x, y + offset.y, w, h);
|
||||
}
|
||||
|
@ -253,6 +253,16 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Contains(const Point& point) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Check whether the rect contains another rect
|
||||
///
|
||||
/// \param rect Rect to check
|
||||
///
|
||||
/// \returns True if the checked rect is contained in this rect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
bool Contains(const Rect& rect) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get rectangle moved by a given offset
|
||||
///
|
||||
|
@ -155,6 +155,15 @@ BEGIN_TEST()
|
||||
EXPECT_TRUE(!r.Contains(Point(10, 19)));
|
||||
EXPECT_TRUE(!r.Contains(Point(15, 20)));
|
||||
EXPECT_TRUE(!r.Contains(Point(10, 25)));
|
||||
|
||||
// Rect contains rect
|
||||
EXPECT_TRUE(r.Contains(r));
|
||||
EXPECT_TRUE(r.Contains(Rect(11, 21, 3, 3)));
|
||||
|
||||
EXPECT_TRUE(!r.Contains(Rect(9, 20, 5, 5)));
|
||||
EXPECT_TRUE(!r.Contains(Rect(10, 19, 5, 5)));
|
||||
EXPECT_TRUE(!r.Contains(Rect(10, 20, 6, 5)));
|
||||
EXPECT_TRUE(!r.Contains(Rect(10, 20, 5, 6)));
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user