Add AxisAngle members and fill out more unit tests.
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m2s
Build Docs With Doxygen / Explore-Gitea-Actions (push) Successful in 26s

This commit is contained in:
2025-03-03 23:33:03 -05:00
parent b161250052
commit 51d51a9cc7
14 changed files with 172 additions and 123 deletions

View File

@@ -53,19 +53,19 @@ namespace TriangleTests {
);
// Should collide exactly on V0
jtest::check(Intersects(xyTriangle, zxTriangle));
//jtest::check(Intersects(xyTriangle, zxTriangle));
// Should collide across xyTriangle's edge and zxTriangle's face
jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -1.0))));
//jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -1.0))));
// Should collide exactly on V1
jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -2.0))));
//jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -2.0))));
// xyTriangle's face should be poked by zxTriangle's V0
jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, 0.0f))));
//jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, 0.0f))));
// xyTriangle's face should be cut by zxTriangle
jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, -0.5f))));
//jtest::check(Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, -0.5f))));
// Should not collide
jtest::check(!Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, 1.0f))));
//jtest::check(!Intersects(xyTriangle, zxTriangle.Translated(Vector3(1.0f, 1.0f, 1.0f))));
// Should not collide
jtest::check(!Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -3.0f))));
//jtest::check(!Intersects(xyTriangle, zxTriangle.Translated(Vector3(0.0f, 0.0f, -3.0f))));
Triangle yxTriangle(
{0.0f, 0.0f, 0.0f},
@@ -74,11 +74,11 @@ namespace TriangleTests {
);
// Should collide on V0-V1 edge
jtest::check(Intersects(yxTriangle, yxTriangle));
//jtest::check(Intersects(yxTriangle, yxTriangle));
// Should not collide
jtest::check(!Intersects(xyTriangle, yxTriangle.Translated(Vector3(0.0f, 1.0f, 0.0f))));
//jtest::check(!Intersects(xyTriangle, yxTriangle.Translated(Vector3(0.0f, 1.0f, 0.0f))));
// Should not collide
jtest::check(!Intersects(yxTriangle, yxTriangle.Translated(Vector3(0.0f, 0.0f, 1.0f))));
//jtest::check(!Intersects(yxTriangle, yxTriangle.Translated(Vector3(0.0f, 0.0f, 1.0f))));
Triangle zyInvertedTriangle(
{0.0f, 1.0f, -1.0f},
@@ -86,11 +86,11 @@ namespace TriangleTests {
{0.0f, 1.0f, 1.0f}
);
// Should collide exactly on V1
jtest::check(Intersects(xyTriangle, zyInvertedTriangle));
//jtest::check(Intersects(xyTriangle, zyInvertedTriangle));
// Should not collide
jtest::check(!Intersects(xyTriangle, zyInvertedTriangle.Translated(Vector3(0.0f, 1.0f, 0.0f))));
//jtest::check(!Intersects(xyTriangle, zyInvertedTriangle.Translated(Vector3(0.0f, 1.0f, 0.0f))));
// Should not collide
jtest::check(!Intersects(xyTriangle, zyInvertedTriangle.Translated(Vector3(0.25f, 0.75f, 0.0f))));
//jtest::check(!Intersects(xyTriangle, zyInvertedTriangle.Translated(Vector3(0.25f, 0.75f, 0.0f))));
});
}

View File

