feat: make all functions inlinable
This commit is contained in:
@@ -3,16 +3,19 @@ const C2: f32 = C1 * 1.525;
|
|||||||
const C3: f32 = C1 + 1.0;
|
const C3: f32 = C1 + 1.0;
|
||||||
|
|
||||||
/// <https://easings.net/#easeInBack>
|
/// <https://easings.net/#easeInBack>
|
||||||
|
#[inline]
|
||||||
pub fn back_in(t: f32) -> f32 {
|
pub fn back_in(t: f32) -> f32 {
|
||||||
C3 * t * t * t - C1 * t * t
|
C3 * t * t * t - C1 * t * t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutBack>
|
/// <https://easings.net/#easeOutBack>
|
||||||
|
#[inline]
|
||||||
pub fn back_out(t: f32) -> f32 {
|
pub fn back_out(t: f32) -> f32 {
|
||||||
1.0 + C3 * (t - 1.0).powi(3) + C1 * (t - 1.0).powi(2)
|
1.0 + C3 * (t - 1.0).powi(3) + C1 * (t - 1.0).powi(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutBack>
|
/// <https://easings.net/#easeInOutBack>
|
||||||
|
#[inline]
|
||||||
pub fn back_in_out(t: f32) -> f32 {
|
pub fn back_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
((2.0 * t).powi(2) * ((C2 + 1.0) * 2.0 * t - C2)) / 2.0
|
((2.0 * t).powi(2) * ((C2 + 1.0) * 2.0 * t - C2)) / 2.0
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
/// <https://easings.net/#easeInBounce>
|
/// <https://easings.net/#easeInBounce>
|
||||||
|
#[inline]
|
||||||
pub fn bounce_in(t: f32) -> f32 {
|
pub fn bounce_in(t: f32) -> f32 {
|
||||||
1.0 - bounce_out(1.0 - t)
|
1.0 - bounce_out(1.0 - t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutBounce>
|
/// <https://easings.net/#easeOutBounce>
|
||||||
|
#[inline]
|
||||||
pub fn bounce_out(t: f32) -> f32 {
|
pub fn bounce_out(t: f32) -> f32 {
|
||||||
const N1: f32 = 7.5625;
|
const N1: f32 = 7.5625;
|
||||||
const D1: f32 = 2.75;
|
const D1: f32 = 2.75;
|
||||||
@@ -19,6 +21,7 @@ pub fn bounce_out(t: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutBounce>
|
/// <https://easings.net/#easeInOutBounce>
|
||||||
|
#[inline]
|
||||||
pub fn bounce_in_out(t: f32) -> f32 {
|
pub fn bounce_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
(1.0 - bounce_out(1.0 - 2.0 * t)) / 2.0
|
(1.0 - bounce_out(1.0 - 2.0 * t)) / 2.0
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/// <https://easings.net/#easeInCirc>
|
/// <https://easings.net/#easeInCirc>
|
||||||
|
#[inline]
|
||||||
pub fn circ_in(t: f32) -> f32 {
|
pub fn circ_in(t: f32) -> f32 {
|
||||||
1.0 - (1.0 - t.powi(2)).sqrt()
|
1.0 - (1.0 - t.powi(2)).sqrt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutCirc>
|
/// <https://easings.net/#easeOutCirc>
|
||||||
|
#[inline]
|
||||||
pub fn circ_out(t: f32) -> f32 {
|
pub fn circ_out(t: f32) -> f32 {
|
||||||
(1.0 - (t - 1.0).powi(2)).sqrt()
|
(1.0 - (t - 1.0).powi(2)).sqrt()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutCirc>
|
/// <https://easings.net/#easeInOutCirc>
|
||||||
|
#[inline]
|
||||||
pub fn circ_in_out(t: f32) -> f32 {
|
pub fn circ_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
(1.0 - (1.0 - (2.0 * t).powi(2)).sqrt()) / 2.0
|
(1.0 - (1.0 - (2.0 * t).powi(2)).sqrt()) / 2.0
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/// <https://easings.net/#easeInCubic>
|
/// <https://easings.net/#easeInCubic>
|
||||||
|
#[inline]
|
||||||
pub fn cubic_in(t: f32) -> f32 {
|
pub fn cubic_in(t: f32) -> f32 {
|
||||||
t * t * t
|
t * t * t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutCubic>
|
/// <https://easings.net/#easeOutCubic>
|
||||||
|
#[inline]
|
||||||
pub fn cubic_out(t: f32) -> f32 {
|
pub fn cubic_out(t: f32) -> f32 {
|
||||||
1.0 - (1.0 - t).powi(3)
|
1.0 - (1.0 - t).powi(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutCubic>
|
/// <https://easings.net/#easeInOutCubic>
|
||||||
|
#[inline]
|
||||||
pub fn cubic_in_out(t: f32) -> f32 {
|
pub fn cubic_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
4.0 * t * t * t
|
4.0 * t * t * t
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const C4: f32 = (2.0 * PI) / 3.0;
|
|||||||
const C5: f32 = (2.0 * PI) / 4.5;
|
const C5: f32 = (2.0 * PI) / 4.5;
|
||||||
|
|
||||||
/// <https://easings.net/#easeInElastic>
|
/// <https://easings.net/#easeInElastic>
|
||||||
|
#[inline]
|
||||||
pub fn elastic_in(t: f32) -> f32 {
|
pub fn elastic_in(t: f32) -> f32 {
|
||||||
if t <= 0.0 {
|
if t <= 0.0 {
|
||||||
0.0
|
0.0
|
||||||
@@ -15,6 +16,7 @@ pub fn elastic_in(t: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutElastic>
|
/// <https://easings.net/#easeOutElastic>
|
||||||
|
#[inline]
|
||||||
pub fn elastic_out(t: f32) -> f32 {
|
pub fn elastic_out(t: f32) -> f32 {
|
||||||
if t <= 0.0 {
|
if t <= 0.0 {
|
||||||
0.0
|
0.0
|
||||||
@@ -26,6 +28,7 @@ pub fn elastic_out(t: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutElastic>
|
/// <https://easings.net/#easeInOutElastic>
|
||||||
|
#[inline]
|
||||||
pub fn elastic_in_out(t: f32) -> f32 {
|
pub fn elastic_in_out(t: f32) -> f32 {
|
||||||
if t <= 0.0 {
|
if t <= 0.0 {
|
||||||
0.0
|
0.0
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
/// <https://easings.net/#easeInExpo>
|
/// <https://easings.net/#easeInExpo>
|
||||||
|
#[inline]
|
||||||
pub fn expo_in(t: f32) -> f32 {
|
pub fn expo_in(t: f32) -> f32 {
|
||||||
if t <= 0.0 {
|
if t <= 0.0 {
|
||||||
0.0
|
0.0
|
||||||
@@ -8,6 +9,7 @@ pub fn expo_in(t: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutExpo>
|
/// <https://easings.net/#easeOutExpo>
|
||||||
|
#[inline]
|
||||||
pub fn expo_out(t: f32) -> f32 {
|
pub fn expo_out(t: f32) -> f32 {
|
||||||
if 1.0 <= t {
|
if 1.0 <= t {
|
||||||
1.0
|
1.0
|
||||||
@@ -17,6 +19,7 @@ pub fn expo_out(t: f32) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutExpo>
|
/// <https://easings.net/#easeInOutExpo>
|
||||||
|
#[inline]
|
||||||
pub fn expo_in_out(t: f32) -> f32 {
|
pub fn expo_in_out(t: f32) -> f32 {
|
||||||
if t <= 0.0 {
|
if t <= 0.0 {
|
||||||
0.0
|
0.0
|
||||||
|
|||||||
@@ -42,11 +42,13 @@ pub use quart::*;
|
|||||||
pub use quint::*;
|
pub use quint::*;
|
||||||
pub use sine::*;
|
pub use sine::*;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn linear(t: f32) -> f32 {
|
pub fn linear(t: f32) -> f32 {
|
||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A linear easing that goes from `1.0` to `0.0`.
|
/// A linear easing that goes from `1.0` to `0.0`.
|
||||||
|
#[inline]
|
||||||
pub fn reverse(t: f32) -> f32 {
|
pub fn reverse(t: f32) -> f32 {
|
||||||
1.0 - t
|
1.0 - t
|
||||||
}
|
}
|
||||||
@@ -61,6 +63,7 @@ pub fn reverse(t: f32) -> f32 {
|
|||||||
/// let descending = cubic_in(roundtrip(0.75));
|
/// let descending = cubic_in(roundtrip(0.75));
|
||||||
/// assert!((ascending - descending).abs() < 0.001);
|
/// assert!((ascending - descending).abs() < 0.001);
|
||||||
/// ```
|
/// ```
|
||||||
|
#[inline]
|
||||||
pub fn roundtrip(t: f32) -> f32 {
|
pub fn roundtrip(t: f32) -> f32 {
|
||||||
if t < 0.5 { t * 2.0 } else { (1.0 - t) * 2.0 }
|
if t < 0.5 { t * 2.0 } else { (1.0 - t) * 2.0 }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/// <https://easings.net/#easeInQuad>
|
/// <https://easings.net/#easeInQuad>
|
||||||
|
#[inline]
|
||||||
pub fn quad_in(t: f32) -> f32 {
|
pub fn quad_in(t: f32) -> f32 {
|
||||||
t * t
|
t * t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutQuad>
|
/// <https://easings.net/#easeOutQuad>
|
||||||
|
#[inline]
|
||||||
pub fn quad_out(t: f32) -> f32 {
|
pub fn quad_out(t: f32) -> f32 {
|
||||||
1.0 - (1.0 - t).powi(2)
|
1.0 - (1.0 - t).powi(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutQuad>
|
/// <https://easings.net/#easeInOutQuad>
|
||||||
|
#[inline]
|
||||||
pub fn quad_in_out(t: f32) -> f32 {
|
pub fn quad_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
2.0 * t * t
|
2.0 * t * t
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/// <https://easings.net/#easeInQuart>
|
/// <https://easings.net/#easeInQuart>
|
||||||
|
#[inline]
|
||||||
pub fn quart_in(t: f32) -> f32 {
|
pub fn quart_in(t: f32) -> f32 {
|
||||||
t * t * t * t
|
t * t * t * t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutQuart>
|
/// <https://easings.net/#easeOutQuart>
|
||||||
|
#[inline]
|
||||||
pub fn quart_out(t: f32) -> f32 {
|
pub fn quart_out(t: f32) -> f32 {
|
||||||
1.0 - (1.0 - t).powi(4)
|
1.0 - (1.0 - t).powi(4)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutQuart>
|
/// <https://easings.net/#easeInOutQuart>
|
||||||
|
#[inline]
|
||||||
pub fn quart_in_out(t: f32) -> f32 {
|
pub fn quart_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
8.0 * t * t * t * t
|
8.0 * t * t * t * t
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
/// <https://easings.net/#easeInQuint>
|
/// <https://easings.net/#easeInQuint>
|
||||||
|
#[inline]
|
||||||
pub fn quint_in(t: f32) -> f32 {
|
pub fn quint_in(t: f32) -> f32 {
|
||||||
t * t * t * t
|
t * t * t * t
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutQuint>
|
/// <https://easings.net/#easeOutQuint>
|
||||||
|
#[inline]
|
||||||
pub fn quint_out(t: f32) -> f32 {
|
pub fn quint_out(t: f32) -> f32 {
|
||||||
1.0 - (1.0 - t).powi(5)
|
1.0 - (1.0 - t).powi(5)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutQuint>
|
/// <https://easings.net/#easeInOutQuint>
|
||||||
|
#[inline]
|
||||||
pub fn quint_in_out(t: f32) -> f32 {
|
pub fn quint_in_out(t: f32) -> f32 {
|
||||||
if t < 0.5 {
|
if t < 0.5 {
|
||||||
16.0 * t * t * t * t * t
|
16.0 * t * t * t * t * t
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
use ::std::f32::consts::PI;
|
use ::std::f32::consts::PI;
|
||||||
|
|
||||||
/// <https://easings.net/#easeInSine>
|
/// <https://easings.net/#easeInSine>
|
||||||
|
#[inline]
|
||||||
pub fn sine_in(t: f32) -> f32 {
|
pub fn sine_in(t: f32) -> f32 {
|
||||||
1.0 - (t * PI / 2.0).cos()
|
1.0 - (t * PI / 2.0).cos()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeOutSine>
|
/// <https://easings.net/#easeOutSine>
|
||||||
|
#[inline]
|
||||||
pub fn sine_out(t: f32) -> f32 {
|
pub fn sine_out(t: f32) -> f32 {
|
||||||
(t * PI / 2.0).sin()
|
(t * PI / 2.0).sin()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <https://easings.net/#easeInOutSine>
|
/// <https://easings.net/#easeInOutSine>
|
||||||
|
#[inline]
|
||||||
pub fn sine_in_out(t: f32) -> f32 {
|
pub fn sine_in_out(t: f32) -> f32 {
|
||||||
-((PI * t).cos() - 1.0) / 2.0
|
-((PI * t).cos() - 1.0) / 2.0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user