mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-09 15:28:29 -04:00
Add another variant of Rect::Contains()
This commit is contained in:
parent
a657e9e52b
commit
0f4eea5aab
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||||
Copyright (C) 2013-2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||||
Copyright (C) 2013-2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
@ -144,6 +144,10 @@ void Rect::SetY2(int y2) {
|
|||||||
h = y2 - y + 1;
|
h = y2 - y + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Rect::Contains(int px, int py) const {
|
||||||
|
return px >= x && py >= y && px <= GetX2() && py <= GetY2();
|
||||||
|
}
|
||||||
|
|
||||||
bool Rect::Contains(const Point& point) const {
|
bool Rect::Contains(const Point& point) const {
|
||||||
return point.x >= x && point.y >= y && point.x <= GetX2() && point.y <= GetY2();
|
return point.x >= x && point.y >= y && point.x <= GetX2() && point.y <= GetY2();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
libSDL2pp - C++11 bindings/wrapper for SDL2
|
libSDL2pp - C++11 bindings/wrapper for SDL2
|
||||||
Copyright (C) 2013-2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
Copyright (C) 2013-2015 Dmitry Marakasov <amdmi3@amdmi3.ru>
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
This software is provided 'as-is', without any express or implied
|
||||||
warranty. In no event will the authors be held liable for any damages
|
warranty. In no event will the authors be held liable for any damages
|
||||||
@ -281,6 +281,17 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void SetY2(int y2);
|
void SetY2(int y2);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Check whether the rect contains given point
|
||||||
|
///
|
||||||
|
/// \param x X coordinate of a point
|
||||||
|
/// \param y Y coordinate of a point
|
||||||
|
///
|
||||||
|
/// \returns True if the point is contained in the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
bool Contains(int x, int y) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check whether the rect contains given point
|
/// \brief Check whether the rect contains given point
|
||||||
///
|
///
|
||||||
|
@ -158,6 +158,14 @@ BEGIN_TEST()
|
|||||||
EXPECT_TRUE(!r.Contains(Point(15, 20)));
|
EXPECT_TRUE(!r.Contains(Point(15, 20)));
|
||||||
EXPECT_TRUE(!r.Contains(Point(10, 25)));
|
EXPECT_TRUE(!r.Contains(Point(10, 25)));
|
||||||
|
|
||||||
|
EXPECT_TRUE(r.Contains(10, 20));
|
||||||
|
EXPECT_TRUE(r.Contains(14, 24));
|
||||||
|
|
||||||
|
EXPECT_TRUE(!r.Contains(9, 20));
|
||||||
|
EXPECT_TRUE(!r.Contains(10, 19));
|
||||||
|
EXPECT_TRUE(!r.Contains(15, 20));
|
||||||
|
EXPECT_TRUE(!r.Contains(10, 25));
|
||||||
|
|
||||||
// Rect contains rect
|
// Rect contains rect
|
||||||
EXPECT_TRUE(r.Contains(r));
|
EXPECT_TRUE(r.Contains(r));
|
||||||
EXPECT_TRUE(r.Contains(Rect(11, 21, 3, 3)));
|
EXPECT_TRUE(r.Contains(Rect(11, 21, 3, 3)));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user