diff --git a/crates/bevy_math/Cargo.toml b/crates/bevy_math/Cargo.toml index 2e92ea89a857e..f635d2a1c1533 100644 --- a/crates/bevy_math/Cargo.toml +++ b/crates/bevy_math/Cargo.toml @@ -28,6 +28,7 @@ smallvec = { version = "1.11" } bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [ "glam", ], optional = true } +variadics_please = "1.1" [dev-dependencies] approx = "0.5" diff --git a/crates/bevy_math/src/curve/easing.rs b/crates/bevy_math/src/curve/easing.rs index 0e5406fa732c7..fe27727de3d2e 100644 --- a/crates/bevy_math/src/curve/easing.rs +++ b/crates/bevy_math/src/curve/easing.rs @@ -8,6 +8,8 @@ use crate::{ Curve, Dir2, Dir3, Dir3A, Quat, Rot2, VectorSpace, }; +use variadics_please::all_tuples_enumerated; + // TODO: Think about merging `Ease` with `StableInterpolate` /// A type whose values can be eased between. @@ -72,6 +74,38 @@ impl Ease for Dir3A { } } +macro_rules! impl_ease_tuple { + ($(#[$meta:meta])* $(($n:tt, $T:ident)),*) => { + $(#[$meta])* + impl<$($T: Ease),*> Ease for ($($T,)*) { + fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve { + let curve_tuple = + ( + $( + <$T as Ease>::interpolating_curve_unbounded(start.$n, end.$n), + )* + ); + + FunctionCurve::new(Interval::EVERYWHERE, move |t| + ( + $( + curve_tuple.$n.sample_unchecked(t), + )* + ) + ) + } + } + }; +} + +all_tuples_enumerated!( + #[doc(fake_variadic)] + impl_ease_tuple, + 1, + 11, + T +); + /// A [`Curve`] that is defined by /// /// - an initial `start` sample value at `t = 0`