diff --git a/src/tween.c b/src/tween.c index d1abfd7..c9a3d59 100644 --- a/src/tween.c +++ b/src/tween.c @@ -264,9 +264,14 @@ double GetTweenPosition(struct Tween* tween) { return tween->pos / tween->duration; } -double GetTweenInterpolation(struct Tween* tween) { - double pos = GetTweenPosition(tween); - switch (tween->style) { +double Interpolate(double pos, TWEEN_STYLE style) { + if (pos < 0.0) { + pos = 0.0; + } + if (pos > 1.0) { + pos = 1.0; + } + switch (style) { case TWEEN_STYLE_LINEAR: return LinearInterpolation(pos); case TWEEN_STYLE_QUADRATIC_IN: @@ -330,7 +335,10 @@ double GetTweenInterpolation(struct Tween* tween) { case TWEEN_STYLE_BOUNCE_IN_OUT: return BounceEaseInOut(pos); } - return pos; +} + +double GetTweenInterpolation(struct Tween* tween) { + return Interpolate(GetTweenPosition(tween), tween->style); } double GetTweenValue(struct Tween* tween) { diff --git a/src/tween.h b/src/tween.h index 7387a9c..6cdb5b7 100644 --- a/src/tween.h +++ b/src/tween.h @@ -84,5 +84,6 @@ double GetTweenPosition(struct Tween* tween); double GetTweenInterpolation(struct Tween* tween); double GetTweenValue(struct Tween* tween); void UpdateTween(struct Tween* tween, double delta); +double Interpolate(double pos, TWEEN_STYLE style); #endif