mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Extend quaternion tests
This commit is contained in:
parent
3ae1fd459a
commit
1ceeea34f4
1 changed files with 35 additions and 18 deletions
|
@ -10,31 +10,48 @@
|
||||||
using matrix4 = core::matrix4;
|
using matrix4 = core::matrix4;
|
||||||
|
|
||||||
static bool matrix_equals(const matrix4 &a, const matrix4 &b) {
|
static bool matrix_equals(const matrix4 &a, const matrix4 &b) {
|
||||||
return a.equals(b, 0.00001f);
|
return a.equals(b, 0.00001f);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("quaternion") {
|
TEST_CASE("quaternion") {
|
||||||
|
|
||||||
// Make sure that the conventions are consistent
|
// Make sure that the conventions are consistent
|
||||||
SECTION("equivalence to euler rotations") {
|
SECTION("equivalence to euler rotations") {
|
||||||
auto test_rotation = [](v3f rad) {
|
auto test_rotation = [](v3f rad) {
|
||||||
matrix4 R;
|
matrix4 R;
|
||||||
R.setRotationRadians(rad);
|
R.setRotationRadians(rad);
|
||||||
v3f rad2;
|
v3f rad2;
|
||||||
core::quaternion(rad).toEuler(rad2);
|
core::quaternion(rad).toEuler(rad2);
|
||||||
matrix4 R2;
|
matrix4 R2;
|
||||||
R2.setRotationRadians(rad2);
|
R2.setRotationRadians(rad2);
|
||||||
CHECK(matrix_equals(R, R2));
|
CHECK(matrix_equals(R, R2));
|
||||||
};
|
};
|
||||||
|
|
||||||
test_rotation({100, 200, 300});
|
Catch::Generators::RandomFloatingGenerator<f32> gen(0.0f, 2 * core::PI, Catch::getSeed());
|
||||||
Catch::Generators::RandomFloatingGenerator<f32> gen(0.0f, 2 * core::PI, Catch::getSeed());
|
for (int i = 0; i < 1000; ++i)
|
||||||
for (int i = 0; i < 1000; ++i)
|
test_rotation(v3f{gen.get(), gen.get(), gen.get()});
|
||||||
test_rotation(v3f{gen.get(), gen.get(), gen.get()});
|
for (int i = 0; i < 4; i++)
|
||||||
for (int i = 0; i < 4; i++)
|
for (int j = 0; j < 4; j++)
|
||||||
for (int j = 0; j < 4; j++)
|
for (int k = 0; k < 4; k++)
|
||||||
for (int k = 0; k < 4; k++)
|
test_rotation(core::PI / 4.0f * v3f(i, j, k));
|
||||||
test_rotation(core::PI / 4.0f * v3f(i, j, k));
|
}
|
||||||
|
|
||||||
|
SECTION("equivalence to rotation matrices") {
|
||||||
|
auto test_rotation = [](v3f rad) {
|
||||||
|
matrix4 R;
|
||||||
|
R.setRotationRadians(rad);
|
||||||
|
matrix4 R2;
|
||||||
|
core::quaternion(R).getMatrix(R2);
|
||||||
|
CHECK(matrix_equals(R, R2));
|
||||||
|
};
|
||||||
|
|
||||||
|
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
Add a link
Reference in a new issue