diff --git a/src/Magnum/Math/Algorithms/Test/QrTest.cpp b/src/Magnum/Math/Algorithms/Test/QrTest.cpp index 2916e6c89..a3399955a 100644 --- a/src/Magnum/Math/Algorithms/Test/QrTest.cpp +++ b/src/Magnum/Math/Algorithms/Test/QrTest.cpp @@ -35,6 +35,7 @@ struct QrTest: Corrade::TestSuite::Tester { explicit QrTest(); void test(); + void decomposeRotationScaling(); void decomposeRotationShear(); }; @@ -46,6 +47,7 @@ typedef Matrix4 Matrix4; QrTest::QrTest() { addTests({&QrTest::test, + &QrTest::decomposeRotationScaling, &QrTest::decomposeRotationShear}); } @@ -67,7 +69,21 @@ void QrTest::test() { CORRADE_COMPARE(qr.second, rExpected); } +void QrTest::decomposeRotationScaling() { + Matrix4 a = Matrix4::rotationZ(35.0_degf)*Matrix4::scaling({1.5f, 2.0f, 1.0f}); + + std::pair qr = Algorithms::qr(a.rotationScaling()); + CORRADE_COMPARE(qr.first*qr.second, a.rotationScaling()); + + auto q4 = Matrix4::from(qr.first, {}); + auto r4 = Matrix4::from(qr.second, {}); + + CORRADE_COMPARE(q4, Matrix4::rotationZ(35.0_degf)); + CORRADE_COMPARE(r4, Matrix4::scaling({1.5f, 2.0f, 1.0f})); +} + void QrTest::decomposeRotationShear() { + /* Like above, but with order flipped, which results in a shear */ Matrix4 a = Matrix4::scaling({1.5f, 2.0f, 1.0f})*Matrix4::rotationZ(35.0_degf); std::pair qr = Algorithms::qr(a.rotationScaling()); diff --git a/src/Magnum/Math/Algorithms/Test/SvdTest.cpp b/src/Magnum/Math/Algorithms/Test/SvdTest.cpp index 7546265f5..63bea48ba 100644 --- a/src/Magnum/Math/Algorithms/Test/SvdTest.cpp +++ b/src/Magnum/Math/Algorithms/Test/SvdTest.cpp @@ -34,6 +34,7 @@ struct SvdTest: Corrade::TestSuite::Tester { explicit SvdTest(); template void test(); + void decomposeRotationScaling(); void decomposeRotationShear(); }; @@ -46,6 +47,7 @@ template using Vector5 = Vector<5, T>; SvdTest::SvdTest() { addTests({&SvdTest::test, &SvdTest::test, + &SvdTest::decomposeRotationScaling, &SvdTest::decomposeRotationShear}); } @@ -94,6 +96,28 @@ template void SvdTest::test() { } } +void SvdTest::decomposeRotationScaling() { + typedef Math::Matrix4 Matrix4; + typedef Math::Matrix3x3 Matrix3x3; + typedef Math::Vector3 Vector3; + + using namespace Math::Literals; + + Matrix4 a = Matrix4::rotationZ(35.0_degf)*Matrix4::scaling({1.5f, 2.0f, 1.0f}); + + Matrix3x3 u{Magnum::NoInit}; + Vector3 w{Magnum::NoInit}; + Matrix3x3 v{Magnum::NoInit}; + std::tie(u, w, v) = Algorithms::svd(a.rotationScaling()); + + CORRADE_COMPARE(u*Matrix3x3::fromDiagonal(w)*v.transposed(), a.rotationScaling()); + + /* V contains flipped signs for the whole matrix, use it to fix the + signs for U */ + CORRADE_COMPARE(w, (Vector3{1.5f, 2.0f, 1.0f})); + CORRADE_COMPARE(Matrix4::from(u*v.transposed(), {}), Matrix4::rotationZ(35.0_degf)); +} + void SvdTest::decomposeRotationShear() { typedef Math::Matrix4 Matrix4; typedef Math::Matrix3x3 Matrix3x3; @@ -101,6 +125,7 @@ void SvdTest::decomposeRotationShear() { using namespace Math::Literals; + /* Like above, but with order flipped, which results in a shear */ Matrix4 a = Matrix4::scaling({1.5f, 2.0f, 1.0f})*Matrix4::rotationZ(35.0_degf); Matrix3x3 u{Magnum::NoInit};