test_quaternion.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /**************************************************************************/
  2. /* test_quaternion.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef TEST_QUATERNION_H
  31. #define TEST_QUATERNION_H
  32. #include "core/math/math_defs.h"
  33. #include "core/math/math_funcs.h"
  34. #include "core/math/quaternion.h"
  35. #include "core/math/vector3.h"
  36. #include "tests/test_macros.h"
  37. namespace TestQuaternion {
  38. Quaternion quat_euler_yxz_deg(Vector3 angle) {
  39. double yaw = Math::deg_to_rad(angle[1]);
  40. double pitch = Math::deg_to_rad(angle[0]);
  41. double roll = Math::deg_to_rad(angle[2]);
  42. // Generate YXZ (Z-then-X-then-Y) Quaternion using single-axis Euler
  43. // constructor and quaternion product, both tested separately.
  44. Quaternion q_y = Quaternion::from_euler(Vector3(0.0, yaw, 0.0));
  45. Quaternion q_p = Quaternion::from_euler(Vector3(pitch, 0.0, 0.0));
  46. Quaternion q_r = Quaternion::from_euler(Vector3(0.0, 0.0, roll));
  47. // Roll-Z is followed by Pitch-X, then Yaw-Y.
  48. Quaternion q_yxz = q_y * q_p * q_r;
  49. return q_yxz;
  50. }
  51. TEST_CASE("[Quaternion] Default Construct") {
  52. Quaternion q;
  53. CHECK(q[0] == 0.0);
  54. CHECK(q[1] == 0.0);
  55. CHECK(q[2] == 0.0);
  56. CHECK(q[3] == 1.0);
  57. }
  58. TEST_CASE("[Quaternion] Construct x,y,z,w") {
  59. // Values are taken from actual use in another project & are valid (except roundoff error).
  60. Quaternion q(0.2391, 0.099, 0.3696, 0.8924);
  61. CHECK(q[0] == doctest::Approx(0.2391));
  62. CHECK(q[1] == doctest::Approx(0.099));
  63. CHECK(q[2] == doctest::Approx(0.3696));
  64. CHECK(q[3] == doctest::Approx(0.8924));
  65. }
  66. TEST_CASE("[Quaternion] Construct AxisAngle 1") {
  67. // Easy to visualize: 120 deg about X-axis.
  68. Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg_to_rad(120.0));
  69. // 0.866 isn't close enough; doctest::Approx doesn't cut much slack!
  70. CHECK(q[0] == doctest::Approx(0.866025)); // Sine of half the angle.
  71. CHECK(q[1] == doctest::Approx(0.0));
  72. CHECK(q[2] == doctest::Approx(0.0));
  73. CHECK(q[3] == doctest::Approx(0.5)); // Cosine of half the angle.
  74. }
  75. TEST_CASE("[Quaternion] Construct AxisAngle 2") {
  76. // Easy to visualize: 30 deg about Y-axis.
  77. Quaternion q(Vector3(0.0, 1.0, 0.0), Math::deg_to_rad(30.0));
  78. CHECK(q[0] == doctest::Approx(0.0));
  79. CHECK(q[1] == doctest::Approx(0.258819)); // Sine of half the angle.
  80. CHECK(q[2] == doctest::Approx(0.0));
  81. CHECK(q[3] == doctest::Approx(0.965926)); // Cosine of half the angle.
  82. }
  83. TEST_CASE("[Quaternion] Construct AxisAngle 3") {
  84. // Easy to visualize: 60 deg about Z-axis.
  85. Quaternion q(Vector3(0.0, 0.0, 1.0), Math::deg_to_rad(60.0));
  86. CHECK(q[0] == doctest::Approx(0.0));
  87. CHECK(q[1] == doctest::Approx(0.0));
  88. CHECK(q[2] == doctest::Approx(0.5)); // Sine of half the angle.
  89. CHECK(q[3] == doctest::Approx(0.866025)); // Cosine of half the angle.
  90. }
  91. TEST_CASE("[Quaternion] Construct AxisAngle 4") {
  92. // More complex & hard to visualize, so test w/ data from online calculator.
  93. Vector3 axis(1.0, 2.0, 0.5);
  94. Quaternion q(axis.normalized(), Math::deg_to_rad(35.0));
  95. CHECK(q[0] == doctest::Approx(0.131239));
  96. CHECK(q[1] == doctest::Approx(0.262478));
  97. CHECK(q[2] == doctest::Approx(0.0656194));
  98. CHECK(q[3] == doctest::Approx(0.953717));
  99. }
  100. TEST_CASE("[Quaternion] Construct from Quaternion") {
  101. Vector3 axis(1.0, 2.0, 0.5);
  102. Quaternion q_src(axis.normalized(), Math::deg_to_rad(35.0));
  103. Quaternion q(q_src);
  104. CHECK(q[0] == doctest::Approx(0.131239));
  105. CHECK(q[1] == doctest::Approx(0.262478));
  106. CHECK(q[2] == doctest::Approx(0.0656194));
  107. CHECK(q[3] == doctest::Approx(0.953717));
  108. }
  109. TEST_CASE("[Quaternion] Construct Euler SingleAxis") {
  110. double yaw = Math::deg_to_rad(45.0);
  111. double pitch = Math::deg_to_rad(30.0);
  112. double roll = Math::deg_to_rad(10.0);
  113. Vector3 euler_y(0.0, yaw, 0.0);
  114. Quaternion q_y = Quaternion::from_euler(euler_y);
  115. CHECK(q_y[0] == doctest::Approx(0.0));
  116. CHECK(q_y[1] == doctest::Approx(0.382684));
  117. CHECK(q_y[2] == doctest::Approx(0.0));
  118. CHECK(q_y[3] == doctest::Approx(0.923879));
  119. Vector3 euler_p(pitch, 0.0, 0.0);
  120. Quaternion q_p = Quaternion::from_euler(euler_p);
  121. CHECK(q_p[0] == doctest::Approx(0.258819));
  122. CHECK(q_p[1] == doctest::Approx(0.0));
  123. CHECK(q_p[2] == doctest::Approx(0.0));
  124. CHECK(q_p[3] == doctest::Approx(0.965926));
  125. Vector3 euler_r(0.0, 0.0, roll);
  126. Quaternion q_r = Quaternion::from_euler(euler_r);
  127. CHECK(q_r[0] == doctest::Approx(0.0));
  128. CHECK(q_r[1] == doctest::Approx(0.0));
  129. CHECK(q_r[2] == doctest::Approx(0.0871558));
  130. CHECK(q_r[3] == doctest::Approx(0.996195));
  131. }
  132. TEST_CASE("[Quaternion] Construct Euler YXZ dynamic axes") {
  133. double yaw = Math::deg_to_rad(45.0);
  134. double pitch = Math::deg_to_rad(30.0);
  135. double roll = Math::deg_to_rad(10.0);
  136. // Generate YXZ comparison data (Z-then-X-then-Y) using single-axis Euler
  137. // constructor and quaternion product, both tested separately.
  138. Vector3 euler_y(0.0, yaw, 0.0);
  139. Quaternion q_y = Quaternion::from_euler(euler_y);
  140. Vector3 euler_p(pitch, 0.0, 0.0);
  141. Quaternion q_p = Quaternion::from_euler(euler_p);
  142. Vector3 euler_r(0.0, 0.0, roll);
  143. Quaternion q_r = Quaternion::from_euler(euler_r);
  144. // Instrinsically, Yaw-Y then Pitch-X then Roll-Z.
  145. // Extrinsically, Roll-Z is followed by Pitch-X, then Yaw-Y.
  146. Quaternion check_yxz = q_y * q_p * q_r;
  147. // Test construction from YXZ Euler angles.
  148. Vector3 euler_yxz(pitch, yaw, roll);
  149. Quaternion q = Quaternion::from_euler(euler_yxz);
  150. CHECK(q[0] == doctest::Approx(check_yxz[0]));
  151. CHECK(q[1] == doctest::Approx(check_yxz[1]));
  152. CHECK(q[2] == doctest::Approx(check_yxz[2]));
  153. CHECK(q[3] == doctest::Approx(check_yxz[3]));
  154. CHECK(q.is_equal_approx(check_yxz));
  155. CHECK(q.get_euler().is_equal_approx(euler_yxz));
  156. CHECK(check_yxz.get_euler().is_equal_approx(euler_yxz));
  157. }
  158. TEST_CASE("[Quaternion] Construct Basis Euler") {
  159. double yaw = Math::deg_to_rad(45.0);
  160. double pitch = Math::deg_to_rad(30.0);
  161. double roll = Math::deg_to_rad(10.0);
  162. Vector3 euler_yxz(pitch, yaw, roll);
  163. Quaternion q_yxz = Quaternion::from_euler(euler_yxz);
  164. Basis basis_axes = Basis::from_euler(euler_yxz);
  165. Quaternion q(basis_axes);
  166. CHECK(q.is_equal_approx(q_yxz));
  167. }
  168. TEST_CASE("[Quaternion] Construct Basis Axes") {
  169. // Arbitrary Euler angles.
  170. Vector3 euler_yxz(Math::deg_to_rad(31.41), Math::deg_to_rad(-49.16), Math::deg_to_rad(12.34));
  171. // Basis vectors from online calculation of rotation matrix.
  172. Vector3 i_unit(0.5545787, 0.1823950, 0.8118957);
  173. Vector3 j_unit(-0.5249245, 0.8337420, 0.1712555);
  174. Vector3 k_unit(-0.6456754, -0.5211586, 0.5581192);
  175. // Quaternion from online calculation.
  176. Quaternion q_calc(0.2016913, -0.4245716, 0.206033, 0.8582598);
  177. // Quaternion from local calculation.
  178. Quaternion q_local = quat_euler_yxz_deg(Vector3(31.41, -49.16, 12.34));
  179. // Quaternion from Euler angles constructor.
  180. Quaternion q_euler = Quaternion::from_euler(euler_yxz);
  181. CHECK(q_calc.is_equal_approx(q_local));
  182. CHECK(q_local.is_equal_approx(q_euler));
  183. // Calculate Basis and construct Quaternion.
  184. // When this is written, C++ Basis class does not construct from basis vectors.
  185. // This is by design, but may be subject to change.
  186. // Workaround by constructing Basis from Euler angles.
  187. // basis_axes = Basis(i_unit, j_unit, k_unit);
  188. Basis basis_axes = Basis::from_euler(euler_yxz);
  189. Quaternion q(basis_axes);
  190. CHECK(basis_axes.get_column(0).is_equal_approx(i_unit));
  191. CHECK(basis_axes.get_column(1).is_equal_approx(j_unit));
  192. CHECK(basis_axes.get_column(2).is_equal_approx(k_unit));
  193. CHECK(q.is_equal_approx(q_calc));
  194. CHECK_FALSE(q.inverse().is_equal_approx(q_calc));
  195. CHECK(q.is_equal_approx(q_local));
  196. CHECK(q.is_equal_approx(q_euler));
  197. CHECK(q[0] == doctest::Approx(0.2016913));
  198. CHECK(q[1] == doctest::Approx(-0.4245716));
  199. CHECK(q[2] == doctest::Approx(0.206033));
  200. CHECK(q[3] == doctest::Approx(0.8582598));
  201. }
  202. TEST_CASE("[Quaternion] Get Euler Orders") {
  203. double x = Math::deg_to_rad(30.0);
  204. double y = Math::deg_to_rad(45.0);
  205. double z = Math::deg_to_rad(10.0);
  206. Vector3 euler(x, y, z);
  207. for (int i = 0; i < 6; i++) {
  208. EulerOrder order = (EulerOrder)i;
  209. Basis basis = Basis::from_euler(euler, order);
  210. Quaternion q = Quaternion(basis);
  211. Vector3 check = q.get_euler(order);
  212. CHECK_MESSAGE(check.is_equal_approx(euler),
  213. "Quaternion get_euler method should return the original angles.");
  214. CHECK_MESSAGE(check.is_equal_approx(basis.get_euler(order)),
  215. "Quaternion get_euler method should behave the same as Basis get_euler.");
  216. }
  217. }
  218. TEST_CASE("[Quaternion] Product (book)") {
  219. // Example from "Quaternions and Rotation Sequences" by Jack Kuipers, p. 108.
  220. Quaternion p(1.0, -2.0, 1.0, 3.0);
  221. Quaternion q(-1.0, 2.0, 3.0, 2.0);
  222. Quaternion pq = p * q;
  223. CHECK(pq[0] == doctest::Approx(-9.0));
  224. CHECK(pq[1] == doctest::Approx(-2.0));
  225. CHECK(pq[2] == doctest::Approx(11.0));
  226. CHECK(pq[3] == doctest::Approx(8.0));
  227. }
  228. TEST_CASE("[Quaternion] Product") {
  229. double yaw = Math::deg_to_rad(45.0);
  230. double pitch = Math::deg_to_rad(30.0);
  231. double roll = Math::deg_to_rad(10.0);
  232. Vector3 euler_y(0.0, yaw, 0.0);
  233. Quaternion q_y = Quaternion::from_euler(euler_y);
  234. CHECK(q_y[0] == doctest::Approx(0.0));
  235. CHECK(q_y[1] == doctest::Approx(0.382684));
  236. CHECK(q_y[2] == doctest::Approx(0.0));
  237. CHECK(q_y[3] == doctest::Approx(0.923879));
  238. Vector3 euler_p(pitch, 0.0, 0.0);
  239. Quaternion q_p = Quaternion::from_euler(euler_p);
  240. CHECK(q_p[0] == doctest::Approx(0.258819));
  241. CHECK(q_p[1] == doctest::Approx(0.0));
  242. CHECK(q_p[2] == doctest::Approx(0.0));
  243. CHECK(q_p[3] == doctest::Approx(0.965926));
  244. Vector3 euler_r(0.0, 0.0, roll);
  245. Quaternion q_r = Quaternion::from_euler(euler_r);
  246. CHECK(q_r[0] == doctest::Approx(0.0));
  247. CHECK(q_r[1] == doctest::Approx(0.0));
  248. CHECK(q_r[2] == doctest::Approx(0.0871558));
  249. CHECK(q_r[3] == doctest::Approx(0.996195));
  250. // Test ZYX dynamic-axes since test data is available online.
  251. // Rotate first about X axis, then new Y axis, then new Z axis.
  252. // (Godot uses YXZ Yaw-Pitch-Roll order).
  253. Quaternion q_yp = q_y * q_p;
  254. CHECK(q_yp[0] == doctest::Approx(0.239118));
  255. CHECK(q_yp[1] == doctest::Approx(0.369644));
  256. CHECK(q_yp[2] == doctest::Approx(-0.099046));
  257. CHECK(q_yp[3] == doctest::Approx(0.892399));
  258. Quaternion q_ryp = q_r * q_yp;
  259. CHECK(q_ryp[0] == doctest::Approx(0.205991));
  260. CHECK(q_ryp[1] == doctest::Approx(0.389078));
  261. CHECK(q_ryp[2] == doctest::Approx(-0.0208912));
  262. CHECK(q_ryp[3] == doctest::Approx(0.897636));
  263. }
  264. TEST_CASE("[Quaternion] xform unit vectors") {
  265. // Easy to visualize: 120 deg about X-axis.
  266. // Transform the i, j, & k unit vectors.
  267. Quaternion q(Vector3(1.0, 0.0, 0.0), Math::deg_to_rad(120.0));
  268. Vector3 i_t = q.xform(Vector3(1.0, 0.0, 0.0));
  269. Vector3 j_t = q.xform(Vector3(0.0, 1.0, 0.0));
  270. Vector3 k_t = q.xform(Vector3(0.0, 0.0, 1.0));
  271. //
  272. CHECK(i_t.is_equal_approx(Vector3(1.0, 0.0, 0.0)));
  273. CHECK(j_t.is_equal_approx(Vector3(0.0, -0.5, 0.866025)));
  274. CHECK(k_t.is_equal_approx(Vector3(0.0, -0.866025, -0.5)));
  275. CHECK(i_t.length_squared() == doctest::Approx(1.0));
  276. CHECK(j_t.length_squared() == doctest::Approx(1.0));
  277. CHECK(k_t.length_squared() == doctest::Approx(1.0));
  278. // Easy to visualize: 30 deg about Y-axis.
  279. q = Quaternion(Vector3(0.0, 1.0, 0.0), Math::deg_to_rad(30.0));
  280. i_t = q.xform(Vector3(1.0, 0.0, 0.0));
  281. j_t = q.xform(Vector3(0.0, 1.0, 0.0));
  282. k_t = q.xform(Vector3(0.0, 0.0, 1.0));
  283. //
  284. CHECK(i_t.is_equal_approx(Vector3(0.866025, 0.0, -0.5)));
  285. CHECK(j_t.is_equal_approx(Vector3(0.0, 1.0, 0.0)));
  286. CHECK(k_t.is_equal_approx(Vector3(0.5, 0.0, 0.866025)));
  287. CHECK(i_t.length_squared() == doctest::Approx(1.0));
  288. CHECK(j_t.length_squared() == doctest::Approx(1.0));
  289. CHECK(k_t.length_squared() == doctest::Approx(1.0));
  290. // Easy to visualize: 60 deg about Z-axis.
  291. q = Quaternion(Vector3(0.0, 0.0, 1.0), Math::deg_to_rad(60.0));
  292. i_t = q.xform(Vector3(1.0, 0.0, 0.0));
  293. j_t = q.xform(Vector3(0.0, 1.0, 0.0));
  294. k_t = q.xform(Vector3(0.0, 0.0, 1.0));
  295. //
  296. CHECK(i_t.is_equal_approx(Vector3(0.5, 0.866025, 0.0)));
  297. CHECK(j_t.is_equal_approx(Vector3(-0.866025, 0.5, 0.0)));
  298. CHECK(k_t.is_equal_approx(Vector3(0.0, 0.0, 1.0)));
  299. CHECK(i_t.length_squared() == doctest::Approx(1.0));
  300. CHECK(j_t.length_squared() == doctest::Approx(1.0));
  301. CHECK(k_t.length_squared() == doctest::Approx(1.0));
  302. }
  303. TEST_CASE("[Quaternion] xform vector") {
  304. // Arbitrary quaternion rotates an arbitrary vector.
  305. Vector3 euler_yzx(Math::deg_to_rad(31.41), Math::deg_to_rad(-49.16), Math::deg_to_rad(12.34));
  306. Basis basis_axes = Basis::from_euler(euler_yzx);
  307. Quaternion q(basis_axes);
  308. Vector3 v_arb(3.0, 4.0, 5.0);
  309. Vector3 v_rot = q.xform(v_arb);
  310. Vector3 v_compare = basis_axes.xform(v_arb);
  311. CHECK(v_rot.length_squared() == doctest::Approx(v_arb.length_squared()));
  312. CHECK(v_rot.is_equal_approx(v_compare));
  313. }
  314. // Test vector xform for a single combination of Quaternion and Vector.
  315. void test_quat_vec_rotate(Vector3 euler_yzx, Vector3 v_in) {
  316. Basis basis_axes = Basis::from_euler(euler_yzx);
  317. Quaternion q(basis_axes);
  318. Vector3 v_rot = q.xform(v_in);
  319. Vector3 v_compare = basis_axes.xform(v_in);
  320. CHECK(v_rot.length_squared() == doctest::Approx(v_in.length_squared()));
  321. CHECK(v_rot.is_equal_approx(v_compare));
  322. }
  323. TEST_CASE("[Stress][Quaternion] Many vector xforms") {
  324. // Many arbitrary quaternions rotate many arbitrary vectors.
  325. // For each trial, check that rotation by Quaternion yields same result as
  326. // rotation by Basis.
  327. const int STEPS = 100; // Number of test steps in each dimension
  328. const double delta = 2.0 * Math_PI / STEPS; // Angle increment per step
  329. const double delta_vec = 20.0 / STEPS; // Vector increment per step
  330. Vector3 vec_arb(1.0, 1.0, 1.0);
  331. double x_angle = -Math_PI;
  332. double y_angle = -Math_PI;
  333. double z_angle = -Math_PI;
  334. for (double i = 0; i < STEPS; ++i) {
  335. vec_arb[0] = -10.0 + i * delta_vec;
  336. x_angle = i * delta - Math_PI;
  337. for (double j = 0; j < STEPS; ++j) {
  338. vec_arb[1] = -10.0 + j * delta_vec;
  339. y_angle = j * delta - Math_PI;
  340. for (double k = 0; k < STEPS; ++k) {
  341. vec_arb[2] = -10.0 + k * delta_vec;
  342. z_angle = k * delta - Math_PI;
  343. Vector3 euler_yzx(x_angle, y_angle, z_angle);
  344. test_quat_vec_rotate(euler_yzx, vec_arb);
  345. }
  346. }
  347. }
  348. }
  349. TEST_CASE("[Quaternion] Finite number checks") {
  350. const real_t x = NAN;
  351. CHECK_MESSAGE(
  352. Quaternion(0, 1, 2, 3).is_finite(),
  353. "Quaternion with all components finite should be finite");
  354. CHECK_FALSE_MESSAGE(
  355. Quaternion(x, 1, 2, 3).is_finite(),
  356. "Quaternion with one component infinite should not be finite.");
  357. CHECK_FALSE_MESSAGE(
  358. Quaternion(0, x, 2, 3).is_finite(),
  359. "Quaternion with one component infinite should not be finite.");
  360. CHECK_FALSE_MESSAGE(
  361. Quaternion(0, 1, x, 3).is_finite(),
  362. "Quaternion with one component infinite should not be finite.");
  363. CHECK_FALSE_MESSAGE(
  364. Quaternion(0, 1, 2, x).is_finite(),
  365. "Quaternion with one component infinite should not be finite.");
  366. CHECK_FALSE_MESSAGE(
  367. Quaternion(x, x, 2, 3).is_finite(),
  368. "Quaternion with two components infinite should not be finite.");
  369. CHECK_FALSE_MESSAGE(
  370. Quaternion(x, 1, x, 3).is_finite(),
  371. "Quaternion with two components infinite should not be finite.");
  372. CHECK_FALSE_MESSAGE(
  373. Quaternion(x, 1, 2, x).is_finite(),
  374. "Quaternion with two components infinite should not be finite.");
  375. CHECK_FALSE_MESSAGE(
  376. Quaternion(0, x, x, 3).is_finite(),
  377. "Quaternion with two components infinite should not be finite.");
  378. CHECK_FALSE_MESSAGE(
  379. Quaternion(0, x, 2, x).is_finite(),
  380. "Quaternion with two components infinite should not be finite.");
  381. CHECK_FALSE_MESSAGE(
  382. Quaternion(0, 1, x, x).is_finite(),
  383. "Quaternion with two components infinite should not be finite.");
  384. CHECK_FALSE_MESSAGE(
  385. Quaternion(0, x, x, x).is_finite(),
  386. "Quaternion with three components infinite should not be finite.");
  387. CHECK_FALSE_MESSAGE(
  388. Quaternion(x, 1, x, x).is_finite(),
  389. "Quaternion with three components infinite should not be finite.");
  390. CHECK_FALSE_MESSAGE(
  391. Quaternion(x, x, 2, x).is_finite(),
  392. "Quaternion with three components infinite should not be finite.");
  393. CHECK_FALSE_MESSAGE(
  394. Quaternion(x, x, x, 3).is_finite(),
  395. "Quaternion with three components infinite should not be finite.");
  396. CHECK_FALSE_MESSAGE(
  397. Quaternion(x, x, x, x).is_finite(),
  398. "Quaternion with four components infinite should not be finite.");
  399. }
  400. } // namespace TestQuaternion
  401. #endif // TEST_QUATERNION_H