Blender V5.3
BLI_math_rotation_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
7#include "BLI_math_base_c.hh"
12#include "BLI_math_vector.hh"
13
14#include "BLI_vector.hh"
15
16#include <cmath>
17
18namespace blender {
19
20/* Test that quaternion converts to itself via matrix. */
21static void test_quat_to_mat_to_quat(float w, float x, float y, float z)
22{
23 float in_quat[4] = {w, x, y, z};
24 float norm_quat[4], matrix[3][3], out_quat[4];
25
26 normalize_qt_qt(norm_quat, in_quat);
27 quat_to_mat3(matrix, norm_quat);
28 mat3_normalized_to_quat(out_quat, matrix);
29
30 /* The expected result is flipped (each orientation corresponds to 2 quaternions). */
31 if (w < 0) {
32 mul_qt_fl(norm_quat, -1);
33 }
34
35 EXPECT_V4_NEAR(norm_quat, out_quat, FLT_EPSILON);
36}
37
38TEST(math_rotation, quat_to_mat_to_quat_rot180)
39{
40 test_quat_to_mat_to_quat(1, 0, 0, 0);
41 test_quat_to_mat_to_quat(0, 1, 0, 0);
42 test_quat_to_mat_to_quat(0, 0, 1, 0);
43 test_quat_to_mat_to_quat(0, 0, 0, 1);
44}
45
46TEST(math_rotation, quat_to_mat_to_quat_rot180n)
47{
48 test_quat_to_mat_to_quat(-1.000f, 0, 0, 0);
49 test_quat_to_mat_to_quat(-1e-20f, -1, 0, 0);
50 test_quat_to_mat_to_quat(-1e-20f, 0, -1, 0);
51 test_quat_to_mat_to_quat(-1e-20f, 0, 0, -1);
52}
53
54TEST(math_rotation, quat_to_mat_to_quat_rot90)
55{
56 const float s2 = 1 / sqrtf(2);
57 test_quat_to_mat_to_quat(s2, s2, 0, 0);
58 test_quat_to_mat_to_quat(s2, -s2, 0, 0);
59 test_quat_to_mat_to_quat(s2, 0, s2, 0);
60 test_quat_to_mat_to_quat(s2, 0, -s2, 0);
61 test_quat_to_mat_to_quat(s2, 0, 0, s2);
62 test_quat_to_mat_to_quat(s2, 0, 0, -s2);
63}
64
65TEST(math_rotation, quat_to_mat_to_quat_rot90n)
66{
67 const float s2 = 1 / sqrtf(2);
68 test_quat_to_mat_to_quat(-s2, s2, 0, 0);
69 test_quat_to_mat_to_quat(-s2, -s2, 0, 0);
70 test_quat_to_mat_to_quat(-s2, 0, s2, 0);
71 test_quat_to_mat_to_quat(-s2, 0, -s2, 0);
72 test_quat_to_mat_to_quat(-s2, 0, 0, s2);
73 test_quat_to_mat_to_quat(-s2, 0, 0, -s2);
74}
75
76TEST(math_rotation, quat_to_mat_to_quat_bad_T83196)
77{
78 test_quat_to_mat_to_quat(0.0032f, 0.9999f, -0.0072f, -0.0100f);
79 test_quat_to_mat_to_quat(0.0058f, 0.9999f, -0.0090f, -0.0101f);
80 test_quat_to_mat_to_quat(0.0110f, 0.9998f, -0.0140f, -0.0104f);
81 test_quat_to_mat_to_quat(0.0142f, 0.9997f, -0.0192f, -0.0107f);
82 test_quat_to_mat_to_quat(0.0149f, 0.9996f, -0.0212f, -0.0107f);
83}
84
85TEST(math_rotation, quat_to_mat_to_quat_bad_negative)
86{
87 /* This shouldn't produce a negative q[0]. */
88 test_quat_to_mat_to_quat(0.5f - 1e-6f, 0, -sqrtf(3) / 2 - 1e-6f, 0);
89}
90
91TEST(math_rotation, quat_to_mat_to_quat_near_1000)
92{
93 test_quat_to_mat_to_quat(0.9999f, 0.01f, -0.001f, -0.01f);
94 test_quat_to_mat_to_quat(0.9999f, 0.02f, -0.002f, -0.02f);
95 test_quat_to_mat_to_quat(0.9999f, 0.03f, -0.003f, -0.03f);
96 test_quat_to_mat_to_quat(0.9999f, 0.04f, -0.004f, -0.04f);
97 test_quat_to_mat_to_quat(0.9999f, 0.05f, -0.005f, -0.05f);
98 test_quat_to_mat_to_quat(0.999f, 0.10f, -0.010f, -0.10f);
99 test_quat_to_mat_to_quat(0.99f, 0.15f, -0.015f, -0.15f);
100 test_quat_to_mat_to_quat(0.98f, 0.20f, -0.020f, -0.20f);
101 test_quat_to_mat_to_quat(0.97f, 0.25f, -0.025f, -0.25f);
102 test_quat_to_mat_to_quat(0.95f, 0.30f, -0.030f, -0.30f);
103}
104
105TEST(math_rotation, quat_to_mat_to_quat_near_0100)
106{
107 test_quat_to_mat_to_quat(0.01f, 0.9999f, -0.001f, -0.01f);
108 test_quat_to_mat_to_quat(0.02f, 0.9999f, -0.002f, -0.02f);
109 test_quat_to_mat_to_quat(0.03f, 0.9999f, -0.003f, -0.03f);
110 test_quat_to_mat_to_quat(0.04f, 0.9999f, -0.004f, -0.04f);
111 test_quat_to_mat_to_quat(0.05f, 0.9999f, -0.005f, -0.05f);
112 test_quat_to_mat_to_quat(0.10f, 0.999f, -0.010f, -0.10f);
113 test_quat_to_mat_to_quat(0.15f, 0.99f, -0.015f, -0.15f);
114 test_quat_to_mat_to_quat(0.20f, 0.98f, -0.020f, -0.20f);
115 test_quat_to_mat_to_quat(0.25f, 0.97f, -0.025f, -0.25f);
116 test_quat_to_mat_to_quat(0.30f, 0.95f, -0.030f, -0.30f);
117}
118
119TEST(math_rotation, quat_to_mat_to_quat_near_0010)
120{
121 test_quat_to_mat_to_quat(0.01f, -0.001f, 0.9999f, -0.01f);
122 test_quat_to_mat_to_quat(0.02f, -0.002f, 0.9999f, -0.02f);
123 test_quat_to_mat_to_quat(0.03f, -0.003f, 0.9999f, -0.03f);
124 test_quat_to_mat_to_quat(0.04f, -0.004f, 0.9999f, -0.04f);
125 test_quat_to_mat_to_quat(0.05f, -0.005f, 0.9999f, -0.05f);
126 test_quat_to_mat_to_quat(0.10f, -0.010f, 0.999f, -0.10f);
127 test_quat_to_mat_to_quat(0.15f, -0.015f, 0.99f, -0.15f);
128 test_quat_to_mat_to_quat(0.20f, -0.020f, 0.98f, -0.20f);
129 test_quat_to_mat_to_quat(0.25f, -0.025f, 0.97f, -0.25f);
130 test_quat_to_mat_to_quat(0.30f, -0.030f, 0.95f, -0.30f);
131}
132
133TEST(math_rotation, quat_to_mat_to_quat_near_0001)
134{
135 test_quat_to_mat_to_quat(0.01f, -0.001f, -0.01f, 0.9999f);
136 test_quat_to_mat_to_quat(0.02f, -0.002f, -0.02f, 0.9999f);
137 test_quat_to_mat_to_quat(0.03f, -0.003f, -0.03f, 0.9999f);
138 test_quat_to_mat_to_quat(0.04f, -0.004f, -0.04f, 0.9999f);
139 test_quat_to_mat_to_quat(0.05f, -0.005f, -0.05f, 0.9999f);
140 test_quat_to_mat_to_quat(0.10f, -0.010f, -0.10f, 0.999f);
141 test_quat_to_mat_to_quat(0.15f, -0.015f, -0.15f, 0.99f);
142 test_quat_to_mat_to_quat(0.20f, -0.020f, -0.20f, 0.98f);
143 test_quat_to_mat_to_quat(0.25f, -0.025f, -0.25f, 0.97f);
144 test_quat_to_mat_to_quat(0.30f, -0.030f, -0.30f, 0.95f);
145}
146
147/* A zeroed matrix converted to a quaternion and back should not add rotation, see: #101848 */
148TEST(math_rotation, quat_to_mat_to_quat_zeroed_matrix)
149{
150 float matrix_zeroed[3][3] = {{0.0f}};
151 float matrix_result[3][3];
152 float matrix_unit[3][3];
153 float out_quat[4];
154
155 unit_m3(matrix_unit);
156 mat3_normalized_to_quat(out_quat, matrix_zeroed);
157 quat_to_mat3(matrix_result, out_quat);
158
159 EXPECT_M3_NEAR(matrix_unit, matrix_result, FLT_EPSILON);
160}
161
162TEST(math_rotation, quat_split_swing_and_twist_negative)
163{
164 const float input[4] = {-0.5f, 0, sqrtf(3) / 2, 0};
165 const float expected_swing[4] = {1.0f, 0, 0, 0};
166 const float expected_twist[4] = {0.5f, 0, -sqrtf(3) / 2, 0};
167 float swing[4], twist[4];
168
169 float twist_angle = quat_split_swing_and_twist(input, 1, swing, twist);
170
171 EXPECT_NEAR(twist_angle, -M_PI * 2 / 3, FLT_EPSILON);
172 EXPECT_V4_NEAR(swing, expected_swing, FLT_EPSILON);
173 EXPECT_V4_NEAR(twist, expected_twist, FLT_EPSILON);
174}
175
176TEST(math_rotation, mat3_normalized_to_quat_fast_degenerate)
177{
178 /* This input will cause floating point issues, which would produce a non-unit
179 * quaternion if the call to `normalize_qt` were to be removed. This
180 * particular matrix was taken from a production file of Pet Projects that
181 * caused problems. */
182 const float input[3][3] = {
183 {1.0000000000, -0.0000006315, -0.0000000027},
184 {0.0000009365, 1.0000000000, -0.0000000307},
185 {0.0000001964, 0.2103530765, 0.9776254892},
186 };
187 const float expect_quat[4] = {
188 0.99860459566116333,
189 -0.052810292690992355,
190 4.9985139582986449e-08,
191 -3.93654971730939e-07,
192 };
193 ASSERT_FLOAT_EQ(1.0f, dot_qtqt(expect_quat, expect_quat))
194 << "expected quaternion should be normal";
195
196 float actual_quat[4];
197 mat3_normalized_to_quat_fast(actual_quat, input);
198 EXPECT_FLOAT_EQ(1.0f, dot_qtqt(actual_quat, actual_quat));
199 EXPECT_V4_NEAR(expect_quat, actual_quat, FLT_EPSILON);
200}
201
202/* -------------------------------------------------------------------- */
205
206static void test_sin_cos_from_fraction_accuracy(const int range, const float expected_eps)
207{
208 for (int i = 0; i < range; i++) {
209 float sin_cos_fl[2];
210 sin_cos_from_fraction(i, range, &sin_cos_fl[0], &sin_cos_fl[1]);
211 const float phi = float(2.0 * M_PI) * (float(i) / float(range));
212 const float sin_cos_test_fl[2] = {sinf(phi), cosf(phi)};
213 EXPECT_V2_NEAR(sin_cos_fl, sin_cos_test_fl, expected_eps);
214 }
215}
216
218TEST(math_rotation, sin_cos_from_fraction_accuracy)
219{
220 for (int range = 1; range <= 64; range++) {
222 }
223}
224
226static void test_sin_cos_from_fraction_symmetry(const int range)
227{
228 /* The expected number of unique numbers depends on the range being a multiple of 4/2/1. */
229 const enum {
230 MULTIPLE_OF_1 = 1,
231 MULTIPLE_OF_2 = 2,
232 MULTIPLE_OF_4 = 3,
233 } multiple_of = (range & 1) ? MULTIPLE_OF_1 : ((range & 3) ? MULTIPLE_OF_2 : MULTIPLE_OF_4);
234
235 Vector<float2> coords;
236 coords.reserve(range);
237 for (int i = 0; i < range; i++) {
238 float sin_cos_fl[2];
239 sin_cos_from_fraction(i, range, &sin_cos_fl[0], &sin_cos_fl[1]);
240 switch (multiple_of) {
241 case MULTIPLE_OF_1: {
242 sin_cos_fl[0] = fabsf(sin_cos_fl[0]);
243 break;
244 }
245 case MULTIPLE_OF_2: {
246 sin_cos_fl[0] = fabsf(sin_cos_fl[0]);
247 sin_cos_fl[1] = fabsf(sin_cos_fl[1]);
248 break;
249 }
250 case MULTIPLE_OF_4: {
251 sin_cos_fl[0] = fabsf(sin_cos_fl[0]);
252 sin_cos_fl[1] = fabsf(sin_cos_fl[1]);
253 if (sin_cos_fl[0] > sin_cos_fl[1]) {
254 std::swap(sin_cos_fl[0], sin_cos_fl[1]);
255 }
256 break;
257 }
258 }
259 coords.append_unchecked(sin_cos_fl);
260 }
261 /* Sort, then count unique items. */
262 std::ranges::sort(coords, [](const float2 &a, const float2 &b) {
263 float delta = b[0] - a[0];
264 if (delta == 0.0f) {
265 delta = b[1] - a[1];
266 }
267 return delta > 0.0f;
268 });
269 int unique_coords_count = 1;
270 if (range > 1) {
271 int i_prev = 0;
272 for (int i = 1; i < range; i_prev = i++) {
273 if (coords[i_prev] != coords[i]) {
274 unique_coords_count += 1;
275 }
276 }
277 }
278 switch (multiple_of) {
279 case MULTIPLE_OF_1: {
280 EXPECT_EQ(unique_coords_count, (range / 2) + 1);
281 break;
282 }
283 case MULTIPLE_OF_2: {
284 EXPECT_EQ(unique_coords_count, (range / 4) + 1);
285 break;
286 }
287 case MULTIPLE_OF_4: {
288 EXPECT_EQ(unique_coords_count, (range / 8) + 1);
289 break;
290 }
291 }
292}
293
294TEST(math_rotation, sin_cos_from_fraction_symmetry)
295{
296 for (int range = 1; range <= 64; range++) {
298 }
299}
300
302
303namespace math::tests {
304
305TEST(math_rotation, DefaultConstructor)
306{
307 Quaternion quat{};
308 EXPECT_EQ(quat.x, 0.0f);
309 EXPECT_EQ(quat.y, 0.0f);
310 EXPECT_EQ(quat.z, 0.0f);
311 EXPECT_EQ(quat.w, 0.0f);
312
313 EulerXYZ eul{};
314 EXPECT_EQ(eul.x(), 0.0f);
315 EXPECT_EQ(eul.y(), 0.0f);
316 EXPECT_EQ(eul.z(), 0.0f);
317}
318
319TEST(math_rotation, RotateDirectionAroundAxis)
320{
321 const float3 a = rotate_direction_around_axis({1, 0, 0}, {0, 0, 1}, M_PI_2);
322 EXPECT_NEAR(a.x, 0.0f, FLT_EPSILON);
323 EXPECT_NEAR(a.y, 1.0f, FLT_EPSILON);
324 EXPECT_NEAR(a.z, 0.0f, FLT_EPSILON);
325 const float3 b = rotate_direction_around_axis({1, 0, 0}, {0, 0, 1}, M_PI);
326 EXPECT_NEAR(b.x, -1.0f, FLT_EPSILON);
327 EXPECT_NEAR(b.y, 0.0f, FLT_EPSILON);
328 EXPECT_NEAR(b.z, 0.0f, FLT_EPSILON);
329 const float3 c = rotate_direction_around_axis({0, 0, 1}, {0, 0, 1}, 0.0f);
330 EXPECT_NEAR(c.x, 0.0f, FLT_EPSILON);
331 EXPECT_NEAR(c.y, 0.0f, FLT_EPSILON);
332 EXPECT_NEAR(c.z, 1.0f, FLT_EPSILON);
333}
334
335TEST(math_rotation, AxisAngleConstructors)
336{
337 AxisAngle a({0.0f, 0.0f, 1.0f}, M_PI_2);
338 EXPECT_V3_NEAR(a.axis(), float3(0, 0, 1), 1e-4);
339 EXPECT_NEAR(float(a.angle()), M_PI_2, 1e-4);
340 EXPECT_NEAR(sin(a.angle()), 1.0f, 1e-4);
341 EXPECT_NEAR(cos(a.angle()), 0.0f, 1e-4);
342
344 EXPECT_V3_NEAR(b.axis(), float3(0, 0, 1), 1e-4);
345 EXPECT_NEAR(float(b.angle()), M_PI_2, 1e-4);
346 EXPECT_NEAR(b.angle().sin(), 1.0f, 1e-4);
347 EXPECT_NEAR(b.angle().cos(), 0.0f, 1e-4);
348
349 AxisAngle axis_angle_basis = AxisAngle(AxisSigned::Y_NEG, M_PI);
350 EXPECT_EQ(axis_angle_basis.axis(), float3(0.0f, -1.0f, 0.0f));
351 EXPECT_EQ(axis_angle_basis.angle(), M_PI);
352
353 AxisAngle c({1.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 0.0f});
354 EXPECT_V3_NEAR(c.axis(), float3(0, 0, 1), 1e-4);
355 EXPECT_NEAR(float(c.angle()), M_PI_2, 1e-4);
356
357 AxisAngle d({1.0f, 0.0f, 0.0f}, {0.0f, -1.0f, 0.0f});
358 EXPECT_V3_NEAR(d.axis(), float3(0, 0, -1), 1e-4);
359 EXPECT_NEAR(float(d.angle()), M_PI_2, 1e-4);
360}
361
362TEST(math_rotation, QuaternionDot)
363{
364 Quaternion q1(1.0f, 2.0f, 3.0f, 4.0f);
365 Quaternion q2(2.0f, -3.0f, 5.0f, 100.0f);
366 EXPECT_EQ(math::dot(q1, q2), 411.0f);
367}
368
369TEST(math_rotation, QuaternionConjugate)
370{
371 Quaternion q1(1.0f, 2.0f, 3.0f, 4.0f);
372 EXPECT_EQ(float4(conjugate(q1)), float4(1.0f, -2.0f, -3.0f, -4.0f));
373}
374
375TEST(math_rotation, QuaternionNormalize)
376{
377 Quaternion q1(1.0f, 2.0f, 3.0f, 4.0f);
378 EXPECT_V4_NEAR(float4(normalize(q1)),
379 float4(0.1825741827, 0.3651483654, 0.5477225780, 0.7302967309),
380 1e-6f);
381}
382
383TEST(math_rotation, QuaternionInvert)
384{
385 Quaternion q1(1.0f, 2.0f, 3.0f, 4.0f);
386 EXPECT_V4_NEAR(float4(invert(q1)), float4(0.0333333f, -0.0666667f, -0.1f, -0.133333f), 1e-4f);
387
388 Quaternion q2(0.927091f, 0.211322f, -0.124857f, 0.283295f);
390 EXPECT_V4_NEAR(float4(result), float4(0.927091f, -0.211322f, 0.124857f, -0.283295f), 1e-4f);
391}
392
393TEST(math_rotation, QuaternionCanonicalize)
394{
395 EXPECT_V4_NEAR(float4(canonicalize(Quaternion(0.5f, 2.0f, 3.0f, 4.0f))),
396 float4(0.5f, 2.0f, 3.0f, 4.0f),
397 1e-4f);
398 EXPECT_V4_NEAR(float4(canonicalize(Quaternion(-0.5f, 2.0f, 3.0f, 4.0f))),
399 float4(0.5f, -2.0f, -3.0f, -4.0f),
400 1e-4f);
401}
402
403TEST(math_rotation, QuaternionAngleBetween)
404{
405 Quaternion q1 = normalize(Quaternion(0.927091f, 0.211322f, -0.124857f, 0.283295f));
406 Quaternion q2 = normalize(Quaternion(-0.083377f, -0.051681f, 0.498261f, -0.86146f));
407 Quaternion q3 = rotation_between(q1, q2);
408 EXPECT_V4_NEAR(float4(q3), float4(-0.394478f, 0.00330195f, 0.284119f, -0.873872f), 1e-4f);
409 EXPECT_NEAR(float(angle_of(q1)), 0.76844f, 1e-4f);
410 EXPECT_NEAR(float(angle_of(q2)), 3.30854f, 1e-4f);
411 EXPECT_NEAR(float(angle_of(q3)), 3.95259f, 1e-4f);
412 EXPECT_NEAR(float(angle_of_signed(q1)), 0.76844f, 1e-4f);
413 EXPECT_NEAR(float(angle_of_signed(q2)), 3.30854f - 2 * M_PI, 1e-4f);
414 EXPECT_NEAR(float(angle_of_signed(q3)), 3.95259f - 2 * M_PI, 1e-4f);
415 EXPECT_NEAR(float(angle_between(q1, q2)), 3.95259f, 1e-4f);
416 EXPECT_NEAR(float(angle_between_signed(q1, q2)), 3.95259f - 2 * M_PI, 1e-4f);
417}
418
419TEST(math_rotation, QuaternionPower)
420{
421 Quaternion q1 = normalize(Quaternion(0.927091f, 0.211322f, -0.124857f, 0.283295f));
422 Quaternion q2 = normalize(Quaternion(-0.083377f, -0.051681f, 0.498261f, -0.86146f));
423
424 EXPECT_V4_NEAR(
425 float4(math::pow(q1, -2.5f)), float4(0.573069, -0.462015, 0.272976, -0.61937), 1e-4);
426 EXPECT_V4_NEAR(
427 float4(math::pow(q1, -0.5f)), float4(0.981604, -0.107641, 0.0635985, -0.144302), 1e-4);
428 EXPECT_V4_NEAR(
429 float4(math::pow(q1, 0.5f)), float4(0.981604, 0.107641, -0.0635985, 0.144302), 1e-4);
430 EXPECT_V4_NEAR(
431 float4(math::pow(q1, 2.5f)), float4(0.573069, 0.462015, -0.272976, 0.61937), 1e-4);
432 EXPECT_V4_NEAR(
433 float4(math::pow(q2, -2.5f)), float4(-0.545272, -0.0434735, 0.419131, -0.72465), 1e-4);
434 EXPECT_V4_NEAR(
435 float4(math::pow(q2, -0.5f)), float4(0.676987, 0.0381699, -0.367999, 0.636246), 1e-4);
436 EXPECT_V4_NEAR(
437 float4(math::pow(q2, 0.5f)), float4(0.676987, -0.0381699, 0.367999, -0.636246), 1e-4);
438 EXPECT_V4_NEAR(
439 float4(math::pow(q2, 2.5f)), float4(-0.545272, 0.0434735, -0.419131, 0.72465), 1e-4);
440}
441
442TEST(math_rotation, QuaternionFromTriangle)
443{
444 float3 v1(0.927091f, 0.211322f, -0.124857f);
445 float3 v2(-0.051681f, 0.498261f, -0.86146f);
446 float3 v3(0.211322f, -0.124857f, 0.283295f);
447 EXPECT_V4_NEAR(float4(from_triangle(v1, v2, v3)),
448 float4(0.255566f, -0.213799f, 0.454253f, 0.826214f),
449 1e-5f);
450 EXPECT_V4_NEAR(float4(from_triangle(v1, v3, v2)),
451 float4(0.103802f, 0.295067f, -0.812945f, 0.491204f),
452 1e-5f);
453}
454
455TEST(math_rotation, QuaternionFromVector)
456{
457 float3 v1(0.927091f, 0.211322f, -0.124857f);
458 float3 v2(-0.051681f, 0.498261f, -0.86146f);
459 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_POS, Axis::X)),
460 float4(0.129047, 0, -0.50443, -0.853755),
461 1e-5f);
462 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_POS, Axis::Y)),
463 float4(0.12474, 0.0330631, -0.706333, -0.696017),
464 1e-5f);
465 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_POS, Axis::Z)),
466 float4(0.111583, -0.0648251, -0.00729451, -0.991612),
467 1e-5f);
468 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_POS, Axis::X)),
469 float4(0.476074, 0.580363, -0.403954, 0.522832),
470 1e-5f);
471 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_POS, Axis::Y)),
472 float4(0.62436, 0.104259, 0, 0.774148),
473 1e-5f);
474 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_POS, Axis::Z)),
475 float4(0.622274, 0.0406802, 0.0509963, 0.780077),
476 1e-5f);
477 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_POS, Axis::X)),
478 float4(0.747014, 0.0737433, -0.655337, 0.0840594),
479 1e-5f);
480 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_POS, Axis::Z)),
481 float4(0.751728, 0.146562, -0.642981, 0),
482 1e-5f);
483 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_POS, Axis::Z)),
484 float4(0.751728, 0.146562, -0.642981, 0),
485 1e-5f);
486 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_NEG, Axis::X)),
487 float4(0.991638, 0, 0.0656442, 0.111104),
488 1e-5f);
489 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_NEG, Axis::Y)),
490 float4(0.706333, 0.696017, 0.12474, 0.0330631),
491 1e-5f);
492 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::X_NEG, Axis::Z)),
493 float4(0.991612, -0.0072946, 0.0648251, 0.111583),
494 1e-5f);
495 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_NEG, Axis::X)),
496 float4(0.580363, -0.476074, -0.522832, -0.403954),
497 1e-5f);
498 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_NEG, Axis::Y)),
499 float4(0.781137, -0.083334, 0, -0.618774),
500 1e-5f);
501 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Y_NEG, Axis::Z)),
502 float4(0.780077, -0.0509963, 0.0406802, -0.622274),
503 1e-5f);
504 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_NEG, Axis::X)),
505 float4(0.0737433, -0.747014, -0.0840594, -0.655337),
506 1e-5f);
507 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_NEG, Axis::Z)),
508 float4(0.659473, -0.167065, 0.732929, 0),
509 1e-5f);
510 EXPECT_V4_NEAR(float4(from_vector(v1, AxisSigned::Z_NEG, Axis::Z)),
511 float4(0.659473, -0.167065, 0.732929, 0),
512 1e-5f);
513
514 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_POS, Axis::X)),
515 float4(0.725211, 0, -0.596013, -0.344729),
516 1e-5f);
517 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_POS, Axis::Y)),
518 float4(0.691325, 0.219092, -0.672309, -0.148561),
519 1e-5f);
520 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_POS, Axis::Z)),
521 float4(0.643761, -0.333919, -0.370346, -0.580442),
522 1e-5f);
523 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_POS, Axis::X)),
524 float4(0.320473, 0.593889, 0.383792, 0.630315),
525 1e-5f);
526 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_POS, Axis::Y)),
527 float4(0.499999, 0.864472, 0, -0.0518617),
528 1e-5f);
529 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_POS, Axis::Z)),
530 float4(0.0447733, 0.0257574, -0.49799, -0.865643),
531 1e-5f);
532 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_POS, Axis::X)),
533 float4(0.646551, 0.193334, -0.174318, 0.717082),
534 1e-5f);
535 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_POS, Axis::Z)),
536 float4(0.965523, 0.258928, 0.0268567, 0),
537 1e-5f);
538 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_POS, Axis::Z)),
539 float4(0.965523, 0.258928, 0.0268567, 0),
540 1e-5f);
541 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_NEG, Axis::X)),
542 float4(0.688527, 0, 0.627768, 0.363095),
543 1e-5f);
544 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_NEG, Axis::Y)),
545 float4(0.672309, 0.148561, 0.691325, 0.219092),
546 1e-5f);
547 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::X_NEG, Axis::Z)),
548 float4(0.580442, -0.370345, 0.333919, 0.643761),
549 1e-5f);
550 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_NEG, Axis::X)),
551 float4(0.593889, -0.320473, -0.630315, 0.383792),
552 1e-5f);
553 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_NEG, Axis::Y)),
554 float4(0.866026, -0.499102, 0, 0.0299423),
555 1e-5f);
556 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Y_NEG, Axis::Z)),
557 float4(0.865643, -0.49799, -0.0257574, 0.0447733),
558 1e-5f);
559 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_NEG, Axis::X)),
560 float4(0.193334, -0.646551, -0.717082, -0.174318),
561 1e-5f);
562 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_NEG, Axis::Z)),
563 float4(0.260317, -0.960371, -0.0996123, 0),
564 1e-5f);
565 EXPECT_V4_NEAR(float4(from_vector(v2, AxisSigned::Z_NEG, Axis::Z)),
566 float4(0.260317, -0.960371, -0.0996123, 0),
567 1e-5f);
568}
569
570TEST(math_rotation, QuaternionWrappedAround)
571{
572 Quaternion q1 = normalize(Quaternion(0.927091f, 0.211322f, -0.124857f, 0.283295f));
573 Quaternion q2 = normalize(Quaternion(-0.083377f, -0.051681f, 0.498261f, -0.86146f));
574 Quaternion q_malformed = Quaternion(0.0f, 0.0f, 0.0f, 0.0f);
575 EXPECT_V4_NEAR(float4(q1.wrapped_around(q2)), float4(-q1), 1e-4f);
576 EXPECT_V4_NEAR(float4(q1.wrapped_around(-q2)), float4(q1), 1e-4f);
577 EXPECT_V4_NEAR(float4(q1.wrapped_around(q_malformed)), float4(q1), 1e-4f);
578}
579
580TEST(math_rotation, QuaternionFromTracking)
581{
582 for (int i : IndexRange(6)) {
583 for (int j : IndexRange(3)) {
584 AxisSigned forward_axis = AxisSigned::from_int(i);
585 Axis up_axis = Axis::from_int(j);
586
587 if (forward_axis.axis() == up_axis) {
588 continue;
589 }
590
592 quat_apply_track(&expect.w, forward_axis.as_int(), up_axis.as_int());
593
594 /* This is the expected axis conversion for curve tangent space to tracked object space. */
597 from_orthonormal_axes(forward_axis, AxisSigned(up_axis)));
599
600 EXPECT_V4_NEAR(float4(result), float4(expect), 1e-5f);
601 }
602 }
603}
604
605TEST(math_rotation, EulerWrappedAround)
606{
607 EulerXYZ eul1 = EulerXYZ(2.08542, -1.12485, -1.23738);
608 EulerXYZ eul2 = EulerXYZ(4.06112, 0.561928, -18.9063);
609 EXPECT_V3_NEAR(float3(eul1.wrapped_around(eul2)), float3(2.08542, -1.12485, -20.0869), 1e-4f);
610 EXPECT_V3_NEAR(float3(eul2.wrapped_around(eul1)), float3(4.06112, 0.561928, -0.0567436), 1e-4f);
611}
612
613TEST(math_rotation, Euler3ToGimbal)
614{
615 /* All the same rotation. */
616 float3 ijk{0.350041, -0.358896, 0.528994};
617 Euler3 euler3_xyz(ijk, EulerOrder::XYZ);
618 Euler3 euler3_xzy(ijk, EulerOrder::XZY);
619 Euler3 euler3_yxz(ijk, EulerOrder::YXZ);
620 Euler3 euler3_yzx(ijk, EulerOrder::YZX);
621 Euler3 euler3_zxy(ijk, EulerOrder::ZXY);
622 Euler3 euler3_zyx(ijk, EulerOrder::ZYX);
623
624 float3x3 mat_xyz = transpose(
625 float3x3({0.808309, -0.504665, 0}, {0.47251, 0.863315, 0}, {0.351241, 0, 1}));
626 float3x3 mat_xzy = transpose(
627 float3x3({0.808309, 0, -0.351241}, {0.504665, 1, -0}, {0.303232, 0, 0.936285}));
628 float3x3 mat_yxz = transpose(
629 float3x3({0.863315, -0.474062, 0}, {0.504665, 0.810963, 0}, {-0, 0.342936, 1}));
630 float3x3 mat_yzx = transpose(
631 float3x3({1, -0.504665, 0}, {0, 0.810963, -0.342936}, {0, 0.296062, 0.939359}));
632 float3x3 mat_zxy = transpose(
633 float3x3({0.936285, 0, -0.329941}, {0, 1, -0.342936}, {0.351241, 0, 0.879508}));
634 float3x3 mat_zyx = transpose(
635 float3x3({1, -0, -0.351241}, {0, 0.939359, -0.321086}, {0, 0.342936, 0.879508}));
636
637 EXPECT_M3_NEAR(to_gimbal_axis(euler3_xyz), mat_xyz, 1e-4);
638 EXPECT_M3_NEAR(to_gimbal_axis(euler3_xzy), mat_xzy, 1e-4);
639 EXPECT_M3_NEAR(to_gimbal_axis(euler3_yxz), mat_yxz, 1e-4);
640 EXPECT_M3_NEAR(to_gimbal_axis(euler3_yzx), mat_yzx, 1e-4);
641 EXPECT_M3_NEAR(to_gimbal_axis(euler3_zxy), mat_zxy, 1e-4);
642 EXPECT_M3_NEAR(to_gimbal_axis(euler3_zyx), mat_zyx, 1e-4);
643}
644
645TEST(math_rotation, CartesianBasis)
646{
647 for (int i : IndexRange(6)) {
648 for (int j : IndexRange(6)) {
649 for (int k : IndexRange(6)) {
650 for (int l : IndexRange(6)) {
651 AxisSigned src_forward = AxisSigned::from_int(i);
653 AxisSigned dst_forward = AxisSigned::from_int(k);
655
656 if ((abs(src_forward) == abs(src_up)) || (abs(dst_forward) == abs(dst_up))) {
657 /* Assertion expected. */
658 continue;
659 }
660
661 float3x3 expect;
662 if (src_forward == dst_forward && src_up == dst_up) {
663 expect = float3x3::identity();
664 }
665 else {
666 /* TODO: Find a way to test without resorting to old C API. */
667 mat3_from_axis_conversion(src_forward.as_int(),
668 src_up.as_int(),
669 dst_forward.as_int(),
670 dst_up.as_int(),
671 expect.ptr());
672 }
673
674 CartesianBasis rotation = rotation_between(from_orthonormal_axes(src_forward, src_up),
675 from_orthonormal_axes(dst_forward, dst_up));
676 EXPECT_EQ(from_rotation<float3x3>(rotation), expect);
677
678 if (src_forward == dst_forward) {
679 expect = float3x3::identity();
680 }
681 else {
682 /* TODO: Find a way to test without resorting to old C API. */
684 src_forward.as_int(), dst_forward.as_int(), expect.ptr());
685 }
686
687 EXPECT_EQ(from_rotation<float3x3>(rotation_between(src_forward, dst_forward)), expect);
688
689 float3 point(1.0f, 2.0f, 3.0f);
690 CartesianBasis rotation_inv = invert(rotation);
691 /* Test inversion identity. */
692 EXPECT_EQ(transform_point(rotation_inv, transform_point(rotation, point)), point);
693 }
694 }
695 }
696 }
697}
698
699TEST(math_rotation, Transform)
700{
701 Quaternion q(0.927091f, 0.211322f, -0.124857f, 0.283295f);
702
703 float3 p(0.576f, -0.6546f, 46.354f);
705 EXPECT_V3_NEAR(result, float3(-4.33722f, -21.661f, 40.7608f), 1e-4f);
706
707 /* Validated using `to_quaternion` before doing the transform. */
708 float3 p2(1.0f, 2.0f, 3.0f);
710 p2);
711 EXPECT_EQ(result, float3(1.0f, 2.0f, 3.0f));
715 p2);
716 EXPECT_EQ(result, float3(-2.0f, 1.0f, 3.0f));
718 EXPECT_EQ(result, float3(3.0f, 1.0f, 2.0f));
720 EXPECT_EQ(result, float3(-2.0f, 3.0f, -1.0f));
721}
722
723TEST(math_rotation, DualQuaternionNormalize)
724{
725 DualQuaternion sum = DualQuaternion(Quaternion(0, 0, 1, 0), Quaternion(0, 1, 0, 1)) * 2.0f;
726 sum += DualQuaternion(Quaternion(1, 0, 0, 0), Quaternion(1, 1, 1, 1), float4x4::identity()) *
727 4.0f;
728 sum += DualQuaternion(Quaternion(1, 0, 0, 0), Quaternion(1, 0, 0, 0), float4x4::identity()) *
729 3.0f;
730
731 sum = normalize(sum);
732
733 /* The difference with the C API. */
734 float len = length(float4(0.777778, 0, 0.222222, 0));
735
736 EXPECT_V4_NEAR(float4(sum.quat), (float4(0.777778, 0, 0.222222, 0) / len), 1e-4f);
737 EXPECT_V4_NEAR(float4(sum.trans), (float4(0.777778, 0.666667, 0.444444, 0.666667) / len), 1e-4f);
739 EXPECT_EQ(sum.scale_weight, 1.0f);
740 EXPECT_EQ(sum.quat_weight, 1.0f);
741}
742
743TEST(math_rotation, DualQuaternionFromMatrix)
744{
745 {
746 float4x4 mat{transpose(float4x4({-2.14123, -0.478481, -1.38296, -2.26029},
747 {-1.28264, 2.87361, 0.0230992, 12.8871},
748 {3.27343, 0.812993, -0.895575, -13.5216},
749 {0, 0, 0, 1}))};
750 float4x4 basemat{transpose(float4x4({0.0988318, 0.91328, 0.39516, 7.73971},
751 {0.16104, -0.406549, 0.899324, 22.8871},
752 {0.981987, -0.0252451, -0.187255, -3.52155},
753 {0, 0, 0, 1}))};
754 float4x4 expected_scale_mat{transpose(float4x4({4.08974, 0.306437, -0.0853435, -31.2277},
755 {-0.445021, 2.97151, -0.250095, -42.5586},
756 {0.146173, 0.473002, 1.62645, -9.75092},
757 {0, 0, 0, 1}))};
758
759 DualQuaternion dq = to_dual_quaternion(mat, basemat);
760 EXPECT_V4_NEAR(float4(dq.quat), float4(0.502368, 0.0543716, -0.854483, -0.120535), 1e-4f);
761 EXPECT_V4_NEAR(float4(dq.trans), float4(22.674, -0.878616, 11.2762, 14.167), 1e-4f);
762 EXPECT_M4_NEAR(dq.scale, expected_scale_mat, 1e-4f);
763 EXPECT_EQ(dq.scale_weight, 1.0f);
764 EXPECT_EQ(dq.quat_weight, 1.0f);
765 }
766 {
767 float4x4 mat{transpose(float4x4({-0.0806635, -1.60529, 2.44763, 26.823},
768 {-1.04583, -0.150756, -0.385074, -22.2225},
769 {-0.123402, 2.32698, 1.66357, 5.397},
770 {0, 0, 0, 1}))};
771 float4x4 basemat{transpose(float4x4({0.0603774, 0.904674, 0.421806, 36.823},
772 {-0.271734, 0.421514, -0.865151, -12.2225},
773 {-0.960477, -0.0623834, 0.27128, 15.397},
774 {0, 0, 0, 1}))};
775 float4x4 expected_scale_mat{transpose(float4x4({0.248852, 2.66363, -0.726295, 71.3985},
776 {0.971507, -0.382422, 1.09917, -69.5943},
777 {-0.331274, 0.8794, 2.67787, -2.88715},
778 {0, 0, 0, 1}))};
779
780 DualQuaternion dq = to_dual_quaternion(mat, basemat);
781 EXPECT_V4_NEAR(float4(dq.quat), float4(0.149898, -0.319339, -0.0441496, -0.934668), 1e-4f);
782 EXPECT_V4_NEAR(float4(dq.trans), float4(-2.20019, 39.6236, 49.052, -16.2077), 1e-4f);
783 EXPECT_M4_NEAR(dq.scale, expected_scale_mat, 1e-4f);
784 EXPECT_EQ(dq.scale_weight, 1.0f);
785 EXPECT_EQ(dq.quat_weight, 1.0f);
786 }
787
788#if 0 /* Generate random matrices. */
789 for (int i = 0; i < 1000; i++) {
790 auto frand = []() { return (std::rand() - RAND_MAX / 2) / float(RAND_MAX); };
792 float3{frand(), frand(), frand()} * 100.0f,
793 EulerXYZ{frand() * 10.0f, frand() * 10.0f, frand() * 10.0f},
794 float3{frand(), frand(), frand()} * 10.0f);
796 mat.location() + 10, EulerXYZ{frand() * 10.0f, frand() * 10.0f, frand() * 10.0f});
797
798 DualQuaternion expect;
799 mat4_to_dquat((DualQuat *)&expect.quat.w, basemat.ptr(), mat.ptr());
800
801 DualQuaternion dq = to_dual_quaternion(mat, basemat);
802 EXPECT_V4_NEAR(float4(dq.quat), float4(expect.quat), 1e-4f);
803 EXPECT_V4_NEAR(float4(dq.trans), float4(expect.trans), 1e-4f);
804 EXPECT_M4_NEAR(dq.scale, expect.scale, 2e-4f);
806 }
807#endif
808}
809
810TEST(math_rotation, DualQuaternionTransform)
811{
812 {
813 float4x4 scale_mat{transpose(float4x4({4.08974, 0.306437, -0.0853435, -31.2277},
814 {-0.445021, 2.97151, -0.250095, -42.5586},
815 {0.146173, 0.473002, 1.62645, -9.75092},
816 {0, 0, 0, 1}))};
817
818 DualQuaternion dq({0.502368, 0.0543716, -0.854483, -0.120535},
819 {22.674, -0.878616, 11.2762, 14.167},
820 scale_mat);
821
822 float3 p0{51.0f, 1647.0f, 12.0f};
823 float3 p1{58.0f, 0.0054f, 10.0f};
824 float3 p2{0.0f, 7854.0f, 111.0f};
825
826 float3x3 crazy_space_mat;
827 float3 p0_expect = p0;
828 float3 p1_expect = p1;
829 float3 p2_expect = p2;
830 mul_v3m3_dq(p0_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
831 mul_v3m3_dq(p1_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
832 mul_v3m3_dq(p2_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
833
834 float3 p0_result = transform_point(dq, p0);
835 float3 p1_result = transform_point(dq, p1);
836 float3 p2_result = transform_point(dq, p2, &crazy_space_mat);
837
838 float4x4 expected_crazy_space_mat{transpose(float3x3({-2.14123, -0.478481, -1.38296},
839 {-1.28264, 2.87361, 0.0230978},
840 {3.27343, 0.812991, -0.895574}))};
841
842 EXPECT_V3_NEAR(p0_result, p0_expect, 1e-2f);
843 EXPECT_V3_NEAR(p1_result, p1_expect, 1e-2f);
844 EXPECT_V3_NEAR(p2_result, p2_expect, 1e-2f);
845 EXPECT_M3_NEAR(crazy_space_mat, expected_crazy_space_mat, 1e-4f);
846 }
847 {
848 float4x4 scale_mat{transpose(float4x4({0.248852, 2.66363, -0.726295, 71.3985},
849 {0.971507, -0.382422, 1.09917, -69.5943},
850 {-0.331274, 0.8794, 2.67787, -2.88715},
851 {0, 0, 0, 1}))};
852
853 DualQuaternion dq({0.149898, -0.319339, -0.0441496, -0.934668},
854 {-2.20019, 39.6236, 49.052, -16.207},
855 scale_mat);
856
857 float3 p0{51.0f, 1647.0f, 12.0f};
858 float3 p1{58.0f, 0.0054f, 10.0f};
859 float3 p2{0.0f, 7854.0f, 111.0f};
860
861 float3x3 crazy_space_mat;
862 float3 p0_expect = p0;
863 float3 p1_expect = p1;
864 float3 p2_expect = p2;
865 mul_v3m3_dq(p0_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
866 mul_v3m3_dq(p1_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
867 mul_v3m3_dq(p2_expect, crazy_space_mat.ptr(), reinterpret_cast<DualQuat *>(&dq));
868
869 float3 p0_result = transform_point(dq, p0);
870 float3 p1_result = transform_point(dq, p1);
871 float3 p2_result = transform_point(dq, p2, &crazy_space_mat);
872
873 float4x4 expected_crazy_space_mat{transpose(float3x3({-0.0806647, -1.60529, 2.44763},
874 {-1.04583, -0.150754, -0.385079},
875 {-0.123401, 2.32698, 1.66357}))};
876
877 EXPECT_V3_NEAR(p0_result, float3(-2591.83, -328.472, 3851.6), 1e-2f);
878 EXPECT_V3_NEAR(p1_result, float3(46.6121, -86.7318, 14.8882), 1e-2f);
879 EXPECT_V3_NEAR(p2_result, float3(-12309.5, -1248.99, 18466.1), 6e-2f);
880 EXPECT_M3_NEAR(crazy_space_mat, expected_crazy_space_mat, 1e-4f);
881 }
882}
883
884TEST(math_axis_angle, AxisAngleFromQuaternion)
885{
886 {
887 const math::AxisAngle axis_angle({0.0f, 1.0f, 0.0f}, math::AngleRadian(0));
888 const math::Quaternion quaternion(1.0f, {0.0f, 0.0f, 0.0f});
889 const math::AxisAngle from_quaternion = math::to_axis_angle(quaternion);
890 EXPECT_V3_NEAR(axis_angle.axis(), from_quaternion.axis(), 1e-6);
891 EXPECT_NEAR(axis_angle.angle().radian(), from_quaternion.angle().radian(), 1e-6);
892 }
893 {
894 const math::AxisAngle axis_angle({0.0f, -1.0f, 0.0f}, math::AngleRadian(0));
895 const math::Quaternion quaternion(-1.0f, {0.0f, 0.0f, 0.0f});
896 const math::AxisAngle from_quaternion = math::to_axis_angle(quaternion);
897 EXPECT_V3_NEAR(axis_angle.axis(), from_quaternion.axis(), 1e-6);
898 EXPECT_NEAR(axis_angle.angle().radian(), from_quaternion.angle().radian(), 1e-6);
899 }
900}
901
902} // namespace math::tests
903} // namespace blender
#define M_PI_2
#define M_PI
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
constexpr IndexRange()=default
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
static constexpr AxisSigned from_int(int axis_int)
constexpr int as_int() const
static constexpr Value Z
static constexpr Axis from_int(const int axis_int)
static constexpr Value X
static constexpr Value Y
#define FLT_EPSILON
#define EXPECT_NEAR(result, expect, threshold)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
TEST(math_rotation, DefaultConstructor)
AngleCartesianBase< float > AngleCartesian
QuaternionBase< T > from_triangle(const VecBase< T, 3 > &v1, const VecBase< T, 3 > &v2, const VecBase< T, 3 > &v3, const VecBase< T, 3 > &normal)
AngleRadianBase< float > AngleRadian
QuaternionBase< T > conjugate(const QuaternionBase< T > &a)
QuaternionBase< float > Quaternion
T cos(const AngleRadianBase< T > &a)
MatBase< T, NumCol, NumRow > transpose(const MatBase< T, NumRow, NumCol > &mat)
T pow(const T &x, const T &power)
QuaternionBase< T > from_vector(const VecBase< T, 3 > &vector, const AxisSigned track_flag, const Axis up_flag)
QuaternionBase< T > to_quaternion(const AxisAngleBase< T, AngleT > &axis_angle)
T length(const VecBase< T, Size > &a)
CartesianBasis rotation_between(const CartesianBasis &a, const CartesianBasis &b)
AngleRadianBase< T > angle_between(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatT from_loc_rot(const typename MatT::loc_type &location, const RotationT &rotation)
AxisAngleBase< float, AngleRadianBase< float > > AxisAngle
AngleRadianBase< T > angle_between_signed(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
EulerXYZBase< float > EulerXYZ
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, 3, 3 > to_gimbal_axis(const Euler3Base< T > &rotation)
CartesianBasis invert(const CartesianBasis &basis)
float3 rotate_direction_around_axis(const float3 &direction, const float3 &axis, float angle)
AngleRadianBase< T > angle_of(const QuaternionBase< T > &q)
DualQuaternionBase< float > DualQuaternion
QuaternionBase< T > invert_normalized(const QuaternionBase< T > &q)
AxisAngleBase< T, AngleT > to_axis_angle(const EulerXYZBase< T > &euler)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
AxisAngleBase< float, AngleCartesianBase< float > > AxisAngleCartesian
QuaternionBase< T > canonicalize(const QuaternionBase< T > &q)
T sin(const AngleRadianBase< T > &a)
Euler3Base< float > Euler3
T abs(const T &a)
AngleRadianBase< T > angle_of_signed(const QuaternionBase< T > &q)
CartesianBasis from_orthonormal_axes(const AxisSigned forward, const AxisSigned up)
MatT from_rotation(const RotationT &rotation)
DualQuaternionBase< T > to_dual_quaternion(const MatBase< T, 4, 4 > &mat, const MatBase< T, 4, 4 > &basemat)
MatT from_loc_rot_scale(const typename MatT::loc_type &location, const RotationT &rotation, const VecBase< typename MatT::base_type, ScaleDim > &scale)
VecBase< T, 3 > transform_point(const CartesianBasis &basis, const VecBase< T, 3 > &v)
BMesh Iterators.
float quat_split_swing_and_twist(const float q_in[4], int axis, float r_swing[4], float r_twist[4])
ATTR_WARN_UNUSED_RESULT const BMLoop * l
void mat3_normalized_to_quat(float q[4], const float mat[3][3])
float dot_qtqt(const float a[4], const float b[4])
static void test_quat_to_mat_to_quat(float w, float x, float y, float z)
static void test_sin_cos_from_fraction_symmetry(const int range)
MatBase< float, 4, 4 > float4x4
void sin_cos_from_fraction(int numerator, int denominator, float *r_sin, float *r_cos)
bool mat3_from_axis_conversion_single(int src_axis, int dst_axis, float r_mat[3][3])
TEST(array_store, Nop)
VecBase< float, 4 > float4
void quat_to_mat3(float m[3][3], const float q[4])
VecBase< float, 2 > float2
void mat3_normalized_to_quat_fast(float q[4], const float mat[3][3])
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
MatBase< float, 3, 3 > float3x3
void quat_apply_track(float quat[4], short axis, short upflag)
void mat4_to_dquat(DualQuat *dq, const float basemat[4][4], const float mat[4][4])
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
void unit_m3(float m[3][3])
ATTR_WARN_UNUSED_RESULT const BMVert * v2
static void test_sin_cos_from_fraction_accuracy(const int range, const float expected_eps)
VecBase< float, 3 > float3
void mul_v3m3_dq(float r[3], float R[3][3], DualQuat *dq)
void mul_qt_fl(float q[4], float f)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
float normalize_qt_qt(float r[4], const float q[4])
#define fabsf
#define sqrtf
#define sinf
#define cosf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const c_style_mat & ptr() const
EulerXYZBase wrapped_around(const EulerXYZBase &reference) const
QuaternionBase wrapped_around(const QuaternionBase &reference) const