Expand Matrix4x4 Tests, still have to correct several.

This commit is contained in:
2025-04-18 15:01:32 -04:00
parent b17e49d1df
commit 3259a8e980

View File

@@ -11,8 +11,7 @@ namespace Matrix4x4Tests {
using namespace J3ML::LinearAlgebra; using namespace J3ML::LinearAlgebra;
using namespace J3ML::Math; using namespace J3ML::Math;
Matrix4x4Unit += Test("Add_Unary", [] Matrix4x4Unit += Test("Add_Unary", [] {
{
Matrix4x4 m(1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16); Matrix4x4 m(1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16);
Matrix4x4 m2 = +m; Matrix4x4 m2 = +m;
jtest::check(m.Equals(m2)); jtest::check(m.Equals(m2));
@@ -111,13 +110,52 @@ namespace Matrix4x4Tests {
}); });
Matrix4x4Unit += Test("CtorFromQuatTrans", [] {}); Matrix4x4Unit += Test("CtorFromQuatTrans", [] {
Matrix4x4Unit += Test("Translate", [] {}); RNG rng;
Matrix4x4Unit += Test("Scale", [] {}); constexpr float SCALE = 1e2f;
Matrix4x4Unit += Test("InverseOrthogonalUniformScale", [] {}); Vector3 t = Vector3::RandomBox(rng, Vector3(-SCALE, -SCALE, -SCALE), Vector3(SCALE, SCALE, SCALE));
Matrix4x4Unit += Test("InverseOrthonormal", [] {}); Quaternion q = Quaternion::RandomRotation(rng);
Matrix4x4Unit += Test("DeterminantCorrectness", [] { });
Matrix4x4Unit += Test("MulMat3x3", [] {}); Matrix4x4 m (q, t);
Vector3 v = Vector3(-1, 5, 20.f);
Vector3 v1 = q * v + t;
Vector3 v2 = m.Transform(v);
jtest::check(v1.Equals(v2));
});
Matrix4x4Unit += Test("Translate", [] {
RNG rng;
constexpr float SCALE = 1e2f;
Vector3 t = Vector3::RandomBox(rng, Vector3(-SCALE, -SCALE, -SCALE), Vector3(SCALE, SCALE, SCALE));
Vector3 t2 = Vector3::RandomBox(rng, Vector3(-SCALE, -SCALE, -SCALE), Vector3(SCALE, SCALE, SCALE));
Matrix4x4 m = Matrix4x4::Translate(t);
Matrix4x4 m2 = Matrix4x4::Translate({t.x, t.y, t.z});
Vector3 v = t + t2;
Vector3 v1 = m.Transform(t2);
Vector3 v2 = m2.Transform(t2);
jtest::check(v1.Equals(v2));
jtest::check(v.Equals(v1));
});
Matrix4x4Unit += Test("Scale", [] {
Matrix4x4 m = Matrix4x4::Scale({2, 4, 6});
Matrix4x4 m2(2,0,0,0, 0,4,0,0, 0,0,6,0, 0,0,0,1);
jtest::check(m.Equals(m2));
});
Matrix4x4Unit += Test("MulMat3x3", [] {
RNG rng;
Matrix3x3 m = Matrix3x3::RandomGeneral(rng, -10.f, 10.f);
Matrix4x4 m_ = m;
Matrix4x4 m2 = Matrix4x4::RandomGeneral(rng, -10.f, 10.f);
Matrix4x4 test = m2 * m;
Matrix4x4 correct = m2 * m_;
jtest::check(test.Equals(correct));
});
} }
inline void Run() { inline void Run() {