summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-12-19 12:10:30 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-12-19 16:33:46 -0800
commitd94a186584162f6159d5d422906e5e13b96461f2 (patch)
tree662984c6abfc246b78cc77ba1c8e6c63ec674f62 /src
parent1f6c4b13708f133295869c5a191373538b79baae (diff)
eina: fix double comparison in eina matrix.
Diffstat (limited to 'src')
-rw-r--r--src/lib/eina/eina_matrix.c70
1 files changed, 46 insertions, 24 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index d7aeebf50a..43da6c7021 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -30,6 +30,7 @@
30#include "eina_rectangle.h" 30#include "eina_rectangle.h"
31#include "eina_quad.h" 31#include "eina_quad.h"
32#include "eina_matrix.h" 32#include "eina_matrix.h"
33#include "eina_util.h"
33 34
34#define MATRIX_XX(m) (m)->xx 35#define MATRIX_XX(m) (m)->xx
35#define MATRIX_XY(m) (m)->xy 36#define MATRIX_XY(m) (m)->xy
@@ -105,12 +106,18 @@ _cos(double x)
105EAPI Eina_Matrix_Type 106EAPI Eina_Matrix_Type
106eina_matrix3_type_get(const Eina_Matrix3 *m) 107eina_matrix3_type_get(const Eina_Matrix3 *m)
107{ 108{
108 if ((MATRIX_ZX(m) != 0) || (MATRIX_ZY(m) != 0) || (MATRIX_ZZ(m) != 1)) 109 if (!EINA_DBL_CMP(MATRIX_ZX(m), 0.0) ||
110 !EINA_DBL_CMP(MATRIX_ZY(m), 0.0) ||
111 !EINA_DBL_CMP(MATRIX_ZZ(m), 1.0))
109 return EINA_MATRIX_TYPE_PROJECTIVE; 112 return EINA_MATRIX_TYPE_PROJECTIVE;
110 else 113 else
111 { 114 {
112 if ((MATRIX_XX(m) == 1) && (MATRIX_XY(m) == 0) && (MATRIX_XZ(m) == 0) && 115 if (EINA_DBL_CMP(MATRIX_XX(m), 1.0) &&
113 (MATRIX_YX(m) == 0) && (MATRIX_YY(m) == 1) && (MATRIX_YZ(m) == 0)) 116 EINA_DBL_CMP(MATRIX_XY(m), 0.0) &&
117 EINA_DBL_CMP(MATRIX_XZ(m), 0.0) &&
118 EINA_DBL_CMP(MATRIX_YX(m), 0.0) &&
119 EINA_DBL_CMP(MATRIX_YY(m), 1.0) &&
120 EINA_DBL_CMP(MATRIX_YZ(m), 0.0))
114 return EINA_MATRIX_TYPE_IDENTITY; 121 return EINA_MATRIX_TYPE_IDENTITY;
115 else 122 else
116 return EINA_MATRIX_TYPE_AFFINE; 123 return EINA_MATRIX_TYPE_AFFINE;
@@ -120,10 +127,22 @@ eina_matrix3_type_get(const Eina_Matrix3 *m)
120EAPI Eina_Matrix_Type 127EAPI Eina_Matrix_Type
121eina_matrix4_type_get(const Eina_Matrix4 *m) 128eina_matrix4_type_get(const Eina_Matrix4 *m)
122{ 129{
123 if ((MATRIX_XX(m) == 1) && (MATRIX_XY(m) == 0) && (MATRIX_XZ(m) == 0) && (MATRIX_XW(m) == 0) && 130 if (EINA_DBL_CMP(MATRIX_XX(m), 1.0) &&
124 (MATRIX_YX(m) == 0) && (MATRIX_YY(m) == 1) && (MATRIX_YZ(m) == 0) && (MATRIX_YW(m) == 0) && 131 EINA_DBL_CMP(MATRIX_XY(m), 0.0) &&
125 (MATRIX_ZX(m) == 0) && (MATRIX_ZY(m) == 0) && (MATRIX_ZZ(m) == 1) && (MATRIX_ZW(m) == 0) && 132 EINA_DBL_CMP(MATRIX_XZ(m), 0.0) &&
126 (MATRIX_WX(m) == 0) && (MATRIX_WY(m) == 0) && (MATRIX_WZ(m) == 0) && (MATRIX_WW(m) == 1)) 133 EINA_DBL_CMP(MATRIX_XW(m), 0.0) &&
134 EINA_DBL_CMP(MATRIX_YX(m), 0.0) &&
135 EINA_DBL_CMP(MATRIX_YY(m), 1.0) &&
136 EINA_DBL_CMP(MATRIX_YZ(m), 0.0) &&
137 EINA_DBL_CMP(MATRIX_YW(m), 0.0) &&
138 EINA_DBL_CMP(MATRIX_ZX(m), 0.0) &&
139 EINA_DBL_CMP(MATRIX_ZY(m), 0.0) &&
140 EINA_DBL_CMP(MATRIX_ZZ(m), 1.0) &&
141 EINA_DBL_CMP(MATRIX_ZW(m), 0.0) &&
142 EINA_DBL_CMP(MATRIX_WX(m), 0.0) &&
143 EINA_DBL_CMP(MATRIX_WY(m), 0.0) &&
144 EINA_DBL_CMP(MATRIX_WZ(m), 0.0) &&
145 EINA_DBL_CMP(MATRIX_WW(m), 1.0))
127 return EINA_MATRIX_TYPE_IDENTITY; 146 return EINA_MATRIX_TYPE_IDENTITY;
128 return EINA_MATRIX_TYPE_AFFINE; 147 return EINA_MATRIX_TYPE_AFFINE;
129} 148}
@@ -261,7 +280,8 @@ eina_matrix3_point_transform(const Eina_Matrix3 *m,
261{ 280{
262 double xrr, yrr; 281 double xrr, yrr;
263 282
264 if (!MATRIX_ZX(m) && !MATRIX_ZY(m)) 283 if (!EINA_DBL_CMP(MATRIX_ZX(m), 0.0) &&
284 !EINA_DBL_CMP(MATRIX_ZY(m), 0.0))
265 { 285 {
266 xrr = (x * MATRIX_XX(m) + y * MATRIX_XY(m) + MATRIX_XZ(m)); 286 xrr = (x * MATRIX_XX(m) + y * MATRIX_XY(m) + MATRIX_XZ(m));
267 yrr = (x * MATRIX_YX(m) + y * MATRIX_YY(m) + MATRIX_YZ(m)); 287 yrr = (x * MATRIX_YX(m) + y * MATRIX_YY(m) + MATRIX_YZ(m));
@@ -381,7 +401,7 @@ eina_matrix3_inverse(const Eina_Matrix3 *m, Eina_Matrix3 *m2)
381 401
382 /* determinant */ 402 /* determinant */
383 scalar = eina_matrix3_determinant(m); 403 scalar = eina_matrix3_determinant(m);
384 if (!scalar) 404 if (EINA_DBL_CMP(scalar, 0.0))
385 { 405 {
386 eina_matrix3_identity(m2); 406 eina_matrix3_identity(m2);
387 return; 407 return;
@@ -425,15 +445,15 @@ eina_matrix3_compose(const Eina_Matrix3 *m1,
425EAPI Eina_Bool 445EAPI Eina_Bool
426eina_matrix3_equal(const Eina_Matrix3 *m1, const Eina_Matrix3 *m2) 446eina_matrix3_equal(const Eina_Matrix3 *m1, const Eina_Matrix3 *m2)
427{ 447{
428 if (m1->xx != m2->xx || 448 if (!EINA_DBL_CMP(m1->xx, m2->xx) ||
429 m1->xy != m2->xy || 449 !EINA_DBL_CMP(m1->xy, m2->xy) ||
430 m1->xz != m2->xz || 450 !EINA_DBL_CMP(m1->xz, m2->xz) ||
431 m1->yx != m2->yx || 451 !EINA_DBL_CMP(m1->yx, m2->yx) ||
432 m1->yy != m2->yy || 452 !EINA_DBL_CMP(m1->yy, m2->yy) ||
433 m1->yz != m2->yz || 453 !EINA_DBL_CMP(m1->yz, m2->yz) ||
434 m1->zx != m2->zx || 454 !EINA_DBL_CMP(m1->zx, m2->zx) ||
435 m1->zy != m2->zy || 455 !EINA_DBL_CMP(m1->zy, m2->zy) ||
436 m1->zz != m2->zz) 456 !EINA_DBL_CMP(m1->zz, m2->zz))
437 return EINA_FALSE; 457 return EINA_FALSE;
438 return EINA_TRUE; 458 return EINA_TRUE;
439} 459}
@@ -582,7 +602,7 @@ eina_matrix3_square_quad_map(Eina_Matrix3 *m, const Eina_Quad *q)
582 double ey = QUAD_Y0(q) - QUAD_Y1(q) + QUAD_Y2(q) - QUAD_Y3(q); 602 double ey = QUAD_Y0(q) - QUAD_Y1(q) + QUAD_Y2(q) - QUAD_Y3(q);
583 603
584 /* paralellogram */ 604 /* paralellogram */
585 if (!ex && !ey) 605 if (EINA_DBL_CMP(ex, 0.0) && EINA_DBL_CMP(ey, 0.0))
586 { 606 {
587 /* create the affine matrix */ 607 /* create the affine matrix */
588 MATRIX_XX(m) = QUAD_X1(q) - QUAD_X0(q); 608 MATRIX_XX(m) = QUAD_X1(q) - QUAD_X0(q);
@@ -607,7 +627,7 @@ eina_matrix3_square_quad_map(Eina_Matrix3 *m, const Eina_Quad *q)
607 double dy2 = QUAD_Y3(q) - QUAD_Y2(q); // y3 - y2 627 double dy2 = QUAD_Y3(q) - QUAD_Y2(q); // y3 - y2
608 double den = (dx1 * dy2) - (dx2 * dy1); 628 double den = (dx1 * dy2) - (dx2 * dy1);
609 629
610 if (!den) 630 if (EINA_DBL_CMP(den, 0.0))
611 return EINA_FALSE; 631 return EINA_FALSE;
612 632
613 MATRIX_ZX(m) = ((ex * dy2) - (dx2 * ey)) / den; 633 MATRIX_ZX(m) = ((ex * dy2) - (dx2 * ey)) / den;
@@ -636,7 +656,7 @@ eina_matrix3_quad_square_map(Eina_Matrix3 *m,
636 656
637 eina_matrix3_inverse(&tmp, m); 657 eina_matrix3_inverse(&tmp, m);
638 /* make the projective matrix3 always have 1 on zz */ 658 /* make the projective matrix3 always have 1 on zz */
639 if (MATRIX_ZZ(m) != 1) 659 if (!EINA_DBL_CMP(MATRIX_ZZ(m), 1.0))
640 { 660 {
641 eina_matrix3_divide(m, MATRIX_ZZ(m)); 661 eina_matrix3_divide(m, MATRIX_ZZ(m));
642 } 662 }
@@ -969,8 +989,10 @@ eina_matrix4_identity(Eina_Matrix4 *out)
969EAPI Eina_Matrix_Type 989EAPI Eina_Matrix_Type
970eina_matrix2_type_get(const Eina_Matrix2 *m) 990eina_matrix2_type_get(const Eina_Matrix2 *m)
971{ 991{
972 if ((MATRIX_XX(m) == 1) && (MATRIX_XY(m) == 0) && 992 if (EINA_DBL_CMP(MATRIX_XX(m), 1.0) &&
973 (MATRIX_YX(m) == 0) && (MATRIX_YY(m) == 1)) 993 EINA_DBL_CMP(MATRIX_XY(m), 0.0) &&
994 EINA_DBL_CMP(MATRIX_YX(m), 0.0) &&
995 EINA_DBL_CMP(MATRIX_YY(m), 1.0))
974 return EINA_MATRIX_TYPE_IDENTITY; 996 return EINA_MATRIX_TYPE_IDENTITY;
975 return EINA_MATRIX_TYPE_AFFINE; 997 return EINA_MATRIX_TYPE_AFFINE;
976} 998}
@@ -1216,7 +1238,7 @@ eina_matrix2_inverse(Eina_Matrix2 *out, const Eina_Matrix2 *mat)
1216 1238
1217 det = MATRIX_XX(mat) * MATRIX_YY(mat) - MATRIX_YX(mat) * MATRIX_XY(mat); 1239 det = MATRIX_XX(mat) * MATRIX_YY(mat) - MATRIX_YX(mat) * MATRIX_XY(mat);
1218 1240
1219 if (det == 0.0) 1241 if (EINA_DBL_CMP(det, 0.0))
1220 return; 1242 return;
1221 1243
1222 det = 1.0 / det; 1244 det = 1.0 / det;