From 273885aa95580b7150c4a9b83061866a55b365c1 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Thu, 10 May 2012 08:41:50 +0000 Subject: [PATCH] ecore: trying to reduce rounding error in ecore. As we move back and forth from double to fixed point, we do have some rounding error. I am trying to limit them at much as possible by reducing the number of computation in double. SVN revision: 70905 --- legacy/ecore/ChangeLog | 4 ++++ legacy/ecore/NEWS | 1 + legacy/ecore/src/lib/ecore/ecore_anim.c | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/legacy/ecore/ChangeLog b/legacy/ecore/ChangeLog index 7805cee358..39960c22b0 100644 --- a/legacy/ecore/ChangeLog +++ b/legacy/ecore/ChangeLog @@ -632,3 +632,7 @@ 2012-05-08 Cedric Bail * Don't over allocate Ecore_Pipe during ecore_init/ecore_shutdown. + +2012-05-10 Cedric Bail + + * Reduce rounding error in ecore_animator_pos_map. diff --git a/legacy/ecore/NEWS b/legacy/ecore/NEWS index 2bda21b69b..40b50bf6a1 100644 --- a/legacy/ecore/NEWS +++ b/legacy/ecore/NEWS @@ -5,6 +5,7 @@ Changes since Ecore 1.2.0: Fixes: * ecore - Prevent running out of fd when cycling ecore_init/ecore_shutdown. + - Reduce rounding error in ecore_animator_pos_map. Ecore 1.2.0 diff --git a/legacy/ecore/src/lib/ecore/ecore_anim.c b/legacy/ecore/src/lib/ecore/ecore_anim.c index 4ced67a787..131929e18f 100644 --- a/legacy/ecore/src/lib/ecore/ecore_anim.c +++ b/legacy/ecore/src/lib/ecore/ecore_anim.c @@ -203,11 +203,13 @@ _pos_map_sin(double in) return eina_f32p32_double_to(eina_f32p32_sin(eina_f32p32_double_from(in))); } +#if 0 static double _pos_map_cos(double in) { return eina_f32p32_double_to(eina_f32p32_cos(eina_f32p32_double_from(in))); } +#endif static double _pos_map_accel_factor(double pos, @@ -258,6 +260,15 @@ _pos_map_spring(double pos, return _pos_map_sin((M_PI / 2.0) + (p2 * len)) * decay; } +#define DBL_TO(Fp) eina_f32p32_double_to(Fp) +#define DBL_FROM(D) eina_f32p32_double_from(D) +#define INT_FROM(I) eina_f32p32_int_from(I) +#define SIN(Fp) eina_f32p32_sin(Fp) +#define COS(Fp) eina_f32p32_cos(Fp) +#define ADD(A, B) eina_f32p32_add(A, B) +#define SUB(A, B) eina_f32p32_sub(A, B) +#define MUL(A, B) eina_f32p32_mul(A, B) + EAPI double ecore_animator_pos_map(double pos, Ecore_Pos_Map map, @@ -274,15 +285,18 @@ ecore_animator_pos_map(double pos, return pos; case ECORE_POS_MAP_ACCELERATE: - pos = 1.0 - _pos_map_sin(M_PI_2 + pos * M_PI_2); + /* pos = 1 - sin(Pi / 2 + pos * Pi / 2); */ + pos = DBL_TO(SUB(INT_FROM(1), SIN(ADD((EINA_F32P32_PI >> 1), MUL(DBL_FROM(pos), (EINA_F32P32_PI >> 1)))))); return pos; case ECORE_POS_MAP_DECELERATE: - pos = _pos_map_sin(pos * M_PI_2); + /* pos = sin(pos * Pi / 2); */ + pos = DBL_TO(SIN(MUL(DBL_FROM(pos), (EINA_F32P32_PI >> 1)))); return pos; case ECORE_POS_MAP_SINUSOIDAL: - pos = (1.0 - _pos_map_cos(pos * M_PI)) / 2.0; + /* pos = (1 - cos(pos * Pi)) / 2 */ + pos = DBL_TO((SUB(INT_FROM(1), COS(MUL(DBL_FROM(pos), EINA_F32P32_PI)))) >> 1); return pos; case ECORE_POS_MAP_ACCELERATE_FACTOR: