Skip to content

Commit

Permalink
Infer Ease on tuples
Browse files Browse the repository at this point in the history
  • Loading branch information
mweatherley committed Dec 23, 2024
1 parent 8d9a00f commit 895d923
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 34 additions & 0 deletions crates/bevy_math/src/curve/easing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<Self> {
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`
Expand Down

0 comments on commit 895d923

Please sign in to comment.