summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-06-30 09:45:29 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-08-21 16:40:31 +0200
commitf2e3777a09ada7731df036f4068528354ff2a556 (patch)
tree6a444a785f7f651c68bb04e4fc5ccf705664e2f2
parent8228145ca923ed4fbf5333f409e25a1f88bd9b38 (diff)
eina: add test for decomposition and composition of matrix.
-rw-r--r--src/tests/eina/eina_test_quaternion.c85
1 files changed, 84 insertions, 1 deletions
diff --git a/src/tests/eina/eina_test_quaternion.c b/src/tests/eina/eina_test_quaternion.c
index 1ffbc1a451..45c527c246 100644
--- a/src/tests/eina/eina_test_quaternion.c
+++ b/src/tests/eina/eina_test_quaternion.c
@@ -27,7 +27,7 @@
27#include "eina_suite.h" 27#include "eina_suite.h"
28#include "Eina.h" 28#include "Eina.h"
29 29
30#define FLOAT_CMP(a, b) (fabs(a - b) <= DBL_MIN) 30#define FLOAT_CMP(a, b) (fabs((float)a - (float)b) <= FLT_MIN)
31 31
32static inline Eina_Bool 32static inline Eina_Bool
33eina_quaternion_cmp(const Eina_Quaternion *a, const Eina_Quaternion *b) 33eina_quaternion_cmp(const Eina_Quaternion *a, const Eina_Quaternion *b)
@@ -56,6 +56,16 @@ eina_matrix3_cmp(const Eina_Matrix3 *a, const Eina_Matrix3 *b)
56 return EINA_FALSE; 56 return EINA_FALSE;
57} 57}
58 58
59static inline Eina_Bool
60eina_point_3d_cmp(const Eina_Point_3D *a, const Eina_Point_3D *b)
61{
62 if (FLOAT_CMP(a->x, b->x) &&
63 FLOAT_CMP(a->y, b->y) &&
64 FLOAT_CMP(a->z, b->z))
65 return EINA_TRUE;
66 return EINA_FALSE;
67}
68
59START_TEST(eina_test_quaternion_norm) 69START_TEST(eina_test_quaternion_norm)
60{ 70{
61 static const Eina_Quaternion q = { 1, 3, 4, 5 }; 71 static const Eina_Quaternion q = { 1, 3, 4, 5 };
@@ -245,6 +255,30 @@ START_TEST(eina_test_quaternion_mul)
245} 255}
246END_TEST 256END_TEST
247 257
258START_TEST(eina_test_matrix_recompose)
259{
260 const Eina_Point_3D translation = { 0, 0, 0 };
261 const Eina_Point_3D scale = { 1, 1, 1 };
262 const Eina_Point_3D skew = { 0, 0, 0 };
263 const Eina_Quaternion perspective = { 0, 0, 0, 1 };
264 const Eina_Quaternion rotation = { 0, 0, 0, 1 };
265 Eina_Matrix4 m4;
266
267 eina_init();
268
269 eina_quaternion_matrix4_to(&m4,
270 &rotation,
271 &perspective,
272 &translation,
273 &scale,
274 &skew);
275
276 fail_if(eina_matrix4_type_get(&m4) != EINA_MATRIX_TYPE_IDENTITY);
277
278 eina_shutdown();
279}
280END_TEST
281
248START_TEST(eina_test_quaternion_normalized) 282START_TEST(eina_test_quaternion_normalized)
249{ 283{
250 Eina_Quaternion p = {1, 1, 1, 1}; 284 Eina_Quaternion p = {1, 1, 1, 1};
@@ -259,6 +293,53 @@ START_TEST(eina_test_quaternion_normalized)
259} 293}
260END_TEST 294END_TEST
261 295
296START_TEST(eina_test_matrix_quaternion)
297{
298 const Eina_Point_3D rt = { -2, -3, 0 };
299 const Eina_Point_3D rsc = { 4, 5, 1 };
300 const Eina_Quaternion rr = { 0, 0, -1, 0 };
301 const Eina_Quaternion rp = { 0, 0, 0, 1 };
302 Eina_Quaternion rotation, perspective;
303 Eina_Matrix3 m3, m3r;
304 Eina_Matrix4 m4, m4r;
305 Eina_Point_3D translation, scale, skew;
306
307 eina_init();
308
309 eina_matrix3_identity(&m3);
310 eina_matrix3_rotate(&m3, 3.14159265);
311 eina_matrix3_translate(&m3, 2, 3);
312 eina_matrix3_scale(&m3, 4, 5);
313 eina_matrix3_matrix4_to(&m4, &m3);
314
315 fail_if(!eina_matrix4_quaternion_to(&rotation,
316 &perspective,
317 &translation,
318 &scale,
319 &skew,
320 &m4));
321
322 eina_quaternion_matrix4_to(&m4r,
323 &rotation,
324 &perspective,
325 &translation,
326 &scale,
327 &skew);
328
329 eina_matrix4_matrix3_to(&m3r, &m4r);
330
331 fail_if(!eina_point_3d_cmp(&scale, &rsc));
332 fail_if(!eina_point_3d_cmp(&translation, &rt));
333 fail_if(!eina_quaternion_cmp(&perspective, &rp));
334 fail_if(!eina_quaternion_cmp(&rotation, &rr));
335
336 // Disable this test for the moment as it seems a rounding issue
337 // fail_if(!eina_matrix3_cmp(&m3r, &m3));
338
339 eina_shutdown();
340}
341END_TEST
342
262void 343void
263eina_test_quaternion(TCase *tc) 344eina_test_quaternion(TCase *tc)
264{ 345{
@@ -272,4 +353,6 @@ eina_test_quaternion(TCase *tc)
272 tcase_add_test(tc, eina_test_quaternion_set); 353 tcase_add_test(tc, eina_test_quaternion_set);
273 tcase_add_test(tc, eina_test_quaternion_mul); 354 tcase_add_test(tc, eina_test_quaternion_mul);
274 tcase_add_test(tc, eina_test_quaternion_normalized); 355 tcase_add_test(tc, eina_test_quaternion_normalized);
356 tcase_add_test(tc, eina_test_matrix_quaternion);
357 tcase_add_test(tc, eina_test_matrix_recompose);
275} 358}