Skip to content

Allow UnevenSampleCurve to infer interpolation arguments from samples #20046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laundmo
Copy link
Contributor

@laundmo laundmo commented Jul 8, 2025

Objective

bevy_math::curve::UnevenSampleCurve was lacking trait bounds on its new method which caused a need to manually specify interpolation function argument types, even though the types are already known from the timed_samples argument.

UnevenSampleCurve::new(
    [(0.1, 1.0), (1.0, 3.0)],
    |x: &f64, y: &f64, t| x.lerp(*y, t)
//      ^ ugly and annoying
)

Solution

This adds the Fn trait bound to the new method, matching the behaviour of SampleCurve.

Testing

I added a test which doesn't actually test for any runtime behaviour, instead writing code that would error before this PR.


Showcase

It's now possible to create a UnevenSampleCurve without specifying the interpolation closure argument types.

UnevenSampleCurve::new(
    [(0.1, 1.0), (1.0, 3.0)],
-   |x: &f64, y: &f64, t| x.lerp(*y, t)
+   |x, y, t| x.lerp(*y, t)
)

Sidenote

Seeing x and y in lerp feels wrong, I've always used a and b to avoid confusion with coordinates.

Copy link
Contributor

@mweatherley mweatherley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants