From 0e8636632478607829a070adc7ba3cff32eb5815 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Wed, 15 Jan 2025 18:18:54 +0100 Subject: [PATCH] Add test for matrix4::getRotationDegrees --- src/unittest/test_irr_matrix4.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/unittest/test_irr_matrix4.cpp b/src/unittest/test_irr_matrix4.cpp index 764b0a5b2..c7f065649 100644 --- a/src/unittest/test_irr_matrix4.cpp +++ b/src/unittest/test_irr_matrix4.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include "catch.h" +#include "catch_amalgamated.hpp" #include "irrMath.h" #include "matrix4.h" #include "irr_v3d.h" @@ -83,4 +84,29 @@ SECTION("getScale") { } } +SECTION("getRotationDegrees") { + auto test_rotation_degrees = [](v3f deg) { + matrix4 S; + Catch::Generators::RandomFloatingGenerator gen(0.1f, 10, Catch::getSeed()); + S.setScale({gen.get(), gen.get(), gen.get()}); + + matrix4 R; + R.setRotationDegrees(deg); + v3f rot = (R * S).getRotationDegrees(); + matrix4 B; + B.setRotationDegrees(rot); + CHECK(matrix_equals(R, B)); + }; + SECTION("returns a rotation equivalent to the original rotation") { + test_rotation_degrees({100, 200, 300}); + Catch::Generators::RandomFloatingGenerator gen(0, 360, Catch::getSeed()); + for (int i = 0; i < 1000; ++i) + test_rotation_degrees(v3f{gen.get(), gen.get(), gen.get()}); + for (f32 i = 0; i < 360; i += 90) + for (f32 j = 0; j < 360; j += 90) + for (f32 k = 0; k < 360; k += 90) + test_rotation_degrees({i, j, k}); + } +} + }