From 5e78cd85dd630ca31ca8c9f0084a2b9e0c737b51 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:10:45 +0100 Subject: [PATCH 01/10] Clear the Quad easing functions --- src/functions/quad.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/functions/quad.rs b/src/functions/quad.rs index 962c315..cac97cd 100644 --- a/src/functions/quad.rs +++ b/src/functions/quad.rs @@ -4,18 +4,18 @@ use super::ease::Easing; pub struct Quad; impl Easing for Quad { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - c * inner_t.powi(2) + b + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + c * t * t + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - -c * inner_t * (inner_t - 2.0) + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + -c * t * (t - 2.0) + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut t = t / (d / 2.0); + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / (d / 2.0); if t < 1.0 { c / 2.0 * t * t + b } From cc17a23be213ff8d0795a2a9dc91fde86010b927 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:15:27 +0100 Subject: [PATCH 02/10] Clear the Back easing functions --- src/functions/back.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/functions/back.rs b/src/functions/back.rs index 8f90952..a35f4b3 100644 --- a/src/functions/back.rs +++ b/src/functions/back.rs @@ -1,32 +1,33 @@ use super::ease::Easing; + /// This struct captures Back easing functions pub struct Back; impl Easing for Back { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { let s = 1.70158_f32; - let inner_t = t / d; - let post_fix = inner_t; - c * (post_fix) * inner_t * ((s + 1.0) * inner_t - s) + b + t = t / d; + c * t * t * ((s + 1.0) * t - s) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { let s = 1.70158_f32; - let inner_t = (t / d) - 1.0; - c * (inner_t * inner_t * ((s + 1.0) * inner_t + s) + 1.0) + b + t = (t / d) - 1.0; + c * (t * t * ((s + 1.0) * t + s) + 1.0) + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { let mut s = 1.70158_f32; - let mut inner_t = t / (d / 2.0); - if inner_t < 1.0 { + t = t / (d / 2.0); + if t < 1.0 { s *= 1.525f32; - return c / 2.0 * (inner_t * inner_t * ((s + 1.0) * inner_t - s)) + b; + c / 2.0 * (t * t * ((s + 1.0) * t - s)) + b + } + else { + t -= 2.0; + s = s * 1.525f32; + c / 2.0 * (t * t * ((s + 1.0) * t + s) + 2.0) + b } - inner_t -= 2.0; - let post_fix: f32 = inner_t; - let inner_s = s * 1.525f32; - return c / 2.0 * (post_fix * inner_t * ((inner_s + 1.0) * inner_t + inner_s) + 2.0) + b; } } From 079d5febbb964ce9263ac77ca44b737214d02250 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:17:34 +0100 Subject: [PATCH 03/10] Clear the Bounce easing functions --- src/functions/bounce.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/functions/bounce.rs b/src/functions/bounce.rs index f06b2e2..0531cca 100644 --- a/src/functions/bounce.rs +++ b/src/functions/bounce.rs @@ -1,4 +1,5 @@ use super::ease::Easing; + /// This struct captures Bounce easing functions pub struct Bounce; @@ -7,23 +8,22 @@ impl Easing for Bounce { c - Bounce::ease_out(d - t, 0.0, c, d) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut inner_t = t / d; - if inner_t < 1.0 / 2.75 { - c * (7.5625 * inner_t * inner_t) + b - } else if inner_t < 2.0 / 2.75 { - inner_t -= 1.5 / 2.75; - c * (7.5625 * inner_t * inner_t + 0.75) + b - } else if inner_t < 2.5 / 2.75 { - inner_t -= 2.25 / 2.75; - c * (7.5625 * inner_t * inner_t + 0.9375) + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + 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; + c * (7.5625 * t * t + 0.75) + b + } else if t < 2.5 / 2.75 { + t -= 2.25 / 2.75; + c * (7.5625 * t * t + 0.9375) + b } else { - inner_t -= 2.625 / 2.75; - c * (7.5625 * inner_t * inner_t + 0.984375) + b + t -= 2.625 / 2.75; + c * (7.5625 * t * t + 0.984375) + b } } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { if t < (d / 2.0) { Bounce::ease_in(t * 2.0, 0.0, c, d) * 0.5 + b From e1ca7a64cf2b8b2d01835615190b01c63b5bca39 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:19:18 +0100 Subject: [PATCH 04/10] Clear the Circ easing functions --- src/functions/circ.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/functions/circ.rs b/src/functions/circ.rs index 57adb98..5bcaed7 100644 --- a/src/functions/circ.rs +++ b/src/functions/circ.rs @@ -1,26 +1,28 @@ use super::ease::Easing; + /// This struct captures Circ easing functions pub struct Circ; impl Easing for Circ { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - -c * ((1.0 - inner_t * inner_t).sqrt() - 1.0) + b + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + -c * ((1.0 - t * t).sqrt() - 1.0) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d - 1.0; - c * (1.0 - inner_t * inner_t).sqrt() + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d - 1.0; + c * (1.0 - t * t).sqrt() + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut inner_t = t / (d / 2.0); - if inner_t < 1.0 { - return -c / 2.0 * ((1.0 - inner_t * inner_t).sqrt() - 1.0) + b; + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / (d / 2.0); + if t < 1.0 { + -c / 2.0 * ((1.0 - t * t).sqrt() - 1.0) + b + } + else { + t -= 2.0; + c / 2.0 * ((1.0 - t * t).sqrt() + 1.0) + b } - - inner_t -= 2.0; - return c / 2.0 * ((1.0 - inner_t * inner_t).sqrt() + 1.0) + b; } } From 3525a228f8bcad18114cf199eb3f3e80a707355d Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:21:23 +0100 Subject: [PATCH 05/10] Clear the Cubic easing functions --- src/functions/cubic.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/functions/cubic.rs b/src/functions/cubic.rs index 583f352..7a6fc22 100644 --- a/src/functions/cubic.rs +++ b/src/functions/cubic.rs @@ -4,23 +4,25 @@ use super::ease::Easing; pub struct Cubic; impl Easing for Cubic { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - c * inner_t.powi(3) + b + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + c * (t * t * t) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d - 1.0; - c * (inner_t.powi(3) + 1.0) + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d - 1.0; + c * ((t * t * t) + 1.0) + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut inner_t = t / (d / 2.0); - if inner_t < 1.0 { - return c / 2.0 * inner_t.powi(3) + b; + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / (d / 2.0); + if t < 1.0 { + c / 2.0 * (t * t * t) + b + } + else { + t = t - 2.0; + c / 2.0 * (t * t * t + 2.0) + b } - inner_t = inner_t - 2.0; - return c / 2.0 * (inner_t.powi(3) + 2.0) + b; } } From 401d6234dc9f9e0d867478b2af6ea2f4b77e70f7 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:24:16 +0100 Subject: [PATCH 06/10] Clear the Elastic easing functions --- src/functions/elastic.rs | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/functions/elastic.rs b/src/functions/elastic.rs index 7a40151..56f76f7 100644 --- a/src/functions/elastic.rs +++ b/src/functions/elastic.rs @@ -5,49 +5,49 @@ use std::f32::consts::PI; pub struct Elastic; impl Easing for Elastic { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { if t == 0.0 { return b; } - let mut inner_t = t / d; - if inner_t == 1.0 { + t = t / d; + if t == 1.0 { return b + c; } let p = d * 0.3; let a = c; let s = p / 4.0; - inner_t -= 1.0; - let post_fix = a * 2_f32.powf(10.0 * inner_t); - let temp = (inner_t * d - s) * (2.0 * PI) / p; - return -(post_fix * temp.sin()) + b; + 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(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { if t == 0.0 { return b; } - let inner_t = t / d; - if inner_t == 1.0 { + t = t / d; + if t == 1.0 { return b + c; } let p = d * 0.3; let a = c; let s = p / 4.0; - let temp = (inner_t * d - s) * (2.0 * PI) / p; - return a * 2_f32.powf(-10.0 * inner_t) * temp.sin() + c + b; + let temp = (t * d - s) * (2.0 * PI) / p; + a * 2_f32.powf(-10.0 * t) * temp.sin() + c + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { if t == 0.0 { return b; } - let mut inner_t = t / (d / 2.0); - if inner_t == 2.0 { + t = t / (d / 2.0); + if t == 2.0 { return b + c; } @@ -55,17 +55,17 @@ impl Easing for Elastic { let a = c; let s = p / 4.0; - if inner_t < 1.0 { - inner_t -= 1.0; - let post_fix = a * 2_f32.powf(10.0 * inner_t); - let temp = (inner_t * d - s) * (2.0 * PI) / p; + if t < 1.0 { + 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; } - inner_t -= 1.0; - let post_fix = a * 2_f32.powf(-10.0 * inner_t); - let temp = (inner_t * d - s) * (2.0 * PI) / p; - return post_fix * temp.sin() * 0.5 + c + b; + 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 } } From 39ae426f7f78f2fc781e96b899e1444b6508994e Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:27:51 +0100 Subject: [PATCH 07/10] Clear the Expo easing functions --- src/functions/expo.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/functions/expo.rs b/src/functions/expo.rs index 3ddc2dd..aec5986 100644 --- a/src/functions/expo.rs +++ b/src/functions/expo.rs @@ -1,4 +1,5 @@ use super::ease::Easing; + /// This struct captures Expo easing functions pub struct Expo; @@ -19,19 +20,21 @@ impl Easing for Expo { } } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { if t == 0.0 { return b; } if t == d { return b + c; } - let mut inner_t = t / (d / 2.0); - if inner_t < 1.0 { - return c / 2.0 * 2_f32.powf(10.0 * (inner_t - 1.0)) + b; + 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; + c / 2.0 * (-(2_f32.powf(-10.0 * t)) + 2.0) + b } - inner_t -= 1.0; - return c / 2.0 * (-(2_f32.powf(-10.0 * inner_t)) + 2.0) + b; } } From db1cbaea359cac04e007a3d5aef25b0e50441553 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:30:10 +0100 Subject: [PATCH 08/10] Clear the Quart easing functions --- src/functions/quart.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/functions/quart.rs b/src/functions/quart.rs index 78faa5f..2879765 100644 --- a/src/functions/quart.rs +++ b/src/functions/quart.rs @@ -1,27 +1,29 @@ use super::ease::Easing; + /// This struct captures Quart easing functions pub struct Quart; impl Easing for Quart { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - c * inner_t.powi(4) + b + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + c * (t * t * t * t) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d - 1.0; - -c * (inner_t.powi(4) - 1.0) + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d - 1.0; + -c * ((t * t * t * t) - 1.0) + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut inner_t = t / (d / 2.0); - - if inner_t < 1.0 { - return c / 2.0 * inner_t * inner_t * inner_t * inner_t + b; + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / (d / 2.0); + if t < 1.0 { + c / 2.0 * (t * t * t * t) + b + } + else { + t -= 2.0; + -c / 2.0 * ((t * t * t * t) - 2.0) + b } - inner_t -= 2.0; - return -c / 2.0 * (inner_t.powi(4) - 2.0) + b; } } From 032da9962461783ace8a54b2f7d27c8ee7816212 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 00:31:50 +0100 Subject: [PATCH 09/10] Clear the Quint easing functions --- src/functions/quint.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/functions/quint.rs b/src/functions/quint.rs index 99f6230..c524cec 100644 --- a/src/functions/quint.rs +++ b/src/functions/quint.rs @@ -4,24 +4,24 @@ use super::ease::Easing; pub struct Quint; impl Easing for Quint { - fn ease_in(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d; - c * inner_t.powi(5) + b + fn ease_in(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d; + c * (t * t * t * t * t) + b } - fn ease_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let inner_t = t / d - 1.0; - c * (inner_t.powi(5) + 1.0) + b + fn ease_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / d - 1.0; + c * ((t * t * t * t * t) + 1.0) + b } - fn ease_in_out(t: f32, b: f32, c: f32, d: f32) -> f32 { - let mut inner_t = t / (d / 2.0); - if inner_t < 1.0 { - return (c / 2.0) * inner_t.powi(5) + b; + fn ease_in_out(mut t: f32, b: f32, c: f32, d: f32) -> f32 { + t = t / (d / 2.0); + if t < 1.0 { + (c / 2.0) * (t * t * t * t * t) + b + } else { + t -= 2.0; + c / 2.0 * ((t * t * t * t * t) + 2.0) + b } - inner_t -= 2.0; - return c / 2.0 * (inner_t.powi(5) + 2.0) + b; - } } From 920f922882cc8b11d1c6b9e984bc01f786112bb4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Thu, 8 Dec 2016 22:41:25 +0100 Subject: [PATCH 10/10] Removes mutability in easing functions --- src/functions/back.rs | 20 ++++++++++---------- src/functions/bounce.rs | 10 +++++----- src/functions/circ.rs | 14 +++++++------- src/functions/cubic.rs | 14 +++++++------- src/functions/elastic.rs | 18 +++++++++--------- src/functions/expo.rs | 6 +++--- src/functions/quad.rs | 14 +++++++------- src/functions/quart.rs | 14 +++++++------- src/functions/quint.rs | 14 +++++++------- 9 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/functions/back.rs b/src/functions/back.rs index a35f4b3..da7d02b 100644 --- a/src/functions/back.rs +++ b/src/functions/back.rs @@ -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 } } diff --git a/src/functions/bounce.rs b/src/functions/bounce.rs index 0531cca..01120b5 100644 --- a/src/functions/bounce.rs +++ b/src/functions/bounce.rs @@ -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 } } diff --git a/src/functions/circ.rs b/src/functions/circ.rs index 5bcaed7..ad21ee3 100644 --- a/src/functions/circ.rs +++ b/src/functions/circ.rs @@ -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 } } diff --git a/src/functions/cubic.rs b/src/functions/cubic.rs index 7a6fc22..2381ce4 100644 --- a/src/functions/cubic.rs +++ b/src/functions/cubic.rs @@ -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 } } diff --git a/src/functions/elastic.rs b/src/functions/elastic.rs index 56f76f7..2901bc3 100644 --- a/src/functions/elastic.rs +++ b/src/functions/elastic.rs @@ -5,12 +5,12 @@ 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; } @@ -18,18 +18,18 @@ impl Easing for Elastic { 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; } @@ -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; } @@ -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 diff --git a/src/functions/expo.rs b/src/functions/expo.rs index aec5986..adcfa63 100644 --- a/src/functions/expo.rs +++ b/src/functions/expo.rs @@ -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 } } diff --git a/src/functions/quad.rs b/src/functions/quad.rs index cac97cd..667f0ff 100644 --- a/src/functions/quad.rs +++ b/src/functions/quad.rs @@ -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 } } diff --git a/src/functions/quart.rs b/src/functions/quart.rs index 2879765..0729491 100644 --- a/src/functions/quart.rs +++ b/src/functions/quart.rs @@ -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 } diff --git a/src/functions/quint.rs b/src/functions/quint.rs index c524cec..f4a1c42 100644 --- a/src/functions/quint.rs +++ b/src/functions/quint.rs @@ -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 } }