From 52f9d944e923a469d3c36fa46229e06d79e8d076 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Sun, 15 Feb 2026 12:01:25 +0100 Subject: [PATCH] feat: make all functions inlinable --- src/back.rs | 3 +++ src/bounce.rs | 3 +++ src/circ.rs | 3 +++ src/cubic.rs | 3 +++ src/elastic.rs | 3 +++ src/expo.rs | 3 +++ src/lib.rs | 3 +++ src/quad.rs | 3 +++ src/quart.rs | 3 +++ src/quint.rs | 3 +++ src/sine.rs | 3 +++ 11 files changed, 33 insertions(+) diff --git a/src/back.rs b/src/back.rs index cdf8cc3..b0922b0 100644 --- a/src/back.rs +++ b/src/back.rs @@ -3,16 +3,19 @@ const C2: f32 = C1 * 1.525; const C3: f32 = C1 + 1.0; /// +#[inline] pub fn back_in(t: f32) -> f32 { C3 * t * t * t - C1 * t * t } /// +#[inline] pub fn back_out(t: f32) -> f32 { 1.0 + C3 * (t - 1.0).powi(3) + C1 * (t - 1.0).powi(2) } /// +#[inline] pub fn back_in_out(t: f32) -> f32 { if t < 0.5 { ((2.0 * t).powi(2) * ((C2 + 1.0) * 2.0 * t - C2)) / 2.0 diff --git a/src/bounce.rs b/src/bounce.rs index 0268b0e..b7ed267 100644 --- a/src/bounce.rs +++ b/src/bounce.rs @@ -1,9 +1,11 @@ /// +#[inline] pub fn bounce_in(t: f32) -> f32 { 1.0 - bounce_out(1.0 - t) } /// +#[inline] pub fn bounce_out(t: f32) -> f32 { const N1: f32 = 7.5625; const D1: f32 = 2.75; @@ -19,6 +21,7 @@ pub fn bounce_out(t: f32) -> f32 { } /// +#[inline] pub fn bounce_in_out(t: f32) -> f32 { if t < 0.5 { (1.0 - bounce_out(1.0 - 2.0 * t)) / 2.0 diff --git a/src/circ.rs b/src/circ.rs index 7bffa3d..f341481 100644 --- a/src/circ.rs +++ b/src/circ.rs @@ -1,14 +1,17 @@ /// +#[inline] pub fn circ_in(t: f32) -> f32 { 1.0 - (1.0 - t.powi(2)).sqrt() } /// +#[inline] pub fn circ_out(t: f32) -> f32 { (1.0 - (t - 1.0).powi(2)).sqrt() } /// +#[inline] pub fn circ_in_out(t: f32) -> f32 { if t < 0.5 { (1.0 - (1.0 - (2.0 * t).powi(2)).sqrt()) / 2.0 diff --git a/src/cubic.rs b/src/cubic.rs index 7726735..9a82119 100644 --- a/src/cubic.rs +++ b/src/cubic.rs @@ -1,14 +1,17 @@ /// +#[inline] pub fn cubic_in(t: f32) -> f32 { t * t * t } /// +#[inline] pub fn cubic_out(t: f32) -> f32 { 1.0 - (1.0 - t).powi(3) } /// +#[inline] pub fn cubic_in_out(t: f32) -> f32 { if t < 0.5 { 4.0 * t * t * t diff --git a/src/elastic.rs b/src/elastic.rs index 8c503ef..6c61543 100644 --- a/src/elastic.rs +++ b/src/elastic.rs @@ -4,6 +4,7 @@ const C4: f32 = (2.0 * PI) / 3.0; const C5: f32 = (2.0 * PI) / 4.5; /// +#[inline] pub fn elastic_in(t: f32) -> f32 { if t <= 0.0 { 0.0 @@ -15,6 +16,7 @@ pub fn elastic_in(t: f32) -> f32 { } /// +#[inline] pub fn elastic_out(t: f32) -> f32 { if t <= 0.0 { 0.0 @@ -26,6 +28,7 @@ pub fn elastic_out(t: f32) -> f32 { } /// +#[inline] pub fn elastic_in_out(t: f32) -> f32 { if t <= 0.0 { 0.0 diff --git a/src/expo.rs b/src/expo.rs index 36f8652..e2ce126 100644 --- a/src/expo.rs +++ b/src/expo.rs @@ -1,4 +1,5 @@ /// +#[inline] pub fn expo_in(t: f32) -> f32 { if t <= 0.0 { 0.0 @@ -8,6 +9,7 @@ pub fn expo_in(t: f32) -> f32 { } /// +#[inline] pub fn expo_out(t: f32) -> f32 { if 1.0 <= t { 1.0 @@ -17,6 +19,7 @@ pub fn expo_out(t: f32) -> f32 { } /// +#[inline] pub fn expo_in_out(t: f32) -> f32 { if t <= 0.0 { 0.0 diff --git a/src/lib.rs b/src/lib.rs index f3239c2..0f8a01f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,11 +42,13 @@ pub use quart::*; pub use quint::*; pub use sine::*; +#[inline] pub fn linear(t: f32) -> f32 { t } /// A linear easing that goes from `1.0` to `0.0`. +#[inline] pub fn reverse(t: f32) -> f32 { 1.0 - t } @@ -61,6 +63,7 @@ pub fn reverse(t: f32) -> f32 { /// let descending = cubic_in(roundtrip(0.75)); /// assert!((ascending - descending).abs() < 0.001); /// ``` +#[inline] pub fn roundtrip(t: f32) -> f32 { if t < 0.5 { t * 2.0 } else { (1.0 - t) * 2.0 } } diff --git a/src/quad.rs b/src/quad.rs index 7a3e241..238598a 100644 --- a/src/quad.rs +++ b/src/quad.rs @@ -1,14 +1,17 @@ /// +#[inline] pub fn quad_in(t: f32) -> f32 { t * t } /// +#[inline] pub fn quad_out(t: f32) -> f32 { 1.0 - (1.0 - t).powi(2) } /// +#[inline] pub fn quad_in_out(t: f32) -> f32 { if t < 0.5 { 2.0 * t * t diff --git a/src/quart.rs b/src/quart.rs index 17dc31a..49c815c 100644 --- a/src/quart.rs +++ b/src/quart.rs @@ -1,14 +1,17 @@ /// +#[inline] pub fn quart_in(t: f32) -> f32 { t * t * t * t } /// +#[inline] pub fn quart_out(t: f32) -> f32 { 1.0 - (1.0 - t).powi(4) } /// +#[inline] pub fn quart_in_out(t: f32) -> f32 { if t < 0.5 { 8.0 * t * t * t * t diff --git a/src/quint.rs b/src/quint.rs index ce75a0f..d5da59b 100644 --- a/src/quint.rs +++ b/src/quint.rs @@ -1,14 +1,17 @@ /// +#[inline] pub fn quint_in(t: f32) -> f32 { t * t * t * t } /// +#[inline] pub fn quint_out(t: f32) -> f32 { 1.0 - (1.0 - t).powi(5) } /// +#[inline] pub fn quint_in_out(t: f32) -> f32 { if t < 0.5 { 16.0 * t * t * t * t * t diff --git a/src/sine.rs b/src/sine.rs index 6552fa1..9001533 100644 --- a/src/sine.rs +++ b/src/sine.rs @@ -1,16 +1,19 @@ use ::std::f32::consts::PI; /// +#[inline] pub fn sine_in(t: f32) -> f32 { 1.0 - (t * PI / 2.0).cos() } /// +#[inline] pub fn sine_out(t: f32) -> f32 { (t * PI / 2.0).sin() } /// +#[inline] pub fn sine_in_out(t: f32) -> f32 { -((PI * t).cos() - 1.0) / 2.0 }