From 389ed07806737801c72487e3a238355a5305b928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 20 Jan 2013 23:56:50 +0100 Subject: [PATCH] SceneGraph: initial per-transformation unit tests. --- src/SceneGraph/Test/CMakeLists.txt | 6 +- .../EuclideanMatrixTransformation2DTest.cpp | 63 +++++++++++++++++++ .../EuclideanMatrixTransformation3DTest.cpp | 63 +++++++++++++++++++ .../Test/MatrixTransformation2DTest.cpp | 63 +++++++++++++++++++ .../Test/MatrixTransformation3DTest.cpp | 63 +++++++++++++++++++ 5 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp create mode 100644 src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp create mode 100644 src/SceneGraph/Test/MatrixTransformation2DTest.cpp create mode 100644 src/SceneGraph/Test/MatrixTransformation3DTest.cpp diff --git a/src/SceneGraph/Test/CMakeLists.txt b/src/SceneGraph/Test/CMakeLists.txt index aa0efa333..86f50974f 100644 --- a/src/SceneGraph/Test/CMakeLists.txt +++ b/src/SceneGraph/Test/CMakeLists.txt @@ -1,4 +1,8 @@ corrade_add_test(SceneGraphAnimableTest AnimableTest.cpp LIBRARIES MagnumSceneGraph) -corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) corrade_add_test(SceneGraphCameraTest CameraTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphEuclideanMatrixTr___2DTest EuclideanMatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphEuclideanMatrixTr___3DTest EuclideanMatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphMatrixTransformation2DTest MatrixTransformation2DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphMatrixTransformation3DTest MatrixTransformation3DTest.cpp LIBRARIES MagnumSceneGraph) +corrade_add_test(SceneGraphObjectTest ObjectTest.cpp LIBRARIES MagnumSceneGraphTestLib) corrade_add_test(SceneGraphSceneTest SceneTest.cpp LIBRARIES MagnumSceneGraph) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp new file mode 100644 index 000000000..86cc2e87f --- /dev/null +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/EuclideanMatrixTransformation2D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester { + public: + explicit EuclideanMatrixTransformation2DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() { + addTests(&EuclideanMatrixTransformation2DTest::fromMatrix, + &EuclideanMatrixTransformation2DTest::toMatrix, + &EuclideanMatrixTransformation2DTest::compose, + &EuclideanMatrixTransformation2DTest::inverted); +} + +void EuclideanMatrixTransformation2DTest::fromMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m); +} + +void EuclideanMatrixTransformation2DTest::toMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m); +} + +void EuclideanMatrixTransformation2DTest::compose() { + Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 child = Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child); +} + +void EuclideanMatrixTransformation2DTest::inverted() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp new file mode 100644 index 000000000..7c396d6a2 --- /dev/null +++ b/src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/EuclideanMatrixTransformation3D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester { + public: + explicit EuclideanMatrixTransformation3DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() { + addTests(&EuclideanMatrixTransformation3DTest::fromMatrix, + &EuclideanMatrixTransformation3DTest::toMatrix, + &EuclideanMatrixTransformation3DTest::compose, + &EuclideanMatrixTransformation3DTest::inverted); +} + +void EuclideanMatrixTransformation3DTest::fromMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m); +} + +void EuclideanMatrixTransformation3DTest::toMatrix() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m); +} + +void EuclideanMatrixTransformation3DTest::compose() { + Matrix4 parent = Matrix4::rotationX(deg(17.0f)); + Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child); +} + +void EuclideanMatrixTransformation3DTest::inverted() { + Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); + CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation3DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation2DTest.cpp b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp new file mode 100644 index 000000000..e8ea6aa2d --- /dev/null +++ b/src/SceneGraph/Test/MatrixTransformation2DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/MatrixTransformation2D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class MatrixTransformation2DTest: public Corrade::TestSuite::Tester { + public: + explicit MatrixTransformation2DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +MatrixTransformation2DTest::MatrixTransformation2DTest() { + addTests(&MatrixTransformation2DTest::fromMatrix, + &MatrixTransformation2DTest::toMatrix, + &MatrixTransformation2DTest::compose, + &MatrixTransformation2DTest::inverted); +} + +void MatrixTransformation2DTest::fromMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::fromMatrix(m), m); +} + +void MatrixTransformation2DTest::toMatrix() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::toMatrix(m), m); +} + +void MatrixTransformation2DTest::compose() { + Matrix3 parent = Matrix3::rotation(deg(17.0f)); + Matrix3 child = Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::compose(parent, child), parent*child); +} + +void MatrixTransformation2DTest::inverted() { + Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); + CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation2DTest) diff --git a/src/SceneGraph/Test/MatrixTransformation3DTest.cpp b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp new file mode 100644 index 000000000..0baf7850c --- /dev/null +++ b/src/SceneGraph/Test/MatrixTransformation3DTest.cpp @@ -0,0 +1,63 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +#include "Math/Constants.h" +#include "SceneGraph/MatrixTransformation3D.h" + +namespace Magnum { namespace SceneGraph { namespace Test { + +class MatrixTransformation3DTest: public Corrade::TestSuite::Tester { + public: + explicit MatrixTransformation3DTest(); + + void fromMatrix(); + void toMatrix(); + void compose(); + void inverted(); +}; + +MatrixTransformation3DTest::MatrixTransformation3DTest() { + addTests(&MatrixTransformation3DTest::fromMatrix, + &MatrixTransformation3DTest::toMatrix, + &MatrixTransformation3DTest::compose, + &MatrixTransformation3DTest::inverted); +} + +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(MatrixTransformation3D<>::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(MatrixTransformation3D<>::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(MatrixTransformation3D<>::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(MatrixTransformation3D<>::inverted(m)*m, Matrix4()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation3DTest)