mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01:00
Add quaternion conversion unit tests
This commit is contained in:
parent
0e86366324
commit
3ae1fd459a
2 changed files with 42 additions and 1 deletions
|
@ -13,6 +13,8 @@ set (UNITTEST_SRCS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_filesys.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_inventory.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_irrptr.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_irr_matrix4.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_irr_quaternion.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_logging.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_lua.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_map.cpp
|
||||
|
@ -54,7 +56,6 @@ set (UNITTEST_CLIENT_SRCS
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/test_eventmanager.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_gameui.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_irr_gltf_mesh_loader.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_irr_matrix4.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_mesh_compare.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/test_keycode.cpp
|
||||
PARENT_SCOPE)
|
||||
|
|
40
src/unittest/test_irr_quaternion.cpp
Normal file
40
src/unittest/test_irr_quaternion.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
// Luanti
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "catch.h"
|
||||
#include "irrMath.h"
|
||||
#include "matrix4.h"
|
||||
#include "quaternion.h"
|
||||
#include "irr_v3d.h"
|
||||
|
||||
using matrix4 = core::matrix4;
|
||||
|
||||
static bool matrix_equals(const matrix4 &a, const matrix4 &b) {
|
||||
return a.equals(b, 0.00001f);
|
||||
}
|
||||
|
||||
TEST_CASE("quaternion") {
|
||||
|
||||
// Make sure that the conventions are consistent
|
||||
SECTION("equivalence to euler rotations") {
|
||||
auto test_rotation = [](v3f rad) {
|
||||
matrix4 R;
|
||||
R.setRotationRadians(rad);
|
||||
v3f rad2;
|
||||
core::quaternion(rad).toEuler(rad2);
|
||||
matrix4 R2;
|
||||
R2.setRotationRadians(rad2);
|
||||
CHECK(matrix_equals(R, R2));
|
||||
};
|
||||
|
||||
test_rotation({100, 200, 300});
|
||||
Catch::Generators::RandomFloatingGenerator<f32> gen(0.0f, 2 * core::PI, Catch::getSeed());
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
test_rotation(v3f{gen.get(), gen.get(), gen.get()});
|
||||
for (int i = 0; i < 4; i++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
for (int k = 0; k < 4; k++)
|
||||
test_rotation(core::PI / 4.0f * v3f(i, j, k));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue