mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-08 06:48:56 -04:00
Add Rect point getters
This commit is contained in:
parent
693cdc659f
commit
8003052f32
@ -306,6 +306,66 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get top left corner of the rect
|
||||||
|
///
|
||||||
|
/// \returns Top left corner of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetTopLeft() const {
|
||||||
|
return Point(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get top right corner of the rect
|
||||||
|
///
|
||||||
|
/// \returns Top right corner of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetTopRight() const {
|
||||||
|
return Point(GetX2(), y);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get bottom left corner of the rect
|
||||||
|
///
|
||||||
|
/// \returns bottom left corner of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetBottomLeft() const {
|
||||||
|
return Point(x, GetY2());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get bottom right corner of the rect
|
||||||
|
///
|
||||||
|
/// \returns Bottom right corner of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetBottomRight() const {
|
||||||
|
return Point(GetX2(), GetY2());
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get size of the rect
|
||||||
|
///
|
||||||
|
/// \returns Size of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetSize() const {
|
||||||
|
return Point(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Get centroid of the rect
|
||||||
|
///
|
||||||
|
/// \returns Centroid of the rect
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
constexpr Point GetCentroid() const {
|
||||||
|
return Point(x + w/2, y + h/2);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Check whether the rect contains given point
|
/// \brief Check whether the rect contains given point
|
||||||
///
|
///
|
||||||
|
@ -290,6 +290,16 @@ BEGIN_TEST()
|
|||||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).Extend(10, 20), Rect(0, 0, 50, 80));
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).Extend(10, 20), Rect(0, 0, 50, 80));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Rect point getters
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetTopLeft(), Point(10, 20));
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetTopRight(), Point(39, 20));
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetBottomLeft(), Point(10, 59));
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetBottomRight(), Point(39, 59));
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetSize(), Point(30, 40));
|
||||||
|
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetCentroid(), Point(25, 40));
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// Rect offset
|
// Rect offset
|
||||||
Rect r(1, 2, 3, 4);
|
Rect r(1, 2, 3, 4);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user