From 5c81f3525087a81f7838550324fae77cab385b1a Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Sun, 15 Feb 2026 12:47:52 +0100 Subject: [PATCH] feat: enable clippy nursery and fix --- src/back.rs | 8 ++++---- src/bounce.rs | 10 +++++----- src/circ.rs | 14 ++++++++++---- src/cubic.rs | 2 +- src/elastic.rs | 10 ++++++---- src/expo.rs | 8 ++++---- src/lib.rs | 3 ++- src/quad.rs | 4 ++-- src/quart.rs | 2 +- src/quint.rs | 2 +- 10 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/back.rs b/src/back.rs index efb4a51..af34768 100644 --- a/src/back.rs +++ b/src/back.rs @@ -6,14 +6,14 @@ const C3: f32 = C1 + 1.0; #[inline] #[must_use] pub fn back_in(t: f32) -> f32 { - C3 * t * t * t - C1 * t * t + (C3 * t * t).mul_add(t, -(C1 * t * t)) } /// #[inline] #[must_use] pub fn back_out(t: f32) -> f32 { - 1.0 + C3 * (t - 1.0).powi(3) + C1 * (t - 1.0).powi(2) + C1.mul_add((t - 1.0).powi(2), C3.mul_add((t - 1.0).powi(3), 1.0)) } /// @@ -21,10 +21,10 @@ pub fn back_out(t: f32) -> f32 { #[must_use] 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 + ((2.0 * t).powi(2) * ((C2 + 1.0) * 2.0).mul_add(t, -C2)) / 2.0 } else { f32::midpoint( - (2.0 * t - 2.0).powi(2) * ((C2 + 1.0) * (t * 2.0 - 2.0) + C2), + 2.0f32.mul_add(t, -2.0).powi(2) * (C2 + 1.0).mul_add(t.mul_add(2.0, -2.0), C2), 2.0, ) } diff --git a/src/bounce.rs b/src/bounce.rs index 415fbbb..dcb5dcf 100644 --- a/src/bounce.rs +++ b/src/bounce.rs @@ -14,11 +14,11 @@ pub fn bounce_out(t: f32) -> f32 { if t < 1.0 / D1 { N1 * t * t } else if t < 2.0 / D1 { - N1 * (t - 1.5 / D1).powi(2) + 0.75 + N1.mul_add((t - 1.5 / D1).powi(2), 0.75) } else if t < 2.5 / D1 { - N1 * (t - 2.25 / D1).powi(2) + 0.937_5 + N1.mul_add((t - 2.25 / D1).powi(2), 0.937_5) } else { - N1 * (t - 2.625 / D1).powi(2) + 0.984_375 + N1.mul_add((t - 2.625 / D1).powi(2), 0.984_375) } } @@ -27,8 +27,8 @@ pub fn bounce_out(t: f32) -> f32 { #[must_use] pub fn bounce_in_out(t: f32) -> f32 { if t < 0.5 { - (1.0 - bounce_out(1.0 - 2.0 * t)) / 2.0 + (1.0 - bounce_out(2.0f32.mul_add(-t, 1.0))) / 2.0 } else { - f32::midpoint(1.0, bounce_out(2.0 * t - 1.0)) + f32::midpoint(1.0, bounce_out(2.0f32.mul_add(t, -1.0))) } } diff --git a/src/circ.rs b/src/circ.rs index d3d95fb..2902026 100644 --- a/src/circ.rs +++ b/src/circ.rs @@ -2,14 +2,14 @@ #[inline] #[must_use] pub fn circ_in(t: f32) -> f32 { - 1.0 - (1.0 - t.powi(2)).sqrt() + 1.0 - t.mul_add(-t, 1.0).sqrt() } /// #[inline] #[must_use] pub fn circ_out(t: f32) -> f32 { - (1.0 - (t - 1.0).powi(2)).sqrt() + (t - 1.0).mul_add(-(t - 1.0), 1.0).sqrt() } /// @@ -17,8 +17,14 @@ pub fn circ_out(t: f32) -> f32 { #[must_use] pub fn circ_in_out(t: f32) -> f32 { if t < 0.5 { - (1.0 - (1.0 - (2.0 * t).powi(2)).sqrt()) / 2.0 + (1.0 - (2.0 * t).mul_add(-(2.0 * t), 1.0).sqrt()) / 2.0 } else { - f32::midpoint((1.0 - (-2.0 * t + 2.0).powi(2)).sqrt(), 1.0) + f32::midpoint( + (-2.0f32) + .mul_add(t, 2.0) + .mul_add(-(-2.0f32).mul_add(t, 2.0), 1.0) + .sqrt(), + 1.0, + ) } } diff --git a/src/cubic.rs b/src/cubic.rs index 42ee24c..8c69370 100644 --- a/src/cubic.rs +++ b/src/cubic.rs @@ -19,6 +19,6 @@ pub fn cubic_in_out(t: f32) -> f32 { if t < 0.5 { 4.0 * t * t * t } else { - 1.0 - (-2.0 * t + 2.0).powi(3) / 2.0 + 1.0 - (-2.0f32).mul_add(t, 2.0).powi(3) / 2.0 } } diff --git a/src/elastic.rs b/src/elastic.rs index 8f3fc6f..7fe8384 100644 --- a/src/elastic.rs +++ b/src/elastic.rs @@ -12,7 +12,7 @@ pub fn elastic_in(t: f32) -> f32 { } else if 1.0 <= t { 1.0 } else { - -2f32.powf(10.0 * t - 10.0) * ((t * 10.0 - 10.75) * C4).sin() + -10.0f32.mul_add(t, -10.0).exp2() * (t.mul_add(10.0, -10.75) * C4).sin() } } @@ -25,7 +25,9 @@ pub fn elastic_out(t: f32) -> f32 { } else if 1.0 <= t { 1.0 } else { - 2f32.powf(-10.0 * t) * ((t * 10.0 - 0.75) * C4).sin() + 1.0 + (-10.0 * t) + .exp2() + .mul_add((t.mul_add(10.0, -0.75) * C4).sin(), 1.0) } } @@ -38,8 +40,8 @@ pub fn elastic_in_out(t: f32) -> f32 { } else if 1.0 <= t { 1.0 } else if t < 0.5 { - -(2f32.powf(20.0 * t - 10.0) * ((20.0 * t - 11.125) * C5).sin()) / 2.0 + -(20.0f32.mul_add(t, -10.0).exp2() * (20.0f32.mul_add(t, -11.125) * C5).sin()) / 2.0 } else { - (2f32.powf(-20.0 * t + 10.0) * ((20.0 * t - 11.125) * C5).sin()) / 2.0 + 1.0 + ((-20.0f32).mul_add(t, 10.0).exp2() * (20.0f32.mul_add(t, -11.125) * C5).sin()) / 2.0 + 1.0 } } diff --git a/src/expo.rs b/src/expo.rs index 9e0881f..106fd75 100644 --- a/src/expo.rs +++ b/src/expo.rs @@ -5,7 +5,7 @@ pub fn expo_in(t: f32) -> f32 { if t <= 0.0 { 0.0 } else { - 2f32.powf(10.0 * t - 10.0) + 10.0f32.mul_add(t, -10.0).exp2() } } @@ -16,7 +16,7 @@ pub fn expo_out(t: f32) -> f32 { if 1.0 <= t { 1.0 } else { - 1.0 - 2f32.powf(-10.0 * t) + 1.0 - (-10.0 * t).exp2() } } @@ -29,8 +29,8 @@ pub fn expo_in_out(t: f32) -> f32 { } else if 1.0 <= t { 1.0 } else if t < 0.5 { - 2f32.powf(20.0 * t - 10.0) / 2.0 + 20.0f32.mul_add(t, -10.0).exp2() / 2.0 } else { - (2.0 - 2f32.powf(-20.0 * t + 10.0)) / 2.0 + (2.0 - (-20.0f32).mul_add(t, 10.0).exp2()) / 2.0 } } diff --git a/src/lib.rs b/src/lib.rs index 7429e3d..27e61df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,7 +20,8 @@ //! assert_eq!(easing(1.0), 1.0); //! ``` -#![warn(clippy::pedantic)] +#![warn(clippy::pedantic, clippy::nursery)] +#![allow(clippy::missing_const_for_fn)] mod back; mod bounce; diff --git a/src/quad.rs b/src/quad.rs index 9c3e485..0d15088 100644 --- a/src/quad.rs +++ b/src/quad.rs @@ -9,7 +9,7 @@ pub fn quad_in(t: f32) -> f32 { #[inline] #[must_use] pub fn quad_out(t: f32) -> f32 { - 1.0 - (1.0 - t).powi(2) + (1.0 - t).mul_add(-(1.0 - t), 1.0) } /// @@ -19,6 +19,6 @@ pub fn quad_in_out(t: f32) -> f32 { if t < 0.5 { 2.0 * t * t } else { - 1.0 - (-2.0 * t + 2.0).powi(2) / 2.0 + 1.0 - (-2.0f32).mul_add(t, 2.0).powi(2) / 2.0 } } diff --git a/src/quart.rs b/src/quart.rs index 711b36f..3a98019 100644 --- a/src/quart.rs +++ b/src/quart.rs @@ -19,6 +19,6 @@ pub fn quart_in_out(t: f32) -> f32 { if t < 0.5 { 8.0 * t * t * t * t } else { - 1.0 - (-2.0 * t + 2.0).powi(4) / 2.0 + 1.0 - (-2.0f32).mul_add(t, 2.0).powi(4) / 2.0 } } diff --git a/src/quint.rs b/src/quint.rs index 11db77f..d7e56a5 100644 --- a/src/quint.rs +++ b/src/quint.rs @@ -19,6 +19,6 @@ pub fn quint_in_out(t: f32) -> f32 { if t < 0.5 { 16.0 * t * t * t * t * t } else { - 1.0 - (-2.0 * t + 2.0).powi(5) / 2.0 + 1.0 - (-2.0f32).mul_add(t, 2.0).powi(5) / 2.0 } }