From 3493a37db82edd7178efc3da6651daede2684f12 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Fri, 8 Nov 2019 06:33:50 +0000 Subject: [PATCH] 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 Differential Revision: https://phab.enlightenment.org/D10467 --- src/lib/eina/eina_matrix.c | 10 +++++++++- src/tests/eina/eina_test_matrix.c | 14 +++++++------- 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 eina_matrix3_rotate(Eina_Matrix3 *m, double rad) { double c, s; -#if 0 + + /* Note: Local functions do not guarantee accuracy. + * Errors occur in the calculation of very small or very large numbers. + * Local cos and sin functions differ from the math header cosf and sinf functions + * by result values. The 4th decimal place is different. + * But local functions are certainly faster than functions in math library. + * Later we would want someone to look at this and improve accuracy. + */ +#if 1 c = cosf(rad); s = sinf(rad); #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) zx, zy, zz; double tx = 20, ty = 30, ret; const double arr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1}; + double rotate_radian = 45.0 * M_PI / 180.0; eina_matrix3_values_set(&m1, 1, 0, 0, @@ -458,13 +459,12 @@ EFL_START_TEST(eina_matrix3_operations) 1, 0, 0, 0, 1, 0, 0, 0, 1); - eina_matrix3_rotate(&m1, M_PI/2); - - fail_if (!MATRIX3_CMP(round(m1.xx), round(m1.xy), round(m1.xz), - round(m1.yx), round(m1.yy), round(m1.yz), - round(m1.zx), round(m1.zy), round(m1.zz), - 0, -1, 0, - 1, 0, 0, + eina_matrix3_rotate(&m1, rotate_radian); + fail_if (!MATRIX3_CMP(m1.xx, m1.xy, m1.xz, + m1.yx, m1.yy, m1.yz, + m1.zx, m1.zy, m1.zz, + cosf(rotate_radian), -sinf(rotate_radian), 0, + sinf(rotate_radian), cosf(rotate_radian), 0, 0, 0, 1)); eina_matrix3_values_set(&m1,