Browse Source

Math: added Geometry::Rectangle::translated().

The Rectangle class needs to be generalized, but this function was needed
for a long time.
pull/34/head
Vladimír Vondruš 13 years ago
parent
commit
ba8489f054
  1. 5
      src/Math/Geometry/Rectangle.h
  2. 9
      src/Math/Geometry/Test/RectangleTest.cpp

5
src/Math/Geometry/Rectangle.h

@ -132,6 +132,11 @@ template<class T> class Rectangle {
/** @brief %Rectangle height */
constexpr T height() const { return _topRight.y() - _bottomLeft.y(); }
/** @brief Translated rectangle */
Rectangle<T> translated(const Vector2<T>& vec) {
return {_bottomLeft + vec, _topRight + vec};
};
private:
Vector2<T> _bottomLeft;
Vector2<T> _topRight;

9
src/Math/Geometry/Test/RectangleTest.cpp

@ -44,6 +44,8 @@ class RectangleTest: public Corrade::TestSuite::Tester {
void compare();
void size();
void translated();
void debug();
void configuration();
};
@ -63,6 +65,8 @@ RectangleTest::RectangleTest() {
&RectangleTest::compare,
&RectangleTest::size,
&RectangleTest::translated,
&RectangleTest::debug,
&RectangleTest::configuration});
}
@ -144,6 +148,11 @@ void RectangleTest::size() {
CORRADE_COMPARE(rect.height(), 7);
}
void RectangleTest::translated() {
CORRADE_COMPARE(Rectanglei({34, 23}, {47, 30}).translated({-17, 40}),
Rectanglei({17, 63}, {30, 70}));
}
void RectangleTest::debug() {
std::ostringstream o;
Debug(&o) << Rectanglei({34, 23}, {47, 30});

Loading…
Cancel
Save