mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 19:05:59 -04:00
Implement Rect::Extend
This commit is contained in:
parent
0de09713c9
commit
14f352dddd
@ -171,6 +171,20 @@ Rect& Rect::Union(const Rect& rect) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
Rect Rect::GetExtension(unsigned int amount) const {
|
||||
Rect r = *this;
|
||||
r.Extend(amount);
|
||||
return r;
|
||||
}
|
||||
|
||||
Rect& Rect::Extend(unsigned int amount) {
|
||||
x -= amount;
|
||||
y -= amount;
|
||||
w += amount * 2;
|
||||
h += amount * 2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Optional<Rect> Rect::GetIntersection(const Rect& rect) const {
|
||||
if (!Intersects(rect))
|
||||
return NullOpt;
|
||||
|
@ -346,6 +346,26 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect& Union(const Rect& rect);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a rect extended by specified amount of pixels
|
||||
///
|
||||
/// \param[in] int Number of pixels to extend by
|
||||
///
|
||||
/// \returns Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect GetExtension(unsigned int amount) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Extend a rect by specified amount of pixels
|
||||
///
|
||||
/// \param[in] int Number of pixels to extend by
|
||||
///
|
||||
/// \returns Extended rect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect& Extend(unsigned int amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Calculate intersection with another rect
|
||||
///
|
||||
|
@ -240,6 +240,15 @@ BEGIN_TEST()
|
||||
EXPECT_TRUE(Rect(30, 40, 1, 1).Union(Rect(10, 20, 1, 1)) == Rect::FromCorners(10, 20, 30, 40));
|
||||
}
|
||||
|
||||
{
|
||||
// Rect extend
|
||||
EXPECT_TRUE(Rect(10, 20, 30, 40).GetExtension(0) == Rect(10, 20, 30, 40));
|
||||
EXPECT_TRUE(Rect(10, 20, 30, 40).GetExtension(10) == Rect(0, 10, 50, 60));
|
||||
|
||||
EXPECT_TRUE(Rect(10, 20, 30, 40).Extend(0) == Rect(10, 20, 30, 40));
|
||||
EXPECT_TRUE(Rect(10, 20, 30, 40).Extend(10) == Rect(0, 10, 50, 60));
|
||||
}
|
||||
|
||||
{
|
||||
// Rect offset
|
||||
Rect r(1, 2, 3, 4);
|
||||
|
Loading…
x
Reference in New Issue
Block a user