mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Add two arguments rect extension methods
This commit is contained in:
parent
f5f96754a1
commit
e6f9cdbf4c
@ -54,11 +54,21 @@ Rect Rect::GetExtension(unsigned int amount) const {
|
||||
return r;
|
||||
}
|
||||
|
||||
Rect Rect::GetExtension(unsigned int hamount, unsigned int vamount) const {
|
||||
Rect r = *this;
|
||||
r.Extend(hamount, vamount);
|
||||
return r;
|
||||
}
|
||||
|
||||
Rect& Rect::Extend(unsigned int amount) {
|
||||
x -= amount;
|
||||
y -= amount;
|
||||
w += amount * 2;
|
||||
h += amount * 2;
|
||||
return Extend(amount, amount);
|
||||
}
|
||||
|
||||
Rect& Rect::Extend(unsigned int hamount, unsigned int vamount) {
|
||||
x -= hamount;
|
||||
y -= vamount;
|
||||
w += hamount * 2;
|
||||
h += vamount * 2;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -385,6 +385,19 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect GetExtension(unsigned int amount) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get a rect extended by specified amount of pixels
|
||||
///
|
||||
/// \param[in] hamount Number of pixels to extend by
|
||||
/// in horizontal direction
|
||||
/// \param[in] vamount Number of pixels to extend by
|
||||
/// in vertical direction
|
||||
///
|
||||
/// \returns Reference to self
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect GetExtension(unsigned int hamount, unsigned int vamount) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Extend a rect by specified amount of pixels
|
||||
///
|
||||
@ -395,6 +408,19 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect& Extend(unsigned int amount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Extend a rect by specified amount of pixels
|
||||
///
|
||||
/// \param[in] hamount Number of pixels to extend by
|
||||
/// in horizontal direction
|
||||
/// \param[in] vamount Number of pixels to extend by
|
||||
/// in vertical direction
|
||||
///
|
||||
/// \returns Extended rect
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Rect& Extend(unsigned int hamount, unsigned int vamount);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Calculate intersection with another rect
|
||||
///
|
||||
|
@ -283,9 +283,11 @@ BEGIN_TEST()
|
||||
// Rect extend
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetExtension(0), Rect(10, 20, 30, 40));
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetExtension(10), Rect(0, 10, 50, 60));
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).GetExtension(10, 20), Rect(0, 0, 50, 80));
|
||||
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).Extend(0), Rect(10, 20, 30, 40));
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).Extend(10), Rect(0, 10, 50, 60));
|
||||
EXPECT_EQUAL(Rect(10, 20, 30, 40).Extend(10, 20), Rect(0, 0, 50, 80));
|
||||
}
|
||||
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user