EAPI double ecore_animator_pos_map(double pos, Ecore_Pos_Map map, double v1, double v2) { /* purely functional - locking not required */ if (pos > 1.0) pos = 1.0; else if (pos < 0.0) pos = 0.0; switch (map) { case ECORE_POS_MAP_LINEAR: return pos; case ECORE_POS_MAP_ACCELERATE: pos = 1.0 - _pos_map_sin(M_PI_2 + pos * M_PI_2); return pos; case ECORE_POS_MAP_DECELERATE: pos = _pos_map_sin(pos * M_PI_2); return pos; case ECORE_POS_MAP_SINUSOIDAL: pos = (1.0 - _pos_map_cos(pos * M_PI)) / 2.0; return pos; case ECORE_POS_MAP_ACCELERATE_FACTOR: pos = _pos_map_accel_factor(pos, v1); return pos; case ECORE_POS_MAP_DECELERATE_FACTOR: pos = 1.0 - _pos_map_accel_factor(1.0 - pos, v1); return pos; case ECORE_POS_MAP_SINUSOIDAL_FACTOR: if (pos < 0.5) pos = _pos_map_accel_factor(pos * 2.0, v1) / 2.0; else pos = 1.0 - (_pos_map_accel_factor((1.0 - pos) * 2.0, v1) / 2.0); return pos; case ECORE_POS_MAP_DIVISOR_INTERP: pos = _pos_map_pow(pos, v1, (int)v2); return pos; case ECORE_POS_MAP_BOUNCE: pos = _pos_map_spring(pos, (int)v2, v1); if (pos < 0.0) pos = -pos; pos = 1.0 - pos; return pos; case ECORE_POS_MAP_SPRING: pos = 1.0 - _pos_map_spring(pos, (int)v2, v1); return pos; default: return pos; } return pos; }
static double _pos_map_spring(double pos, int bounces, double decfac) { int segnum, segpos, b1, b2; double len, decay, decpos, p2; if (bounces < 0) bounces = 0; p2 = _pos_map_pow(pos, 0.5, 3); len = (M_PI / 2.0) + ((double)bounces * M_PI); segnum = (bounces * 2) + 1; segpos = 2 * (((int)(p2 * segnum) + 1) / 2); b1 = segpos; b2 = segnum + 1; if (b1 < 0) b1 = 0; decpos = (double)b1 / (double)b2; decay = _pos_map_accel_factor(1.0 - decpos, decfac); return _pos_map_sin((M_PI / 2.0) + (p2 * len)) * decay; }
EAPI double ecore_animator_pos_map(double pos, Ecore_Pos_Map map, double v1, double v2) { /* purely functional - locking not required */ if (pos > 1.0) pos = 1.0; else if (pos < 0.0) pos = 0.0; switch (map) { case ECORE_POS_MAP_LINEAR: return pos; case ECORE_POS_MAP_ACCELERATE: /* 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 = 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 - 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: pos = _pos_map_accel_factor(pos, v1); return pos; case ECORE_POS_MAP_DECELERATE_FACTOR: pos = 1.0 - _pos_map_accel_factor(1.0 - pos, v1); return pos; case ECORE_POS_MAP_SINUSOIDAL_FACTOR: if (pos < 0.5) pos = _pos_map_accel_factor(pos * 2.0, v1) / 2.0; else pos = 1.0 - (_pos_map_accel_factor((1.0 - pos) * 2.0, v1) / 2.0); return pos; case ECORE_POS_MAP_DIVISOR_INTERP: pos = _pos_map_pow(pos, v1, (int)v2); return pos; case ECORE_POS_MAP_BOUNCE: pos = _pos_map_spring(pos, (int)v2, v1); if (pos < 0.0) pos = -pos; pos = 1.0 - pos; return pos; case ECORE_POS_MAP_SPRING: pos = 1.0 - _pos_map_spring(pos, (int)v2, v1); return pos; default: return pos; } return pos; }