diff --git a/src/Magnum/SceneGraph/Test/AnimableTest.cpp b/src/Magnum/SceneGraph/Test/AnimableTest.cpp index bdedab482..ad7485d29 100644 --- a/src/Magnum/SceneGraph/Test/AnimableTest.cpp +++ b/src/Magnum/SceneGraph/Test/AnimableTest.cpp @@ -27,47 +27,58 @@ #include #include -#include "Magnum/SceneGraph/Animable.h" +#include "Magnum/SceneGraph/AbstractFeature.hpp" +#include "Magnum/SceneGraph/Animable.hpp" #include "Magnum/SceneGraph/AnimableGroup.h" -#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/SceneGraph/FeatureGroup.hpp" +#include "Magnum/SceneGraph/MatrixTransformation3D.hpp" +#include "Magnum/SceneGraph/Object.hpp" namespace Magnum { namespace SceneGraph { namespace Test { namespace { struct AnimableTest: TestSuite::Tester { explicit AnimableTest(); - void state(); - void step(); - void duration(); - void repeat(); - void stop(); - void pause(); + template void state(); + template void step(); + template void duration(); + template void repeat(); + template void stop(); + template void pause(); void deleteWhileRunning(); void debug(); }; -typedef SceneGraph::Object Object3D; - AnimableTest::AnimableTest() { - addTests({&AnimableTest::state, - &AnimableTest::step, - &AnimableTest::duration, - &AnimableTest::repeat, - &AnimableTest::stop, - &AnimableTest::pause, + addTests({&AnimableTest::state, + &AnimableTest::state, + &AnimableTest::step, + &AnimableTest::step, + &AnimableTest::duration, + &AnimableTest::duration, + &AnimableTest::repeat, + &AnimableTest::repeat, + &AnimableTest::stop, + &AnimableTest::stop, + &AnimableTest::pause, + &AnimableTest::pause, &AnimableTest::deleteWhileRunning, &AnimableTest::debug}); } -void AnimableTest::state() { - class StateTrackingAnimable: public SceneGraph::Animable3D { +template using Object3D = SceneGraph::Object>; + +template void AnimableTest::state() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class StateTrackingAnimable: public SceneGraph::BasicAnimable3D { public: - StateTrackingAnimable(AbstractObject3D& object, AnimableGroup3D* group = nullptr): SceneGraph::Animable3D(object, group) { - setDuration(1.0f); + StateTrackingAnimable(AbstractBasicObject3D& object, BasicAnimableGroup3D* group = nullptr): SceneGraph::BasicAnimable3D{object, group} { + this->setDuration(1.0f); } std::string trackedState; @@ -81,8 +92,8 @@ void AnimableTest::state() { void animationStopped() override { trackedState += "stopped"; } }; - Object3D object; - AnimableGroup3D group; + Object3D object; + BasicAnimableGroup3D group; CORRADE_COMPARE(group.runningCount(), 0); /* Verify initial state */ @@ -157,11 +168,11 @@ void AnimableTest::state() { CORRADE_COMPARE(group.runningCount(), 2); } -class OneShotAnimable: public SceneGraph::Animable3D { +template class OneShotAnimable: public SceneGraph::BasicAnimable3D { public: - OneShotAnimable(AbstractObject3D& object, AnimableGroup3D* group = nullptr): SceneGraph::Animable3D(object, group), time(-1.0f) { - setDuration(10.0f); - setState(AnimationState::Running); + explicit OneShotAnimable(AbstractBasicObject3D& object, BasicAnimableGroup3D* group = nullptr): SceneGraph::BasicAnimable3D{object, group}, time{-1.0f} { + this->setDuration(10.0f); + this->setState(AnimationState::Running); } Float time; @@ -181,10 +192,12 @@ class OneShotAnimable: public SceneGraph::Animable3D { } }; -void AnimableTest::step() { - class InifiniteAnimable: public SceneGraph::Animable3D { +template void AnimableTest::step() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class InifiniteAnimable: public SceneGraph::BasicAnimable3D { public: - InifiniteAnimable(AbstractObject3D& object, AnimableGroup3D* group = nullptr): SceneGraph::Animable3D(object, group), time(-1.0f), delta(0.0f) {} + InifiniteAnimable(AbstractBasicObject3D& object, BasicAnimableGroup3D* group = nullptr): SceneGraph::BasicAnimable3D{object, group}, time{-1.0f}, delta{0.0f} {} Float time, delta; @@ -195,9 +208,9 @@ void AnimableTest::step() { } }; - Object3D object; - AnimableGroup3D group; - InifiniteAnimable animable(object, &group); + Object3D object; + BasicAnimableGroup3D group; + InifiniteAnimable animable{object, &group}; /* Calling step() if no object is running should do nothing */ group.step(5.0f, 0.5f); @@ -219,10 +232,12 @@ void AnimableTest::step() { CORRADE_COMPARE(animable.delta, 0.75f); } -void AnimableTest::duration() { - Object3D object; - AnimableGroup3D group; - OneShotAnimable animable(object, &group); +template void AnimableTest::duration() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D object; + BasicAnimableGroup3D group; + OneShotAnimable animable{object, &group}; CORRADE_VERIFY(!animable.isRepeated()); /* First animation step is in duration, verify that animation is still @@ -240,13 +255,15 @@ void AnimableTest::duration() { CORRADE_COMPARE(animable.time, 0.0f); } -void AnimableTest::repeat() { - class RepeatingAnimable: public SceneGraph::Animable3D { +template void AnimableTest::repeat() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class RepeatingAnimable: public SceneGraph::BasicAnimable3D { public: - RepeatingAnimable(AbstractObject3D& object, AnimableGroup3D* group = nullptr): SceneGraph::Animable3D(object, group), time(-1.0f) { - setDuration(10.0f); - setState(AnimationState::Running); - setRepeated(true); + RepeatingAnimable(AbstractBasicObject3D& object, BasicAnimableGroup3D* group = nullptr): SceneGraph::BasicAnimable3D{object, group}, time(-1.0f) { + this->setDuration(10.0f); + this->setState(AnimationState::Running); + this->setRepeated(true); } Float time; @@ -257,9 +274,9 @@ void AnimableTest::repeat() { } }; - Object3D object; - AnimableGroup3D group; - RepeatingAnimable animable(object, &group); + Object3D object; + BasicAnimableGroup3D group; + RepeatingAnimable animable{object, &group}; CORRADE_COMPARE(animable.repeatCount(), 0); /* First animation steps is in first loop iteration */ @@ -301,10 +318,12 @@ void AnimableTest::repeat() { CORRADE_COMPARE(animable.state(), AnimationState::Stopped); } -void AnimableTest::stop() { - Object3D object; - AnimableGroup3D group; - OneShotAnimable animable(object, &group); +template void AnimableTest::stop() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D object; + BasicAnimableGroup3D group; + OneShotAnimable animable(object, &group); CORRADE_COMPARE(animable.repeatCount(), 0); /* Eat up some absolute time */ @@ -326,10 +345,12 @@ void AnimableTest::stop() { CORRADE_COMPARE(animable.time, 0.0f); } -void AnimableTest::pause() { - Object3D object; - AnimableGroup3D group; - OneShotAnimable animable(object, &group); +template void AnimableTest::pause() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D object; + BasicAnimableGroup3D group; + OneShotAnimable animable(object, &group); /* First two steps, animation is running */ group.step(1.0f, 0.5f); @@ -357,12 +378,12 @@ void AnimableTest::pause() { } void AnimableTest::deleteWhileRunning() { - Object3D object; + Object3D object; AnimableGroup3D group; CORRADE_COMPARE(group.runningCount(), 0); { - OneShotAnimable animable(object, &group); + OneShotAnimable animable(object, &group); /* Eat up some absolute time */ group.step(1.0f, 0.5f); diff --git a/src/Magnum/SceneGraph/Test/CMakeLists.txt b/src/Magnum/SceneGraph/Test/CMakeLists.txt index 353d10595..3f6fb633e 100644 --- a/src/Magnum/SceneGraph/Test/CMakeLists.txt +++ b/src/Magnum/SceneGraph/Test/CMakeLists.txt @@ -40,6 +40,7 @@ corrade_add_test(SceneGraphTranslationTransfo___Test TranslationTransformationTe set_property(TARGET SceneGraphDualComplexTransfo___Test SceneGraphDualQuaternionTran___Test + SceneGraphObjectTest SceneGraphRigidMatrixTrans___2DTest SceneGraphRigidMatrixTrans___3DTest SceneGraphTranslationRotat___2DTest diff --git a/src/Magnum/SceneGraph/Test/CameraTest.cpp b/src/Magnum/SceneGraph/Test/CameraTest.cpp index aa3580224..61985fec8 100644 --- a/src/Magnum/SceneGraph/Test/CameraTest.cpp +++ b/src/Magnum/SceneGraph/Test/CameraTest.cpp @@ -27,11 +27,14 @@ #include #include -#include "Magnum/SceneGraph/Camera.hpp" /* only for aspectRatioFix(), so it doesn't have to be exported */ +#include "Magnum/SceneGraph/AbstractFeature.hpp" +#include "Magnum/SceneGraph/Camera.hpp" #include "Magnum/SceneGraph/Camera.h" -#include "Magnum/SceneGraph/Drawable.h" -#include "Magnum/SceneGraph/MatrixTransformation2D.h" -#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/SceneGraph/Drawable.hpp" +#include "Magnum/SceneGraph/FeatureGroup.hpp" +#include "Magnum/SceneGraph/MatrixTransformation2D.hpp" +#include "Magnum/SceneGraph/MatrixTransformation3D.hpp" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { @@ -39,97 +42,117 @@ namespace Magnum { namespace SceneGraph { namespace Test { namespace { struct CameraTest: TestSuite::Tester { explicit CameraTest(); - void fixAspectRatio(); - void defaultProjection2D(); - void defaultProjection3D(); - void projectionCorrectedInvertedY(); - void projectionSize2D(); - void projectionSizeOrthographic(); - void projectionSizePerspective(); - void projectionSizeViewport(); - - void draw(); - void drawOrdered(); + template void fixAspectRatio(); + template void defaultProjection2D(); + template void defaultProjection3D(); + template void projectionCorrectedInvertedY(); + template void projectionSize2D(); + template void projectionSizeOrthographic(); + template void projectionSizePerspective(); + template void projectionSizeViewport(); + + template void draw(); + template void drawOrdered(); }; -typedef SceneGraph::Object Object2D; -typedef SceneGraph::Object Object3D; -typedef SceneGraph::Scene Scene3D; - CameraTest::CameraTest() { - addTests({&CameraTest::fixAspectRatio, - &CameraTest::defaultProjection2D, - &CameraTest::defaultProjection3D, - &CameraTest::projectionCorrectedInvertedY, - &CameraTest::projectionSize2D, - &CameraTest::projectionSizeOrthographic, - &CameraTest::projectionSizePerspective, - &CameraTest::projectionSizeViewport, - - &CameraTest::draw, - &CameraTest::drawOrdered}); + addTests({ + &CameraTest::fixAspectRatio, + &CameraTest::fixAspectRatio, + &CameraTest::defaultProjection2D, + &CameraTest::defaultProjection2D, + &CameraTest::defaultProjection3D, + &CameraTest::defaultProjection3D, + &CameraTest::projectionCorrectedInvertedY, + &CameraTest::projectionCorrectedInvertedY, + &CameraTest::projectionSize2D, + &CameraTest::projectionSize2D, + &CameraTest::projectionSizeOrthographic, + &CameraTest::projectionSizeOrthographic, + &CameraTest::projectionSizePerspective, + &CameraTest::projectionSizePerspective, + &CameraTest::projectionSizeViewport, + &CameraTest::projectionSizeViewport, + + &CameraTest::draw, + &CameraTest::draw, + &CameraTest::drawOrdered, + &CameraTest::drawOrdered}); } -void CameraTest::fixAspectRatio() { - Vector2 projectionScale(0.5f, 1.0f/3.0f); +template using Object2D = SceneGraph::Object>; +template using Object3D = SceneGraph::Object>; +template using Scene3D = SceneGraph::Scene>; + +template void CameraTest::fixAspectRatio() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Vector2 projectionScale(T(0.5), T(1.0)/T(3.0)); Vector2i size(400, 300); /* Division by zero */ - Vector2 projectionScaleZeroY(0.5f, 0.0f); - Vector2 projectionScaleZeroX(0.0f, 0.5f); + Math::Vector2 projectionScaleZeroY(T(0.5), T(0.0)); + Math::Vector2 projectionScaleZeroX(T(0.0), T(0.5)); Vector2i sizeZeroY(400, 0); Vector2i sizeZeroX(0, 300); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Matrix4()); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Clip, projectionScaleZeroX, size)), Math::Matrix4{}); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Clip, projectionScaleZeroY, size)), Math::Matrix4{}); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Clip, projectionScale, sizeZeroY)), Math::Matrix4{}); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Extend, projectionScale, sizeZeroX)), Math::Matrix4{}); /* Not preserved */ - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Matrix4()); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::NotPreserved, projectionScale, size)), Math::Matrix4{}); /* Clip */ - Matrix4 expectedClip({1.0f, 0.0f, 0.0f, 0.0f}, - {0.0f, 4.0f/3.0f, 0.0f, 0.0f}, - {0.0f, 0.0f, 1.0f, 0.0f}, - {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, Vector2(0.5f), size)), expectedClip); + Math::Matrix4 expectedClip( + {T(1.0), T(0.0), T(0.0), T(0.0)}, + {T(0.0), T(4.0)/T(3.0), T(0.0), T(0.0)}, + {T(0.0), T(0.0), T(1.0), T(0.0)}, + {T(0.0), T(0.0), T(0.0), T(1.0)}); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Clip, Math::Vector2{T(0.5)}, size)), expectedClip); Matrix4 expectedClipRectangle({1.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 2.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Clip, projectionScale, size)), expectedClipRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Clip, projectionScale, size)), Math::Matrix4{expectedClipRectangle}); /* Extend */ Matrix4 expectedExtend({3.0f/4.0f, 0.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, Vector2(0.5f), size)), expectedExtend); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Extend, Math::Vector2{T(0.5)}, size)), Math::Matrix4{expectedExtend}); Matrix4 expectedExtendRectangle({0.5f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f, 0.0f}, {0.0f, 0.0f, 0.0f, 1.0f}); - CORRADE_COMPARE((Implementation::aspectRatioFix<3, Float>(AspectRatioPolicy::Extend, projectionScale, size)), expectedExtendRectangle); + CORRADE_COMPARE((Implementation::aspectRatioFix<3, T>(AspectRatioPolicy::Extend, projectionScale, size)), Math::Matrix4{expectedExtendRectangle}); } -void CameraTest::defaultProjection2D() { - Object2D o; - Camera2D camera(o); - CORRADE_COMPARE(camera.projectionMatrix(), Matrix3()); - CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f)); +template void CameraTest::defaultProjection2D() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + BasicCamera2D camera{o}; + CORRADE_COMPARE(camera.projectionMatrix(), Math::Matrix3{}); + CORRADE_COMPARE(camera.projectionSize(), Math::Vector2{T(2.0)}); } -void CameraTest::defaultProjection3D() { - Object3D o; - Camera3D camera(o); - CORRADE_COMPARE(camera.projectionMatrix(), Matrix4()); - CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f)); +template void CameraTest::defaultProjection3D() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + BasicCamera3D camera{o}; + CORRADE_COMPARE(camera.projectionMatrix(), Math::Matrix4{}); + CORRADE_COMPARE(camera.projectionSize(), Math::Vector2{T(2.0)}); } -void CameraTest::projectionCorrectedInvertedY() { - Object2D o; - Camera2D camera(o); - camera.setProjectionMatrix(Matrix3::projection({4.0f, -2.0f})) +template void CameraTest::projectionCorrectedInvertedY() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + BasicCamera2D camera{o}; + camera.setProjectionMatrix(Math::Matrix3::projection({T(4.0), T(-2.0)})) .setAspectRatioPolicy(AspectRatioPolicy::Extend) .setViewport({4, 4}); @@ -137,133 +160,145 @@ void CameraTest::projectionCorrectedInvertedY() { Matrix3 expected{{0.5f, 0.0f, 0.0f}, {0.0f, -0.5f, 0.0f}, {0.0f, 0.0f, 1.0f}}; - CORRADE_COMPARE(camera.projectionMatrix(), expected); + CORRADE_COMPARE(camera.projectionMatrix(), Math::Matrix3{expected}); } -void CameraTest::projectionSize2D() { - Vector2 projectionSize(4.0f, 3.0f); - Object2D o; - Camera2D camera(o); - camera.setProjectionMatrix(Matrix3::projection(projectionSize)); +template void CameraTest::projectionSize2D() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Vector2 projectionSize{T(4.0), T(3.0)}; + Object2D o; + BasicCamera2D camera{o}; + camera.setProjectionMatrix(Math::Matrix3::projection(projectionSize)); CORRADE_COMPARE(camera.projectionSize(), projectionSize); } -void CameraTest::projectionSizeOrthographic() { - Vector2 projectionSizeRectangle(5.0f, 4.0f); - Object3D o; - Camera3D camera(o); - camera.setProjectionMatrix(Matrix4::orthographicProjection(projectionSizeRectangle, 1, 9)); +template void CameraTest::projectionSizeOrthographic() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Vector2 projectionSizeRectangle{T(5.0), T(4.0)}; + Object3D o; + BasicCamera3D camera{o}; + camera.setProjectionMatrix(Math::Matrix4::orthographicProjection(projectionSizeRectangle, 1, 9)); CORRADE_COMPARE(camera.projectionSize(), projectionSizeRectangle); } -void CameraTest::projectionSizePerspective() { - Object3D o; - Camera3D camera(o); - camera.setProjectionMatrix(Matrix4::perspectiveProjection(Deg(27.0f), 2.35f, 32.0f, 100)); - CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f, 0.204322f)); +template void CameraTest::projectionSizePerspective() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + BasicCamera3D camera{o}; + camera.setProjectionMatrix(Math::Matrix4::perspectiveProjection(Math::Deg(T(27.0)), T(2.35), T(32.0), 100)); + CORRADE_COMPARE(camera.projectionSize(), (Math::Vector2{T(0.480157518160232), T(0.20432234815329)})); } -void CameraTest::projectionSizeViewport() { - Object3D o; - Camera3D camera(o); +template void CameraTest::projectionSizeViewport() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + BasicCamera3D camera(o); camera.setViewport({200, 300}); - CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f, 2.0f)); + CORRADE_COMPARE(camera.projectionSize(), (Math::Vector2{T(2.0), T(2.0)})); camera.setAspectRatioPolicy(AspectRatioPolicy::Extend); - CORRADE_COMPARE(camera.projectionSize(), Vector2(2.0f, 3.0f)); + CORRADE_COMPARE(camera.projectionSize(), (Math::Vector2{T(2.0), T(3.0)})); camera.setAspectRatioPolicy(AspectRatioPolicy::Clip); - CORRADE_COMPARE(camera.projectionSize(), Vector2(4.0f/3.0f, 2.0f)); + CORRADE_COMPARE(camera.projectionSize(), (Math::Vector2{T(4.0)/T(3.0), T(2.0)})); } -void CameraTest::draw() { - class Drawable: public SceneGraph::Drawable3D { +template void CameraTest::draw() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class Drawable: public SceneGraph::BasicDrawable3D { public: - Drawable(AbstractObject3D& object, DrawableGroup3D* group, Matrix4& result): SceneGraph::Drawable3D(object, group), result(result) {} + Drawable(AbstractBasicObject3D& object, BasicDrawableGroup3D* group, Math::Matrix4& result): SceneGraph::BasicDrawable3D{object, group}, result(result) {} protected: - void draw(const Matrix4& transformationMatrix, Camera3D&) override { + void draw(const Math::Matrix4& transformationMatrix, BasicCamera3D&) override { result = transformationMatrix; } private: - Matrix4& result; + Math::Matrix4& result; }; - DrawableGroup3D group; - Scene3D scene; + BasicDrawableGroup3D group; + Scene3D scene; - Object3D first(&scene); - Matrix4 firstTransformation; - first.scale(Vector3(5.0f)); - new Drawable(first, &group, firstTransformation); + Object3D first(&scene); + Math::Matrix4 firstTransformation; + first.scale(Math::Vector3{T(5.0)}); + new Drawable{first, &group, firstTransformation}; - Object3D second(&scene); - Matrix4 secondTransformation; - second.translate(Vector3::yAxis(3.0f)); - new Drawable(second, &group, secondTransformation); + Object3D second(&scene); + Math::Matrix4 secondTransformation; + second.translate(Math::Vector3::yAxis(T(3.0))); + new Drawable{second, &group, secondTransformation}; - Object3D third(&second); - Matrix4 thirdTransformation; - third.translate(Vector3::zAxis(-1.5f)); - new Drawable(third, &group, thirdTransformation); + Object3D third(&second); + Math::Matrix4 thirdTransformation; + third.translate(Math::Vector3::zAxis(T(-1.5))); + new Drawable{third, &group, thirdTransformation}; - Camera3D camera(third); + BasicCamera3D camera{third}; camera.draw(group); - CORRADE_COMPARE(firstTransformation, Matrix4::translation({0.0f, -3.0f, 1.5f})*Matrix4::scaling(Vector3(5.0f))); - CORRADE_COMPARE(secondTransformation, Matrix4::translation(Vector3::zAxis(1.5f))); - CORRADE_COMPARE(thirdTransformation, Matrix4()); + CORRADE_COMPARE(firstTransformation, Math::Matrix4::translation({T(0.0), T(-3.0), T(1.5)})*Math::Matrix4::scaling(Math::Vector3(T(5.0)))); + CORRADE_COMPARE(secondTransformation, Math::Matrix4::translation(Math::Vector3::zAxis(T(1.5)))); + CORRADE_COMPARE(thirdTransformation, Math::Matrix4{}); } -void CameraTest::drawOrdered() { - class Drawable: public SceneGraph::Drawable3D { +template void CameraTest::drawOrdered() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class Drawable: public SceneGraph::BasicDrawable3D { public: - Drawable(AbstractObject3D& object, DrawableGroup3D* group, std::vector& result): SceneGraph::Drawable3D(object, group), _result(result) {} + Drawable(AbstractBasicObject3D& object, BasicDrawableGroup3D* group, std::vector>& result): SceneGraph::BasicDrawable3D{object, group}, _result(result) {} protected: - void draw(const Matrix4& transformationMatrix, Camera3D&) override { + void draw(const Math::Matrix4& transformationMatrix, BasicCamera3D&) override { _result.push_back(transformationMatrix); } private: - std::vector& _result; + std::vector>& _result; }; - DrawableGroup3D group; - Scene3D scene; + BasicDrawableGroup3D group; + Scene3D scene; - std::vector transformations; + std::vector> transformations; - Object3D first(&scene); - first.scale(Vector3(5.0f)) - .translate(Vector3::zAxis(-1.0f)); + Object3D first{&scene}; + first.scale(Math::Vector3{T(5.0)}) + .translate(Math::Vector3::zAxis(T(-1.0))); new Drawable{first, &group, transformations}; - Object3D second(&scene); - second.translate(Vector3::zAxis(3.0f)); + Object3D second{&scene}; + second.translate(Math::Vector3::zAxis(T(3.0))); new Drawable{second, &group, transformations}; - Object3D third(&second); - third.translate(Vector3::zAxis(-1.5f)); + Object3D third{&second}; + third.translate(Math::Vector3::zAxis(T(-1.5))); new Drawable{third, &group, transformations}; - Camera3D camera(third); + BasicCamera3D camera{third}; - std::vector, Matrix4>> drawableTransformations = camera.drawableTransformations(group); + std::vector>, Math::Matrix4>> drawableTransformations = camera.drawableTransformations(group); std::sort(drawableTransformations.begin(), drawableTransformations.end(), - [](const std::pair, Matrix4>& a, - const std::pair, Matrix4>& b) { + [](const std::pair>, Math::Matrix4>& a, + const std::pair>, Math::Matrix4>& b) { return a.second.translation().z() < b.second.translation().z(); }); camera.draw(drawableTransformations); /* Should be ordered front to back, most negative Z first */ - CORRADE_COMPARE_AS(transformations, (std::vector{ - Matrix4::translation(Vector3::zAxis(-2.5f))*Matrix4::scaling(Vector3{5.0f}), /* first */ - Matrix4{}, /* third */ - Matrix4::translation(Vector3::zAxis(1.5f)) /* second */ + CORRADE_COMPARE_AS(transformations, (std::vector>{ + Math::Matrix4::translation(Math::Vector3::zAxis(T(-2.5)))*Math::Matrix4::scaling(Math::Vector3{T(5.0)}), /* first */ + Math::Matrix4{}, /* third */ + Math::Matrix4::translation(Math::Vector3::zAxis(T(1.5))) /* second */ }), TestSuite::Compare::Container); } diff --git a/src/Magnum/SceneGraph/Test/DualComplexTransformationTest.cpp b/src/Magnum/SceneGraph/Test/DualComplexTransformationTest.cpp index d66e21542..6dcf9e060 100644 --- a/src/Magnum/SceneGraph/Test/DualComplexTransformationTest.cpp +++ b/src/Magnum/SceneGraph/Test/DualComplexTransformationTest.cpp @@ -28,174 +28,212 @@ #include #include "Magnum/SceneGraph/DualComplexTransformation.h" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object2D; -typedef Scene Scene2D; - struct DualComplexTransformationTest: TestSuite::Tester { explicit DualComplexTransformationTest(); - void fromMatrix(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void setTransformationInvalid(); - void resetTransformation(); - void transform(); - void transformInvalid(); - void translate(); - void rotate(); - void normalizeRotation(); + template void fromMatrix(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void setTransformationInvalid(); + template void resetTransformation(); + template void transform(); + template void transformInvalid(); + template void translate(); + template void rotate(); + template void normalizeRotation(); }; DualComplexTransformationTest::DualComplexTransformationTest() { - addTests({&DualComplexTransformationTest::fromMatrix, - &DualComplexTransformationTest::toMatrix, - &DualComplexTransformationTest::compose, - &DualComplexTransformationTest::inverted, - - &DualComplexTransformationTest::setTransformation, - &DualComplexTransformationTest::setTransformationInvalid, - &DualComplexTransformationTest::resetTransformation, - &DualComplexTransformationTest::transform, - &DualComplexTransformationTest::transformInvalid, - &DualComplexTransformationTest::translate, - &DualComplexTransformationTest::rotate, - &DualComplexTransformationTest::normalizeRotation}); + addTests({ + &DualComplexTransformationTest::fromMatrix, + &DualComplexTransformationTest::fromMatrix, + &DualComplexTransformationTest::toMatrix, + &DualComplexTransformationTest::toMatrix, + &DualComplexTransformationTest::compose, + &DualComplexTransformationTest::compose, + &DualComplexTransformationTest::inverted, + &DualComplexTransformationTest::inverted, + + &DualComplexTransformationTest::setTransformation, + &DualComplexTransformationTest::setTransformation, + &DualComplexTransformationTest::setTransformationInvalid, + &DualComplexTransformationTest::setTransformationInvalid, + &DualComplexTransformationTest::resetTransformation, + &DualComplexTransformationTest::resetTransformation, + &DualComplexTransformationTest::transform, + &DualComplexTransformationTest::transform, + &DualComplexTransformationTest::transformInvalid, + &DualComplexTransformationTest::transformInvalid, + &DualComplexTransformationTest::translate, + &DualComplexTransformationTest::translate, + &DualComplexTransformationTest::rotate, + &DualComplexTransformationTest::rotate, + &DualComplexTransformationTest::normalizeRotation, + &DualComplexTransformationTest::normalizeRotation}); } using namespace Math::Literals; -void DualComplexTransformationTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), c); +template using Object2D = Object>; +template using Scene2D = Scene>; + +template void DualComplexTransformationTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + Math::DualComplex c = Math::DualComplex::rotation(Math::Deg{T(17.0)})*Math::DualComplex::translation({1.0, T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), c); } -void DualComplexTransformationTest::toMatrix() { - DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(c), m); +template void DualComplexTransformationTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualComplex c = Math::DualComplex::rotation(Math::Deg{T(17.0)})*Math::DualComplex::translation({T(1.0), T(-0.3)}); + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(c), m); } -void DualComplexTransformationTest::compose() { - DualComplex parent = DualComplex::rotation(Deg(17.0f)); - DualComplex child = DualComplex::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void DualComplexTransformationTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualComplex parent = Math::DualComplex::rotation(Math::Deg{T(17.0)}); + Math::DualComplex child = Math::DualComplex::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void DualComplexTransformationTest::inverted() { - DualComplex c = DualComplex::rotation(Deg(17.0f))*DualComplex::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(c)*c, DualComplex()); +template void DualComplexTransformationTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualComplex c = Math::DualComplex::rotation(Math::Deg{T(17.0)})*Math::DualComplex::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(c)*c, Math::DualComplex{}); } -void DualComplexTransformationTest::setTransformation() { - Object2D o; +template void DualComplexTransformationTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(DualComplex::rotation(Deg(17.0f))); + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene2D s; + Scene2D s; s.setClean(); - s.setTransformation(DualComplex::rotation(Deg(17.0f))); + s.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix3{}); } -void DualComplexTransformationTest::setTransformationInvalid() { +template void DualComplexTransformationTest::setTransformationInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - Object2D o; + Object2D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error redirectError{&out}; - o.setTransformation(DualComplex({1.0f, 2.0f}, {})); + o.setTransformation(Math::DualComplex({T(1.0), T(2.0)}, {})); CORRADE_COMPARE(out.str(), "SceneGraph::DualComplexTransformation::setTransformation(): the dual complex number is not normalized\n"); } -void DualComplexTransformationTest::resetTransformation() { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); - CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); +template void DualComplexTransformationTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix3{}); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3{}); } -void DualComplexTransformationTest::transform() { +template void DualComplexTransformationTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); - o.transform(DualComplex::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); + o.transform(Math::DualComplex::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); - o.transformLocal(DualComplex::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); + o.transformLocal(Math::DualComplex::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void DualComplexTransformationTest::transformInvalid() { +template void DualComplexTransformationTest::transformInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif /* Can't transform with non-rigid transformation */ - Object2D o; + Object2D o; std::ostringstream out; Error redirectError{&out}; - o.transform(DualComplex({1.0f, 2.0f}, {})); + o.transform(Math::DualComplex{{T(1.0), T(2.0)}, {}}); CORRADE_COMPARE(out.str(), "SceneGraph::DualComplexTransformation::transform(): the dual complex number is not normalized\n"); } -void DualComplexTransformationTest::translate() { +template void DualComplexTransformationTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); - o.translate({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); - o.translateLocal({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void DualComplexTransformationTest::rotate() { +template void DualComplexTransformationTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(DualComplex::translation({1.0f, -0.3f})) - .rotate(Complex::rotation(7.0_degf)) - .rotate(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::DualComplex::translation({T(1.0), T(-0.3)})) + .rotate(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotate(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } { - Object2D o; - o.setTransformation(DualComplex::translation({1.0f, -0.3f})) - .rotateLocal(Complex::rotation(7.0_degf)) - .rotateLocal(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::DualComplex::translation({T(1.0), T(-0.3)})) + .rotateLocal(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotateLocal(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } } -void DualComplexTransformationTest::normalizeRotation() { - Object2D o; - o.setTransformation(DualComplex::rotation(Deg(17.0f))); +template void DualComplexTransformationTest::normalizeRotation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation(Math::DualComplex::rotation(Math::Deg{T(17.0)})); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})); } }}}} diff --git a/src/Magnum/SceneGraph/Test/DualQuaternionTransformationTest.cpp b/src/Magnum/SceneGraph/Test/DualQuaternionTransformationTest.cpp index 9d5f2b55d..74dafb664 100644 --- a/src/Magnum/SceneGraph/Test/DualQuaternionTransformationTest.cpp +++ b/src/Magnum/SceneGraph/Test/DualQuaternionTransformationTest.cpp @@ -28,204 +28,245 @@ #include #include "Magnum/SceneGraph/DualQuaternionTransformation.h" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object3D; -typedef Scene Scene3D; - struct DualQuaternionTransformationTest: TestSuite::Tester { explicit DualQuaternionTransformationTest(); - void fromMatrix(); - void fromMatrixInvalid(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void setTransformationInvalid(); - void resetTransformation(); - void transform(); - void transformInvalid(); - void translate(); - void rotate(); - void normalizeRotation(); + template void fromMatrix(); + template void fromMatrixInvalid(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void setTransformationInvalid(); + template void resetTransformation(); + template void transform(); + template void transformInvalid(); + template void translate(); + template void rotate(); + template void normalizeRotation(); }; DualQuaternionTransformationTest::DualQuaternionTransformationTest() { - addTests({&DualQuaternionTransformationTest::fromMatrix, - &DualQuaternionTransformationTest::fromMatrixInvalid, - &DualQuaternionTransformationTest::toMatrix, - &DualQuaternionTransformationTest::compose, - &DualQuaternionTransformationTest::inverted, - - &DualQuaternionTransformationTest::setTransformation, - &DualQuaternionTransformationTest::setTransformationInvalid, - &DualQuaternionTransformationTest::resetTransformation, - &DualQuaternionTransformationTest::transform, - &DualQuaternionTransformationTest::transformInvalid, - &DualQuaternionTransformationTest::translate, - &DualQuaternionTransformationTest::rotate, - &DualQuaternionTransformationTest::normalizeRotation}); + addTests({ + &DualQuaternionTransformationTest::fromMatrix, + &DualQuaternionTransformationTest::fromMatrix, + &DualQuaternionTransformationTest::fromMatrixInvalid, + &DualQuaternionTransformationTest::fromMatrixInvalid, + &DualQuaternionTransformationTest::toMatrix, + &DualQuaternionTransformationTest::toMatrix, + &DualQuaternionTransformationTest::compose, + &DualQuaternionTransformationTest::compose, + &DualQuaternionTransformationTest::inverted, + &DualQuaternionTransformationTest::inverted, + + &DualQuaternionTransformationTest::setTransformation, + &DualQuaternionTransformationTest::setTransformation, + &DualQuaternionTransformationTest::setTransformationInvalid, + &DualQuaternionTransformationTest::setTransformationInvalid, + &DualQuaternionTransformationTest::resetTransformation, + &DualQuaternionTransformationTest::resetTransformation, + &DualQuaternionTransformationTest::transform, + &DualQuaternionTransformationTest::transform, + &DualQuaternionTransformationTest::transformInvalid, + &DualQuaternionTransformationTest::transformInvalid, + &DualQuaternionTransformationTest::translate, + &DualQuaternionTransformationTest::translate, + &DualQuaternionTransformationTest::rotate, + &DualQuaternionTransformationTest::rotate, + &DualQuaternionTransformationTest::normalizeRotation, + &DualQuaternionTransformationTest::normalizeRotation}); } using namespace Math::Literals; -void DualQuaternionTransformationTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), q); +template using Object3D = Object>; +template using Scene3D = Scene>; + +template void DualQuaternionTransformationTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + Math::DualQuaternion q = Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())*Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), q); } -void DualQuaternionTransformationTest::fromMatrixInvalid() { +template void DualQuaternionTransformationTest::fromMatrixInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream out; Error redirectError{&out}; - Implementation::Transformation::fromMatrix(Matrix4::scaling(Vector3(4.0f))); + Implementation::Transformation>::fromMatrix(Math::Matrix4::scaling(Math::Vector3{T(4.0)})); CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation: the matrix doesn't represent rigid transformation\n"); } -void DualQuaternionTransformationTest::toMatrix() { - DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(q), m); +template void DualQuaternionTransformationTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualQuaternion q = Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())*Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)}); + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(q), m); } -void DualQuaternionTransformationTest::compose() { - DualQuaternion parent = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis()); - DualQuaternion child = DualQuaternion::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void DualQuaternionTransformationTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualQuaternion parent = Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis()); + Math::DualQuaternion child = Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void DualQuaternionTransformationTest::inverted() { - DualQuaternion q = DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())*DualQuaternion::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(q)*q, DualQuaternion()); +template void DualQuaternionTransformationTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::DualQuaternion q = Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())*Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(q)*q, Math::DualQuaternion{}); } -void DualQuaternionTransformationTest::setTransformation() { - Object3D o; +template void DualQuaternionTransformationTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene3D s; + Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); + s.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix4{}); } -void DualQuaternionTransformationTest::setTransformationInvalid() { +template void DualQuaternionTransformationTest::setTransformationInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - Object3D o; + Object3D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error redirectError{&out}; - o.setTransformation(DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {})); + o.setTransformation(Math::DualQuaternion({{T(1.0), T(2.0), T(3.0)}, T(4.0)}, {})); CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation::setTransformation(): the dual quaternion is not normalized\n"); } -void DualQuaternionTransformationTest::resetTransformation() { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); - CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); +template void DualQuaternionTransformationTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix4{}); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4{}); } -void DualQuaternionTransformationTest::transform() { +template void DualQuaternionTransformationTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); - o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + o.transform(Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); - o.transformLocal(DualQuaternion::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + o.transformLocal(Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void DualQuaternionTransformationTest::transformInvalid() { +template void DualQuaternionTransformationTest::transformInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif /* Can't transform with non-rigid transformation */ - Object3D o; + Object3D o; std::ostringstream out; Error redirectError{&out}; - o.transform(DualQuaternion({{1.0f, 2.0f, 3.0f}, 4.0f}, {})); + o.transform(Math::DualQuaternion({{T(1.0), T(2.0), T(3.0)}, T(4.0)}, {})); CORRADE_COMPARE(out.str(), "SceneGraph::DualQuaternionTransformation::transform(): the dual quaternion is not normalized\n"); } -void DualQuaternionTransformationTest::translate() { +template void DualQuaternionTransformationTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); - o.translate({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + o.translate({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); - o.translateLocal({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + o.translateLocal({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void DualQuaternionTransformationTest::rotate() { +template void DualQuaternionTransformationTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})) - .rotateX(17.0_degf) - .rotateY(25.0_degf) - .rotateZ(-23.0_degf) - .rotate(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotate(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); - CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.transform(Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateX(Math::Deg{T(17.0)}) + .rotateY(Math::Deg{T(25.0)}) + .rotateZ(-Math::Deg{T(23.0)}) + .rotate(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotate(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4{ + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})}); } { - Object3D o; - o.transform(DualQuaternion::translation({1.0f, -0.3f, 2.3f})) - .rotateXLocal(17.0_degf) - .rotateYLocal(25.0_degf) - .rotateZLocal(-23.0_degf) - .rotateLocal(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotateLocal(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); - CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + Object3D o; + o.transform(Math::DualQuaternion::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateXLocal(Math::Deg{T(17.0)}) + .rotateYLocal(Math::Deg{T(25.0)}) + .rotateZLocal(-Math::Deg{T(23.0)}) + .rotateLocal(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotateLocal(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4{ + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})}); } } -void DualQuaternionTransformationTest::normalizeRotation() { - Object3D o; - o.setTransformation(DualQuaternion::rotation(Deg(17.0f), Vector3::xAxis())); +template void DualQuaternionTransformationTest::normalizeRotation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.setTransformation(Math::DualQuaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } }}}} diff --git a/src/Magnum/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/Magnum/SceneGraph/Test/MatrixTransformation2DTest.cpp index 05ea13af9..6fd17b250 100644 --- a/src/Magnum/SceneGraph/Test/MatrixTransformation2DTest.cpp +++ b/src/Magnum/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -26,164 +26,199 @@ #include #include "Magnum/Math/Complex.h" -#include "Magnum/SceneGraph/MatrixTransformation2D.h" +#include "Magnum/SceneGraph/MatrixTransformation2D.hpp" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object2D; -typedef Scene Scene2D; - struct MatrixTransformation2DTest: TestSuite::Tester { explicit MatrixTransformation2DTest(); - void fromMatrix(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void resetTransformation(); - void transform(); - void translate(); - void rotate(); - void scale(); - void reflect(); + template void fromMatrix(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void resetTransformation(); + template void transform(); + template void translate(); + template void rotate(); + template void scale(); + template void reflect(); }; MatrixTransformation2DTest::MatrixTransformation2DTest() { - addTests({&MatrixTransformation2DTest::fromMatrix, - &MatrixTransformation2DTest::toMatrix, - &MatrixTransformation2DTest::compose, - &MatrixTransformation2DTest::inverted, - - &MatrixTransformation2DTest::setTransformation, - &MatrixTransformation2DTest::resetTransformation, - &MatrixTransformation2DTest::transform, - &MatrixTransformation2DTest::translate, - &MatrixTransformation2DTest::rotate, - &MatrixTransformation2DTest::scale, - &MatrixTransformation2DTest::reflect}); + addTests({ + &MatrixTransformation2DTest::fromMatrix, + &MatrixTransformation2DTest::fromMatrix, + &MatrixTransformation2DTest::toMatrix, + &MatrixTransformation2DTest::toMatrix, + &MatrixTransformation2DTest::compose, + &MatrixTransformation2DTest::compose, + &MatrixTransformation2DTest::inverted, + &MatrixTransformation2DTest::inverted, + + &MatrixTransformation2DTest::setTransformation, + &MatrixTransformation2DTest::setTransformation, + &MatrixTransformation2DTest::resetTransformation, + &MatrixTransformation2DTest::resetTransformation, + &MatrixTransformation2DTest::transform, + &MatrixTransformation2DTest::transform, + &MatrixTransformation2DTest::translate, + &MatrixTransformation2DTest::translate, + &MatrixTransformation2DTest::rotate, + &MatrixTransformation2DTest::rotate, + &MatrixTransformation2DTest::scale, + &MatrixTransformation2DTest::scale, + &MatrixTransformation2DTest::reflect, + &MatrixTransformation2DTest::reflect}); } using namespace Math::Literals; -void MatrixTransformation2DTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object2D = Object>; +template using Scene2D = Scene>; + +template void MatrixTransformation2DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void MatrixTransformation2DTest::toMatrix() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void MatrixTransformation2DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(m), m); } -void MatrixTransformation2DTest::compose() { - Matrix3 parent = Matrix3::rotation(Deg(17.0f)); - Matrix3 child = Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void MatrixTransformation2DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 parent = Math::Matrix3::rotation(Math::Deg{T(17.0)}); + Math::Matrix3 child = Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void MatrixTransformation2DTest::inverted() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix3()); +template void MatrixTransformation2DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(m)*m, Math::Matrix3{}); } -void MatrixTransformation2DTest::setTransformation() { +template void MatrixTransformation2DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + /* Dirty after setting transformation */ - Object2D o; + Object2D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix3::rotation(Deg(17.0f))); + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene2D s; + Scene2D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix3::rotation(Deg(17.0f))); + s.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix3{}); } -void MatrixTransformation2DTest::resetTransformation() { - Object2D o; - o.rotate(Deg(17.0f)); - CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); +template void MatrixTransformation2DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.rotate(Math::Deg{T(17.0)}); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix3{}); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3{}); } -void MatrixTransformation2DTest::transform() { +template void MatrixTransformation2DTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.transform(Matrix3::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.transform(Math::Matrix3::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.transformLocal(Matrix3::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.transformLocal(Math::Matrix3::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void MatrixTransformation2DTest::translate() { +template void MatrixTransformation2DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.translate({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.translateLocal({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void MatrixTransformation2DTest::rotate() { +template void MatrixTransformation2DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})) - .rotate(Complex::rotation(7.0_degf)) - .rotate(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})) + .rotate(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotate(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})) - .rotateLocal(Complex::rotation(7.0_degf)) - .rotateLocal(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})) + .rotateLocal(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotateLocal(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } } -void MatrixTransformation2DTest::scale() { +template void MatrixTransformation2DTest::scale() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.scale({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.scale({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::scaling({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.scaleLocal({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::scaling({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.scaleLocal({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::scaling({T(1.0), T(-0.3)})); } } -void MatrixTransformation2DTest::reflect() { +template void MatrixTransformation2DTest::reflect() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.reflect(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.reflect(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::reflection(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.reflectLocal(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.reflectLocal(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::reflection(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()})); } } diff --git a/src/Magnum/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/Magnum/SceneGraph/Test/MatrixTransformation3DTest.cpp index 16b5da594..cd402d62c 100644 --- a/src/Magnum/SceneGraph/Test/MatrixTransformation3DTest.cpp +++ b/src/Magnum/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -26,180 +26,215 @@ #include #include "Magnum/Math/Quaternion.h" -#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.hpp" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object3D; -typedef Scene Scene3D; - struct MatrixTransformation3DTest: TestSuite::Tester { explicit MatrixTransformation3DTest(); - void fromMatrix(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void resetTransformation(); - void transform(); - void translate(); - void rotate(); - void scale(); - void reflect(); + template void fromMatrix(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void resetTransformation(); + template void transform(); + template void translate(); + template void rotate(); + template void scale(); + template void reflect(); }; MatrixTransformation3DTest::MatrixTransformation3DTest() { - addTests({&MatrixTransformation3DTest::fromMatrix, - &MatrixTransformation3DTest::toMatrix, - &MatrixTransformation3DTest::compose, - &MatrixTransformation3DTest::inverted, - - &MatrixTransformation3DTest::setTransformation, - &MatrixTransformation3DTest::resetTransformation, - &MatrixTransformation3DTest::transform, - &MatrixTransformation3DTest::translate, - &MatrixTransformation3DTest::rotate, - &MatrixTransformation3DTest::scale, - &MatrixTransformation3DTest::reflect}); + addTests({ + &MatrixTransformation3DTest::fromMatrix, + &MatrixTransformation3DTest::fromMatrix, + &MatrixTransformation3DTest::toMatrix, + &MatrixTransformation3DTest::toMatrix, + &MatrixTransformation3DTest::compose, + &MatrixTransformation3DTest::compose, + &MatrixTransformation3DTest::inverted, + &MatrixTransformation3DTest::inverted, + + &MatrixTransformation3DTest::setTransformation, + &MatrixTransformation3DTest::setTransformation, + &MatrixTransformation3DTest::resetTransformation, + &MatrixTransformation3DTest::resetTransformation, + &MatrixTransformation3DTest::transform, + &MatrixTransformation3DTest::transform, + &MatrixTransformation3DTest::translate, + &MatrixTransformation3DTest::translate, + &MatrixTransformation3DTest::rotate, + &MatrixTransformation3DTest::rotate, + &MatrixTransformation3DTest::scale, + &MatrixTransformation3DTest::scale, + &MatrixTransformation3DTest::reflect, + &MatrixTransformation3DTest::reflect}); } using namespace Math::Literals; -void MatrixTransformation3DTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object3D = Object>; +template using Scene3D = Scene>; + +template void MatrixTransformation3DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void MatrixTransformation3DTest::toMatrix() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void MatrixTransformation3DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(m), m); } -void MatrixTransformation3DTest::compose() { - Matrix4 parent = Matrix4::rotationX(Deg(17.0f)); - Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void MatrixTransformation3DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 parent = Math::Matrix4::rotationX(Math::Deg{T(17.0)}); + Math::Matrix4 child = Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void MatrixTransformation3DTest::inverted() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix4()); +template void MatrixTransformation3DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(m)*m, Math::Matrix4{}); } -void MatrixTransformation3DTest::setTransformation() { +template void MatrixTransformation3DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + /* Dirty after setting transformation */ - Object3D o; + Object3D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene3D s; + Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix4::rotationX(Deg(17.0f))); + s.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix4()); } -void MatrixTransformation3DTest::resetTransformation() { - Object3D o; - o.rotateX(Deg(17.0f)); - CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); +template void MatrixTransformation3DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.rotateX(Math::Deg{T(17.0)}); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix4()); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4()); } -void MatrixTransformation3DTest::transform() { +template void MatrixTransformation3DTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.transform(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.transformLocal(Matrix4::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.transformLocal(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void MatrixTransformation3DTest::translate() { +template void MatrixTransformation3DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.translate({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.translateLocal({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void MatrixTransformation3DTest::rotate() { +template void MatrixTransformation3DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})) - .rotateX(17.0_degf) - .rotateY(25.0_degf) - .rotateZ(-23.0_degf) - .rotate(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotate(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateX(Math::Deg{T(17.0)}) + .rotateY(Math::Deg{T(25.0)}) + .rotateZ(Math::Deg{T(-23.0)}) + .rotate(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotate(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::translation({1.0f, -0.3f, 2.3f})); + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})) - .rotateXLocal(17.0_degf) - .rotateYLocal(25.0_degf) - .rotateZLocal(-23.0_degf) - .rotateLocal(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotateLocal(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateXLocal(Math::Deg{T(17.0)}) + .rotateYLocal(Math::Deg{T(25.0)}) + .rotateZLocal(Math::Deg{T(-23.0)}) + .rotateLocal(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotateLocal(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})); } } -void MatrixTransformation3DTest::scale() { +template void MatrixTransformation3DTest::scale() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.scale({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.scale({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::scaling({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.scaleLocal({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.scaleLocal({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::scaling({T(1.0), T(-0.3), T(2.3)})); } } -void MatrixTransformation3DTest::reflect() { +template void MatrixTransformation3DTest::reflect() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.reflect(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.reflect(Math::Vector3{T(-1.0)/Math::Constants::sqrt3()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::reflection(Math::Vector3(T(-1.0)/Math::Constants::sqrt3()))*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.reflectLocal(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.reflectLocal(Math::Vector3(T(-1.0)/Math::Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::reflection(Math::Vector3(T(-1.0)/Math::Constants::sqrt3()))); } } diff --git a/src/Magnum/SceneGraph/Test/ObjectTest.cpp b/src/Magnum/SceneGraph/Test/ObjectTest.cpp index 067a1e05c..b032a2a61 100644 --- a/src/Magnum/SceneGraph/Test/ObjectTest.cpp +++ b/src/Magnum/SceneGraph/Test/ObjectTest.cpp @@ -28,7 +28,9 @@ #include #include -#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/SceneGraph/AbstractFeature.hpp" +#include "Magnum/SceneGraph/MatrixTransformation3D.hpp" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { @@ -36,86 +38,108 @@ namespace Magnum { namespace SceneGraph { namespace Test { namespace { struct ObjectTest: TestSuite::Tester { explicit ObjectTest(); - void addFeature(); - - void parenting(); - void addChild(); - void move(); - void scene(); - void setParentKeepTransformation(); - void setParentKeepTransformationInvalid(); - void absoluteTransformation(); - void transformations(); - void transformationsRelative(); - void transformationsOrphan(); - void transformationsDuplicate(); - void setClean(); - void setCleanListHierarchy(); - void setCleanListBulk(); - - void rangeBasedForChildren(); - void rangeBasedForFeatures(); + template void addFeature(); + + template void parenting(); + template void addChild(); + template void move(); + template void scene(); + template void setParentKeepTransformation(); + template void setParentKeepTransformationInvalid(); + template void absoluteTransformation(); + template void transformations(); + template void transformationsRelative(); + template void transformationsOrphan(); + template void transformationsDuplicate(); + template void setClean(); + template void setCleanListHierarchy(); + template void setCleanListBulk(); + + template void rangeBasedForChildren(); + template void rangeBasedForFeatures(); }; -typedef SceneGraph::Object Object3D; -typedef SceneGraph::Scene Scene3D; +ObjectTest::ObjectTest() { + addTests({ + &ObjectTest::addFeature, + &ObjectTest::addFeature, + + &ObjectTest::parenting, + &ObjectTest::parenting, + &ObjectTest::addChild, + &ObjectTest::addChild, + &ObjectTest::move, + &ObjectTest::move, + &ObjectTest::scene, + &ObjectTest::scene, + &ObjectTest::setParentKeepTransformation, + &ObjectTest::setParentKeepTransformation, + &ObjectTest::setParentKeepTransformationInvalid, + &ObjectTest::setParentKeepTransformationInvalid, + &ObjectTest::absoluteTransformation, + &ObjectTest::absoluteTransformation, + &ObjectTest::transformations, + &ObjectTest::transformations, + &ObjectTest::transformationsRelative, + &ObjectTest::transformationsRelative, + &ObjectTest::transformationsOrphan, + &ObjectTest::transformationsOrphan, + &ObjectTest::transformationsDuplicate, + &ObjectTest::transformationsDuplicate, + &ObjectTest::setClean, + &ObjectTest::setClean, + &ObjectTest::setCleanListHierarchy, + &ObjectTest::setCleanListHierarchy, + &ObjectTest::setCleanListBulk, + &ObjectTest::setCleanListBulk, + + &ObjectTest::rangeBasedForChildren, + &ObjectTest::rangeBasedForChildren, + &ObjectTest::rangeBasedForFeatures, + &ObjectTest::rangeBasedForFeatures}); +} + +template using Object3D = SceneGraph::Object>; +template using Scene3D = SceneGraph::Scene>; -class CachingObject: public Object3D, AbstractFeature3D { +template class CachingObject: public Object3D, AbstractBasicFeature3D { public: - CachingObject(Object3D* parent = nullptr): Object3D(parent), AbstractFeature3D(*this) { - setCachedTransformations(CachedTransformation::Absolute); + CachingObject(Object3D* parent = nullptr): Object3D(parent), AbstractBasicFeature3D{*this} { + this->setCachedTransformations(CachedTransformation::Absolute); } - Matrix4 cleanedAbsoluteTransformation; + Math::Matrix4 cleanedAbsoluteTransformation; protected: - void clean(const Matrix4& absoluteTransformation) override { + void clean(const Math::Matrix4& absoluteTransformation) override { cleanedAbsoluteTransformation = absoluteTransformation; } }; -ObjectTest::ObjectTest() { - addTests({&ObjectTest::addFeature, - - &ObjectTest::parenting, - &ObjectTest::addChild, - &ObjectTest::move, - &ObjectTest::scene, - &ObjectTest::setParentKeepTransformation, - &ObjectTest::setParentKeepTransformationInvalid, - &ObjectTest::absoluteTransformation, - &ObjectTest::transformations, - &ObjectTest::transformationsRelative, - &ObjectTest::transformationsOrphan, - &ObjectTest::transformationsDuplicate, - &ObjectTest::setClean, - &ObjectTest::setCleanListHierarchy, - &ObjectTest::setCleanListBulk, - - &ObjectTest::rangeBasedForChildren, - &ObjectTest::rangeBasedForFeatures}); -} +template void ObjectTest::addFeature() { + setTestCaseTemplateName(Math::TypeTraits::name()); -void ObjectTest::addFeature() { - class MyFeature: public AbstractFeature3D { + class MyFeature: public AbstractBasicFeature3D { public: - explicit MyFeature(AbstractObject3D& object, Int&, Containers::Pointer&&): AbstractFeature3D{object} {} + explicit MyFeature(AbstractBasicObject3D& object, Int&, Containers::Pointer&&): AbstractBasicFeature3D{object} {} }; - Object3D o; + Object3D o; CORRADE_VERIFY(o.features().isEmpty()); /* Test perfect forwarding as well */ int a = 0; - MyFeature& f = o.addFeature(a, Containers::Pointer{}); + MyFeature& f = o.template addFeature(a, Containers::Pointer{}); CORRADE_VERIFY(!o.features().isEmpty()); CORRADE_COMPARE(&f.object(), &o); } -void ObjectTest::parenting() { - Object3D root; +template void ObjectTest::parenting() { + setTestCaseTemplateName(Math::TypeTraits::name()); - Object3D* childOne = new Object3D(&root); - Object3D* childTwo = new Object3D(&root); + Object3D root; + + Object3D* childOne = new Object3D(&root); + Object3D* childTwo = new Object3D(&root); CORRADE_VERIFY(childOne->parent() == &root); CORRADE_VERIFY(childTwo->parent() == &root); @@ -141,26 +165,30 @@ void ObjectTest::parenting() { CORRADE_VERIFY(childOne->children().isEmpty()); } -void ObjectTest::addChild() { - class MyObject: public Object3D { +template void ObjectTest::addChild() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + class MyObject: public Object3D { public: - explicit MyObject(Int&, Containers::Pointer&&, Object3D* parent = nullptr): Object3D{parent} {} + explicit MyObject(Int&, Containers::Pointer&&, Object3D* parent = nullptr): Object3D{parent} {} }; - Object3D o; + Object3D o; CORRADE_VERIFY(o.children().isEmpty()); /* Test perfect forwarding as well */ int a = 0; - MyObject& p = o.addChild(a, Containers::Pointer{}); + MyObject& p = o.template addChild(a, Containers::Pointer{}); CORRADE_VERIFY(!o.children().isEmpty()); CORRADE_COMPARE(p.parent(), &o); } -void ObjectTest::move() { - Scene3D scene; - Object3D* a = new Object3D{&scene}; - Object3D* b = new Object3D{&scene}; - Object3D* c = new Object3D{&scene}; +template void ObjectTest::move() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D scene; + Object3D* a = new Object3D{&scene}; + Object3D* b = new Object3D{&scene}; + Object3D* c = new Object3D{&scene}; CORRADE_COMPARE(a->nextSibling(), b); CORRADE_COMPARE(b->nextSibling(), c); @@ -177,29 +205,33 @@ void ObjectTest::move() { CORRADE_COMPARE(a->nextSibling(), nullptr); } -void ObjectTest::scene() { - Scene3D scene; +template void ObjectTest::scene() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D scene; CORRADE_VERIFY(scene.scene() == &scene); - Object3D* childOne = new Object3D(&scene); - Object3D* childTwo = new Object3D(childOne); + Object3D* childOne = new Object3D(&scene); + Object3D* childTwo = new Object3D(childOne); - Object3D orphan; - Object3D* childOfOrphan = new Object3D(&orphan); + Object3D orphan; + Object3D* childOfOrphan = new Object3D(&orphan); CORRADE_VERIFY(childTwo->scene() == &scene); CORRADE_VERIFY(childOfOrphan->scene() == nullptr); } -void ObjectTest::setParentKeepTransformation() { - Object3D root; - root.rotateZ(Deg(35.0f)); +template void ObjectTest::setParentKeepTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D root; + root.rotateZ(Math::Deg{T(35.0)}); - Object3D* childOne = new Object3D(&root); - Object3D* childTwo = new Object3D(&root); + Object3D* childOne = new Object3D(&root); + Object3D* childTwo = new Object3D(&root); - childOne->translate(Vector3::xAxis(2.0f)); - childTwo->rotateY(Deg(90.0f)); + childOne->translate(Math::Vector3::xAxis(T(2.0))); + childTwo->rotateY(Math::Deg{90.0}); /* Reparent to another and keep absolute transformation */ auto transformation = childOne->absoluteTransformation(); @@ -208,116 +240,126 @@ void ObjectTest::setParentKeepTransformation() { CORRADE_COMPARE(childOne->absoluteTransformation(), transformation); } -void ObjectTest::setParentKeepTransformationInvalid() { +template void ObjectTest::setParentKeepTransformationInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - Object3D root; - root.rotateZ(Deg(35.0f)); + Object3D root; + root.rotateZ(Math::Deg{35.0}); - Object3D* child = new Object3D(&root); + Object3D* child = new Object3D(&root); /* Old parent and new parent must share the same scene */ std::ostringstream o; Error redirectError{&o}; - Scene3D scene; + Scene3D scene; child->setParentKeepTransformation(&scene); CORRADE_COMPARE(o.str(), "SceneGraph::Object::setParentKeepTransformation(): both parents must be in the same scene\n"); } -void ObjectTest::absoluteTransformation() { - Scene3D s; +template void ObjectTest::absoluteTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D s; /* Proper transformation composition */ - Object3D o(&s); - o.translate(Vector3::xAxis(2.0f)); - CORRADE_COMPARE(o.transformation(), Matrix4::translation(Vector3::xAxis(2.0f))); + Object3D o(&s); + o.translate(Math::Vector3::xAxis(T(2.0))); + CORRADE_COMPARE(o.transformation(), Math::Matrix4::translation(Math::Vector3::xAxis(T(2.0)))); CORRADE_COMPARE(o.transformation(), o.transformationMatrix()); - Object3D o2(&o); - o2.rotateY(Deg(90.0f)); + Object3D o2(&o); + o2.rotateY(Math::Deg{90.0}); CORRADE_COMPARE(o2.absoluteTransformation(), - Matrix4::translation(Vector3::xAxis(2.0f))*Matrix4::rotationY(Deg(90.0f))); + Math::Matrix4::translation(Math::Vector3::xAxis(T(2.0)))*Math::Matrix4::rotationY(Math::Deg{90.0})); CORRADE_COMPARE(o2.absoluteTransformation(), o2.absoluteTransformationMatrix()); /* Transformation of root object */ - Object3D o3; - o3.translate({1.0f, 2.0f, 3.0f}); - CORRADE_COMPARE(o3.absoluteTransformation(), Matrix4::translation({1.0f, 2.0f, 3.0f})); + Object3D o3; + o3.translate({T(1.0), T(2.0), T(3.0)}); + CORRADE_COMPARE(o3.absoluteTransformation(), Math::Matrix4::translation({T(1.0), T(2.0), T(3.0)})); } -void ObjectTest::transformations() { - Scene3D s; +template void ObjectTest::transformations() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D s; - Matrix4 initial = Matrix4::rotationX(Deg(90.0f)).inverted(); + Math::Matrix4 initial = Math::Matrix4::rotationX(Math::Deg{90.0}).inverted(); /* Empty list */ - CORRADE_COMPARE(s.transformations({}, initial), std::vector()); + CORRADE_COMPARE(s.transformations({}, initial), std::vector>{}); /* Scene alone */ - CORRADE_COMPARE(s.transformations({s}, initial), std::vector{initial}); + CORRADE_COMPARE(s.transformations({s}, initial), std::vector>{initial}); /* One object */ - Object3D first(&s); - first.rotateZ(Deg(30.0f)); - Object3D second(&first); - second.scale(Vector3(0.5f)); - CORRADE_COMPARE(s.transformations({second}, initial), std::vector{ - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)) + Object3D first(&s); + first.rotateZ(Math::Deg{30.0}); + Object3D second(&first); + second.scale(Math::Vector3(T(0.5))); + CORRADE_COMPARE(s.transformations({second}, initial), std::vector>{ + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::scaling(Math::Vector3(T(0.5))) }); /* One object and scene */ - CORRADE_COMPARE(s.transformations({second, s}, initial), (std::vector{ - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), + CORRADE_COMPARE(s.transformations({second, s}, initial), (std::vector>{ + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::scaling(Math::Vector3(T(0.5))), initial })); /* Two objects with foreign joint */ - Object3D third(&first); - third.translate(Vector3::xAxis(5.0f)); - CORRADE_COMPARE(s.transformations({second, third}, initial), (std::vector{ - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), + Object3D third(&first); + third.translate(Math::Vector3::xAxis(T(5.0))); + CORRADE_COMPARE(s.transformations({second, third}, initial), (std::vector>{ + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::scaling(Math::Vector3(T(0.5))), + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::translation(Math::Vector3::xAxis(T(5.0))), })); /* Three objects with joint as one of them */ - CORRADE_COMPARE(s.transformations({second, third, first}, initial), (std::vector{ - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), - initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), - initial*Matrix4::rotationZ(Deg(30.0f)), + CORRADE_COMPARE(s.transformations({second, third, first}, initial), (std::vector>{ + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::scaling(Math::Vector3(T(0.5))), + initial*Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::translation(Math::Vector3::xAxis(T(5.0))), + initial*Math::Matrix4::rotationZ(Math::Deg{30.0}), })); } -void ObjectTest::transformationsRelative() { +template void ObjectTest::transformationsRelative() { + setTestCaseTemplateName(Math::TypeTraits::name()); + CORRADE_SKIP("Transformations not relative to scene are not implemented yet."); - Scene3D s; - Object3D first(&s); - first.rotateZ(Deg(30.0f)); - Object3D second(&first); - second.scale(Vector3(0.5f)); - Object3D third(&first); - third.translate(Vector3::xAxis(5.0f)); + Scene3D s; + Object3D first(&s); + first.rotateZ(Math::Deg{30.0}); + Object3D second(&first); + second.scale(Math::Vector3(T(0.5))); + Object3D third(&first); + third.translate(Math::Vector3::xAxis(T(5.0))); /* Transformation relative to another object */ - CORRADE_COMPARE(second.transformations({third}), std::vector{ - Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) + CORRADE_COMPARE(second.transformations({third}), std::vector>{ + Math::Matrix4::scaling(Math::Vector3(T(0.5))).inverted()*Math::Matrix4::translation(Math::Vector3::xAxis(T(5.0))) }); /* Transformation relative to another object, not part of any scene (but should work) */ - Object3D orphanParent1; - orphanParent1.rotate(Deg(31.0f), Vector3(1.0f).normalized()); - Object3D orphanParent(&orphanParent1); - Object3D orphan1(&orphanParent); - orphan1.scale(Vector3::xScale(3.0f)); - Object3D orphan2(&orphanParent); - orphan2.translate(Vector3::zAxis(5.0f)); - CORRADE_COMPARE(orphan1.transformations({orphan2}), std::vector{ - Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) + Object3D orphanParent1; + orphanParent1.rotate(Math::Deg{31.0}, Math::Vector3(T(1.0)).normalized()); + Object3D orphanParent(&orphanParent1); + Object3D orphan1(&orphanParent); + orphan1.scale(Math::Vector3::xScale(T(3.0))); + Object3D orphan2(&orphanParent); + orphan2.translate(Math::Vector3::zAxis(T(5.0))); + CORRADE_COMPARE(orphan1.transformations({orphan2}), std::vector>{ + Math::Matrix4::scaling(Math::Vector3::xScale(T(3.0))).inverted()*Math::Matrix4::translation(Math::Vector3::zAxis(T(5.0))) }); } -void ObjectTest::transformationsOrphan() { +template void ObjectTest::transformationsOrphan() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif @@ -326,68 +368,72 @@ void ObjectTest::transformationsOrphan() { Error redirectError{&o}; /* Transformation of objects not part of the same scene */ - Scene3D s; - Object3D orphan; - CORRADE_COMPARE(s.transformations({orphan}), std::vector()); + Scene3D s; + Object3D orphan; + CORRADE_COMPARE(s.transformations({orphan}), std::vector>{}); CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n"); } -void ObjectTest::transformationsDuplicate() { - Scene3D s; - Object3D first(&s); - first.rotateZ(Deg(30.0f)); - Object3D second(&first); - second.scale(Vector3(0.5f)); - Object3D third(&first); - third.translate(Vector3::xAxis(5.0f)); - - Matrix4 firstExpected = Matrix4::rotationZ(Deg(30.0f)); - Matrix4 secondExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)); - Matrix4 thirdExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)); - CORRADE_COMPARE(s.transformations({second, third, second, first, third}), (std::vector{ +template void ObjectTest::transformationsDuplicate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D s; + Object3D first(&s); + first.rotateZ(Math::Deg{T(30.0)}); + Object3D second(&first); + second.scale(Math::Vector3(T(0.5))); + Object3D third(&first); + third.translate(Math::Vector3::xAxis(T(5.0))); + + Math::Matrix4 firstExpected = Math::Matrix4::rotationZ(Math::Deg{30.0}); + Math::Matrix4 secondExpected = Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::scaling(Math::Vector3(T(0.5))); + Math::Matrix4 thirdExpected = Math::Matrix4::rotationZ(Math::Deg{30.0})*Math::Matrix4::translation(Math::Vector3::xAxis(T(5.0))); + CORRADE_COMPARE(s.transformations({second, third, second, first, third}), (std::vector>{ secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected })); } -void ObjectTest::setClean() { - Scene3D scene; +template void ObjectTest::setClean() { + setTestCaseTemplateName(Math::TypeTraits::name()); - class CachingFeature: public AbstractFeature3D { + Scene3D scene; + + class CachingFeature: public AbstractBasicFeature3D { public: - explicit CachingFeature(AbstractObject3D& object): AbstractFeature3D{object} { - setCachedTransformations(CachedTransformation::Absolute); + explicit CachingFeature(AbstractBasicObject3D& object): AbstractBasicFeature3D{object} { + this->setCachedTransformations(CachedTransformation::Absolute); } - Matrix4 cleanedAbsoluteTransformation; + Math::Matrix4 cleanedAbsoluteTransformation; - void clean(const Matrix4& absoluteTransformation) override { + void clean(const Math::Matrix4& absoluteTransformation) override { cleanedAbsoluteTransformation = absoluteTransformation; } }; - class CachingInvertedFeature: public AbstractFeature3D { + class CachingInvertedFeature: public AbstractBasicFeature3D { public: - explicit CachingInvertedFeature(AbstractObject3D& object): AbstractFeature3D{object} { - setCachedTransformations(CachedTransformation::InvertedAbsolute); + explicit CachingInvertedFeature(AbstractBasicObject3D& object): AbstractBasicFeature3D{object} { + this->setCachedTransformations(CachedTransformation::InvertedAbsolute); } - Matrix4 cleanedInvertedAbsoluteTransformation; + Math::Matrix4 cleanedInvertedAbsoluteTransformation; - void cleanInverted(const Matrix4& invertedAbsoluteTransformation) override { + void cleanInverted(const Math::Matrix4& invertedAbsoluteTransformation) override { cleanedInvertedAbsoluteTransformation = invertedAbsoluteTransformation; } }; - CachingObject* childOne = new CachingObject(&scene); - childOne->scale(Vector3(2.0f)); + CachingObject* childOne = new CachingObject{&scene}; + childOne->scale(Math::Vector3(T(2.0))); - CachingObject* childTwo = new CachingObject(childOne); - childTwo->translate(Vector3::xAxis(1.0f)); + CachingObject* childTwo = new CachingObject{childOne}; + childTwo->translate(Math::Vector3::xAxis(T(1.0))); CachingFeature* childTwoFeature = new CachingFeature(*childTwo); CachingInvertedFeature* childTwoFeature2 = new CachingInvertedFeature(*childTwo); - CachingObject* childThree = new CachingObject(childTwo); - childThree->rotate(Deg(90.0f), Vector3::yAxis()); + CachingObject* childThree = new CachingObject{childTwo}; + childThree->rotate(Math::Deg{90.0}, Math::Vector3::yAxis()); /* Object is dirty at the beginning */ CORRADE_VERIFY(scene.isDirty()); @@ -416,16 +462,16 @@ void ObjectTest::setClean() { CORRADE_VERIFY(childThree->isDirty()); /* If the object itself is already clean, it shouldn't clean it again */ - childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit}; + childOne->cleanedAbsoluteTransformation = Math::Matrix4{Math::ZeroInit}; CORRADE_VERIFY(!childOne->isDirty()); childOne->setClean(); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Math::Matrix4{Math::ZeroInit}); /* If any object in the hierarchy is already clean, it shouldn't clean it again */ CORRADE_VERIFY(!childOne->isDirty()); CORRADE_VERIFY(childTwo->isDirty()); childTwo->setClean(); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Math::Matrix4{Math::ZeroInit}); /* Remove object from tree => make it and its children dirty */ childThree->setClean(); @@ -441,40 +487,42 @@ void ObjectTest::setClean() { /* Set object transformation => make it and its children dirty (but not parents) */ childThree->setClean(); - childTwo->setTransformation(Matrix4::translation(Vector3::xAxis(1.0f))); + childTwo->setTransformation(Math::Matrix4::translation(Math::Vector3::xAxis(T(1.0)))); CORRADE_VERIFY(!scene.isDirty()); CORRADE_VERIFY(childTwo->isDirty()); CORRADE_VERIFY(childThree->isDirty()); } -void ObjectTest::setCleanListHierarchy() { - Scene3D scene; +template void ObjectTest::setCleanListHierarchy() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D scene; - class CachingFeature: public AbstractFeature3D { + class CachingFeature: public AbstractBasicFeature3D { public: - explicit CachingFeature(AbstractObject3D& object): AbstractFeature3D{object} { - setCachedTransformations(CachedTransformation::Absolute); + explicit CachingFeature(AbstractBasicObject3D& object): AbstractBasicFeature3D{object} { + this->setCachedTransformations(CachedTransformation::Absolute); } - Matrix4 cleanedAbsoluteTransformation; + Math::Matrix4 cleanedAbsoluteTransformation; - void clean(const Matrix4& absoluteTransformation) override { + void clean(const Math::Matrix4& absoluteTransformation) override { cleanedAbsoluteTransformation = absoluteTransformation; } }; - CachingObject* childOne = new CachingObject(&scene); - childOne->scale(Vector3(2.0f)); + CachingObject* childOne = new CachingObject{&scene}; + childOne->scale(Math::Vector3(T(2.0))); - CachingObject* childTwo = new CachingObject(childOne); - childTwo->translate(Vector3::xAxis(1.0f)); + CachingObject* childTwo = new CachingObject{childOne}; + childTwo->translate(Math::Vector3::xAxis(T(1.0))); CachingFeature* childTwoFeature = new CachingFeature(*childTwo); - CachingObject* childThree = new CachingObject(childTwo); - childThree->rotate(Deg(90.0f), Vector3::yAxis()); + CachingObject* childThree = new CachingObject{childTwo}; + childThree->rotate(Math::Deg{90.0}, Math::Vector3::yAxis()); /* Clean the object and all its dirty parents (but not children) */ - Scene3D::setClean({*childTwo}); + Scene3D::setClean({*childTwo}); CORRADE_VERIFY(!scene.isDirty()); CORRADE_VERIFY(!childOne->isDirty()); CORRADE_VERIFY(!childTwo->isDirty()); @@ -486,31 +534,33 @@ void ObjectTest::setCleanListHierarchy() { CORRADE_COMPARE(childTwoFeature->cleanedAbsoluteTransformation, childTwo->absoluteTransformationMatrix()); /* If the object itself is already clean, it shouldn't clean it again */ - childOne->cleanedAbsoluteTransformation = Matrix4{Math::ZeroInit}; + childOne->cleanedAbsoluteTransformation = Math::Matrix4{Math::ZeroInit}; CORRADE_VERIFY(!childOne->isDirty()); - Scene3D::setClean({*childOne}); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); + Scene3D::setClean({*childOne}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Math::Matrix4{Math::ZeroInit}); /* If any object in the hierarchy is already clean, it shouldn't clean it again */ CORRADE_VERIFY(!childOne->isDirty()); childTwo->setDirty(); - Scene3D::setClean({*childTwo}); - CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4{Math::ZeroInit}); + Scene3D::setClean({*childTwo}); + CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Math::Matrix4{Math::ZeroInit}); } -void ObjectTest::setCleanListBulk() { +template void ObjectTest::setCleanListBulk() { + setTestCaseTemplateName(Math::TypeTraits::name()); + /* Verify it doesn't crash when passed empty list */ - Object3D::setClean({}); + Object3D::setClean({}); - Scene3D scene; - Object3D a(&scene); - Object3D b(&scene); + Scene3D scene; + Object3D a(&scene); + Object3D b(&scene); b.setClean(); - Object3D c(&scene); - c.translate(Vector3::zAxis(3.0f)); - CachingObject d(&c); - d.scale(Vector3(-2.0f)); - Object3D e(&scene); + Object3D c(&scene); + c.translate(Math::Vector3::zAxis(T(3.0))); + CachingObject d(&c); + d.scale(Math::Vector3(T(-2.0))); + Object3D e(&scene); /* All objects should be cleaned */ CORRADE_VERIFY(a.isDirty()); @@ -518,7 +568,7 @@ void ObjectTest::setCleanListBulk() { CORRADE_VERIFY(c.isDirty()); CORRADE_VERIFY(d.isDirty()); CORRADE_VERIFY(e.isDirty()); - Object3D::setClean({a, b, c, d, e}); + Object3D::setClean({a, b, c, d, e}); CORRADE_VERIFY(!a.isDirty()); CORRADE_VERIFY(!b.isDirty()); CORRADE_VERIFY(!c.isDirty()); @@ -526,33 +576,37 @@ void ObjectTest::setCleanListBulk() { CORRADE_VERIFY(!e.isDirty()); /* Verify that right transformation was passed */ - CORRADE_COMPARE(d.cleanedAbsoluteTransformation, Matrix4::translation(Vector3::zAxis(3.0f))*Matrix4::scaling(Vector3(-2.0f))); + CORRADE_COMPARE(d.cleanedAbsoluteTransformation, Math::Matrix4::translation(Math::Vector3::zAxis(T(3.0)))*Math::Matrix4::scaling(Math::Vector3(T(-2.0)))); } -void ObjectTest::rangeBasedForChildren() { - Scene3D scene; - Object3D a(&scene); - Object3D b(&scene); - Object3D c(&scene); +template void ObjectTest::rangeBasedForChildren() { + setTestCaseTemplateName(Math::TypeTraits::name()); - std::vector objects; + Scene3D scene; + Object3D a{&scene}; + Object3D b{&scene}; + Object3D c{&scene}; + + std::vector*> objects; for(auto&& i: scene.children()) objects.push_back(&i); - CORRADE_COMPARE(objects, (std::vector{&a, &b, &c})); + CORRADE_COMPARE(objects, (std::vector*>{&a, &b, &c})); } -void ObjectTest::rangeBasedForFeatures() { - struct Feature: AbstractFeature3D { - explicit Feature(AbstractObject3D& object): AbstractFeature3D{object} {} +template void ObjectTest::rangeBasedForFeatures() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + struct Feature: AbstractBasicFeature3D { + explicit Feature(AbstractBasicObject3D& object): AbstractBasicFeature3D{object} {} }; - Object3D object; - Feature a(object); - Feature b(object); - Feature c(object); + Object3D object; + Feature a{object}; + Feature b{object}; + Feature c{object}; - std::vector features; + std::vector*> features; for(auto&& i: object.features()) features.push_back(&i); - CORRADE_COMPARE(features, (std::vector{&a, &b, &c})); + CORRADE_COMPARE(features, (std::vector*>{&a, &b, &c})); } }}}} diff --git a/src/Magnum/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp b/src/Magnum/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp index 8d5e49fbe..d22049315 100644 --- a/src/Magnum/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp +++ b/src/Magnum/SceneGraph/Test/RigidMatrixTransformation2DTest.cpp @@ -28,202 +28,246 @@ #include #include "Magnum/Math/Complex.h" -#include "Magnum/SceneGraph/RigidMatrixTransformation2D.h" +#include "Magnum/SceneGraph/Object.hpp" +#include "Magnum/SceneGraph/RigidMatrixTransformation2D.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object2D; -typedef Scene Scene2D; - struct RigidMatrixTransformation2DTest: TestSuite::Tester { explicit RigidMatrixTransformation2DTest(); - void fromMatrix(); - void fromMatrixInvalid(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void setTransformationInvalid(); - void resetTransformation(); - void transform(); - void transformInvalid(); - void translate(); - void rotate(); - void reflect(); - void normalizeRotation(); + template void fromMatrix(); + template void fromMatrixInvalid(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void setTransformationInvalid(); + template void resetTransformation(); + template void transform(); + template void transformInvalid(); + template void translate(); + template void rotate(); + template void reflect(); + template void normalizeRotation(); }; RigidMatrixTransformation2DTest::RigidMatrixTransformation2DTest() { - addTests({&RigidMatrixTransformation2DTest::fromMatrix, - &RigidMatrixTransformation2DTest::fromMatrixInvalid, - &RigidMatrixTransformation2DTest::toMatrix, - &RigidMatrixTransformation2DTest::compose, - &RigidMatrixTransformation2DTest::inverted, - - &RigidMatrixTransformation2DTest::setTransformation, - &RigidMatrixTransformation2DTest::setTransformationInvalid, - &RigidMatrixTransformation2DTest::resetTransformation, - &RigidMatrixTransformation2DTest::transform, - &RigidMatrixTransformation2DTest::transformInvalid, - &RigidMatrixTransformation2DTest::translate, - &RigidMatrixTransformation2DTest::rotate, - &RigidMatrixTransformation2DTest::reflect, - &RigidMatrixTransformation2DTest::normalizeRotation}); + addTests({ + &RigidMatrixTransformation2DTest::fromMatrix, + &RigidMatrixTransformation2DTest::fromMatrix, + &RigidMatrixTransformation2DTest::fromMatrixInvalid, + &RigidMatrixTransformation2DTest::fromMatrixInvalid, + &RigidMatrixTransformation2DTest::toMatrix, + &RigidMatrixTransformation2DTest::toMatrix, + &RigidMatrixTransformation2DTest::compose, + &RigidMatrixTransformation2DTest::compose, + &RigidMatrixTransformation2DTest::inverted, + &RigidMatrixTransformation2DTest::inverted, + + &RigidMatrixTransformation2DTest::setTransformation, + &RigidMatrixTransformation2DTest::setTransformation, + &RigidMatrixTransformation2DTest::setTransformationInvalid, + &RigidMatrixTransformation2DTest::setTransformationInvalid, + &RigidMatrixTransformation2DTest::resetTransformation, + &RigidMatrixTransformation2DTest::resetTransformation, + &RigidMatrixTransformation2DTest::transform, + &RigidMatrixTransformation2DTest::transform, + &RigidMatrixTransformation2DTest::transformInvalid, + &RigidMatrixTransformation2DTest::transformInvalid, + &RigidMatrixTransformation2DTest::translate, + &RigidMatrixTransformation2DTest::translate, + &RigidMatrixTransformation2DTest::rotate, + &RigidMatrixTransformation2DTest::rotate, + &RigidMatrixTransformation2DTest::reflect, + &RigidMatrixTransformation2DTest::reflect, + &RigidMatrixTransformation2DTest::normalizeRotation, + &RigidMatrixTransformation2DTest::normalizeRotation}); } using namespace Math::Literals; -void RigidMatrixTransformation2DTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object2D = Object>; +template using Scene2D = Scene>; + +template void RigidMatrixTransformation2DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void RigidMatrixTransformation2DTest::fromMatrixInvalid() { +template void RigidMatrixTransformation2DTest::fromMatrixInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream out; Error redirectError{&out}; - Implementation::Transformation::fromMatrix(Matrix3::scaling(Vector2(4.0f))); + Implementation::Transformation>::fromMatrix(Math::Matrix3::scaling(Math::Vector2{T(4.0)})); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D: the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation2DTest::toMatrix() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void RigidMatrixTransformation2DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(m), m); } -void RigidMatrixTransformation2DTest::compose() { - Matrix3 parent = Matrix3::rotation(Deg(17.0f)); - Matrix3 child = Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void RigidMatrixTransformation2DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 parent = Math::Matrix3::rotation(Math::Deg(T(17.0))); + Math::Matrix3 child = Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void RigidMatrixTransformation2DTest::inverted() { - Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix3()); +template void RigidMatrixTransformation2DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(m)*m, Math::Matrix3{}); } -void RigidMatrixTransformation2DTest::setTransformation() { - Object2D o; +template void RigidMatrixTransformation2DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix3::rotation(Deg(17.0f))); + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene2D s; + Scene2D s; s.setClean(); - s.setTransformation(Matrix3::rotation(Deg(17.0f))); + s.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix3()); } -void RigidMatrixTransformation2DTest::setTransformationInvalid() { +template void RigidMatrixTransformation2DTest::setTransformationInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - Object2D o; + Object2D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error redirectError{&out}; - o.setTransformation(Matrix3::scaling(Vector2(3.0f))); + o.setTransformation(Math::Matrix3::scaling(Math::Vector2{T(3.0)})); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D::setTransformation(): the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation2DTest::resetTransformation() { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); +template void RigidMatrixTransformation2DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix3()); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3()); } -void RigidMatrixTransformation2DTest::transform() { +template void RigidMatrixTransformation2DTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.transform(Matrix3::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.transform(Math::Matrix3::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.transformLocal(Matrix3::translation({1.0f, -0.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.transformLocal(Math::Matrix3::translation({T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void RigidMatrixTransformation2DTest::transformInvalid() { +template void RigidMatrixTransformation2DTest::transformInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif /* Can't transform with non-rigid transformation */ - Object2D o; + Object2D o; std::ostringstream out; Error redirectError{&out}; - o.transform(Matrix3::scaling(Vector2(3.0f))); + o.transform(Math::Matrix3::scaling(Math::Vector2{T(3.0)})); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation2D::transform(): the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation2DTest::translate() { +template void RigidMatrixTransformation2DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.translate({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.translateLocal({1.0f, -0.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } } -void RigidMatrixTransformation2DTest::rotate() { +template void RigidMatrixTransformation2DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})) - .rotate(Complex::rotation(7.0_degf)) - .rotate(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})) + .rotate(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotate(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)})); } { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})) - .rotateLocal(Complex::rotation(7.0_degf)) - .rotateLocal(10.0_degf); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})) + .rotateLocal(Math::Complex::rotation(Math::Deg{T(7.0)})) + .rotateLocal(Math::Deg{T(10.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } } -void RigidMatrixTransformation2DTest::reflect() { +template void RigidMatrixTransformation2DTest::reflect() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.reflect(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.reflect(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::reflection(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()})*Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); - o.reflectLocal(Vector2(-1.0f/Constants::sqrt2())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.reflectLocal(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::reflection(Math::Vector2{T(-1.0)/Math::Constants::sqrt2()})); } } -void RigidMatrixTransformation2DTest::normalizeRotation() { - Object2D o; - o.setTransformation(Matrix3::rotation(Deg(17.0f))); +template void RigidMatrixTransformation2DTest::normalizeRotation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::rotation(Math::Deg{T(17.0)})); } }}}} diff --git a/src/Magnum/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp b/src/Magnum/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp index 8d8e0744b..0a4228b48 100644 --- a/src/Magnum/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp +++ b/src/Magnum/SceneGraph/Test/RigidMatrixTransformation3DTest.cpp @@ -28,219 +28,263 @@ #include #include "Magnum/Math/Quaternion.h" -#include "Magnum/SceneGraph/RigidMatrixTransformation3D.h" +#include "Magnum/SceneGraph/Object.hpp" +#include "Magnum/SceneGraph/RigidMatrixTransformation3D.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object3D; -typedef Scene Scene3D; - struct RigidMatrixTransformation3DTest: TestSuite::Tester { explicit RigidMatrixTransformation3DTest(); - void fromMatrix(); - void fromMatrixInvalid(); - void toMatrix(); - void compose(); - void inverted(); - - void setTransformation(); - void setTransformationInvalid(); - void resetTransformation(); - void transform(); - void transformInvalid(); - void translate(); - void rotate(); - void reflect(); - void normalizeRotation(); + template void fromMatrix(); + template void fromMatrixInvalid(); + template void toMatrix(); + template void compose(); + template void inverted(); + + template void setTransformation(); + template void setTransformationInvalid(); + template void resetTransformation(); + template void transform(); + template void transformInvalid(); + template void translate(); + template void rotate(); + template void reflect(); + template void normalizeRotation(); }; RigidMatrixTransformation3DTest::RigidMatrixTransformation3DTest() { - addTests({&RigidMatrixTransformation3DTest::fromMatrix, - &RigidMatrixTransformation3DTest::fromMatrixInvalid, - &RigidMatrixTransformation3DTest::toMatrix, - &RigidMatrixTransformation3DTest::compose, - &RigidMatrixTransformation3DTest::inverted, - - &RigidMatrixTransformation3DTest::setTransformation, - &RigidMatrixTransformation3DTest::setTransformationInvalid, - &RigidMatrixTransformation3DTest::resetTransformation, - &RigidMatrixTransformation3DTest::transform, - &RigidMatrixTransformation3DTest::transformInvalid, - &RigidMatrixTransformation3DTest::translate, - &RigidMatrixTransformation3DTest::rotate, - &RigidMatrixTransformation3DTest::reflect, - &RigidMatrixTransformation3DTest::normalizeRotation}); + addTests({ + &RigidMatrixTransformation3DTest::fromMatrix, + &RigidMatrixTransformation3DTest::fromMatrix, + &RigidMatrixTransformation3DTest::fromMatrixInvalid, + &RigidMatrixTransformation3DTest::fromMatrixInvalid, + &RigidMatrixTransformation3DTest::toMatrix, + &RigidMatrixTransformation3DTest::toMatrix, + &RigidMatrixTransformation3DTest::compose, + &RigidMatrixTransformation3DTest::compose, + &RigidMatrixTransformation3DTest::inverted, + &RigidMatrixTransformation3DTest::inverted, + + &RigidMatrixTransformation3DTest::setTransformation, + &RigidMatrixTransformation3DTest::setTransformation, + &RigidMatrixTransformation3DTest::setTransformationInvalid, + &RigidMatrixTransformation3DTest::setTransformationInvalid, + &RigidMatrixTransformation3DTest::resetTransformation, + &RigidMatrixTransformation3DTest::resetTransformation, + &RigidMatrixTransformation3DTest::transform, + &RigidMatrixTransformation3DTest::transform, + &RigidMatrixTransformation3DTest::transformInvalid, + &RigidMatrixTransformation3DTest::transformInvalid, + &RigidMatrixTransformation3DTest::translate, + &RigidMatrixTransformation3DTest::translate, + &RigidMatrixTransformation3DTest::rotate, + &RigidMatrixTransformation3DTest::rotate, + &RigidMatrixTransformation3DTest::reflect, + &RigidMatrixTransformation3DTest::reflect, + &RigidMatrixTransformation3DTest::normalizeRotation, + &RigidMatrixTransformation3DTest::normalizeRotation}); } using namespace Math::Literals; -void RigidMatrixTransformation3DTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object3D = Object>; +template using Scene3D = Scene>; + +template void RigidMatrixTransformation3DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void RigidMatrixTransformation3DTest::fromMatrixInvalid() { +template void RigidMatrixTransformation3DTest::fromMatrixInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream o; Error redirectError{&o}; - Implementation::Transformation::fromMatrix(Matrix4::scaling(Vector3(4.0f))); + Implementation::Transformation>::fromMatrix(Math::Matrix4::scaling(Math::Vector3(T(4.0)))); CORRADE_COMPARE(o.str(), "SceneGraph::RigidMatrixTransformation3D: the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation3DTest::toMatrix() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void RigidMatrixTransformation3DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(Math::Matrix4{m}), Math::Matrix4{m}); } -void RigidMatrixTransformation3DTest::compose() { - Matrix4 parent = Matrix4::rotationX(Deg(17.0f)); - Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void RigidMatrixTransformation3DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 parent = Math::Matrix4::rotationX(Math::Deg{T(17.0)}); + Math::Matrix4 child = Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void RigidMatrixTransformation3DTest::inverted() { - Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix4()); +template void RigidMatrixTransformation3DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(m)*m, Math::Matrix4{}); } -void RigidMatrixTransformation3DTest::setTransformation() { - Object3D o; +template void RigidMatrixTransformation3DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})); /* Scene cannot be transformed */ - Scene3D s; + Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix4::rotationX(Deg(17.0f))); + s.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix4()); } -void RigidMatrixTransformation3DTest::setTransformationInvalid() { +template void RigidMatrixTransformation3DTest::setTransformationInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif - Object3D o; + Object3D o; /* Can't transform with non-rigid transformation */ std::ostringstream out; Error redirectError{&out}; - o.setTransformation(Matrix4::scaling(Vector3(3.0f))); + o.setTransformation(Math::Matrix4::scaling(Math::Vector3(T(3.0)))); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation3D::setTransformation(): the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation3DTest::resetTransformation() { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); +template void RigidMatrixTransformation3DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix4()); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4()); } -void RigidMatrixTransformation3DTest::transform() { +template void RigidMatrixTransformation3DTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.transform(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.transformLocal(Matrix4::translation({1.0f, -0.3f, 2.3f})); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.transformLocal(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void RigidMatrixTransformation3DTest::transformInvalid() { +template void RigidMatrixTransformation3DTest::transformInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif /* Can't transform with non-rigid transformation */ - Object3D o; + Object3D o; std::ostringstream out; Error redirectError{&out}; - o.transform(Matrix4::scaling(Vector3(3.0f))); + o.transform(Math::Matrix4::scaling(Math::Vector3(T(3.0)))); CORRADE_COMPARE(out.str(), "SceneGraph::RigidMatrixTransformation3D::transform(): the matrix doesn't represent rigid transformation\n"); } -void RigidMatrixTransformation3DTest::translate() { +template void RigidMatrixTransformation3DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.translate({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.translateLocal({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } } -void RigidMatrixTransformation3DTest::rotate() { +template void RigidMatrixTransformation3DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})) - .rotateX(17.0_degf) - .rotateY(25.0_degf) - .rotateZ(-23.0_degf) - .rotate(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotate(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateX(Math::Deg{T(17.0)}) + .rotateY(Math::Deg{T(25.0)}) + .rotateZ(Math::Deg{T(-23.0)}) + .rotate(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotate(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::translation({1.0f, -0.3f, 2.3f})); + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); } { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})) - .rotateXLocal(17.0_degf) - .rotateYLocal(25.0_degf) - .rotateZLocal(-23.0_degf) - .rotateLocal(Quaternion::rotation(36.0_degf, Vector3{1.0f/Constants::sqrt3()})) - .rotateLocal(60.0_degf, Vector3{1.0f/Constants::sqrt3()}); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})) + .rotateXLocal(Math::Deg{T(17.0)}) + .rotateYLocal(Math::Deg{T(25.0)}) + .rotateZLocal(Math::Deg{T(-23.0)}) + .rotateLocal(Math::Quaternion::rotation(Math::Deg{T(36.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})) + .rotateLocal(Math::Deg{T(60.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(Deg(17.0f))* - Matrix4::rotationY(Deg(25.0f))* - Matrix4::rotationZ(Deg(-23.0f))* - Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})); } } -void RigidMatrixTransformation3DTest::reflect() { +template void RigidMatrixTransformation3DTest::reflect() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.reflect(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.reflect(Math::Vector3(T(-1.0)/Math::Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::reflection(Math::Vector3(T(-1.0)/Math::Constants::sqrt3()))*Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); - o.reflectLocal(Vector3(-1.0f/Constants::sqrt3())); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); + o.reflectLocal(Math::Vector3(T(-1.0)/Math::Constants::sqrt3())); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::reflection(Math::Vector3(T(-1.0)/Math::Constants::sqrt3()))); } } -void RigidMatrixTransformation3DTest::normalizeRotation() { - Object3D o; - o.setTransformation(Matrix4::rotationX(Deg(17.0f))); +template void RigidMatrixTransformation3DTest::normalizeRotation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{T(17.0)})); o.normalizeRotation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } }}}} diff --git a/src/Magnum/SceneGraph/Test/SceneTest.cpp b/src/Magnum/SceneGraph/Test/SceneTest.cpp index 1f99bb2de..32d978355 100644 --- a/src/Magnum/SceneGraph/Test/SceneTest.cpp +++ b/src/Magnum/SceneGraph/Test/SceneTest.cpp @@ -25,7 +25,8 @@ #include -#include "Magnum/SceneGraph/MatrixTransformation3D.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.hpp" +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { @@ -33,32 +34,39 @@ namespace Magnum { namespace SceneGraph { namespace Test { namespace { struct SceneTest: TestSuite::Tester { explicit SceneTest(); - void transformation(); - void parent(); + template void transformation(); + template void parent(); }; -typedef SceneGraph::Scene Scene3D; -typedef SceneGraph::Object Object3D; - SceneTest::SceneTest() { - addTests({&SceneTest::transformation, - &SceneTest::parent}); + addTests({ + &SceneTest::transformation, + &SceneTest::transformation, + &SceneTest::parent, + &SceneTest::parent}); } -void SceneTest::transformation() { - Scene3D scene; +template using Object3D = SceneGraph::Object>; +template using Scene3D = SceneGraph::Scene>; + +template void SceneTest::transformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); - Object3D* scenePointer = &scene; - scenePointer->setTransformation(Matrix4::translation({1.0f, 1.0f, 1.0f})); - CORRADE_COMPARE(scene.transformation(), Matrix4()); + Scene3D scene; + + Object3D* scenePointer = &scene; + scenePointer->setTransformation(Math::Matrix4::translation({T(1.0), T(1.0), T(1.0)})); + CORRADE_COMPARE(scene.transformation(), Math::Matrix4{}); } -void SceneTest::parent() { - Scene3D scene; +template void SceneTest::parent() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Scene3D scene; /* Scene parent cannot be changed */ - Object3D* scenePointer = &scene; - Object3D object; + Object3D* scenePointer = &scene; + Object3D object; scenePointer->setParent(&object); CORRADE_VERIFY(scene.parent() == nullptr); CORRADE_VERIFY(scene.children().isEmpty()); diff --git a/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp b/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp index 7e8c5e165..a0651780a 100644 --- a/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp +++ b/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation2DTest.cpp @@ -25,215 +25,250 @@ #include +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/TranslationRotationScalingTransformation2D.h" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object2D; -typedef Scene Scene2D; - struct TranslationRotationScalingTransformation2DTest: TestSuite::Tester { explicit TranslationRotationScalingTransformation2DTest(); - void fromMatrix(); - void toMatrix(); - void compose(); - void inverted(); + template void fromMatrix(); + template void toMatrix(); + template void compose(); + template void inverted(); - void defaults(); - void setTransformation(); - void setTransformationRotateALot(); - void resetTransformation(); + template void defaults(); + template void setTransformation(); + template void setTransformationRotateALot(); + template void resetTransformation(); - void translate(); - void rotate(); - void scale(); + template void translate(); + template void rotate(); + template void scale(); }; TranslationRotationScalingTransformation2DTest::TranslationRotationScalingTransformation2DTest() { - addTests({&TranslationRotationScalingTransformation2DTest::fromMatrix, - &TranslationRotationScalingTransformation2DTest::toMatrix, - &TranslationRotationScalingTransformation2DTest::compose, - &TranslationRotationScalingTransformation2DTest::inverted, - - &TranslationRotationScalingTransformation2DTest::defaults, - &TranslationRotationScalingTransformation2DTest::setTransformation, - &TranslationRotationScalingTransformation2DTest::setTransformationRotateALot, - &TranslationRotationScalingTransformation2DTest::resetTransformation, - - &TranslationRotationScalingTransformation2DTest::translate, - &TranslationRotationScalingTransformation2DTest::rotate, - &TranslationRotationScalingTransformation2DTest::scale}); + addTests({ + &TranslationRotationScalingTransformation2DTest::fromMatrix, + &TranslationRotationScalingTransformation2DTest::fromMatrix, + &TranslationRotationScalingTransformation2DTest::toMatrix, + &TranslationRotationScalingTransformation2DTest::toMatrix, + &TranslationRotationScalingTransformation2DTest::compose, + &TranslationRotationScalingTransformation2DTest::compose, + &TranslationRotationScalingTransformation2DTest::inverted, + &TranslationRotationScalingTransformation2DTest::inverted, + + &TranslationRotationScalingTransformation2DTest::defaults, + &TranslationRotationScalingTransformation2DTest::defaults, + &TranslationRotationScalingTransformation2DTest::setTransformation, + &TranslationRotationScalingTransformation2DTest::setTransformation, + &TranslationRotationScalingTransformation2DTest::setTransformationRotateALot, + &TranslationRotationScalingTransformation2DTest::setTransformationRotateALot, + &TranslationRotationScalingTransformation2DTest::resetTransformation, + &TranslationRotationScalingTransformation2DTest::resetTransformation, + + &TranslationRotationScalingTransformation2DTest::translate, + &TranslationRotationScalingTransformation2DTest::translate, + &TranslationRotationScalingTransformation2DTest::rotate, + &TranslationRotationScalingTransformation2DTest::rotate, + &TranslationRotationScalingTransformation2DTest::scale, + &TranslationRotationScalingTransformation2DTest::scale}); } using namespace Math::Literals; -void TranslationRotationScalingTransformation2DTest::fromMatrix() { - Matrix3 m = Matrix3::rotation(17.0_degf)*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object2D = Object>; +template using Scene2D = Scene>; + +template void TranslationRotationScalingTransformation2DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void TranslationRotationScalingTransformation2DTest::toMatrix() { - Matrix3 m = Matrix3::rotation(17.0_degf)*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void TranslationRotationScalingTransformation2DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(m), m); } -void TranslationRotationScalingTransformation2DTest::compose() { - Matrix3 parent = Matrix3::rotation(17.0_degf); - Matrix3 child = Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void TranslationRotationScalingTransformation2DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 parent = Math::Matrix3::rotation(Math::Deg{T(17.0)}); + Math::Matrix3 child = Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void TranslationRotationScalingTransformation2DTest::inverted() { - Matrix3 m = Matrix3::rotation(17.0_degf)*Matrix3::translation({1.0f, -0.3f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix3()); +template void TranslationRotationScalingTransformation2DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix3 m = Math::Matrix3::rotation(Math::Deg{T(17.0)})*Math::Matrix3::translation({T(1.0), T(-0.3)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(m)*m, Math::Matrix3{}); } -void TranslationRotationScalingTransformation2DTest::defaults() { - Object2D o; - CORRADE_COMPARE(o.translation(), Vector2{}); - CORRADE_COMPARE(o.rotation(), Complex{}); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3{}); +template void TranslationRotationScalingTransformation2DTest::defaults() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + CORRADE_COMPARE(o.translation(), Math::Vector2{}); + CORRADE_COMPARE(o.rotation(), Math::Complex{}); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3{}); } -void TranslationRotationScalingTransformation2DTest::setTransformation() { +template void TranslationRotationScalingTransformation2DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + /* Dirty after setting transformation */ - Object2D o; + Object2D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); o.setTransformation( - Matrix3::translation({7.0f, -1.0f})* - Matrix3::rotation(17.0_degf)* - Matrix3::scaling({1.5f, 0.5f})); + Math::Matrix3::translation({T(7.0), T(-1.0)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})* + Math::Matrix3::scaling({T(1.5), T(0.5)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.translation(), (Vector2{7.0f, -1.0f})); - CORRADE_COMPARE(o.rotation(), Complex::rotation(17.0_degf)); - CORRADE_COMPARE(o.scaling(), (Vector2{1.5f, 0.5f})); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(7.0), T(-1.0)})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(17.0)})); + CORRADE_COMPARE(o.scaling(), (Math::Vector2{T(1.5), T(0.5)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({7.0f, -1.0f})* - Matrix3::rotation(17.0_degf)* - Matrix3::scaling({1.5f, 0.5f})); + Math::Matrix3::translation({T(7.0), T(-1.0)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})* + Math::Matrix3::scaling({T(1.5), T(0.5)})); /* Scene cannot be transformed */ - Scene2D s; + Scene2D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix3::rotation(17.0_degf)); + s.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix3{}); } -void TranslationRotationScalingTransformation2DTest::setTransformationRotateALot() { - Object2D o; +template void TranslationRotationScalingTransformation2DTest::setTransformationRotateALot() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; o.setTransformation( - Matrix3::translation({7.0f, -1.0f})* - Matrix3::rotation(225.0_degf)* - Matrix3::scaling({1.5f, 0.5f})); - CORRADE_COMPARE(o.translation(), (Vector2{7.0f, -1.0f})); + Math::Matrix3::translation({T(7.0), T(-1.0)})* + Math::Matrix3::rotation(Math::Deg{T(225.0)})* + Math::Matrix3::scaling({T(1.5), T(0.5)})); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(7.0), T(-1.0)})); /* Rotation of more than 180° causes either the rotation matrix or scaling to contain negative signs, verify we get a proper matrix back again */ - CORRADE_COMPARE(o.rotation(), Complex::rotation(225.0_degf)); - CORRADE_COMPARE(o.scaling(), (Vector2{1.5f, 0.5f})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(225.0)})); + CORRADE_COMPARE(o.scaling(), (Math::Vector2{T(1.5), T(0.5)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({7.0f, -1.0f})* - Matrix3::rotation(225.0_degf)* - Matrix3::scaling({1.5f, 0.5f})); + Math::Matrix3::translation({T(7.0), T(-1.0)})* + Math::Matrix3::rotation(Math::Deg{T(225.0)})* + Math::Matrix3::scaling({T(1.5), T(0.5)})); } -void TranslationRotationScalingTransformation2DTest::resetTransformation() { - Object2D o; - o.rotate(17.0_degf); - CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); +template void TranslationRotationScalingTransformation2DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.rotate(Math::Deg{T(17.0)}); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix3{}); o.resetTransformation(); - CORRADE_COMPARE(o.translation(), Vector2{}); - CORRADE_COMPARE(o.rotation(), Complex{}); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(o.translation(), Math::Vector2{}); + CORRADE_COMPARE(o.rotation(), Math::Complex{}); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3{}); } -void TranslationRotationScalingTransformation2DTest::translate() { +template void TranslationRotationScalingTransformation2DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(17.0_degf)); - o.translate({1.0f, -0.3f}) - .translate({1.0f, 0.1f}); - CORRADE_COMPARE(o.translation(), (Vector2{2.0f, -0.2f})); - CORRADE_COMPARE(o.rotation(), Complex::rotation(17.0_degf)); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translate({T(1.0), T(-0.3)}) + .translate({T(1.0), T(0.1)}); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(2.0), T(-0.2)})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(17.0)})); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({1.0f, 0.1f})* - Matrix3::translation({1.0f, -0.3f})* - Matrix3::rotation(17.0_degf)); + Math::Matrix3::translation({T(1.0), T(0.1)})* + Math::Matrix3::translation({T(1.0), T(-0.3)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(17.0_degf)); - o.translateLocal({1.0f, -0.3f}) - .translateLocal({1.0f, 0.1f}); - CORRADE_COMPARE(o.translation(), (Vector2{2.0f, -0.2f})); - CORRADE_COMPARE(o.rotation(), Complex::rotation(17.0_degf)); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.translateLocal({T(1.0), T(-0.3)}) + .translateLocal({T(1.0), T(0.1)}); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(2.0), T(-0.2)})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(17.0)})); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({1.0f, -0.3f})* - Matrix3::translation({1.0f, 0.1f})* - Matrix3::rotation(17.0_degf)); + Math::Matrix3::translation({T(1.0), T(-0.3)})* + Math::Matrix3::translation({T(1.0), T(0.1)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})); } } -void TranslationRotationScalingTransformation2DTest::rotate() { +template void TranslationRotationScalingTransformation2DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})); - o.rotate(Complex::rotation(17.0_degf)) - .rotate(-96.0_degf); - CORRADE_COMPARE(o.translation(), (Vector2{1.0f, -0.3f})); - CORRADE_COMPARE(o.rotation(), Complex::rotation(-79.0_degf)); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})); + o.rotate(Math::Complex::rotation(Math::Deg{T(17.0)})) + .rotate(Math::Deg{T(-96.0)}); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(-79.0)})); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({1.0f, -0.3f})* - Matrix3::rotation(-96.0_degf)* - Matrix3::rotation(17.0_degf)); + Math::Matrix3::translation({T(1.0), T(-0.3)})* + Math::Matrix3::rotation(Math::Deg{T(-96.0)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})); } { - Object2D o; - o.setTransformation(Matrix3::translation({1.0f, -0.3f})); - o.rotateLocal(Complex::rotation(17.0_degf)) - .rotateLocal(-96.0_degf); - CORRADE_COMPARE(o.translation(), (Vector2{1.0f, -0.3f})); - CORRADE_COMPARE(o.rotation(), Complex::rotation(-79.0_degf)); - CORRADE_COMPARE(o.scaling(), Vector2{1.0f}); + Object2D o; + o.setTransformation(Math::Matrix3::translation({T(1.0), T(-0.3)})); + o.rotateLocal(Math::Complex::rotation(Math::Deg{T(17.0)})) + .rotateLocal(Math::Deg{T(-96.0)}); + CORRADE_COMPARE(o.translation(), (Math::Vector2{T(1.0), T(-0.3)})); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(-79.0)})); + CORRADE_COMPARE(o.scaling(), Math::Vector2{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::translation({1.0f, -0.3f})* - Matrix3::rotation(17.0_degf)* - Matrix3::rotation(-96.0_degf)); + Math::Matrix3::translation({T(1.0), T(-0.3)})* + Math::Matrix3::rotation(Math::Deg{T(17.0)})* + Math::Matrix3::rotation(Math::Deg{T(-96.0)})); } } -void TranslationRotationScalingTransformation2DTest::scale() { +template void TranslationRotationScalingTransformation2DTest::scale() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object2D o; - o.setTransformation(Matrix3::rotation(17.0_degf)); - o.scale({1.0f, -0.3f}) - .scale({0.5f, 1.1f}); - CORRADE_COMPARE(o.translation(), Vector2{}); - CORRADE_COMPARE(o.rotation(), Complex::rotation(17.0_degf)); - CORRADE_COMPARE(o.scaling(), (Vector2{0.5f, -0.33f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.scale({T(1.0), T(-0.3)}) + .scale({T(0.5), T(1.1)}); + CORRADE_COMPARE(o.translation(), Math::Vector2{}); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(17.0)})); + CORRADE_COMPARE(o.scaling(), (Math::Vector2{T(0.5), T(-0.33)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::rotation(17.0_degf)* - Matrix3::scaling({0.5f, 1.1f})* - Matrix3::scaling({1.0f, -0.3f})); + Math::Matrix3::rotation(Math::Deg{T(17.0)})* + Math::Matrix3::scaling({T(0.5), T(1.1)})* + Math::Matrix3::scaling({T(1.0), T(-0.3)})); } { - Object2D o; - o.setTransformation(Matrix3::rotation(17.0_degf)); - o.scaleLocal({1.0f, -0.3f}) - .scaleLocal({0.5f, 1.1f}); - CORRADE_COMPARE(o.translation(), Vector2{}); - CORRADE_COMPARE(o.rotation(), Complex::rotation(17.0_degf)); - CORRADE_COMPARE(o.scaling(), (Vector2{0.5f, -0.33f})); + Object2D o; + o.setTransformation(Math::Matrix3::rotation(Math::Deg{T(17.0)})); + o.scaleLocal({T(1.0), T(-0.3)}) + .scaleLocal({T(0.5), T(1.1)}); + CORRADE_COMPARE(o.translation(), Math::Vector2{}); + CORRADE_COMPARE(o.rotation(), Math::Complex::rotation(Math::Deg{T(17.0)})); + CORRADE_COMPARE(o.scaling(), (Math::Vector2{T(0.5), T(-0.33)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix3::rotation(17.0_degf)* - Matrix3::scaling({1.0f, -0.3f})* - Matrix3::scaling({0.5f, 1.1f})); + Math::Matrix3::rotation(Math::Deg{T(17.0)})* + Math::Matrix3::scaling({T(1.0), T(-0.3)})* + Math::Matrix3::scaling({T(0.5), T(1.1)})); } } diff --git a/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp b/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp index db0438ea0..986c043b3 100644 --- a/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp +++ b/src/Magnum/SceneGraph/Test/TranslationRotationScalingTransformation3DTest.cpp @@ -25,231 +25,266 @@ #include +#include "Magnum/SceneGraph/Object.hpp" #include "Magnum/SceneGraph/TranslationRotationScalingTransformation3D.h" #include "Magnum/SceneGraph/Scene.h" namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object3D; -typedef Scene Scene3D; - struct TranslationRotationScalingTransformation3DTest: TestSuite::Tester { explicit TranslationRotationScalingTransformation3DTest(); - void fromMatrix(); - void toMatrix(); - void compose(); - void inverted(); + template void fromMatrix(); + template void toMatrix(); + template void compose(); + template void inverted(); - void defaults(); - void setTransformation(); - void setTransformationRotateALot(); - void resetTransformation(); + template void defaults(); + template void setTransformation(); + template void setTransformationRotateALot(); + template void resetTransformation(); - void translate(); - void rotate(); - void scale(); + template void translate(); + template void rotate(); + template void scale(); }; TranslationRotationScalingTransformation3DTest::TranslationRotationScalingTransformation3DTest() { - addTests({&TranslationRotationScalingTransformation3DTest::fromMatrix, - &TranslationRotationScalingTransformation3DTest::toMatrix, - &TranslationRotationScalingTransformation3DTest::compose, - &TranslationRotationScalingTransformation3DTest::inverted, - - &TranslationRotationScalingTransformation3DTest::defaults, - &TranslationRotationScalingTransformation3DTest::setTransformation, - &TranslationRotationScalingTransformation3DTest::setTransformationRotateALot, - &TranslationRotationScalingTransformation3DTest::resetTransformation, - - &TranslationRotationScalingTransformation3DTest::translate, - &TranslationRotationScalingTransformation3DTest::rotate, - &TranslationRotationScalingTransformation3DTest::scale}); + addTests({ + &TranslationRotationScalingTransformation3DTest::fromMatrix, + &TranslationRotationScalingTransformation3DTest::fromMatrix, + &TranslationRotationScalingTransformation3DTest::toMatrix, + &TranslationRotationScalingTransformation3DTest::toMatrix, + &TranslationRotationScalingTransformation3DTest::compose, + &TranslationRotationScalingTransformation3DTest::compose, + &TranslationRotationScalingTransformation3DTest::inverted, + &TranslationRotationScalingTransformation3DTest::inverted, + + &TranslationRotationScalingTransformation3DTest::defaults, + &TranslationRotationScalingTransformation3DTest::defaults, + &TranslationRotationScalingTransformation3DTest::setTransformation, + &TranslationRotationScalingTransformation3DTest::setTransformation, + &TranslationRotationScalingTransformation3DTest::setTransformationRotateALot, + &TranslationRotationScalingTransformation3DTest::setTransformationRotateALot, + &TranslationRotationScalingTransformation3DTest::resetTransformation, + &TranslationRotationScalingTransformation3DTest::resetTransformation, + + &TranslationRotationScalingTransformation3DTest::translate, + &TranslationRotationScalingTransformation3DTest::translate, + &TranslationRotationScalingTransformation3DTest::rotate, + &TranslationRotationScalingTransformation3DTest::rotate, + &TranslationRotationScalingTransformation3DTest::scale, + &TranslationRotationScalingTransformation3DTest::scale}); } using namespace Math::Literals; -void TranslationRotationScalingTransformation3DTest::fromMatrix() { - Matrix4 m = Matrix4::rotationX(17.0_degf)*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(m), m); +template using Object3D = Object>; +template using Scene3D = Scene>; + +template void TranslationRotationScalingTransformation3DTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(m), m); } -void TranslationRotationScalingTransformation3DTest::toMatrix() { - Matrix4 m = Matrix4::rotationX(17.0_degf)*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(m), m); +template void TranslationRotationScalingTransformation3DTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(m), m); } -void TranslationRotationScalingTransformation3DTest::compose() { - Matrix4 parent = Matrix4::rotationX(17.0_degf); - Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), parent*child); +template void TranslationRotationScalingTransformation3DTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 parent = Math::Matrix4::rotationX(Math::Deg{T(17.0)}); + Math::Matrix4 child = Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)}); + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), parent*child); } -void TranslationRotationScalingTransformation3DTest::inverted() { - Matrix4 m = Matrix4::rotationX(17.0_degf)*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); - CORRADE_COMPARE(Implementation::Transformation::inverted(m)*m, Matrix4()); +template void TranslationRotationScalingTransformation3DTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Math::Matrix4 m = Math::Matrix4::rotationX(Math::Deg{T(17.0)})*Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})*Math::Matrix4::scaling({T(2.0), T(1.4), T(-2.1)}); + CORRADE_COMPARE(Implementation::Transformation>::inverted(Math::Matrix4{m})*Math::Matrix4{m}, Math::Matrix4{}); } -void TranslationRotationScalingTransformation3DTest::defaults() { - Object3D o; - CORRADE_COMPARE(o.translation(), Vector3{}); - CORRADE_COMPARE(o.rotation(), Quaternion{}); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4{}); +template void TranslationRotationScalingTransformation3DTest::defaults() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + CORRADE_COMPARE(o.translation(), Math::Vector3{}); + CORRADE_COMPARE(o.rotation(), Math::Quaternion{}); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4{}); } -void TranslationRotationScalingTransformation3DTest::setTransformation() { +template void TranslationRotationScalingTransformation3DTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + /* Dirty after setting transformation */ - Object3D o; + Object3D o; o.setClean(); CORRADE_VERIFY(!o.isDirty()); o.setTransformation( - Matrix4::translation({7.0f, -1.0f, 2.2f})* - Matrix4::rotationX(17.0_degf)* - Matrix4::scaling({1.5f, 0.5f, 3.0f})); + Math::Matrix4::translation({T(7.0), T(-1.0), T(2.2)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::scaling({T(1.5), T(0.5), T(3.0)})); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.translation(), (Vector3{7.0f, -1.0f, 2.2f})); - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), (Vector3{1.5f, 0.5f, 3.0f})); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(7.0), T(-1.0), T(2.2)})); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), (Math::Vector3{T(1.5), T(0.5), T(3.0)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({7.0f, -1.0f, 2.2f})* - Matrix4::rotationX(17.0_degf)* - Matrix4::scaling({1.5f, 0.5f, 3.0f})); + Math::Matrix4::translation({T(7.0), T(-1.0), T(2.2)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::scaling({T(1.5), T(0.5), T(3.0)})); /* Scene cannot be transformed */ - Scene3D s; + Scene3D s; s.setClean(); CORRADE_VERIFY(!s.isDirty()); - s.setTransformation(Matrix4::rotationX(17.0_degf)); + s.setTransformation(Math::Matrix4::rotationX(Math::Deg{17.0})); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix4{}); } -void TranslationRotationScalingTransformation3DTest::setTransformationRotateALot() { - Object3D o; +template void TranslationRotationScalingTransformation3DTest::setTransformationRotateALot() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; o.setTransformation( - Matrix4::translation({7.0f, -1.0f, 2.2f})* - Matrix4::rotationX(225.0_degf)* - Matrix4::scaling({1.5f, 0.5f, 3.0f})); - CORRADE_COMPARE(o.translation(), (Vector3{7.0f, -1.0f, 2.2f})); + Math::Matrix4::translation({T(7.0), T(-1.0), T(2.2)})* + Math::Matrix4::rotationX(Math::Deg{T(225.0)})* + Math::Matrix4::scaling({T(1.5), T(0.5), T(3.0)})); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(7.0), T(-1.0), T(2.2)})); /* Rotation of more than 180° causes either the rotation matrix or scaling to contain negative signs, verify we get a proper matrix back again */ - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(225.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), (Vector3{1.5f, 0.5f, 3.0f})); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(225.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), (Math::Vector3{T(1.5), T(0.5), T(3.0)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({7.0f, -1.0f, 2.2f})* - Matrix4::rotationX(225.0_degf)* - Matrix4::scaling({1.5f, 0.5f, 3.0f})); + Math::Matrix4::translation({T(7.0), T(-1.0), T(2.2)})* + Math::Matrix4::rotationX(Math::Deg{T(225.0)})* + Math::Matrix4::scaling({T(1.5), T(0.5), T(3.0)})); } -void TranslationRotationScalingTransformation3DTest::resetTransformation() { - Object3D o; - o.rotateX(17.0_degf); - CORRADE_VERIFY(o.transformationMatrix() != Matrix4()); +template void TranslationRotationScalingTransformation3DTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object3D o; + o.rotateX(Math::Deg{17.0}); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix4{}); o.resetTransformation(); - CORRADE_COMPARE(o.translation(), Vector3{}); - CORRADE_COMPARE(o.rotation(), Quaternion{}); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix4()); + CORRADE_COMPARE(o.translation(), Math::Vector3{}); + CORRADE_COMPARE(o.rotation(), Math::Quaternion{}); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix4()); } -void TranslationRotationScalingTransformation3DTest::translate() { +template void TranslationRotationScalingTransformation3DTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(17.0_degf)); - o.translate({1.0f, -0.3f, 2.3f}) - .translate({1.0f, 0.1f, 0.2f}); - CORRADE_COMPARE(o.translation(), (Vector3{2.0f, -0.2f, 2.5f})); - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{17.0})); + o.translate({T(1.0), T(-0.3), T(2.3)}) + .translate({T(1.0), T(0.1), T(0.2)}); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(2.0), T(-0.2), T(2.5)})); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, 0.1f, 0.2f})* - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(17.0_degf)); + Math::Matrix4::translation({T(1.0), T(0.1), T(0.2)})* + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(17.0_degf)); - o.translateLocal({1.0f, -0.3f, 2.3f}) - .translateLocal({1.0f, 0.1f, 0.2f}); - CORRADE_COMPARE(o.translation(), (Vector3{2.0f, -0.2f, 2.5f})); - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{17.0})); + o.translateLocal({T(1.0), T(-0.3), T(2.3)}) + .translateLocal({T(1.0), T(0.1), T(0.2)}); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(2.0), T(-0.2), T(2.5)})); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::translation({1.0f, 0.1f, 0.2f})* - Matrix4::rotationX(17.0_degf)); + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::translation({T(1.0), T(0.1), T(0.2)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } } -void TranslationRotationScalingTransformation3DTest::rotate() { +template void TranslationRotationScalingTransformation3DTest::rotate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); - o.rotateX(17.0_degf) - .rotateY(25.0_degf) - .rotateZ(-23.0_degf) - .rotate(96.0_degf, Vector3{1.0f/Constants::sqrt3()}); - CORRADE_COMPARE(o.translation(), (Vector3{1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + o.rotateX(Math::Deg{T(17.0)}) + .rotateY(Math::Deg{T(25.0)}) + .rotateZ(Math::Deg{T(-23.0)}) + .rotate(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(1.0), T(-0.3), T(2.3)})); CORRADE_COMPARE(o.rotation(), - Quaternion::rotation(96.0_degf, Vector3{1.0f/Constants::sqrt3()})* - Quaternion::rotation(-23.0_degf, Vector3::zAxis())* - Quaternion::rotation(25.0_degf, Vector3::yAxis())* - Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); + Math::Quaternion::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})* + Math::Quaternion::rotation(Math::Deg{T(-23.0)}, Math::Vector3::zAxis())* + Math::Quaternion::rotation(Math::Deg{T(25.0)}, Math::Vector3::yAxis())* + Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotation(96.0_degf, Vector3{1.0f/Constants::sqrt3()})* - Matrix4::rotationZ(-23.0_degf)* - Matrix4::rotationY(25.0_degf)* - Matrix4::rotationX(17.0_degf)); + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotation(Math::Deg{T(96.0)},Math::Vector3{T(1.0)/Math::Constants::sqrt3()})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})); } { - Object3D o; - o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); - o.rotateXLocal(17.0_degf) - .rotateYLocal(25.0_degf) - .rotateZLocal(-23.0_degf) - .rotateLocal(96.0_degf, Vector3{1.0f/Constants::sqrt3()}); - CORRADE_COMPARE(o.translation(), (Vector3{1.0f, -0.3f, 2.3f})); + Object3D o; + o.setTransformation(Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})); + o.rotateXLocal(Math::Deg{T(17.0)}) + .rotateYLocal(Math::Deg{T(25.0)}) + .rotateZLocal(Math::Deg{T(-23.0)}) + .rotateLocal(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()}); + CORRADE_COMPARE(o.translation(), (Math::Vector3{T(1.0), T(-0.3), T(2.3)})); CORRADE_COMPARE(o.rotation(), - Quaternion::rotation(17.0_degf, Vector3::xAxis())* - Quaternion::rotation(25.0_degf, Vector3::yAxis())* - Quaternion::rotation(-23.0_degf, Vector3::zAxis())* - Quaternion::rotation(96.0_degf, Vector3(1.0f/Constants::sqrt3()))); - CORRADE_COMPARE(o.scaling(), Vector3{1.0f}); + Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())* + Math::Quaternion::rotation(Math::Deg{T(25.0)}, Math::Vector3::yAxis())* + Math::Quaternion::rotation(Math::Deg{T(-23.0)}, Math::Vector3::zAxis())* + Math::Quaternion::rotation(Math::Deg{T(96.0)}, Math::Vector3(T(1.0)/Math::Constants::sqrt3()))); + CORRADE_COMPARE(o.scaling(), Math::Vector3{T(1.0)}); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::translation({1.0f, -0.3f, 2.3f})* - Matrix4::rotationX(17.0_degf)* - Matrix4::rotationY(25.0_degf)* - Matrix4::rotationZ(-23.0_degf)* - Matrix4::rotation(96.0_degf, Vector3{1.0f/Constants::sqrt3()})); + Math::Matrix4::translation({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::rotationY(Math::Deg{T(25.0)})* + Math::Matrix4::rotationZ(Math::Deg{T(-23.0)})* + Math::Matrix4::rotation(Math::Deg{T(96.0)}, Math::Vector3{T(1.0)/Math::Constants::sqrt3()})); } } -void TranslationRotationScalingTransformation3DTest::scale() { +template void TranslationRotationScalingTransformation3DTest::scale() { + setTestCaseTemplateName(Math::TypeTraits::name()); + { - Object3D o; - o.setTransformation(Matrix4::rotationX(17.0_degf)); - o.scale({1.0f, -0.3f, 2.3f}) - .scale({0.5f, 1.1f, 2.0f}); - CORRADE_COMPARE(o.translation(), Vector3{}); - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), (Vector3{0.5f, -0.33f, 4.6f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{17.0})); + o.scale({T(1.0), T(-0.3), T(2.3)}) + .scale({T(0.5), T(1.1), T(2.0)}); + CORRADE_COMPARE(o.translation(), Math::Vector3{}); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), (Math::Vector3{T(0.5), T(-0.33), T(4.6)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotationX(17.0_degf)* - Matrix4::scaling({0.5f, 1.1f, 2.0f})* - Matrix4::scaling({1.0f, -0.3f, 2.3f})); + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::scaling({T(0.5), T(1.1), T(2.0)})* + Math::Matrix4::scaling({T(1.0), T(-0.3), T(2.3)})); } { - Object3D o; - o.setTransformation(Matrix4::rotationX(17.0_degf)); - o.scaleLocal({1.0f, -0.3f, 2.3f}) - .scaleLocal({0.5f, 1.1f, 2.0f}); - CORRADE_COMPARE(o.translation(), Vector3{}); - CORRADE_COMPARE(o.rotation(), Quaternion::rotation(17.0_degf, Vector3::xAxis())); - CORRADE_COMPARE(o.scaling(), (Vector3{0.5f, -0.33f, 4.6f})); + Object3D o; + o.setTransformation(Math::Matrix4::rotationX(Math::Deg{17.0})); + o.scaleLocal({T(1.0), T(-0.3), T(2.3)}) + .scaleLocal({T(0.5), T(1.1), T(2.0)}); + CORRADE_COMPARE(o.translation(), Math::Vector3{}); + CORRADE_COMPARE(o.rotation(), Math::Quaternion::rotation(Math::Deg{T(17.0)}, Math::Vector3::xAxis())); + CORRADE_COMPARE(o.scaling(), (Math::Vector3{T(0.5), T(-0.33), T(4.6)})); CORRADE_COMPARE(o.transformationMatrix(), - Matrix4::rotationX(17.0_degf)* - Matrix4::scaling({1.0f, -0.3f, 2.3f})* - Matrix4::scaling({0.5f, 1.1f, 2.0f})); + Math::Matrix4::rotationX(Math::Deg{T(17.0)})* + Math::Matrix4::scaling({T(1.0), T(-0.3), T(2.3)})* + Math::Matrix4::scaling({T(0.5), T(1.1), T(2.0)})); } } diff --git a/src/Magnum/SceneGraph/Test/TranslationTransformationTest.cpp b/src/Magnum/SceneGraph/Test/TranslationTransformationTest.cpp index 0350d29c0..f6dbea805 100644 --- a/src/Magnum/SceneGraph/Test/TranslationTransformationTest.cpp +++ b/src/Magnum/SceneGraph/Test/TranslationTransformationTest.cpp @@ -33,114 +33,145 @@ namespace Magnum { namespace SceneGraph { namespace Test { namespace { -typedef Object Object2D; -typedef Scene Scene2D; - struct TranslationTransformationTest: TestSuite::Tester { explicit TranslationTransformationTest(); - void fromMatrix(); - void fromMatrixInvalid(); - void toMatrix(); - void compose(); - void inverted(); + template void fromMatrix(); + template void fromMatrixInvalid(); + template void toMatrix(); + template void compose(); + template void inverted(); - void setTransformation(); - void resetTransformation(); - void transform(); - void translate(); + template void setTransformation(); + template void resetTransformation(); + template void transform(); + template void translate(); - void integral(); + template void integral(); }; TranslationTransformationTest::TranslationTransformationTest() { - addTests({&TranslationTransformationTest::fromMatrix, - &TranslationTransformationTest::fromMatrixInvalid, - &TranslationTransformationTest::toMatrix, - &TranslationTransformationTest::compose, - &TranslationTransformationTest::inverted, - - &TranslationTransformationTest::setTransformation, - &TranslationTransformationTest::resetTransformation, - &TranslationTransformationTest::transform, - &TranslationTransformationTest::translate, - - &TranslationTransformationTest::integral}); + addTests({ + &TranslationTransformationTest::fromMatrix, + &TranslationTransformationTest::fromMatrix, + &TranslationTransformationTest::fromMatrixInvalid, + &TranslationTransformationTest::fromMatrixInvalid, + &TranslationTransformationTest::toMatrix, + &TranslationTransformationTest::toMatrix, + &TranslationTransformationTest::compose, + &TranslationTransformationTest::compose, + &TranslationTransformationTest::inverted, + &TranslationTransformationTest::inverted, + + &TranslationTransformationTest::setTransformation, + &TranslationTransformationTest::setTransformation, + &TranslationTransformationTest::resetTransformation, + &TranslationTransformationTest::resetTransformation, + &TranslationTransformationTest::transform, + &TranslationTransformationTest::transform, + &TranslationTransformationTest::translate, + &TranslationTransformationTest::translate, + + &TranslationTransformationTest::integral, + &TranslationTransformationTest::integral}); } -void TranslationTransformationTest::fromMatrix() { - const Vector2 v(1.0f, -0.3f); - CORRADE_COMPARE(Implementation::Transformation::fromMatrix(Matrix3::translation(v)), v); +template using Object2D = Object>; +template using Scene2D = Scene>; + +template void TranslationTransformationTest::fromMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + const Math::Vector2 v{T(1.0), T(-0.3)}; + CORRADE_COMPARE(Implementation::Transformation>::fromMatrix(Math::Matrix3::translation(v)), v); } -void TranslationTransformationTest::fromMatrixInvalid() { +template void TranslationTransformationTest::fromMatrixInvalid() { + setTestCaseTemplateName(Math::TypeTraits::name()); + #ifdef CORRADE_NO_ASSERT CORRADE_SKIP("CORRADE_NO_ASSERT defined, can't test assertions"); #endif std::ostringstream o; Error redirectError{&o}; - Implementation::Transformation::fromMatrix(Matrix3::scaling(Vector2(4.0f))); + Implementation::Transformation>::fromMatrix(Math::Matrix3::scaling(Math::Vector2{T(4.0)})); CORRADE_COMPARE(o.str(), "SceneGraph::TranslationTransformation: the matrix doesn't represent pure translation\n"); } -void TranslationTransformationTest::toMatrix() { - const Vector2 v(1.0f, -0.3f); - CORRADE_COMPARE(Implementation::Transformation::toMatrix(v), Matrix3::translation(v)); +template void TranslationTransformationTest::toMatrix() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + const Math::Vector2 v{T(1.0), T(-0.3)}; + CORRADE_COMPARE(Implementation::Transformation>::toMatrix(v), Math::Matrix3::translation(v)); } -void TranslationTransformationTest::compose() { - const Vector2 parent(-0.5f, 2.0f); - const Vector2 child(1.0f, -0.3f); - CORRADE_COMPARE(Implementation::Transformation::compose(parent, child), Vector2(0.5f, 1.7f)); +template void TranslationTransformationTest::compose() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + const Math::Vector2 parent{T(-0.5), T(2.0)}; + const Math::Vector2 child{T(1.0), T(-0.3)}; + CORRADE_COMPARE(Implementation::Transformation>::compose(parent, child), (Math::Vector2{T(0.5), T(1.7)})); } -void TranslationTransformationTest::inverted() { - const Vector2 v(1.0f, -0.3f); - CORRADE_COMPARE(Implementation::Transformation::inverted(v), Vector2(-1.0f, 0.3f)); +template void TranslationTransformationTest::inverted() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + const Math::Vector2 v{T(1.0), T(-0.3)}; + CORRADE_COMPARE(Implementation::Transformation>::inverted(v), (Math::Vector2{T(-1.0), T(0.3)})); } -void TranslationTransformationTest::setTransformation() { - Object2D o; +template void TranslationTransformationTest::setTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; /* Dirty after setting transformation */ o.setClean(); CORRADE_VERIFY(!o.isDirty()); - o.setTransformation({1.0f, -0.3f}); + o.setTransformation({T(1.0), T(-0.3)}); CORRADE_VERIFY(o.isDirty()); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})); /* Scene cannot be transformed */ - Scene2D s; + Scene2D s; s.setClean(); - s.setTransformation({1.0f, -0.3f}); + s.setTransformation({T(1.0), T(-0.3)}); CORRADE_VERIFY(!s.isDirty()); - CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(s.transformationMatrix(), Math::Matrix3{}); } -void TranslationTransformationTest::resetTransformation() { - Object2D o; - o.setTransformation({1.0f, -0.3f}); - CORRADE_VERIFY(o.transformationMatrix() != Matrix3()); +template void TranslationTransformationTest::resetTransformation() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation({T(1.0), T(-0.3)}); + CORRADE_VERIFY(o.transformationMatrix() != Math::Matrix3{}); o.resetTransformation(); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3()); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3{}); } -void TranslationTransformationTest::transform() { - Object2D o; - o.setTransformation({1.0f, -0.3f}) - .transform({-0.5f, 2.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({0.5f, 1.7f})); +template void TranslationTransformationTest::transform() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation({T(1.0), T(-0.3)}) + .transform({T(-0.5), T(2.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(0.5), T(1.7)})); } -void TranslationTransformationTest::translate() { - Object2D o; - o.setTransformation({1.0f, -0.3f}) - .translate({-0.5f, 2.0f}); - CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::translation({-0.5f, 2.0f})); +template void TranslationTransformationTest::translate() { + setTestCaseTemplateName(Math::TypeTraits::name()); + + Object2D o; + o.setTransformation({T(1.0), T(-0.3)}) + .translate({T(-0.5), T(2.0)}); + CORRADE_COMPARE(o.transformationMatrix(), Math::Matrix3::translation({T(1.0), T(-0.3)})*Math::Matrix3::translation({T(-0.5), T(2.0)})); } -void TranslationTransformationTest::integral() { +template void TranslationTransformationTest::integral() { + setTestCaseTemplateName(Math::TypeTraits::name()); + typedef Object> Object2Di; Object2Di o;