cedric pushed a commit to branch master.

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

commit ce4146ec6303671e072ca2cbb29b1fec069faf0c
Author: se.osadchy <se.osad...@samsung.com>
Date:   Wed Dec 2 14:14:17 2015 -0800

    evas: fix bug with logic with eina_matrix in evas_3d_utils
    
    Summary: Also need to fix logically dead code in coverity.
    
    Reviewers: raster, Hermet, cedric
    
    Subscribers: jpeg
    
    Maniphest Tasks: T2832
    
    Differential Revision: https://phab.enlightenment.org/D3346
    
    Signed-off-by: Cedric BAIL <ced...@osg.samsung.com>
---
 src/Makefile_Evas.am                 |  1 +
 src/lib/eina/eina_matrix.c           | 32 ++++++++++++++--------------
 src/lib/evas/include/evas_3d_utils.h | 32 ++++++++++++++--------------
 src/tests/evas/evas_suite.c          |  1 +
 src/tests/evas/evas_suite.h          |  1 +
 src/tests/evas/evas_test_matrix.c    | 41 ++++++++++++++++++++++++++++++++++++
 6 files changed, 76 insertions(+), 32 deletions(-)

diff --git a/src/Makefile_Evas.am b/src/Makefile_Evas.am
index 0c9a214..3c1f491 100644
--- a/src/Makefile_Evas.am
+++ b/src/Makefile_Evas.am
@@ -2132,6 +2132,7 @@ tests/evas/evas_test_image.c \
 tests/evas/evas_test_mesh.c \
 tests/evas/evas_test_mask.c \
 tests/evas/evas_test_evasgl.c \
+tests/evas/evas_test_matrix.c \
 tests/evas/evas_tests_helpers.h \
 tests/evas/evas_suite.h
 
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 7a1469c..13362f9 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -1004,40 +1004,40 @@ eina_matrix4_multiply(Eina_Matrix4 *out, const 
Eina_Matrix4 *mat_a,
      }
 
    MATRIX_XX(out) = MATRIX_XX(mat_a) * MATRIX_XX(mat_b) + MATRIX_YX(mat_a) * 
