cedric pushed a commit to branch master.

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

commit 48f75713e5aba37320eb2dbf4856a7f041741a2d
Author: Oleksandr Shcherbina <o.shcherb...@samsung.com>
Date:   Tue Mar 15 11:20:52 2016 -0700

    eina: fix eina vector in case output vector the same as target vector
    
    Summary:
    Use aditional temporary vector for intermedia results in case output vector
    the same as target vector in functions:
    eina_vector2_transform,
    eina_vector2_homogeneous_direction_transform,
    eina_vector3_cross_product,
    eina_vector3_transform,
    eina_vector3_homogeneous_direction_transform
    It was in original version (in evas_vecN, module evas_3d_utils.h)
    Enrich test suit for this case.
    
    Reviewers: jpeg, cedric
    
    Reviewed By: cedric
    
    Differential Revision: https://phab.enlightenment.org/D3795
    
    Signed-off-by: Cedric Bail <ced...@osg.samsung.com>
---
 src/lib/eina/eina_inline_vector.x | 46 ++++++++++++++++++++++++++++-----------
 src/tests/eina/eina_test_vector.c | 18 +++++++++++++++
 2 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/lib/eina/eina_inline_vector.x 
b/src/lib/eina/eina_inline_vector.x
index d7dd8d8..040c054 100644
--- a/src/lib/eina/eina_inline_vector.x
+++ b/src/lib/eina/eina_inline_vector.x
@@ -117,8 +117,12 @@ static inline void
 eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m,
                        const Eina_Vector2 *v)
 {
-   out->x = (m->xx * v->x) + (m->yx * v->y);
-   out->y = (m->xy * v->x) + (m->yy * v->y);
+   Eina_Vector2 tmp;
+
+   tmp.x = (m->xx * v->x) + (m->yx * v->y);
+   tmp.y = (m->xy * v->x) + (m->yy * v->y);
+
+   eina_vector2_copy(out, &tmp);
 }
 
 static inline void
@@ -139,8 +143,12 @@ eina_vector2_homogeneous_direction_transform(Eina_Vector2 
*out,
                                              const Eina_Matrix3 *m,
                                              const Eina_Vector2 *v)
 {
-   out->x = (m->xx * v->x) + (m->yx * v->y);
-   out->y = (m->xy * v->x) + (m->yy * v->y);
+   Eina_Vector2 tmp;
+
+   tmp.x = (m->xx * v->x) + (m->yx * v->y);
+   tmp.y = (m->xy * v->x) + (m->yy * v->y);
+
+   eina_vector2_copy(out, &tmp);
 }
 
 static inline void
@@ -216,9 +224,13 @@ eina_vector3_dot_product(const Eina_Vector3 *a, const 
Eina_Vector3 *b)
 static inline void
 eina_vector3_cross_product(Eina_Vector3 *out, const Eina_Vector3 *a, const 
Eina_Vector3 *b)
 {
-   out->x = a->y * b->z - a->z * b->y;
-   out->y = a->z * b->x - a->x * b->z;
-   out->z = a->x * b->y - a->y * b->x;
+   Eina_Vector3 tmp;
+
+   tmp.x = a->y * b->z - a->z * b->y;
+   tmp.y = a->z * b->x - a->x * b->z;
+   tmp.z = a->x * b->y - a->y * b->x;
+
+   eina_vector3_copy(out, &tmp);
 }
 
 static inline double
@@ -271,29 +283,37 @@ eina_vector3_normalize(Eina_Vector3 *out, const 
Eina_Vector3 *v)
 static inline void
 eina_vector3_transform(Eina_Vector3 *out, const Eina_Matrix3 *m,  const 
Eina_Vector3 *v)
 {
+   Eina_Vector3 tmp;
+
    if (eina_matrix3_type_get(m) == EINA_MATRIX_TYPE_IDENTITY)
      {
         eina_vector3_copy(out, v);
         return;
      }
 
-   out->x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
-   out->y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
-   out->z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * 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);
+
+   eina_vector3_copy(out, &tmp);
 }
 
 static inline void
 eina_vector3_homogeneous_direction_transform(Eina_Vector3 *out, const 
Eina_Matrix4 *m,  const Eina_Vector3 *v)
 {
+   Eina_Vector3 tmp;
+
    if (eina_matrix4_type_get(m) == EINA_MATRIX_TYPE_IDENTITY)
      {
         eina_vector3_copy(out, v);
         return;
      }
 
-   out->x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
-   out->y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
-   out->z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * 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);
+
+   eina_vector3_copy(out, &tmp);
 }
 
 static inline void
diff --git a/src/tests/eina/eina_test_vector.c 
b/src/tests/eina/eina_test_vector.c
index a155ef8..4a7e3ff 100644
--- a/src/tests/eina/eina_test_vector.c
+++ b/src/tests/eina/eina_test_vector.c
@@ -89,16 +89,24 @@ START_TEST(eina_test_vector2_operations)
    eina_vector2_transform(&v3, &m2, &v1);
    fail_if((v3.x != 6) || (v3.y != 6));
 
+   eina_vector2_transform(&v3, &m2, &v3);
+   fail_if((v3.x != 24) || (v3.y != 24));
+
    eina_matrix3_values_set(&m3,
                           2, 2, 2,
                           2, 2, 2,
                           2, 2, 2);
+
    eina_vector2_homogeneous_position_transform(&v3, &m3, &v1);
    fail_if((v3.x != 1) || (v3.y != 1));
 
+
    eina_vector2_homogeneous_direction_transform(&v3, &m3, &v1);
    fail_if((v3.x != 6) || (v3.y != 6));
 
+   eina_vector2_homogeneous_direction_transform(&v3, &m3, &v3);
+   fail_if((v3.x != 24) || (v3.y != 24));
+
    eina_shutdown();
 }
 END_TEST
@@ -151,6 +159,10 @@ START_TEST(eina_test_vector3_operations)
    eina_vector3_cross_product(&v3, &v1, &v2);
    fail_if((v3.x != -5) || (v3.y != 10) || (v3.z != -5));
 
+   eina_vector3_cross_product(&v3, &v1, &v3);
+   fail_if((v3.x != -40) || (v3.y != -10) || (v3.z != 20));
+
+
    res = eina_vector3_length_get(&v2);
    fail_if((res - sqrt(75)) > DBL_EPSILON);
 
@@ -178,6 +190,9 @@ START_TEST(eina_test_vector3_operations)
    eina_vector3_transform(&v3, &m3, &v1);
    fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12));
 
+   eina_vector3_transform(&v3, &m3, &v3);
+   fail_if((v3.x != 72) || (v3.y != 72) || (v3.z != 72));
+
    eina_matrix4_values_set(&m4,
                           2, 2, 2, 2,
                           2, 2, 2, 2,
@@ -220,6 +235,9 @@ START_TEST(eina_test_vector3_operations)
    eina_vector3_homogeneous_direction_transform(&v3, &m4, &v1);
    fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12));
 
+   eina_vector3_homogeneous_direction_transform(&v3, &m4, &v3);
+   fail_if((v3.x != 72) || (v3.y != 72) || (v3.z != 72));
+
    eina_shutdown();
 }
 END_TEST

-- 


Reply via email to