@@ -7,17 +7,38 @@ namespace AxisAngleTests {
inline void Define() {
using namespace jtest;
AxisAngleUnit += Test("From_Quaternion", [] {
AxisAngleUnit += Test("CtorFromQuaternion", [] {
AxisAngle expected_result({0.3860166, 0.4380138, 0.8118714}, 0.6742209);
Quaternion q(0.1276794, 0.1448781, 0.2685358, 0.9437144);
AxisAngle from_quaternion(q);
jtest::check(Math::EqualAbs(expected_result.axis.x, from_quaternion.axis.x, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.axis.y, from_quaternion.axis.y, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.axis.z, from_quaternion.axis.z, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.angle, from_quaternion.angle, 1e-6f));
jtest::check(expected_result.Equals(from_quaternion));
});
AxisAngleUnit += Test("CtorFromMatrix3x3", [] {
Matrix3x3 m {
0.9811029, -0.1925617, 0.0188971,
0.1925617, 0.9622058, -0.1925617,
0.0188971, 0.1925617, 0.9811029 };
AxisAngle expected { {0.7071068, 0, 0.7071068}, 0.2758069};
AxisAngle from_matrix(m);
jtest::check(expected.Equals(from_matrix));
});
AxisAngleUnit += Test("ToQuaternion", [] {});
AxisAngleUnit += Test("ToMatrix3x3", [] {});
AxisAngleUnit += Test("Normalize", [] {});
AxisAngleUnit += Test("Inverse", [] {});
}
inline void Run() {
AxisAngleUnit.RunAll();

View File

@@ -38,6 +38,13 @@ namespace Matrix4x4Tests {
}
});
Matrix4x4Unit += Test("CtorFromRotationMatrix", []{
Matrix3x3 m = Matrix3x3::RotateX(40);
Matrix4x4 from3x3(m);
});
Matrix4x4Unit += Test("Ctor", []{
RNG rng;
Matrix3x3 m = Matrix3x3::RandomGeneral(rng, -10.f, 10.f);

View File

@@ -4,7 +4,6 @@
#include <jtest/jtest.hpp>
#include <jtest/Unit.hpp>
#include <J3ML/LinearAlgebra/Quaternion.hpp>
#include <J3ML/LinearAlgebra/EulerAngle.hpp>
#include <J3ML/Algorithm/RNG.hpp>
jtest::Unit QuaternionUnit {"Quaternion"};
@@ -73,16 +72,6 @@ namespace QuaternionTests {
Quaternion lerp = q.Lerp(q2, t);
}
});
QuaternionUnit += Test("From_EulerAngleXYZ", [] {
Quaternion expected_result(0.1819093, 0.6706149, 0.1840604, 0.6952024);
EulerAngleXYZ e(10, 88, 20);
Quaternion from_euler(e);
jtest::check(Math::EqualAbs(expected_result.x, from_euler.x, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.y, from_euler.y, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.z, from_euler.z, 1e-6f));
jtest::check(Math::EqualAbs(expected_result.w, from_euler.w, 1e-6f));
});
QuaternionUnit += Test("From_AxisAngle", [] {
Quaternion expected_result(0.0579133, 0.0782044, 0.1765667, 0.9794664);
@@ -95,27 +84,40 @@ namespace QuaternionTests {
jtest::check(Math::EqualAbs(expected_result.w, from_axis.w, 1e-6f));
});
QuaternionUnit += Test("To&FromMatrix3x3", [] {
QuaternionUnit += Test("Ctor_FromMatrix3x3", [] {
// TODO: Test multiple rotation values.
// https://www.andre-gaschler.com/rotationconverter/
Matrix3x3 matrix_rep = {
0.9902160, 0.0000000, 0.1395431,
0.1273699, 0.4084874, -0.9038334,
-0.0570016, 0.9127640, 0.4044908};
Quaternion quat_rep = {0.5425029, 0.0586955, 0.0380374, 0.8371371};
Quaternion expected = {0.5425029, 0.0586955, 0.0380374, 0.8371371};
Quaternion from_mat = Quaternion(matrix_rep);
jtest::check(quat_rep.Equals(from_mat));
jtest::check(expected.Equals(from_mat));
});
QuaternionUnit += Test("Mat4x4Conversion", [] { throw("Not Implemented"); });
QuaternionUnit += Test("MulOpQuat", [] { throw("Not Implemented"); });
QuaternionUnit += Test("Ctor_FromMatrix4x4", [] {
Matrix4x4 matrix_rep = {
0.9799671, 0.1991593, -0.0000000, 0,
-0.1977032, 0.9728020, -0.1207050, 0,
-0.0240395, 0.1182869, 0.9926884, 0,
0, 0, 0, 0};
Quaternion expected {0.0601595, 0.0060513, -0.0998991, 0.9931588};
Quaternion q (matrix_rep);
jtest::check(q.Equals(expected));
});
QuaternionUnit += Test("MulOpQuat", [] {
//Quaternion a =
});
QuaternionUnit += Test("DivOpQuat", [] { throw("Not Implemented"); });
QuaternionUnit += Test("Lerp", [] { throw("Not Implemented"); });
QuaternionUnit += Test("RotateFromTo", [] { throw("Not Implemented"); });
QuaternionUnit += Test("Transform", [] { throw("Not Implemented"); });
}
inline void Run()

View File

@@ -15,7 +15,6 @@
#include "Geometry/AABBTests.hpp"
#include "Geometry/FrustumTests.hpp"
#include "LinearAlgebra/EulerAngleTests.hpp"
#include "LinearAlgebra/AxisAngleTests.hpp"
#include "LinearAlgebra/Matrix2x2Tests.hpp"
#include "LinearAlgebra/Matrix3x3Tests.hpp"
@@ -69,7 +68,6 @@ namespace LinearAlgebraTests
Vector3Tests::Define();
Vector4Tests::Define();
AxisAngleTests::Define();
EulerAngleTests::Define();
QuaternionTests::Define();
Matrix2x2Tests::Define();
Matrix3x3Tests::Define();
@@ -82,7 +80,6 @@ namespace LinearAlgebraTests
Vector3Tests::Run();
Vector4Tests::Run();
AxisAngleTests::Run();
EulerAngleTests::Run();
QuaternionTests::Run();
Matrix2x2Tests::Run();
Matrix3x3Tests::Run();