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>
This commit is contained in:
Oleksandr Shcherbina 2016-03-15 11:20:52 -07:00 committed by Cedric Bail
parent 8706d03b43
commit 48f75713e5
2 changed files with 51 additions and 13 deletions

View File

@ -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

View File

@ -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