From 08080e2d13887f8a450130560acc8bd2094e1989 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Wed, 7 Dec 2016 22:26:25 +0100 Subject: [PATCH] Fix the quad_ease_in_out function --- src/functions/quad.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/functions/quad.rs b/src/functions/quad.rs index bf810e5..962c315 100644 --- a/src/functions/quad.rs +++ b/src/functions/quad.rs @@ -1,4 +1,5 @@ use super::ease::Easing; + /// This struct captures quadratic easing functions pub struct Quad; @@ -14,12 +15,14 @@ impl Easing for Quad { } fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / (d / 2.0); - if inner_t < 1.0 { - return (c / 2.0 * (inner_t.powi(2))) + b; + let mut t = t / (d / 2.0); + if t < 1.0 { + c / 2.0 * t * t + b + } + else { + t -= 1.0; + -c / 2.0 * (t * (t - 2.0) - 1.0) + b } - let temp = inner_t - 1.0; - return -c / 2.0 * (((inner_t - 2.0) * (temp)) - 1.0) + b; } } @@ -40,7 +43,7 @@ mod test { #[test] fn ease_in_out() { assert_relative_eq!(super::Quad::ease_in_out(1.0, 2.0, 3.0, 4.0), 2.37500); - assert_relative_eq!(super::Quad::ease_in_out(51.0, 1.0, 100.0, 100.0), 51.979999); + assert_relative_eq!(super::Quad::ease_in_out(51.0, 1.0, 100.0, 100.0), 52.98); } }