easing-functions
easing-functions copied to clipboard
easeInOutCubic is wrong
I'm trying your easeInOutCubic:
double easeInOutCubic( double t ) {
return t < 0.5 ? 4 * t * t * t : 1 + (--t) * (2 * (--t)) * (2 * t);
}
But it returns wrong result for case t >= 0.5.
I guess the correct implementation is
return t < 0.5 ? 4 * t * t * t : (t-1)*(2*t-2)*(2*t-2)+1
(from https://gist.github.com/gre/1650294)
--t
is useful but sometimes get tricky to debug. In this case the second and third parentheses should be 2*t - 2
but in the repo it's 2*(t-2)
which of course gives wrong results
Using --t and t several times in an expression like this is unfortunately not useful at all, it's Undefined Behaviour. You can't rely on the order of evaluation without sequence points.