From e2b4e483159d60968f97fe3964d5f6c5dec85557 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 14 Sep 2016 17:54:25 +1000 Subject: [PATCH] test: add matrix/quaternion consistency checks --- Makefile.am | 1 + test/affine.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/affine.cpp diff --git a/Makefile.am b/Makefile.am index 4c356ba1..03ff8e33 100644 --- a/Makefile.am +++ b/Makefile.am @@ -385,6 +385,7 @@ TEST_BIN = \ test/alloc/dynamic \ test/alloc/linear \ test/alloc/stack \ + test/affine \ test/backtrace \ test/bezier \ test/bitwise \ diff --git a/test/affine.cpp b/test/affine.cpp new file mode 100644 index 00000000..66c3159a --- /dev/null +++ b/test/affine.cpp @@ -0,0 +1,73 @@ +#include "tap.hpp" + +#include "vector.hpp" +#include "matrix.hpp" +#include "quaternion.hpp" + + +/////////////////////////////////////////////////////////////////////////////// +void +test_mq_axis (util::TAP::logger &tap) +{ + static const struct { + util::vector3f euler; + const char *msg; + } TESTS[] = { + { { 1, 0, 0 }, "x-axis" }, + { { 0, 1, 0 }, "y-axis" }, + { { 0, 0, 1 }, "z-axis" }, + }; + + for (auto t: TESTS) { + auto m = util::matrix4f::rotation (1, t.euler); + auto q = util::quaternionf::rotation (1, t.euler); + + auto diff = sum (abs (m - q.as_matrix ())); + tap.expect_le (diff, 1e-6f, "matrix/quaternion rotation identities, %s", t.msg); + } +} + + +/////////////////////////////////////////////////////////////////////////////// +void +test_mq_euler (util::TAP::logger &tap) +{ + static const struct { + util::vector3f euler; + const char *msg; + } TESTS[] = { + { { 0, 0, 0 }, "zeroes" }, + { { 1, 0, 0 }, "x-axis" }, + { { 0, 1, 0 }, "y-axis" }, + { { 0, 0, 1 }, "z-axis" }, + { { 1, 1, 1 }, "ones" }, + { { 9, 9, 9 }, "nines" } + }; + + for (auto t: TESTS) { + auto m = util::matrix4f::rotation (t.euler[0], { 1, 0, 0 }) * + util::matrix4f::rotation (t.euler[1], { 0, 1, 0 }) * + util::matrix4f::rotation (t.euler[2], { 0, 0, 1 }); + auto q = ( + util::quaternionf::rotation (t.euler[0], { 1, 0, 0 }) * + util::quaternionf::rotation (t.euler[1], { 0, 1, 0 }) * + util::quaternionf::rotation (t.euler[2], { 0, 0, 1 }) + ).as_matrix (); + + auto diff = util::sum (abs (m - q)); + tap.expect_le (diff, 1e-6f, "matrix-quaternion xyz euler rotations, %s", t.msg); + } +} + + +/////////////////////////////////////////////////////////////////////////////// +int +main (int, char**) +{ + util::TAP::logger tap; + + test_mq_axis (tap); + test_mq_euler (tap); + + return tap.status (); +}