summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunsuChoi <jsuya.choi@samsung.com>2019-11-08 06:33:50 +0000
committerCedric BAIL <cedric.bail@free.fr>2019-11-15 11:52:01 -0800
commit3493a37db82edd7178efc3da6651daede2684f12 (patch)
tree4308992ca2f0735c2e97455342d8e86365e65c05
parentf6b066df2a530160f1ca55ccfe2adb952516b6e9 (diff)
Eina_Matrix : Use math header for cosf and sinf of rotate function.
The local cos and sin functions differ from the math header cos and sin functions by result values The 4th decimal place is different. Computing large numbers can cause errors. Reviewed-by: Cedric BAIL <cedric.bail@free.fr> Differential Revision: https://phab.enlightenment.org/D10467
-rw-r--r--src/lib/eina/eina_matrix.c10
-rw-r--r--src/tests/eina/eina_test_matrix.c14
2 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/eina/eina_matrix.c b/src/lib/eina/eina_matrix.c
index 1c848f3e98..ad7cdb03ff 100644
--- a/src/lib/eina/eina_matrix.c
+++ b/src/lib/eina/eina_matrix.c
@@ -542,7 +542,15 @@ EAPI void
542eina_matrix3_rotate(Eina_Matrix3 *m, double rad) 542eina_matrix3_rotate(Eina_Matrix3 *m, double rad)
543{ 543{
544 double c, s; 544 double c, s;
545#if 0 545
546 /* Note: Local functions do not guarantee accuracy.
547 * Errors occur in the calculation of very small or very large numbers.
548 * Local cos and sin functions differ from the math header cosf and sinf functions
549 * by result values. The 4th decimal place is different.
550 * But local functions are certainly faster than functions in math library.
551 * Later we would want someone to look at this and improve accuracy.
552 */
553#if 1
546 c = cosf(rad); 554 c = cosf(rad);
547 s = sinf(rad); 555 s = sinf(rad);
548#else 556#else
diff --git a/src/tests/eina/eina_test_matrix.c b/src/tests/eina/eina_test_matrix.c
index 1d54f21e3f..ac3afa827f 100644
--- a/src/tests/eina/eina_test_matrix.c
+++ b/src/tests/eina/eina_test_matrix.c
@@ -400,6 +400,7 @@ EFL_START_TEST(eina_matrix3_operations)
400 zx, zy, zz; 400 zx, zy, zz;
401 double tx = 20, ty = 30, ret; 401 double tx = 20, ty = 30, ret;
402 const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; 402 const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
403 double rotate_radian = 45.0 * M_PI / 180.0;
403 404
404 eina_matrix3_values_set(&m1, 405 eina_matrix3_values_set(&m1,
405 1, 0, 0, 406 1, 0, 0,
@@ -458,13 +459,12 @@ EFL_START_TEST(eina_matrix3_operations)
458 1, 0, 0, 459 1, 0, 0,
459 0, 1, 0, 460 0, 1, 0,
460 0, 0, 1); 461 0, 0, 1);
461 eina_matrix3_rotate(&m1, M_PI/2); 462 eina_matrix3_rotate(&m1, rotate_radian);
462 463 fail_if (!MATRIX3_CMP(m1.xx, m1.xy, m1.xz,
463 fail_if (!MATRIX3_CMP(round(m1.xx), round(m1.xy), round(m1.xz), 464 m1.yx, m1.yy, m1.yz,
464 round(m1.yx), round(m1.yy), round(m1.yz), 465 m1.zx, m1.zy, m1.zz,
465 round(m1.zx), round(m1.zy), round(m1.zz), 466 cosf(rotate_radian), -sinf(rotate_radian), 0,
466 0, -1, 0, 467 sinf(rotate_radian), cosf(rotate_radian), 0,
467 1, 0, 0,
468 0, 0, 1)); 468 0, 0, 1));
469 469
470 eina_matrix3_values_set(&m1, 470 eina_matrix3_values_set(&m1,