From 768798fb5b25cf44945c8b12f4fefbe0eaad26d6 Mon Sep 17 00:00:00 2001 From: Matthew Mott Date: Sat, 20 Mar 2021 17:15:36 +0000 Subject: [PATCH] Add tests for Matrix4 affine inverse (translation and scale) --- test/math/Matrix4.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/math/Matrix4.cpp b/test/math/Matrix4.cpp index e328d6321c..a2a321aeeb 100644 --- a/test/math/Matrix4.cpp +++ b/test/math/Matrix4.cpp @@ -515,6 +515,38 @@ TEST(MathTest, MatrixTransformation) EXPECT_EQ(a.t().z(), 53) << "Matrix4::t failed"; } +TEST(MathTest, MatrixScaleAffineInverse) +{ + // Construct a scale matrix + Vector3 SCALE(2, 4, 8); + Matrix4 scaleMat = Matrix4::getScale(SCALE); + EXPECT_EQ(scaleMat.getScale(), SCALE); + + // Get the affine inverse + Matrix4 inverse = scaleMat.getInverse(); + + // Inverse must have inverted scale factors + EXPECT_EQ(inverse.getScale(), + Vector3(1.0 / SCALE.x(), 1.0 / SCALE.y(), 1.0 / SCALE.z())); +} + +TEST(MathTest, MatrixTranslationAffineInverse) +{ + // Construct a translation matrix + Vector3 TRANS(4, 32, -8); + Matrix4 transMat = Matrix4::getTranslation(TRANS); + EXPECT_EQ(transMat.getScale(), Vector3(1, 1, 1)); + + // Get the affine inverse + Matrix4 inverse = transMat.getInverse(); + + // Check resulting matrix + EXPECT_EQ(inverse, Matrix4::byRows(1, 0, 0, -TRANS.x(), + 0, 1, 0, -TRANS.y(), + 0, 0, 1, -TRANS.z(), + 0, 0, 0, 1)); +} + TEST(MathTest, MatrixFullInverse) { auto a = Matrix4::byColumns(3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59);