Commit 38d3d37
authored
Allow UnevenSampleCurve to infer interpolation arguments from samples (#20046)
# 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.
```rs
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.
```diff
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.1 parent 9a5d907 commit 38d3d37
1 file changed
+11
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
283 | 286 | | |
284 | 287 | | |
285 | 288 | | |
| |||
403 | 406 | | |
404 | 407 | | |
405 | 408 | | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
406 | 416 | | |
0 commit comments