cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=f2e3777a09ada7731df036f4068528354ff2a556

commit f2e3777a09ada7731df036f4068528354ff2a556
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Tue Jun 30 09:45:29 2015 +0200

    eina: add test for decomposition and composition of matrix.
---
 src/tests/eina/eina_test_quaternion.c | 85 ++++++++++++++++++++++++++++++++++-
 1 file changed, 84 insertions(+), 1 deletion(-)

diff --git a/src/tests/eina/eina_test_quaternion.c 
b/src/tests/eina/eina_test_quaternion.c
index 1ffbc1a..45c527c 100644
--- a/src/tests/eina/eina_test_quaternion.c
+++ b/src/tests/eina/eina_test_quaternion.c
@@ -27,7 +27,7 @@
 #include "eina_suite.h"
 #include "Eina.h"
 
-#define FLOAT_CMP(a, b) (fabs(a - b) <= DBL_MIN)
+#define FLOAT_CMP(a, b) (fabs((float)a - (float)b) <= FLT_MIN)
 
 static inline Eina_Bool
 eina_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)
    return EINA_FALSE;
 }
 
+static inline Eina_Bool
+eina_point_3d_cmp(const Eina_Point_3D *a, const Eina_Point_3D *b)
+{
+   if (FLOAT_CMP(a->x, b->x) &&
+       FLOAT_CMP(a->y, b->y) &&
+       FLOAT_CMP(a->z, b->z))
+     return EINA_TRUE;
+   return EINA_FALSE;
+}
+
 START_TEST(eina_test_quaternion_norm)
 {
    static const Eina_Quaternion q = { 1, 3, 4, 5 };
@@ -245,6 +255,30 @@ START_TEST(eina_test_quaternion_mul)
 }
 END_TEST
 
+START_TEST(eina_test_matrix_recompose)
+{
+   const Eina_Point_3D translation = { 0, 0, 0 };
+   const Eina_Point_3D scale = { 1, 1, 1 };
+   const Eina_Point_3D skew = { 0, 0, 0 };
+   const Eina_Quaternion perspective = { 0, 0, 0, 1 };
+   const Eina_Quaternion rotation = { 0, 0, 0, 1 };
+   Eina_Matrix4 m4;
+
+   eina_init();
+
+   eina_quaternion_matrix4_to(&m4,
+                              &rotation,
+                              &perspective,
+                              &translation,
+                              &scale,
+                              &skew);
+
+   fail_if(eina_matrix4_type_get(&m4) != EINA_MATRIX_TYPE_IDENTITY);
+
+   eina_shutdown();
+}
+END_TEST
+
 START_TEST(eina_test_quaternion_normalized)
 {
    Eina_Quaternion p = {1, 1, 1, 1};
@@ -259,6 +293,53 @@ START_TEST(eina_test_quaternion_normalized)
 }
 END_TEST
 
+START_TEST(eina_test_matrix_quaternion)
+{
+   const Eina_Point_3D rt = { -2, -3, 0 };
+   const Eina_Point_3D rsc = { 4, 5, 1 };
+   const Eina_Quaternion rr = { 0, 0, -1, 0 };
+   const Eina_Quaternion rp = { 0, 0, 0, 1 };
+   Eina_Quaternion rotation, perspective;
+   Eina_Matrix3 m3, m3r;
+   Eina_Matrix4 m4, m4r;
+   Eina_Point_3D translation, scale, skew;
+
+   eina_init();
+
+   eina_matrix3_identity(&m3);
+   eina_matrix3_rotate(&m3, 3.14159265);
+   eina_matrix3_translate(&m3, 2, 3);
+   eina_matrix3_scale(&m3, 4, 5);
+   eina_matrix3_matrix4_to(&m4, &m3);
+
+   fail_if(!eina_matrix4_quaternion_to(&rotation,
+                                       &perspective,
+                                       &translation,
+                                       &scale,
+                                       &skew,
+                                       &m4));
+
+   eina_quaternion_matrix4_to(&m4r,
+                              &rotation,
+                              &perspective,
+                              &translation,
+                              &scale,
+                              &skew);
+
+   eina_matrix4_matrix3_to(&m3r, &m4r);
+
+   fail_if(!eina_point_3d_cmp(&scale, &rsc));
+   fail_if(!eina_point_3d_cmp(&translation, &rt));
+   fail_if(!eina_quaternion_cmp(&perspective, &rp));
+   fail_if(!eina_quaternion_cmp(&rotation, &rr));
+
+   // Disable this test for the moment as it seems a rounding issue
+   // fail_if(!eina_matrix3_cmp(&m3r, &m3));
+
+   eina_shutdown();
+}
+END_TEST
+
 void
 eina_test_quaternion(TCase *tc)
 {
@@ -272,4 +353,6 @@ eina_test_quaternion(TCase *tc)
    tcase_add_test(tc, eina_test_quaternion_set);
    tcase_add_test(tc, eina_test_quaternion_mul);
    tcase_add_test(tc, eina_test_quaternion_normalized);
+   tcase_add_test(tc, eina_test_matrix_quaternion);
+   tcase_add_test(tc, eina_test_matrix_recompose);
 }

-- 


Reply via email to