From a0252484d21885a3d16a2d455a4c62f5d6110860 Mon Sep 17 00:00:00 2001
From: Philip Trettner <Philip.Trettner@rwth-aachen.de>
Date: Fri, 4 Dec 2020 16:18:25 +0100
Subject: [PATCH] compose test

---
 extern/typed-geometry           |  2 +-
 tests/feature/matrix/compose.cc | 57 +++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 tests/feature/matrix/compose.cc

diff --git a/extern/typed-geometry b/extern/typed-geometry
index 23d12b2..bb4235d 160000
--- a/extern/typed-geometry
+++ b/extern/typed-geometry
@@ -1 +1 @@
-Subproject commit 23d12b23ad62e2c0bef0be2d569e100dca2ce846
+Subproject commit bb4235d244995d800e7aec5a3e7de5155bd90d3d
diff --git a/tests/feature/matrix/compose.cc b/tests/feature/matrix/compose.cc
new file mode 100644
index 0000000..2cb73ee
--- /dev/null
+++ b/tests/feature/matrix/compose.cc
@@ -0,0 +1,57 @@
+#include "test.hh"
+
+TG_FUZZ_TEST(Mat4, DecomposeUniform)
+{
+    auto t0 = uniform_vec(rng, tg::aabb3(-10, 10));
+    auto s0 = uniform(rng, .1f, 2.f);
+    auto R0 = tg::rotation_around(tg::uniform<tg::dir3>(rng), tg::uniform<tg::angle>(rng));
+
+    auto M = tg::translation(t0) * R0 * tg::scaling<3>(s0);
+
+    auto MM = tg::compose_transformation(t0, tg::mat3(R0), s0);
+
+    auto p = uniform(rng, tg::aabb3(-10, 10));
+
+    tg::vec3 t1;
+    tg::mat3 R1;
+    float s1;
+    tg::decompose_transformation(M, t1, R1, s1);
+
+    CHECK(t1 == approx(t0, 0.01f));
+    CHECK(s1 == approx(s0).epsilon(0.01f));
+
+    auto q0 = M * p;
+    auto q1 = tg::pos3(R1 * (s1 * tg::vec3(p)) + t1);
+    auto q2 = MM * p;
+
+    CHECK(q1 == approx(q0, 0.01f));
+    CHECK(q2 == approx(q0, 0.01f));
+}
+
+TG_FUZZ_TEST(Mat4, DecomposeNonUniform)
+{
+    auto t0 = uniform_vec(rng, tg::aabb3(-10, 10));
+    auto s0 = tg::size3(uniform(rng, tg::aabb3(0.1f, 2.f)));
+    auto R0 = tg::rotation_around(tg::uniform<tg::dir3>(rng), tg::uniform<tg::angle>(rng));
+
+    auto M = tg::translation(t0) * R0 * tg::scaling(s0);
+
+    auto MM = tg::compose_transformation(t0, tg::mat3(R0), s0);
+
+    auto p = uniform(rng, tg::aabb3(-10, 10));
+
+    tg::vec3 t1;
+    tg::mat3 R1;
+    tg::size3 s1;
+    tg::decompose_transformation(M, t1, R1, s1);
+
+    CHECK(t1 == approx(t0, 0.01f));
+    CHECK(s1 == approx(s0, 0.01f));
+
+    auto q0 = M * p;
+    auto q1 = tg::pos3(R1 * (tg::vec3(p) * s1) + t1);
+    auto q2 = MM * p;
+
+    CHECK(q1 == approx(q0, 0.01f));
+    CHECK(q2 == approx(q0, 0.01f));
+}
-- 
GitLab