diff --git a/src/Shapes/Test/CapsuleTest.cpp b/src/Shapes/Test/CapsuleTest.cpp index b4fd8a048..03bd09848 100644 --- a/src/Shapes/Test/CapsuleTest.cpp +++ b/src/Shapes/Test/CapsuleTest.cpp @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. */ +#include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Magnum.h" #include "Shapes/Capsule.h" @@ -36,19 +37,34 @@ class CapsuleTest: public TestSuite::Tester { public: CapsuleTest(); - void transformed(); + void transformed2D(); + void transformed3D(); void transformedAverageScaling(); void collisionPoint(); void collisionSphere(); }; CapsuleTest::CapsuleTest() { - addTests({&CapsuleTest::transformed, + addTests({&CapsuleTest::transformed2D, + &CapsuleTest::transformed3D, &CapsuleTest::collisionPoint, &CapsuleTest::collisionSphere}); } -void CapsuleTest::transformed() { +void CapsuleTest::transformed2D() { + const Shapes::Capsule2D capsule({1.0f, 2.0f}, {-1.0f, -2.0f}, 7.0f); + + const auto transformed = capsule.transformed(Matrix3::rotation(Deg(90.0f))); + CORRADE_COMPARE(transformed.a(), Vector2(-2.0f, 1.0f)); + CORRADE_COMPARE(transformed.b(), Vector2(2.0f, -1.0f)); + CORRADE_COMPARE(transformed.radius(), 7.0f); + + /* Apply average scaling to radius */ + const auto scaled = capsule.transformed(Matrix3::scaling({-Constants::sqrt2(), 2.0f})); + CORRADE_COMPARE(scaled.radius(), Constants::sqrt3()*7.0f); +} + +void CapsuleTest::transformed3D() { const Shapes::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); const auto transformed = capsule.transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis())); diff --git a/src/Shapes/Test/SphereTest.cpp b/src/Shapes/Test/SphereTest.cpp index 70f413be5..538a5b282 100644 --- a/src/Shapes/Test/SphereTest.cpp +++ b/src/Shapes/Test/SphereTest.cpp @@ -22,6 +22,7 @@ DEALINGS IN THE SOFTWARE. */ +#include "Math/Matrix3.h" #include "Math/Matrix4.h" #include "Magnum.h" #include "Shapes/LineSegment.h" @@ -36,7 +37,8 @@ class SphereTest: public TestSuite::Tester { public: SphereTest(); - void transformed(); + void transformed2D(); + void transformed3D(); void collisionPoint(); void collisionLine(); void collisionLineSegment(); @@ -44,14 +46,32 @@ class SphereTest: public TestSuite::Tester { }; SphereTest::SphereTest() { - addTests({&SphereTest::transformed, + addTests({&SphereTest::transformed2D, + &SphereTest::transformed3D, &SphereTest::collisionPoint, &SphereTest::collisionLine, &SphereTest::collisionLineSegment, &SphereTest::collisionSphere}); } -void SphereTest::transformed() { +void SphereTest::transformed2D() { + const Shapes::Sphere2D sphere({1.0f, 2.0f}, 7.0f); + + const auto transformed = sphere.transformed(Matrix3::rotation(Deg(90.0f))); + CORRADE_COMPARE(transformed.position(), Vector2(-2.0f, 1.0f)); + CORRADE_COMPARE(transformed.radius(), 7.0f); + + /* Symmetric scaling */ + const auto scaled = sphere.transformed(Matrix3::scaling(Vector2(2.0f))); + CORRADE_COMPARE(scaled.position(), Vector2(2.0f, 4.0f)); + CORRADE_COMPARE(scaled.radius(), 14.0f); + + /* Apply average scaling to radius */ + const auto nonEven = sphere.transformed(Matrix3::scaling({-Constants::sqrt2(), 2.0f})); + CORRADE_COMPARE(nonEven.radius(), Constants::sqrt3()*7.0f); +} + +void SphereTest::transformed3D() { const Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); const auto transformed = sphere.transformed(Matrix4::rotation(Deg(90.0f), Vector3::yAxis()));