MATRIX_XY(mat_b) +
-                    MATRIX_ZX(mat_a) * MATRIX_XZ(mat_b) + mat_a->wx * 
MATRIX_XW(mat_b);
+                    MATRIX_ZX(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WX(mat_a) * 
MATRIX_XW(mat_b);
    MATRIX_YX(out) = MATRIX_XX(mat_a) * MATRIX_YX(mat_b) + MATRIX_YX(mat_a) * 
MATRIX_YY(mat_b) +
-                    MATRIX_ZX(mat_a) * MATRIX_YZ(mat_b) + mat_a->wx * 
MATRIX_YW(mat_b);
+                    MATRIX_ZX(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WX(mat_a) * 
MATRIX_YW(mat_b);
    MATRIX_ZX(out) = MATRIX_XX(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YX(mat_a) * 
MATRIX_ZY(mat_b) +
-                    MATRIX_ZX(mat_a) * MATRIX_ZZ(mat_b) + mat_a->wx * 
MATRIX_ZW(mat_b);
+                    MATRIX_ZX(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WX(mat_a) * 
MATRIX_ZW(mat_b);
    MATRIX_WX(out) = MATRIX_XX(mat_a) * MATRIX_WX(mat_b) + MATRIX_YX(mat_a) * 
MATRIX_WY(mat_b) +
-                    MATRIX_ZX(mat_a) * MATRIX_WZ(mat_b) + mat_a->wx * 
MATRIX_WW(mat_b);
+                    MATRIX_ZX(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WX(mat_a) * 
MATRIX_WW(mat_b);
 
    MATRIX_XY(out) = MATRIX_XY(mat_a) * MATRIX_XX(mat_b) + MATRIX_YY(mat_a) * 
MATRIX_XY(mat_b) +
-                    MATRIX_ZY(mat_a) * MATRIX_XZ(mat_b) + mat_a->wy * 
MATRIX_XW(mat_b);
+                    MATRIX_ZY(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WY(mat_a) * 
MATRIX_XW(mat_b);
    MATRIX_YY(out) = MATRIX_XY(mat_a) * MATRIX_YX(mat_b) + MATRIX_YY(mat_a) * 
MATRIX_YY(mat_b) +
-                    MATRIX_ZY(mat_a) * MATRIX_YZ(mat_b) + mat_a->wy * 
MATRIX_YW(mat_b);
+                    MATRIX_ZY(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WY(mat_a) * 
MATRIX_YW(mat_b);
    MATRIX_ZY(out) = MATRIX_XY(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YY(mat_a) * 
MATRIX_ZY(mat_b) +
-                    MATRIX_ZY(mat_a) * MATRIX_ZZ(mat_b) + mat_a->wy * 
MATRIX_ZW(mat_b);
+                    MATRIX_ZY(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WY(mat_a) * 
MATRIX_ZW(mat_b);
    MATRIX_WY(out) = MATRIX_XY(mat_a) * MATRIX_WX(mat_b) + MATRIX_YY(mat_a) * 
MATRIX_WY(mat_b) +
-                    MATRIX_ZY(mat_a) * MATRIX_WZ(mat_b) + mat_a->wy * 
MATRIX_WW(mat_b);
+                    MATRIX_ZY(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WY(mat_a) * 
MATRIX_WW(mat_b);
 
    MATRIX_XZ(out) = MATRIX_XZ(mat_a) * MATRIX_XX(mat_b) + MATRIX_YZ(mat_a) * 
MATRIX_XY(mat_b) +
-                    MATRIX_ZZ(mat_a) * MATRIX_XZ(mat_b) + mat_a->wz * 
MATRIX_XW(mat_b);
+                    MATRIX_ZZ(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WZ(mat_a) * 
MATRIX_XW(mat_b);
    MATRIX_YZ(out) = MATRIX_XZ(mat_a) * MATRIX_YX(mat_b) + MATRIX_YZ(mat_a) * 
MATRIX_YY(mat_b) +
-                    MATRIX_ZZ(mat_a) * MATRIX_YZ(mat_b) + mat_a->wz * 
MATRIX_YW(mat_b);
+                    MATRIX_ZZ(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WZ(mat_a) * 
MATRIX_YW(mat_b);
    MATRIX_ZZ(out) = MATRIX_XZ(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YZ(mat_a) * 
MATRIX_ZY(mat_b) +
-                    MATRIX_ZZ(mat_a) * MATRIX_ZZ(mat_b) + mat_a->wz * 
MATRIX_ZW(mat_b);
+                    MATRIX_ZZ(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WZ(mat_a) * 
MATRIX_ZW(mat_b);
    MATRIX_WZ(out) = MATRIX_XZ(mat_a) * MATRIX_WX(mat_b) + MATRIX_YZ(mat_a) * 
MATRIX_WY(mat_b) +
-                    MATRIX_ZZ(mat_a) * MATRIX_WZ(mat_b) + mat_a->wz * 
MATRIX_WW(mat_b);
+                    MATRIX_ZZ(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WZ(mat_a) * 
MATRIX_WW(mat_b);
 
    MATRIX_XW(out) = MATRIX_XW(mat_a) * MATRIX_XX(mat_b) + MATRIX_YW(mat_a) * 
MATRIX_XY(mat_b) +
-                    MATRIX_ZW(mat_a) * MATRIX_XZ(mat_b) + mat_a->ww * 
MATRIX_XW(mat_b);
+                    MATRIX_ZW(mat_a) * MATRIX_XZ(mat_b) + MATRIX_WW(mat_a) * 
MATRIX_XW(mat_b);
    MATRIX_YW(out) = MATRIX_XW(mat_a) * MATRIX_YX(mat_b) + MATRIX_YW(mat_a) * 
MATRIX_YY(mat_b) +
-                    MATRIX_ZW(mat_a) * MATRIX_YZ(mat_b) + mat_a->ww * 
MATRIX_YW(mat_b);
+                    MATRIX_ZW(mat_a) * MATRIX_YZ(mat_b) + MATRIX_WW(mat_a) * 
MATRIX_YW(mat_b);
    MATRIX_ZW(out) = MATRIX_XW(mat_a) * MATRIX_ZX(mat_b) + MATRIX_YW(mat_a) * 
MATRIX_ZY(mat_b) +
-                    MATRIX_ZW(mat_a) * MATRIX_ZZ(mat_b) + mat_a->ww * 
MATRIX_ZW(mat_b);
+                    MATRIX_ZW(mat_a) * MATRIX_ZZ(mat_b) + MATRIX_WW(mat_a) * 
MATRIX_ZW(mat_b);
    MATRIX_WW(out) = MATRIX_XW(mat_a) * MATRIX_WX(mat_b) + MATRIX_YW(mat_a) * 
MATRIX_WY(mat_b) +
-                    MATRIX_ZW(mat_a) * MATRIX_WZ(mat_b) + mat_a->ww * 
MATRIX_WW(mat_b);
+                    MATRIX_ZW(mat_a) * MATRIX_WZ(mat_b) + MATRIX_WW(mat_a) * 
MATRIX_WW(mat_b);
 }
 
 EAPI void
diff --git a/src/lib/evas/include/evas_3d_utils.h 
b/src/lib/evas/include/evas_3d_utils.h
index 52a9511..f3d4ed0 100644
--- a/src/lib/evas/include/evas_3d_utils.h
+++ b/src/lib/evas/include/evas_3d_utils.h
@@ -373,8 +373,8 @@ evas_vec3_homogeneous_position_transform(Evas_Vec3 *out, 
const Evas_Vec3 *v, con
         return;
      }
 
-   tmp.x = (m->xx * v->x) + (m->zw * v->y) + (m->zx  * v->z) + m->wx;
-   tmp.y = (m->xy * v->x) + (m->yx * v->y) + (m->zy  * v->z) + m->wy;
+   tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z) + m->wx;
+   tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z) + m->wy;
    tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z) + m->wz;
 
    evas_vec3_scale(out, &tmp,
@@ -392,8 +392,8 @@ evas_vec3_homogeneous_direction_transform(Evas_Vec3 *out, 
const Evas_Vec3 *v, co
         return;
      }
 
-   tmp.x = (m->xx * v->x) + (m->zw * v->y) + (m->zx  * v->z);
-   tmp.y = (m->xy * v->x) + (m->yx * v->y) + (m->zy  * v->z);
+   tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
+   tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
    tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z);
 
    evas_vec3_copy(out, &tmp);
@@ -953,17 +953,17 @@ evas_mat4_build(Eina_Matrix4 *out,
    evas_vec4_quaternion_rotation_matrix_get(orientation, &rot);
 
    out->xx = scale->x * rot.xx;
-   out->xy = scale->y * rot.xy;
-   out->xz = scale->z * rot.xz;
+   out->xy = scale->x * rot.xy;
+   out->xz = scale->x * rot.xz;
    out->xw = 0.0;
 
-   out->yx = scale->x * rot.yx;
+   out->yx = scale->y * rot.yx;
    out->yy = scale->y * rot.yy;
-   out->yz = scale->z * rot.yz;
+   out->yz = scale->y * rot.yz;
    out->yw = 0.0;
 
-   out->zx = scale->x * rot.zx;
-   out->zy = scale->y * rot.zy;
+   out->zx = scale->z * rot.zx;
+   out->zy = scale->z * rot.zy;
    out->zz = scale->z * rot.zz;
    out->zw = 0.0;
 
@@ -998,17 +998,17 @@ evas_mat4_inverse_build(Eina_Matrix4 *out, const 
Evas_Vec3 *position,
    evas_vec4_quaternion_rotation_matrix_get(&inv_rotation, &rot);
 
    out->xx = inv_scale.x * rot.xx;
-   out->xy = inv_scale.y * rot.xy;
-   out->xz = inv_scale.z * rot.xz;
+   out->xy = inv_scale.x * rot.xy;
+   out->xz = inv_scale.x * rot.xz;
    out->xw = 0.0;
 
-   out->yx = inv_scale.x * rot.yx;
+   out->yx = inv_scale.y * rot.yx;
    out->yy = inv_scale.y * rot.yy;
-   out->yz = inv_scale.z * rot.yz;
+   out->yz = inv_scale.y * rot.yz;
    out->yw = 0.0;
 
-   out->zx = inv_scale.x * rot.zx;
-   out->zy = inv_scale.y * rot.zy;
+   out->zx = inv_scale.z * rot.zx;
+   out->zy = inv_scale.z * rot.zy;
    out->zz = inv_scale.z * rot.zz;
    out->zw = 0.0;
 
diff --git a/src/tests/evas/evas_suite.c b/src/tests/evas/evas_suite.c
index 10a8d27..3654ab6 100644
--- a/src/tests/evas/evas_suite.c
+++ b/src/tests/evas/evas_suite.c
@@ -30,6 +30,7 @@ static const Evas_Test_Case etc[] = {
   { "Masking", evas_test_mask },
   { "Evas GL", evas_test_evasgl },
   { "Object Smart", evas_test_object_smart },
+  { "Matrix", evas_test_matrix },
   { NULL, NULL }
 };
 
diff --git a/src/tests/evas/evas_suite.h b/src/tests/evas/evas_suite.h
index bf77aee..cb22dd4 100644
--- a/src/tests/evas/evas_suite.h
+++ b/src/tests/evas/evas_suite.h
@@ -15,5 +15,6 @@ void evas_test_mesh(TCase *tc);
 void evas_test_mask(TCase *tc);
 void evas_test_evasgl(TCase *tc);
 void evas_test_object_smart(TCase *tc);
+void evas_test_matrix(TCase *tc);
 
 #endif /* _EVAS_SUITE_H */
diff --git a/src/tests/evas/evas_test_matrix.c 
b/src/tests/evas/evas_test_matrix.c
new file mode 100644
index 0000000..26e8b02
--- /dev/null
+++ b/src/tests/evas/evas_test_matrix.c
@@ -0,0 +1,41 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+
+#include "../../lib/evas/include/evas_common_private.h"
+#include "../../lib/evas/include/evas_private.h"
+#include "evas_suite.h"
+#include "Evas.h"
+#include "evas_tests_helpers.h"
+
+START_TEST(evas_matrix)
+{
+   Evas_Vec3 position;
+   Evas_Vec4 orientation;
+   Evas_Vec3 scale;
+   Eina_Matrix4 mat;
+
+   evas_vec3_set(&position, 5.0, 3.0, 2.0);
+   evas_vec4_set(&orientation, 30.0, 1.0, 0.0, 0.0);
+   evas_vec3_set(&scale, 1.0, 2.0, 1.0);
+
+   evas_mat4_build(&mat, &position, &orientation, &scale);
+   fail_if((mat.xx != -1) || (mat.xy != 60) ||
+           (mat.wx != 5) || (mat.wy != 3) ||
+           (mat.wz != 2) || (mat.ww != 1));
+
+   evas_mat4_inverse_build(&mat, &position, &orientation, &scale);
+   fail_if((mat.xx - 0.99 < DBL_EPSILON) || (mat.xy - 0.0 < DBL_EPSILON) ||
+           (mat.yx -0.0 < DBL_EPSILON) || (mat.yy -0.49 < DBL_EPSILON));
+}
+END_TEST
+
+void evas_test_matrix(TCase *tc)
+{
+   tcase_add_test(tc, evas_matrix);
+}

-- 


Reply via email to