Skip to content

Commit

Permalink
Removes mutability in easing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 8, 2016
1 parent 032da99 commit 920f922
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 62 deletions.
20 changes: 10 additions & 10 deletions src/functions/back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ use super::ease::Easing;
pub struct Back;

impl Easing for Back {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let s = 1.70158_f32;
t = t / d;
let t = t / d;
c * t * t * ((s + 1.0) * t - s) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let s = 1.70158_f32;
t = (t / d) - 1.0;
let t = (t / d) - 1.0;
c * (t * t * ((s + 1.0) * t + s) + 1.0) + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
let mut s = 1.70158_f32;
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let s = 1.70158_f32;
let t = t / (d / 2.0);
if t < 1.0 {
s *= 1.525f32;
let s = s * 1.525f32;
c / 2.0 * (t * t * ((s + 1.0) * t - s)) + b
}
else {
t -= 2.0;
s = s * 1.525f32;
let t = t - 2.0;
let s = s * 1.525f32;
c / 2.0 * (t * t * ((s + 1.0) * t + s) + 2.0) + b
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/functions/bounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ impl Easing for Bounce {
c - Bounce::ease_out(d - t, 0.0, c, d) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
if t < 1.0 / 2.75 {
c * (7.5625 * t * t) + b
} else if t < 2.0 / 2.75 {
t -= 1.5 / 2.75;
let t = t - 1.5 / 2.75;
c * (7.5625 * t * t + 0.75) + b
} else if t < 2.5 / 2.75 {
t -= 2.25 / 2.75;
let t = t - 2.25 / 2.75;
c * (7.5625 * t * t + 0.9375) + b
} else {
t -= 2.625 / 2.75;
let t = t - 2.625 / 2.75;
c * (7.5625 * t * t + 0.984375) + b
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/functions/circ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use super::ease::Easing;
pub struct Circ;

impl Easing for Circ {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
-c * ((1.0 - t * t).sqrt() - 1.0) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d - 1.0;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d - 1.0;
c * (1.0 - t * t).sqrt() + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / (d / 2.0);
if t < 1.0 {
-c / 2.0 * ((1.0 - t * t).sqrt() - 1.0) + b
}
else {
t -= 2.0;
let t = t - 2.0;
c / 2.0 * ((1.0 - t * t).sqrt() + 1.0) + b
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/functions/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use super::ease::Easing;
pub struct Cubic;

impl Easing for Cubic {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
c * (t * t * t) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d - 1.0;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d - 1.0;
c * ((t * t * t) + 1.0) + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / (d / 2.0);
if t < 1.0 {
c / 2.0 * (t * t * t) + b
}
else {
t = t - 2.0;
let t = t - 2.0;
c / 2.0 * (t * t * t + 2.0) + b
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/functions/elastic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@ use std::f32::consts::PI;
pub struct Elastic;

impl Easing for Elastic {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
if t == 0.0 {
return b;
}

t = t / d;
let t = t / d;
if t == 1.0 {
return b + c;
}

let p = d * 0.3;
let a = c;
let s = p / 4.0;
t -= 1.0;
let t = t - 1.0;
let post_fix = a * 2_f32.powf(10.0 * t);
let temp = (t * d - s) * (2.0 * PI) / p;
-(post_fix * temp.sin()) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
if t == 0.0 {
return b;
}

t = t / d;
let t = t / d;
if t == 1.0 {
return b + c;
}
Expand All @@ -41,12 +41,12 @@ impl Easing for Elastic {
a * 2_f32.powf(-10.0 * t) * temp.sin() + c + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
if t == 0.0 {
return b;
}

t = t / (d / 2.0);
let t = t / (d / 2.0);
if t == 2.0 {
return b + c;
}
Expand All @@ -56,13 +56,13 @@ impl Easing for Elastic {
let s = p / 4.0;

if t < 1.0 {
t -= 1.0;
let t = t - 1.0;
let post_fix = a * 2_f32.powf(10.0 * t);
let temp = (t * d - s) * (2.0 * PI) / p;
return -0.5 * (post_fix * temp.sin()) + b;
}

t -= 1.0;
let t = t - 1.0;
let post_fix = a * 2_f32.powf(-10.0 * t);
let temp = (t * d - s) * (2.0 * PI) / p;
post_fix * temp.sin() * 0.5 + c + b
Expand Down
6 changes: 3 additions & 3 deletions src/functions/expo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ impl Easing for Expo {
}
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
if t == 0.0 {
return b;
}
if t == d {
return b + c;
}
t = t / (d / 2.0);
let t = t / (d / 2.0);
if t < 1.0 {
c / 2.0 * 2_f32.powf(10.0 * (t - 1.0)) + b
}
else {
t -= 1.0;
let t = t - 1.0;
c / 2.0 * (-(2_f32.powf(-10.0 * t)) + 2.0) + b
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/functions/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use super::ease::Easing;
pub struct Quad;

impl Easing for Quad {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
c * t * t + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
-c * t * (t - 2.0) + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / (d / 2.0);
if t < 1.0 {
c / 2.0 * t * t + b
}
else {
t -= 1.0;
let t = t - 1.0;
-c / 2.0 * (t * (t - 2.0) - 1.0) + b
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/functions/quart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use super::ease::Easing;
pub struct Quart;

impl Easing for Quart {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
c * (t * t * t * t) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d - 1.0;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d - 1.0;
-c * ((t * t * t * t) - 1.0) + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / (d / 2.0);
if t < 1.0 {
c / 2.0 * (t * t * t * t) + b
}
else {
t -= 2.0;
let t = t - 2.0;
-c / 2.0 * ((t * t * t * t) - 2.0) + b
}

Expand Down
14 changes: 7 additions & 7 deletions src/functions/quint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use super::ease::Easing;
pub struct Quint;

impl Easing for Quint {
fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d;
fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d;
c * (t * t * t * t * t) + b
}

fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / d - 1.0;
fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / d - 1.0;
c * ((t * t * t * t * t) + 1.0) + b
}

fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 {
t = t / (d / 2.0);
fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 {
let t = t / (d / 2.0);
if t < 1.0 {
(c / 2.0) * (t * t * t * t * t) + b
} else {
t -= 2.0;
let t = t - 2.0;
c / 2.0 * ((t * t * t * t * t) + 2.0) + b
}
}
Expand Down

0 comments on commit 920f922

Please sign in to comment.