mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-22 17:18:39 +00:00
Code style fixes.
This commit is contained in:
parent
24e9db07ec
commit
af3f696423
43 changed files with 493 additions and 484 deletions
|
@ -9,7 +9,7 @@
|
|||
using matrix4 = core::matrix4;
|
||||
|
||||
static bool matrix_equals(const matrix4 &a, const matrix4 &b) {
|
||||
return a.equals(b, 0.00001f);
|
||||
return a.equals(b, 0.00001f);
|
||||
}
|
||||
|
||||
constexpr v3f x{1, 0, 0};
|
||||
|
@ -19,68 +19,68 @@ constexpr v3f z{0, 0, 1};
|
|||
TEST_CASE("matrix4") {
|
||||
|
||||
SECTION("setRotationRadians") {
|
||||
SECTION("rotation order is ZYX (matrix notation)") {
|
||||
v3f rot{1, 2, 3};
|
||||
matrix4 X, Y, Z, ZYX;
|
||||
X.setRotationRadians({rot.X, 0, 0});
|
||||
Y.setRotationRadians({0, rot.Y, 0});
|
||||
Z.setRotationRadians({0, 0, rot.Z});
|
||||
ZYX.setRotationRadians(rot);
|
||||
CHECK(!matrix_equals(X * Y * Z, ZYX));
|
||||
CHECK(!matrix_equals(X * Z * Y, ZYX));
|
||||
CHECK(!matrix_equals(Y * X * Z, ZYX));
|
||||
CHECK(!matrix_equals(Y * Z * X, ZYX));
|
||||
CHECK(!matrix_equals(Z * X * Y, ZYX));
|
||||
CHECK(matrix_equals(Z * Y * X, ZYX));
|
||||
}
|
||||
SECTION("rotation order is ZYX (matrix notation)") {
|
||||
v3f rot{1, 2, 3};
|
||||
matrix4 X, Y, Z, ZYX;
|
||||
X.setRotationRadians({rot.X, 0, 0});
|
||||
Y.setRotationRadians({0, rot.Y, 0});
|
||||
Z.setRotationRadians({0, 0, rot.Z});
|
||||
ZYX.setRotationRadians(rot);
|
||||
CHECK(!matrix_equals(X * Y * Z, ZYX));
|
||||
CHECK(!matrix_equals(X * Z * Y, ZYX));
|
||||
CHECK(!matrix_equals(Y * X * Z, ZYX));
|
||||
CHECK(!matrix_equals(Y * Z * X, ZYX));
|
||||
CHECK(!matrix_equals(Z * X * Y, ZYX));
|
||||
CHECK(matrix_equals(Z * Y * X, ZYX));
|
||||
}
|
||||
|
||||
const f32 quarter_turn = core::PI / 2;
|
||||
const f32 quarter_turn = core::PI / 2;
|
||||
|
||||
// See https://en.wikipedia.org/wiki/Right-hand_rule#/media/File:Cartesian_coordinate_system_handedness.svg
|
||||
// for a visualization of what handedness means for rotations
|
||||
// See https://en.wikipedia.org/wiki/Right-hand_rule#/media/File:Cartesian_coordinate_system_handedness.svg
|
||||
// for a visualization of what handedness means for rotations
|
||||
|
||||
SECTION("rotation is right-handed") {
|
||||
SECTION("rotation around the X-axis is Z-up, counter-clockwise") {
|
||||
matrix4 X;
|
||||
X.setRotationRadians({quarter_turn, 0, 0});
|
||||
CHECK(X.transformVect(x).equals(x));
|
||||
CHECK(X.transformVect(y).equals(z));
|
||||
CHECK(X.transformVect(z).equals(-y));
|
||||
}
|
||||
SECTION("rotation is right-handed") {
|
||||
SECTION("rotation around the X-axis is Z-up, counter-clockwise") {
|
||||
matrix4 X;
|
||||
X.setRotationRadians({quarter_turn, 0, 0});
|
||||
CHECK(X.transformVect(x).equals(x));
|
||||
CHECK(X.transformVect(y).equals(z));
|
||||
CHECK(X.transformVect(z).equals(-y));
|
||||
}
|
||||
|
||||
SECTION("rotation around the Y-axis is Z-up, clockwise") {
|
||||
matrix4 Y;
|
||||
Y.setRotationRadians({0, quarter_turn, 0});
|
||||
CHECK(Y.transformVect(y).equals(y));
|
||||
CHECK(Y.transformVect(x).equals(-z));
|
||||
CHECK(Y.transformVect(z).equals(x));
|
||||
}
|
||||
SECTION("rotation around the Y-axis is Z-up, clockwise") {
|
||||
matrix4 Y;
|
||||
Y.setRotationRadians({0, quarter_turn, 0});
|
||||
CHECK(Y.transformVect(y).equals(y));
|
||||
CHECK(Y.transformVect(x).equals(-z));
|
||||
CHECK(Y.transformVect(z).equals(x));
|
||||
}
|
||||
|
||||
SECTION("rotation around the Z-axis is Y-up, counter-clockwise") {
|
||||
matrix4 Z;
|
||||
Z.setRotationRadians({0, 0, quarter_turn});
|
||||
CHECK(Z.transformVect(z).equals(z));
|
||||
CHECK(Z.transformVect(x).equals(y));
|
||||
CHECK(Z.transformVect(y).equals(-x));
|
||||
}
|
||||
}
|
||||
SECTION("rotation around the Z-axis is Y-up, counter-clockwise") {
|
||||
matrix4 Z;
|
||||
Z.setRotationRadians({0, 0, quarter_turn});
|
||||
CHECK(Z.transformVect(z).equals(z));
|
||||
CHECK(Z.transformVect(x).equals(y));
|
||||
CHECK(Z.transformVect(y).equals(-x));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("getScale") {
|
||||
SECTION("correctly gets the length of each row of the 3x3 submatrix") {
|
||||
matrix4 A(
|
||||
1, 2, 3, 0,
|
||||
4, 5, 6, 0,
|
||||
7, 8, 9, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
v3f scale = A.getScale();
|
||||
CHECK(scale.equals(v3f(
|
||||
v3f(1, 2, 3).getLength(),
|
||||
v3f(4, 5, 6).getLength(),
|
||||
v3f(7, 8, 9).getLength()
|
||||
)));
|
||||
}
|
||||
SECTION("correctly gets the length of each row of the 3x3 submatrix") {
|
||||
matrix4 A(
|
||||
1, 2, 3, 0,
|
||||
4, 5, 6, 0,
|
||||
7, 8, 9, 0,
|
||||
0, 0, 0, 1
|
||||
);
|
||||
v3f scale = A.getScale();
|
||||
CHECK(scale.equals(v3f(
|
||||
v3f(1, 2, 3).getLength(),
|
||||
v3f(4, 5, 6).getLength(),
|
||||
v3f(7, 8, 9).getLength()
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -42,14 +42,14 @@ const char *TestSettings::config_text_before =
|
|||
"floaty_thing = 1.1\n"
|
||||
"stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n"
|
||||
"coord = (1, 2, 4.5)\n"
|
||||
"coord_invalid = (1,2,3\n"
|
||||
"coord_invalid_2 = 1, 2, 3 test\n"
|
||||
"coord_invalid_3 = (test, something, stupid)\n"
|
||||
"coord_invalid_4 = (1, test, 3)\n"
|
||||
"coord_invalid_5 = ()\n"
|
||||
"coord_invalid_6 = (1, 2)\n"
|
||||
"coord_invalid_7 = (1)\n"
|
||||
"coord_no_parenthesis = 1,2,3\n"
|
||||
"coord_invalid = (1,2,3\n"
|
||||
"coord_invalid_2 = 1, 2, 3 test\n"
|
||||
"coord_invalid_3 = (test, something, stupid)\n"
|
||||
"coord_invalid_4 = (1, test, 3)\n"
|
||||
"coord_invalid_5 = ()\n"
|
||||
"coord_invalid_6 = (1, 2)\n"
|
||||
"coord_invalid_7 = (1)\n"
|
||||
"coord_no_parenthesis = 1,2,3\n"
|
||||
" # this is just a comment\n"
|
||||
"this is an invalid line\n"
|
||||
"asdf = {\n"
|
||||
|
@ -103,14 +103,14 @@ const char *TestSettings::config_text_after =
|
|||
"}\n"
|
||||
"zoop = true\n"
|
||||
"coord2 = (1,2,3.25)\n"
|
||||
"coord_invalid = (1,2,3\n"
|
||||
"coord_invalid_2 = 1, 2, 3 test\n"
|
||||
"coord_invalid_3 = (test, something, stupid)\n"
|
||||
"coord_invalid_4 = (1, test, 3)\n"
|
||||
"coord_invalid_5 = ()\n"
|
||||
"coord_invalid_6 = (1, 2)\n"
|
||||
"coord_invalid_7 = (1)\n"
|
||||
"coord_no_parenthesis = 1,2,3\n"
|
||||
"coord_invalid = (1,2,3\n"
|
||||
"coord_invalid_2 = 1, 2, 3 test\n"
|
||||
"coord_invalid_3 = (test, something, stupid)\n"
|
||||
"coord_invalid_4 = (1, test, 3)\n"
|
||||
"coord_invalid_5 = ()\n"
|
||||
"coord_invalid_6 = (1, 2)\n"
|
||||
"coord_invalid_7 = (1)\n"
|
||||
"coord_no_parenthesis = 1,2,3\n"
|
||||
"floaty_thing_2 = 1.25\n"
|
||||
"groupy_thing = {\n"
|
||||
" animals = cute\n"
|
||||
|
@ -169,20 +169,20 @@ void TestSettings::testAllSettings()
|
|||
UASSERT(s.getV3F("coord2").value().Y == 2.0);
|
||||
UASSERT(s.getV3F("coord2").value().Z == 3.25);
|
||||
|
||||
std::optional<v3f> testNotExist;
|
||||
UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist));
|
||||
EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist"));
|
||||
std::optional<v3f> testNotExist;
|
||||
UASSERT(!s.getV3FNoEx("coord_not_exist", testNotExist));
|
||||
EXCEPTION_CHECK(SettingNotFoundException, s.getV3F("coord_not_exist"));
|
||||
|
||||
UASSERT(!s.getV3F("coord_invalid").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_2").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_3").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_4").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_5").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_6").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_7").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_2").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_3").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_4").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_5").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_6").has_value());
|
||||
UASSERT(!s.getV3F("coord_invalid_7").has_value());
|
||||
|
||||
std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
|
||||
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
|
||||
std::optional<v3f> testNoParenthesis = s.getV3F("coord_no_parenthesis");
|
||||
UASSERT(testNoParenthesis.value() == v3f(1, 2, 3));
|
||||
|
||||
// Test settings groups
|
||||
Settings *group = s.getGroup("asdf");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue