Add two arguments rect extension methods

This commit is contained in:
Dmitry Marakasov 2015-11-27 16:42:30 +03:00
parent f5f96754a1
commit e6f9cdbf4c
3 changed files with 42 additions and 4 deletions

View File

@ -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;
}

View File

@ -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
///

View File

@ -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));
}
{