Skip to content

Commit

Permalink
Merge pull request #5 from Kerollmops/master
Browse files Browse the repository at this point in the history
Fix the quad_ease_in_out function
  • Loading branch information
orhanbalci authored Dec 7, 2016
2 parents 9bebf96 + 08080e2 commit 02023b9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/functions/quad.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::ease::Easing;

/// This struct captures quadratic easing functions
pub struct Quad;

Expand All @@ -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;
}
}

Expand All @@ -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);
}

}

0 comments on commit 02023b9

Please sign in to comment.