diff --git a/crates/bevy_math/src/curve/sample_curves.rs b/crates/bevy_math/src/curve/sample_curves.rs index f0fa928abb..ea9b88f2ce 100644 --- a/crates/bevy_math/src/curve/sample_curves.rs +++ b/crates/bevy_math/src/curve/sample_curves.rs @@ -279,7 +279,10 @@ impl UnevenSampleCurve { pub fn new( timed_samples: impl IntoIterator, interpolation: I, - ) -> Result { + ) -> Result + where + I: Fn(&T, &T, f32) -> T, + { Ok(Self { core: UnevenCore::new(timed_samples)?, interpolation, @@ -403,4 +406,11 @@ mod tests { let _: Box = Box::new(UnevenSampleCurve::new(keyframes, bar).unwrap()); let _: Box = Box::new(UnevenSampleCurve::new(keyframes, baz).unwrap()); } + #[test] + fn test_infer_interp_arguments() { + // it should be possible to infer the x and y arguments of the interpolation function + // from the input samples. If that becomes impossible, this will fail to compile. + SampleCurve::new(Interval::UNIT, [0.0, 1.0], |x, y, t| x.lerp(*y, t)).ok(); + UnevenSampleCurve::new([(0.1, 1.0), (1.0, 3.0)], |x, y, t| x.lerp(*y, t)).ok(); + } }