summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOleksandr Shcherbina <o.shcherbina@samsung.com>2016-03-15 11:20:52 -0700
committerCedric Bail <cedric@osg.samsung.com>2016-03-15 11:20:55 -0700
commit48f75713e5aba37320eb2dbf4856a7f041741a2d (patch)
tree3a2d036eb79b90cdcc675b16038981a114a8166f /src
parent8706d03b43a59578e9c0965545efbc13f4407cab (diff)
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 <cedric@osg.samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_inline_vector.x46
-rw-r--r--src/tests/eina/eina_test_vector.c18
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 d7dd8d87b9..040c0549ff 100644
--- a/src/lib/eina/eina_inline_vector.x
+++ b/src/lib/eina/eina_inline_vector.x
@@ -117,8 +117,12 @@ static inline void
117eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m, 117eina_vector2_transform(Eina_Vector2 *out, const Eina_Matrix2 *m,
118 const Eina_Vector2 *v) 118 const Eina_Vector2 *v)
119{ 119{
120 out->x = (m->xx * v->x) + (m->yx * v->y); 120 Eina_Vector2 tmp;
121 out->y = (m->xy * v->x) + (m->yy * v->y); 121
122 tmp.x = (m->xx * v->x) + (m->yx * v->y);
123 tmp.y = (m->xy * v->x) + (m->yy * v->y);
124
125 eina_vector2_copy(out, &tmp);
122} 126}
123 127
124static inline void 128static inline void
@@ -139,8 +143,12 @@ eina_vector2_homogeneous_direction_transform(Eina_Vector2 *out,
139 const Eina_Matrix3 *m, 143 const Eina_Matrix3 *m,
140 const Eina_Vector2 *v) 144 const Eina_Vector2 *v)
141{ 145{
142 out->x = (m->xx * v->x) + (m->yx * v->y); 146 Eina_Vector2 tmp;
143 out->y = (m->xy * v->x) + (m->yy * v->y); 147
148 tmp.x = (m->xx * v->x) + (m->yx * v->y);
149 tmp.y = (m->xy * v->x) + (m->yy * v->y);
150
151 eina_vector2_copy(out, &tmp);
144} 152}
145 153
146static inline void 154static inline void
@@ -216,9 +224,13 @@ eina_vector3_dot_product(const Eina_Vector3 *a, const Eina_Vector3 *b)
216static inline void 224static inline void
217eina_vector3_cross_product(Eina_Vector3 *out, const Eina_Vector3 *a, const Eina_Vector3 *b) 225eina_vector3_cross_product(Eina_Vector3 *out, const Eina_Vector3 *a, const Eina_Vector3 *b)
218{ 226{
219 out->x = a->y * b->z - a->z * b->y; 227 Eina_Vector3 tmp;
220 out->y = a->z * b->x - a->x * b->z; 228
221 out->z = a->x * b->y - a->y * b->x; 229 tmp.x = a->y * b->z - a->z * b->y;
230 tmp.y = a->z * b->x - a->x * b->z;
231 tmp.z = a->x * b->y - a->y * b->x;
232
233 eina_vector3_copy(out, &tmp);
222} 234}
223 235
224static inline double 236static inline double
@@ -271,29 +283,37 @@ eina_vector3_normalize(Eina_Vector3 *out, const Eina_Vector3 *v)
271static inline void 283static inline void
272eina_vector3_transform(Eina_Vector3 *out, const Eina_Matrix3 *m, const Eina_Vector3 *v) 284eina_vector3_transform(Eina_Vector3 *out, const Eina_Matrix3 *m, const Eina_Vector3 *v)
273{ 285{
286 Eina_Vector3 tmp;
287
274 if (eina_matrix3_type_get(m) == EINA_MATRIX_TYPE_IDENTITY) 288 if (eina_matrix3_type_get(m) == EINA_MATRIX_TYPE_IDENTITY)
275 { 289 {
276 eina_vector3_copy(out, v); 290 eina_vector3_copy(out, v);
277 return; 291 return;
278 } 292 }
279 293
280 out->x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z); 294 tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
281 out->y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z); 295 tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
282 out->z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z); 296 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z);
297
298 eina_vector3_copy(out, &tmp);
283} 299}
284 300
285static inline void 301static inline void
286eina_vector3_homogeneous_direction_transform(Eina_Vector3 *out, const Eina_Matrix4 *m, const Eina_Vector3 *v) 302eina_vector3_homogeneous_direction_transform(Eina_Vector3 *out, const Eina_Matrix4 *m, const Eina_Vector3 *v)
287{ 303{
304 Eina_Vector3 tmp;
305
288 if (eina_matrix4_type_get(m) == EINA_MATRIX_TYPE_IDENTITY) 306 if (eina_matrix4_type_get(m) == EINA_MATRIX_TYPE_IDENTITY)
289 { 307 {
290 eina_vector3_copy(out, v); 308 eina_vector3_copy(out, v);
291 return; 309 return;
292 } 310 }
293 311
294 out->x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z); 312 tmp.x = (m->xx * v->x) + (m->yx * v->y) + (m->zx * v->z);
295 out->y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z); 313 tmp.y = (m->xy * v->x) + (m->yy * v->y) + (m->zy * v->z);
296 out->z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z); 314 tmp.z = (m->xz * v->x) + (m->yz * v->y) + (m->zz * v->z);
315
316 eina_vector3_copy(out, &tmp);
297} 317}
298 318
299static inline void 319static inline void
diff --git a/src/tests/eina/eina_test_vector.c b/src/tests/eina/eina_test_vector.c
index a155ef8062..4a7e3ffe79 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)
89 eina_vector2_transform(&v3, &m2, &v1); 89 eina_vector2_transform(&v3, &m2, &v1);
90 fail_if((v3.x != 6) || (v3.y != 6)); 90 fail_if((v3.x != 6) || (v3.y != 6));
91 91
92 eina_vector2_transform(&v3, &m2, &v3);
93 fail_if((v3.x != 24) || (v3.y != 24));
94
92 eina_matrix3_values_set(&m3, 95 eina_matrix3_values_set(&m3,
93 2, 2, 2, 96 2, 2, 2,
94 2, 2, 2, 97 2, 2, 2,
95 2, 2, 2); 98 2, 2, 2);
99
96 eina_vector2_homogeneous_position_transform(&v3, &m3, &v1); 100 eina_vector2_homogeneous_position_transform(&v3, &m3, &v1);
97 fail_if((v3.x != 1) || (v3.y != 1)); 101 fail_if((v3.x != 1) || (v3.y != 1));
98 102
103
99 eina_vector2_homogeneous_direction_transform(&v3, &m3, &v1); 104 eina_vector2_homogeneous_direction_transform(&v3, &m3, &v1);
100 fail_if((v3.x != 6) || (v3.y != 6)); 105 fail_if((v3.x != 6) || (v3.y != 6));
101 106
107 eina_vector2_homogeneous_direction_transform(&v3, &m3, &v3);
108 fail_if((v3.x != 24) || (v3.y != 24));
109
102 eina_shutdown(); 110 eina_shutdown();
103} 111}
104END_TEST 112END_TEST
@@ -151,6 +159,10 @@ START_TEST(eina_test_vector3_operations)
151 eina_vector3_cross_product(&v3, &v1, &v2); 159 eina_vector3_cross_product(&v3, &v1, &v2);
152 fail_if((v3.x != -5) || (v3.y != 10) || (v3.z != -5)); 160 fail_if((v3.x != -5) || (v3.y != 10) || (v3.z != -5));
153 161
162 eina_vector3_cross_product(&v3, &v1, &v3);
163 fail_if((v3.x != -40) || (v3.y != -10) || (v3.z != 20));
164
165
154 res = eina_vector3_length_get(&v2); 166 res = eina_vector3_length_get(&v2);
155 fail_if((res - sqrt(75)) > DBL_EPSILON); 167 fail_if((res - sqrt(75)) > DBL_EPSILON);
156 168
@@ -178,6 +190,9 @@ START_TEST(eina_test_vector3_operations)
178 eina_vector3_transform(&v3, &m3, &v1); 190 eina_vector3_transform(&v3, &m3, &v1);
179 fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12)); 191 fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12));
180 192
193 eina_vector3_transform(&v3, &m3, &v3);
194 fail_if((v3.x != 72) || (v3.y != 72) || (v3.z != 72));
195
181 eina_matrix4_values_set(&m4, 196 eina_matrix4_values_set(&m4,
182 2, 2, 2, 2, 197 2, 2, 2, 2,
183 2, 2, 2, 2, 198 2, 2, 2, 2,
@@ -220,6 +235,9 @@ START_TEST(eina_test_vector3_operations)
220 eina_vector3_homogeneous_direction_transform(&v3, &m4, &v1); 235 eina_vector3_homogeneous_direction_transform(&v3, &m4, &v1);
221 fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12)); 236 fail_if((v3.x != 12) || (v3.y != 12) || (v3.z != 12));
222 237
238 eina_vector3_homogeneous_direction_transform(&v3, &m4, &v3);
239 fail_if((v3.x != 72) || (v3.y != 72) || (v3.z != 72));
240
223 eina_shutdown(); 241 eina_shutdown();
224} 242}
225END_TEST 243END_TEST