QuatTests.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "UnitTestFramework.h"
  5. #include <Jolt/Math/Mat44.h>
  6. #include <Jolt/Math/Quat.h>
  7. #include <Jolt/Core/StringTools.h>
  8. #include <random>
  9. TEST_SUITE("QuatTests")
  10. {
  11. TEST_CASE("TestQuatSetXYZW")
  12. {
  13. Quat q(0, 0, 0, 0);
  14. CHECK(q == Quat(0, 0, 0, 0));
  15. q.SetX(1);
  16. q.SetY(2);
  17. q.SetZ(3);
  18. q.SetW(4);
  19. CHECK(q == Quat(1, 2, 3, 4));
  20. q.Set(4, 3, 2, 1);
  21. CHECK(q == Quat(4, 3, 2, 1));
  22. }
  23. TEST_CASE("TestQuatEqual")
  24. {
  25. CHECK(Quat(1, 2, 3, 4) == Quat(1, 2, 3, 4));
  26. CHECK(Quat(1, 2, 3, 4) != Quat(0, 2, 3, 4));
  27. CHECK(Quat(1, 2, 3, 4) != Quat(1, 0, 3, 4));
  28. CHECK(Quat(1, 2, 3, 4) != Quat(1, 2, 0, 4));
  29. CHECK(Quat(1, 2, 3, 4) != Quat(1, 2, 3, 0));
  30. }
  31. TEST_CASE("TestQuatZero")
  32. {
  33. Quat zero = Quat::sZero();
  34. CHECK(zero == Quat(0, 0, 0, 0));
  35. }
  36. TEST_CASE("TestQuatIdentity")
  37. {
  38. Quat identity = Quat::sIdentity();
  39. CHECK_APPROX_EQUAL(identity.GetX(), 0.0f);
  40. CHECK_APPROX_EQUAL(identity.GetY(), 0.0f);
  41. CHECK_APPROX_EQUAL(identity.GetZ(), 0.0f);
  42. CHECK_APPROX_EQUAL(identity.GetW(), 1.0f);
  43. }
  44. TEST_CASE("TestQuatIsNaN")
  45. {
  46. CHECK(Quat(numeric_limits<float>::quiet_NaN(), 0, 0, 0).IsNaN());
  47. CHECK(Quat(0, numeric_limits<float>::quiet_NaN(), 0, 0).IsNaN());
  48. CHECK(Quat(0, 0, numeric_limits<float>::quiet_NaN(), 0).IsNaN());
  49. CHECK(Quat(0, 0, 0, numeric_limits<float>::quiet_NaN()).IsNaN());
  50. }
  51. TEST_CASE("TestQuatOperators")
  52. {
  53. CHECK(-Quat(1, 2, 3, 4) == Quat(-1, -2, -3, -4));
  54. CHECK(Quat(1, 2, 3, 4) + Quat(5, 6, 7, 8) == Quat(6, 8, 10, 12));
  55. CHECK(Quat(5, 6, 7, 8) - Quat(4, 3, 2, 1) == Quat(1, 3, 5, 7));
  56. CHECK(Quat(1, 2, 3, 4) * 5.0f == Quat(5, 10, 15, 20));
  57. CHECK(5.0f * Quat(1, 2, 3, 4) == Quat(5, 10, 15, 20));
  58. CHECK(Quat(2, 4, 6, 8) / 2.0f == Quat(1, 2, 3, 4));
  59. Quat v(1, 2, 3, 4);
  60. v += Quat(5, 6, 7, 8);
  61. CHECK(v == Quat(6, 8, 10, 12));
  62. v -= Quat(4, 3, 2, 1);
  63. CHECK(v == Quat(2, 5, 8, 11));
  64. v *= 2.0f;
  65. CHECK(v == Quat(4, 10, 16, 22));
  66. v /= 2.0f;
  67. CHECK(v == Quat(2, 5, 8, 11));
  68. }
  69. TEST_CASE("TestQuatPerpendicular")
  70. {
  71. Quat q1(1, 2, 3, 4);
  72. CHECK(q1.GetPerpendicular().Dot(q1) == 0.0f);
  73. Quat q2(-5, 4, -3, 2);
  74. CHECK(q2.GetPerpendicular().Dot(q2) == 0.0f);
  75. }
  76. TEST_CASE("TestQuatNormalized")
  77. {
  78. CHECK(Quat(1, 0, 0, 0).IsNormalized());
  79. CHECK(Quat(-0.7071067f, 0.7071067f, 0, 0).IsNormalized());
  80. CHECK(Quat(0.5773502f, -0.5773502f, 0.5773502f, 0).IsNormalized());
  81. CHECK(Quat(0.5f, -0.5f, 0.5f, -0.5f).IsNormalized());
  82. CHECK(!Quat(2, 0, 0, 0).IsNormalized());
  83. CHECK(!Quat(0, 2, 0, 0).IsNormalized());
  84. CHECK(!Quat(0, 0, 2, 0).IsNormalized());
  85. CHECK(!Quat(0, 0, 0, 2).IsNormalized());
  86. }
  87. TEST_CASE("TestQuatConvertMatrix")
  88. {
  89. UnitTestRandom random;
  90. uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
  91. for (int i = 0; i < 1000; ++i)
  92. {
  93. Vec3 axis = Vec3::sRandom(random);
  94. float angle = zero_to_two_pi(random);
  95. Mat44 m1 = Mat44::sRotation(axis, angle);
  96. Quat q1 = m1.GetQuaternion();
  97. Quat q2 = Quat::sRotation(axis, angle);
  98. CHECK_APPROX_EQUAL(q1, q2);
  99. Mat44 m2 = Mat44::sRotation(q2);
  100. CHECK_APPROX_EQUAL(m1, m2);
  101. }
  102. }
  103. TEST_CASE("TestQuatMultiplyVec3")
  104. {
  105. UnitTestRandom random;
  106. uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
  107. for (int i = 0; i < 1000; ++i)
  108. {
  109. Vec3 axis = Vec3::sRandom(random);
  110. float angle = zero_to_two_pi(random);
  111. Mat44 m1 = Mat44::sRotation(axis, angle);
  112. Quat q1 = Quat::sRotation(axis, angle);
  113. Vec3 rv = 10.0f * Vec3::sRandom(random);
  114. Vec3 r1 = m1 * rv;
  115. Vec3 r2 = q1 * rv;
  116. CHECK_APPROX_EQUAL(r1, r2, 1.0e-5f);
  117. Vec3 r3 = q1.InverseRotate(r2);
  118. CHECK_APPROX_EQUAL(r3, rv, 1.0e-5f);
  119. }
  120. }
  121. TEST_CASE("TestQuatRotateAxisXYZ")
  122. {
  123. UnitTestRandom random;
  124. uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
  125. for (int i = 0; i < 1000; ++i)
  126. {
  127. Vec3 axis = Vec3::sRandom(random);
  128. float angle = zero_to_two_pi(random);
  129. Quat q1 = Quat::sRotation(axis, angle);
  130. Vec3 r1 = q1 * Vec3::sAxisX();
  131. Vec3 r2 = q1.RotateAxisX();
  132. CHECK_APPROX_EQUAL(r1, r2, 1.0e-5f);
  133. r1 = q1 * Vec3::sAxisY();
  134. r2 = q1.RotateAxisY();
  135. CHECK_APPROX_EQUAL(r1, r2, 1.0e-5f);
  136. r1 = q1 * Vec3::sAxisZ();
  137. r2 = q1.RotateAxisZ();
  138. CHECK_APPROX_EQUAL(r1, r2, 1.0e-5f);
  139. }
  140. }
  141. TEST_CASE("TestQuatMultiplyQuat")
  142. {
  143. {
  144. // We use a right handed system, so test that: i * j = k
  145. Quat r1 = Quat(1, 0, 0, 0) * Quat(0, 1, 0, 0);
  146. Quat r2 = Quat(0, 0, 1, 0);
  147. CHECK(r1.IsClose(r2));
  148. }
  149. {
  150. // Test: j * i = -k
  151. Quat r1 = Quat(0, 1, 0, 0) * Quat(1, 0, 0, 0);
  152. Quat r2 = Quat(0, 0, -1, 0);
  153. CHECK(r1.IsClose(r2));
  154. }
  155. {
  156. // Test predefined multiplication
  157. Quat r1 = Quat(2, 3, 4, 1) * Quat(6, 7, 8, 5);
  158. Quat r2 = Quat(12, 30, 24, -60);
  159. CHECK(r1.IsClose(r2));
  160. }
  161. // Compare random matrix multiplications with quaternion multiplications
  162. UnitTestRandom random;
  163. uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
  164. for (int i = 0; i < 1000; ++i)
  165. {
  166. Vec3 axis1 = Vec3::sRandom(random);
  167. float angle1 = zero_to_two_pi(random);
  168. Quat q1 = Quat::sRotation(axis1, angle1);
  169. Mat44 m1 = Mat44::sRotation(axis1, angle1);
  170. Vec3 axis2 = Vec3::sRandom(random);
  171. float angle2 = zero_to_two_pi(random);
  172. Quat q2 = Quat::sRotation(axis2, angle2);
  173. Mat44 m2 = Mat44::sRotation(axis2, angle2);
  174. Quat r1 = q1 * q2;
  175. Quat r2 = (m1 * m2).GetQuaternion();
  176. CHECK_APPROX_EQUAL(r1, r2);
  177. }
  178. }
  179. TEST_CASE("TestQuatRotationAxisAngle")
  180. {
  181. Mat44 r1 = Mat44::sRotation(Vec3(1, 0, 0), 0.1f * JPH_PI);
  182. Mat44 r2 = Mat44::sRotation(Quat::sRotation(Vec3(1, 0, 0), 0.1f * JPH_PI));
  183. CHECK_APPROX_EQUAL(r1, r2);
  184. r1 = Mat44::sRotation(Vec3(0, 1, 0), 0.2f * JPH_PI);
  185. r2 = Mat44::sRotation(Quat::sRotation(Vec3(0, 1, 0), 0.2f * JPH_PI));
  186. CHECK_APPROX_EQUAL(r1, r2);
  187. r1 = Mat44::sRotation(Vec3(0, 0, 1), 0.3f * JPH_PI);
  188. r2 = Mat44::sRotation(Quat::sRotation(Vec3(0, 0, 1), 0.3f * JPH_PI));
  189. CHECK_APPROX_EQUAL(r1, r2);
  190. }
  191. TEST_CASE("TestQuatGetAxisAngle")
  192. {
  193. // Test identity rotation
  194. {
  195. Vec3 axis;
  196. float angle;
  197. Quat::sIdentity().GetAxisAngle(axis, angle);
  198. CHECK_APPROX_EQUAL(Vec3::sZero(), axis);
  199. CHECK_APPROX_EQUAL(0.0f, angle);
  200. }
  201. {
  202. Vec3 axis;
  203. float angle;
  204. (-Quat::sIdentity()).GetAxisAngle(axis, angle);
  205. CHECK_APPROX_EQUAL(Vec3::sZero(), axis);
  206. CHECK_APPROX_EQUAL(0.0f, angle);
  207. }
  208. // Test positive rotation
  209. Quat q1 = Quat::sRotation(Vec3(0, 1, 0), 0.2f * JPH_PI);
  210. {
  211. Vec3 axis;
  212. float angle;
  213. q1.GetAxisAngle(axis, angle);
  214. CHECK_APPROX_EQUAL(Vec3(0, 1, 0), axis);
  215. CHECK_APPROX_EQUAL(0.2f * JPH_PI, angle, 1.0e-5f);
  216. }
  217. {
  218. Vec3 axis;
  219. float angle;
  220. (-q1).GetAxisAngle(axis, angle);
  221. CHECK_APPROX_EQUAL(Vec3(0, 1, 0), axis);
  222. CHECK_APPROX_EQUAL(0.2f * JPH_PI, angle, 1.0e-5f);
  223. }
  224. // Test negative rotation
  225. Quat q2 = Quat::sRotation(Vec3(0, 1, 0), -0.2f * JPH_PI);
  226. {
  227. Vec3 axis;
  228. float angle;
  229. q2.GetAxisAngle(axis, angle);
  230. CHECK_APPROX_EQUAL(Vec3(0, -1, 0), axis);
  231. CHECK_APPROX_EQUAL(0.2f * JPH_PI, angle, 1.0e-5f);
  232. }
  233. {
  234. Vec3 axis;
  235. float angle;
  236. (-q2).GetAxisAngle(axis, angle);
  237. CHECK_APPROX_EQUAL(Vec3(0, -1, 0), axis);
  238. CHECK_APPROX_EQUAL(0.2f * JPH_PI, angle, 1.0e-5f);
  239. }
  240. // Test keeping range between [0, PI]
  241. Quat q3 = Quat::sRotation(Vec3(0, 1, 0), 1.1f * JPH_PI);
  242. {
  243. Vec3 axis;
  244. float angle;
  245. q3.GetAxisAngle(axis, angle);
  246. CHECK_APPROX_EQUAL(Vec3(0, -1, 0), axis);
  247. CHECK_APPROX_EQUAL(0.9f * JPH_PI, angle, 1.0e-5f);
  248. }
  249. {
  250. Vec3 axis;
  251. float angle;
  252. (-q3).GetAxisAngle(axis, angle);
  253. CHECK_APPROX_EQUAL(Vec3(0, -1, 0), axis);
  254. CHECK_APPROX_EQUAL(0.9f * JPH_PI, angle, 1.0e-5f);
  255. }
  256. }
  257. TEST_CASE("TestQuatInverse")
  258. {
  259. UnitTestRandom random;
  260. uniform_real_distribution<float> zero_to_two_pi(0.0f, 2.0f * JPH_PI);
  261. for (int i = 0; i < 1000; ++i)
  262. {
  263. Vec3 axis = Vec3::sRandom(random);
  264. float angle = zero_to_two_pi(random);
  265. Quat q1 = Quat::sRotation(axis, angle);
  266. Quat q2 = q1.Inversed();
  267. CHECK_APPROX_EQUAL(Quat::sIdentity(), q1 * q2);
  268. }
  269. }
  270. TEST_CASE("TestQuatConjugate")
  271. {
  272. CHECK(Quat(1, 2, 3, 4).Conjugated() == Quat(-1, -2, -3, 4));
  273. CHECK(Quat(-1, -2, -3, -4).Conjugated() == Quat(1, 2, 3, -4));
  274. }
  275. TEST_CASE("TestQuatEnsureWPositive")
  276. {
  277. CHECK(Quat(1, -2, 3, -4).EnsureWPositive() == Quat(-1, 2, -3, 4));
  278. CHECK(Quat(-4, 5, -6, 7).EnsureWPositive() == Quat(-4, 5, -6, 7));
  279. CHECK(Quat(1, 2, 3, 0).EnsureWPositive() == Quat(1, 2, 3, 0));
  280. }
  281. TEST_CASE("TestQuatStoreFloat3")
  282. {
  283. Float3 q1;
  284. Quat(0.7071067f, 0, 0, -0.7071067f).StoreFloat3(&q1);
  285. CHECK(q1 == Float3(-0.7071067f, 0, 0));
  286. Float3 q2;
  287. Quat(0, 0.7071067f, 0, 0.7071067f).StoreFloat3(&q2);
  288. CHECK(q2 == Float3(0, 0.7071067f, 0));
  289. Float3 q3;
  290. Quat(0, 0, 1, 0).StoreFloat3(&q3);
  291. CHECK(q3 == Float3(0, 0, 1));
  292. }
  293. TEST_CASE("TestQuatGetTwistAxis")
  294. {
  295. Quat q1 = Quat::sRotation(Vec3::sAxisX(), DegreesToRadians(-10.0f));
  296. Quat q2 = Quat::sRotation(Vec3::sAxisY(), DegreesToRadians(20.0f));
  297. Quat q = q1 * q2;
  298. Quat twist1 = q.GetTwist(Vec3::sAxisX());
  299. CHECK_APPROX_EQUAL(twist1, q1);
  300. Quat swing1 = twist1.Inversed() * q;
  301. CHECK_APPROX_EQUAL(swing1, q2);
  302. Quat twist2 = swing1.GetTwist(Vec3::sAxisY());
  303. CHECK_APPROX_EQUAL(twist2, q2);
  304. Quat swing2 = twist2.Inversed() * swing1;
  305. CHECK_APPROX_EQUAL(swing2, Quat::sIdentity());
  306. CHECK(Quat::sZero().GetTwist(Vec3::sAxisX()) == Quat::sIdentity());
  307. }
  308. TEST_CASE("TestQuatGetRotationAngle")
  309. {
  310. Quat q1 = Quat::sRotation(Vec3::sAxisX(), DegreesToRadians(-10.0f));
  311. Quat q2 = Quat::sRotation(Vec3::sAxisY(), DegreesToRadians(20.0f));
  312. Quat q3 = Quat::sRotation(Vec3::sAxisZ(), DegreesToRadians(-95.0f));
  313. float a = q1.GetRotationAngle(Vec3::sAxisX());
  314. CHECK_APPROX_EQUAL(a, DegreesToRadians(-10.0f), 1.0e-5f);
  315. a = q2.GetRotationAngle(Vec3::sAxisY());
  316. CHECK_APPROX_EQUAL(a, DegreesToRadians(20.0f), 1.0e-5f);
  317. a = q3.GetRotationAngle(Vec3::sAxisZ());
  318. CHECK_APPROX_EQUAL(a, DegreesToRadians(-95.0f), 1.0e-5f);
  319. a = (q1 * q2).GetRotationAngle(Vec3::sAxisX());
  320. CHECK_APPROX_EQUAL(a, DegreesToRadians(-10.0f), 1.0e-5f);
  321. a = (q3 * q1).GetRotationAngle(Vec3::sAxisX());
  322. CHECK_APPROX_EQUAL(a, DegreesToRadians(-10.0f), 1.0e-5f);
  323. }
  324. TEST_CASE("TestQuatGetEulerAngles")
  325. {
  326. Vec3 input(DegreesToRadians(-10.0f), DegreesToRadians(20.0f), DegreesToRadians(-95.0f));
  327. Quat qx = Quat::sRotation(Vec3::sAxisX(), input.GetX());
  328. Quat qy = Quat::sRotation(Vec3::sAxisY(), input.GetY());
  329. Quat qz = Quat::sRotation(Vec3::sAxisZ(), input.GetZ());
  330. Quat q = qz * qy * qx;
  331. Quat q2 = Quat::sEulerAngles(input);
  332. CHECK_APPROX_EQUAL(q, q2);
  333. Vec3 angles = q2.GetEulerAngles();
  334. CHECK_APPROX_EQUAL(angles, input);
  335. }
  336. TEST_CASE("TestQuatRotationFromTo")
  337. {
  338. {
  339. // Parallel vectors
  340. Vec3 v1(10, 0, 0);
  341. Vec3 v2(20, 0, 0);
  342. Quat q = Quat::sFromTo(v1, v2);
  343. CHECK_APPROX_EQUAL(q, Quat::sIdentity());
  344. }
  345. {
  346. // Perpendicular vectors
  347. Vec3 v1(10, 0, 0);
  348. Vec3 v2(0, 20, 0);
  349. Quat q = Quat::sFromTo(v1, v2);
  350. CHECK_APPROX_EQUAL(v2.Normalized(), (q * v1).Normalized());
  351. }
  352. {
  353. // Vectors with 180 degree angle
  354. Vec3 v1(10, 0, 0);
  355. Vec3 v2(-20, 0, 0);
  356. Quat q = Quat::sFromTo(v1, v2);
  357. CHECK_APPROX_EQUAL(v2.Normalized(), (q * v1).Normalized());
  358. }
  359. {
  360. // Test v1 zero
  361. Vec3 v1 = Vec3::sZero();
  362. Vec3 v2(10, 0, 0);
  363. Quat q = Quat::sFromTo(v1, v2);
  364. CHECK(q == Quat::sIdentity());
  365. }
  366. {
  367. // Test v2 zero
  368. Vec3 v1(10, 0, 0);
  369. Vec3 v2 = Vec3::sZero();
  370. Quat q = Quat::sFromTo(v1, v2);
  371. CHECK(q == Quat::sIdentity());
  372. }
  373. {
  374. // Length of a vector is squared inside the function: try with sqrt(FLT_MIN) to see if that still returns a valid rotation
  375. Vec3 v1(0, sqrt(FLT_MIN), 0);
  376. Vec3 v2(1, 0, 0);
  377. Quat q = Quat::sFromTo(v1, v2);
  378. CHECK_APPROX_EQUAL(v2.Normalized(), (q * v1).Normalized());
  379. }
  380. }
  381. TEST_CASE("TestQuatRotationFromToRandom")
  382. {
  383. UnitTestRandom random;
  384. uniform_real_distribution<float> one_to_ten(1.0f, 10.0f);
  385. for (int i = 0; i < 1000; ++i)
  386. {
  387. Vec3 v1 = one_to_ten(random) * Vec3::sRandom(random);
  388. Vec3 v2 = one_to_ten(random) * Vec3::sRandom(random);
  389. Quat q = Quat::sFromTo(v1, v2);
  390. Vec3 v1t = (q * v1).Normalized();
  391. Vec3 v2t = v2.Normalized();
  392. CHECK_APPROX_EQUAL(v2t, v1t, 1.0e-5f);
  393. }
  394. }
  395. TEST_CASE("TestQuatConvertToString")
  396. {
  397. Quat v(1, 2, 3, 4);
  398. CHECK(ConvertToString(v) == "1, 2, 3, 4");
  399. }
  400. TEST_CASE("TestQuatLERP")
  401. {
  402. Quat v1(1, 2, 3, 4);
  403. Quat v2(5, 6, 7, 8);
  404. CHECK(v1.LERP(v2, 0.25f) == Quat(2, 3, 4, 5));
  405. }
  406. TEST_CASE("TestQuatSLERP")
  407. {
  408. Quat v1 = Quat::sIdentity();
  409. Quat v2 = Quat::sRotation(Vec3::sAxisX(), 0.99f * JPH_PI);
  410. CHECK_APPROX_EQUAL(v1.SLERP(v2, 0.25f), Quat::sRotation(Vec3::sAxisX(), 0.25f * 0.99f * JPH_PI));
  411. // Check that we ignore the sign
  412. Quat v3 = Quat(1, 2, 3, 4).Normalized();
  413. CHECK_APPROX_EQUAL(v3.SLERP(-v3, 0.5f), v3);
  414. }
  415. TEST_CASE("TestQuatMultiplyImaginary")
  416. {
  417. UnitTestRandom random;
  418. for (int i = 0; i < 1000; ++i)
  419. {
  420. Vec3 imaginary = Vec3::sRandom(random);
  421. Quat quat = Quat::sRandom(random);
  422. Quat r1 = Quat::sMultiplyImaginary(imaginary, quat);
  423. Quat r2 = Quat(Vec4(imaginary, 0)) * quat;
  424. CHECK_APPROX_EQUAL(r1, r2);
  425. }
  426. }
  427. TEST_CASE("TestQuatCompressUnitQuat")
  428. {
  429. UnitTestRandom random;
  430. for (int i = 0; i < 1000; ++i)
  431. {
  432. Quat quat = Quat::sRandom(random);
  433. uint32 compressed = quat.CompressUnitQuat();
  434. Quat decompressed = Quat::sDecompressUnitQuat(compressed);
  435. Vec3 axis;
  436. float angle;
  437. (quat * decompressed.Conjugated()).GetAxisAngle(axis, angle);
  438. CHECK(abs(angle) < 0.009f);
  439. }
  440. }
  441. }