From 36368fb32f15f69f2bd6ee5a3b1bcb19b120fb33 Mon Sep 17 00:00:00 2001
From: jpreiss <jamesalanpreiss@gmail.com>
Date: Mon, 1 Jun 2020 21:01:08 -0700
Subject: [PATCH] quat low precision ops testing

---
 test.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/test.c b/test.c
index d6e13f0..603d6d2 100644
--- a/test.c
+++ b/test.c
@@ -215,6 +215,37 @@ void test_qslerp()
 	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[] = {
@@ -223,6 +254,7 @@ voidvoid_fn test_fns[] = {
 	test_quat_conversions,
 	test_qvectovec,
 	test_qslerp,
+	test_quat_lowprecision,
 };
 
 static int i_test = -1;
-- 
2.20.1