From: jpreiss Date: Tue, 2 Jun 2020 04:01:08 +0000 (-0700) Subject: quat low precision ops testing X-Git-Url: https://git.owens.tech/assets/static/dummy.html/assets/static/dummy.html/git?a=commitdiff_plain;h=36368fb32f15f69f2bd6ee5a3b1bcb19b120fb33;p=forks%2Fcmath3d.git quat low precision ops testing --- 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;