quat low precision ops testing master
authorjpreiss <jamesalanpreiss@gmail.com>
Tue, 2 Jun 2020 04:01:08 +0000 (21:01 -0700)
committerjpreiss <jamesalanpreiss@gmail.com>
Tue, 2 Jun 2020 04:03:17 +0000 (21:03 -0700)
test.c

diff --git a/test.c b/test.c
index d6e13f0..603d6d2 100644 (file)
--- a/test.c
+++ b/test.c
@@ -215,6 +215,37 @@ void test_qslerp()
        printf("%s passed\n", __func__);
 }
 
        printf("%s passed\n", __func__);
 }
 
+void test_quat_lowprecision()
+{
+       srand(20); // deterministic
+
+       int const N = 10000;
+
+       for (int i = 0; i < N; ++i) {
+               struct vec rpy = vscl(1e-2f, randcube());
+               struct quat exact = rpy2quat(rpy);
+               struct quat approx = rpy2quat_small(rpy);
+               assert(qanglebetween(exact, approx) < 1e-3f);
+       }
+
+       for (int i = 0; i < N; ++i) {
+               struct vec gyro = randsphere();
+               struct quat init = randquat();
+               int steps = 100;
+               float t = randu(0.1, 2.0);
+               float dt = t / steps;
+               struct quat q = init;
+               for (int j = 0; j < steps; ++j) {
+                       q = quat_gyro_update(q, gyro, dt);
+               }
+               struct quat target = qqmul(qaxisangle(gyro, t), init);
+               assert(qanglebetween(q, target) < 1e-6f);
+       }
+
+       printf("%s passed\n", __func__);
+}
+
+
 // micro test framework
 typedef void (*voidvoid_fn)(void);
 voidvoid_fn test_fns[] = {
 // micro test framework
 typedef void (*voidvoid_fn)(void);
 voidvoid_fn test_fns[] = {
@@ -223,6 +254,7 @@ voidvoid_fn test_fns[] = {
        test_quat_conversions,
        test_qvectovec,
        test_qslerp,
        test_quat_conversions,
        test_qvectovec,
        test_qslerp,
+       test_quat_lowprecision,
 };
 
 static int i_test = -1;
 };
 
 static int i_test = -1;