mirror of https://github.com/mosra/magnum.git
Browse Source
Encourages vectorization and generic usage even more. Some functions were rewritten to make use of the new features, resulting in shorter and more readable code. This also fixes the annoying naming collision with WINAPI Rectangle() function. The old Rectangle is now subclass of Range2D, is marked as deprecated and will be removed in future release.pull/34/head
39 changed files with 231 additions and 524 deletions
@ -1,176 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <sstream> |
||||
#include <TestSuite/Tester.h> |
||||
#include <Utility/Configuration.h> |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
|
||||
namespace Magnum { namespace Math { namespace Geometry { namespace Test { |
||||
|
||||
class RectangleTest: public Corrade::TestSuite::Tester { |
||||
public: |
||||
RectangleTest(); |
||||
|
||||
void construct(); |
||||
void constructDefault(); |
||||
void constructFromSize(); |
||||
void constructConversion(); |
||||
void constructCopy(); |
||||
|
||||
void access(); |
||||
void compare(); |
||||
void size(); |
||||
|
||||
void translated(); |
||||
|
||||
void debug(); |
||||
void configuration(); |
||||
}; |
||||
|
||||
typedef Geometry::Rectangle<Float> Rectangle; |
||||
typedef Geometry::Rectangle<Int> Rectanglei; |
||||
typedef Vector2<Int> Vector2i; |
||||
|
||||
RectangleTest::RectangleTest() { |
||||
addTests({&RectangleTest::construct, |
||||
&RectangleTest::constructDefault, |
||||
&RectangleTest::constructFromSize, |
||||
&RectangleTest::constructConversion, |
||||
&RectangleTest::constructCopy, |
||||
|
||||
&RectangleTest::access, |
||||
&RectangleTest::compare, |
||||
&RectangleTest::size, |
||||
|
||||
&RectangleTest::translated, |
||||
|
||||
&RectangleTest::debug, |
||||
&RectangleTest::configuration}); |
||||
} |
||||
|
||||
void RectangleTest::construct() { |
||||
constexpr Rectanglei a({3, 5}, {23, 78}); |
||||
CORRADE_COMPARE(a, Rectanglei({3, 5}, {23, 78})); |
||||
} |
||||
|
||||
void RectangleTest::constructDefault() { |
||||
constexpr Rectanglei a; |
||||
CORRADE_COMPARE(a, Rectanglei({0, 0}, {0, 0})); |
||||
} |
||||
|
||||
void RectangleTest::constructFromSize() { |
||||
CORRADE_COMPARE(Rectanglei::fromSize({3, 5}, {23, 78}), Rectanglei({3, 5}, {26, 83})); |
||||
} |
||||
|
||||
void RectangleTest::constructConversion() { |
||||
constexpr Rectangle a({1.3f, 2.7f}, {-15.0f, 7.0f}); |
||||
#ifndef CORRADE_GCC46_COMPATIBILITY |
||||
constexpr /* Not constexpr under GCC < 4.7 */ |
||||
#endif |
||||
Rectanglei b(a); |
||||
CORRADE_COMPARE(b, Rectanglei({1, 2}, {-15, 7})); |
||||
|
||||
/* Implicit conversion is not allowed */ |
||||
CORRADE_VERIFY(!(std::is_convertible<Rectangle, Rectanglei>::value)); |
||||
} |
||||
|
||||
void RectangleTest::constructCopy() { |
||||
constexpr Rectanglei a({3, 5}, {23, 78}); |
||||
constexpr Rectanglei b(a); |
||||
CORRADE_COMPARE(b, Rectanglei({3, 5}, {23, 78})); |
||||
} |
||||
|
||||
void RectangleTest::access() { |
||||
Rectanglei rect({34, 23}, {47, 30}); |
||||
constexpr Rectanglei crect({34, 23}, {47, 30}); |
||||
|
||||
CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23)); |
||||
CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30)); |
||||
CORRADE_COMPARE(rect.bottom(), 23); |
||||
CORRADE_COMPARE(rect.top(), 30); |
||||
CORRADE_COMPARE(rect.left(), 34); |
||||
CORRADE_COMPARE(rect.right(), 47); |
||||
CORRADE_COMPARE(rect.bottomLeft(), Vector2i(34, 23)); |
||||
CORRADE_COMPARE(rect.topRight(), Vector2i(47, 30)); |
||||
|
||||
constexpr Int bottom = crect.bottom(); |
||||
constexpr Int top = crect.top(); |
||||
constexpr Int left = crect.left(); |
||||
constexpr Int right = crect.right(); |
||||
CORRADE_COMPARE(bottom, 23); |
||||
CORRADE_COMPARE(top, 30); |
||||
CORRADE_COMPARE(left, 34); |
||||
CORRADE_COMPARE(right, 47); |
||||
|
||||
constexpr Vector2i bottomLeft = crect.bottomLeft(); |
||||
constexpr Vector2i topRight = crect.topRight(); |
||||
CORRADE_COMPARE(bottomLeft, Vector2i(34, 23)); |
||||
CORRADE_COMPARE(topRight, Vector2i(47, 30)); |
||||
|
||||
CORRADE_COMPARE(rect.topLeft(), Vector2i(34, 30)); |
||||
CORRADE_COMPARE(rect.bottomRight(), Vector2i(47, 23)); |
||||
} |
||||
|
||||
void RectangleTest::compare() { |
||||
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) == Rectanglei({34, 23}, {47, 30})); |
||||
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({34, 23}, {48, 30})); |
||||
CORRADE_VERIFY(Rectanglei({34, 23}, {47, 30}) != Rectanglei({35, 23}, {47, 30})); |
||||
} |
||||
|
||||
void RectangleTest::size() { |
||||
Rectanglei rect({34, 23}, {47, 30}); |
||||
|
||||
CORRADE_COMPARE(rect.size(), Vector2i(13, 7)); |
||||
CORRADE_COMPARE(rect.width(), 13); |
||||
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}); |
||||
|
||||
CORRADE_COMPARE(o.str(), "Rectangle({34, 23}, {47, 30})\n"); |
||||
} |
||||
|
||||
void RectangleTest::configuration() { |
||||
Corrade::Utility::Configuration c; |
||||
|
||||
Rectangle rect({3.0f, 3.125f}, {9.0f, 9.55f}); |
||||
std::string value("3 3.125 9 9.55"); |
||||
|
||||
c.setValue("rectangle", rect); |
||||
CORRADE_COMPARE(c.value("rectangle"), value); |
||||
CORRADE_COMPARE(c.value<Rectangle>("rectangle"), rect); |
||||
} |
||||
|
||||
}}}} |
||||
|
||||
CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::RectangleTest) |
||||
@ -1,38 +0,0 @@
|
||||
/*
|
||||
This file is part of Magnum. |
||||
|
||||
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a |
||||
copy of this software and associated documentation files (the "Software"), |
||||
to deal in the Software without restriction, including without limitation |
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||
and/or sell copies of the Software, and to permit persons to whom the |
||||
Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included |
||||
in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||
DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include "Math/Geometry/Rectangle.h" |
||||
|
||||
namespace Corrade { namespace Utility { |
||||
|
||||
#ifndef DOXYGEN_GENERATING_OUTPUT |
||||
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Float>>; |
||||
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Int>>; |
||||
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::UnsignedInt>>; |
||||
#ifndef MAGNUM_TARGET_GLES |
||||
template struct ConfigurationValue<Magnum::Math::Geometry::Rectangle<Magnum::Double>>; |
||||
#endif |
||||
#endif |
||||
|
||||
}} |
||||
Loading…
Reference in new issue