-
-
Couldn't load subscription status.
- Fork 4.2k
[Merged by Bors] - Add Beziers to bevy_math
#7653
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9f1d944
Initial cubic bezier implementation
aevyrie 358b47b
Add trait methods to types
aevyrie cbd556a
Rename `into_points` to `to_points`
aevyrie 91a6f0c
Refactor to use generic function instead of trait.
aevyrie 7b884b6
Ensure implementation functions are inlined
aevyrie 25beaea
generic impl with benchmarks
aevyrie d1df0d8
Remove unnecessary `return`s
aevyrie af90a00
Update crates/bevy_math/src/bezier.rs
aevyrie 09354af
REview feedback
aevyrie 6786399
Improve easing API
aevyrie c8c4eef
Improve docs
aevyrie d0253ca
Doc corrections
aevyrie de415cc
Mark inline code art as text
aevyrie b5077e7
Update crates/bevy_math/src/bezier.rs
aevyrie 7c2ea64
fn cannot be constant
aevyrie 41e6624
Apply suggestions from code review
aevyrie 2aa5a94
Add tests, update docs, improve constructor
aevyrie 109a17f
ci fixes
aevyrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
|
|
||
| use bevy_math::*; | ||
|
|
||
| fn easing(c: &mut Criterion) { | ||
| let cubic_bezier = CubicBezierEasing::new(vec2(0.25, 0.1), vec2(0.25, 1.0)); | ||
| c.bench_function("easing_1000", |b| { | ||
| b.iter(|| { | ||
| (0..1000).map(|i| i as f32 / 1000.0).for_each(|t| { | ||
| cubic_bezier.ease(black_box(t)); | ||
| }) | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| fn fifteen_degree(c: &mut Criterion) { | ||
| let bezier = Bezier::<Vec3A, 16>::new([ | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| ]); | ||
| c.bench_function("fifteen_degree_position", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn quadratic_2d(c: &mut Criterion) { | ||
| let bezier = QuadraticBezier2d::new([[0.0, 0.0], [0.0, 1.0], [1.0, 1.0]]); | ||
| c.bench_function("quadratic_position_Vec2", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn quadratic(c: &mut Criterion) { | ||
| let bezier = QuadraticBezier3d::new([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 1.0]]); | ||
| c.bench_function("quadratic_position_Vec3A", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn quadratic_vec3(c: &mut Criterion) { | ||
| let bezier = Bezier::<Vec3, 3>::new([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [1.0, 1.0, 1.0]]); | ||
| c.bench_function("quadratic_position_Vec3", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn cubic_2d(c: &mut Criterion) { | ||
| let bezier = CubicBezier2d::new([[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]); | ||
| c.bench_function("cubic_position_Vec2", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn cubic(c: &mut Criterion) { | ||
| let bezier = CubicBezier3d::new([ | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| ]); | ||
| c.bench_function("cubic_position_Vec3A", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn cubic_vec3(c: &mut Criterion) { | ||
| let bezier = Bezier::<Vec3, 4>::new([ | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| ]); | ||
| c.bench_function("cubic_position_Vec3", |b| { | ||
| b.iter(|| bezier.position(black_box(0.5))); | ||
| }); | ||
| } | ||
|
|
||
| fn build_pos_cubic(c: &mut Criterion) { | ||
| let bezier = CubicBezier3d::new([ | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| ]); | ||
| c.bench_function("build_pos_cubic_100_points", |b| { | ||
| b.iter(|| bezier.iter_positions(black_box(100)).collect::<Vec<_>>()); | ||
| }); | ||
| } | ||
|
|
||
| fn build_accel_cubic(c: &mut Criterion) { | ||
| let bezier = CubicBezier3d::new([ | ||
| [0.0, 0.0, 0.0], | ||
| [0.0, 1.0, 0.0], | ||
| [1.0, 0.0, 0.0], | ||
| [1.0, 1.0, 1.0], | ||
| ]); | ||
| c.bench_function("build_accel_cubic_100_points", |b| { | ||
| b.iter(|| bezier.iter_positions(black_box(100)).collect::<Vec<_>>()); | ||
| }); | ||
| } | ||
|
|
||
| criterion_group!( | ||
| benches, | ||
| easing, | ||
| fifteen_degree, | ||
| quadratic_2d, | ||
| quadratic, | ||
| quadratic_vec3, | ||
| cubic_2d, | ||
| cubic, | ||
| cubic_vec3, | ||
| build_pos_cubic, | ||
| build_accel_cubic, | ||
| ); | ||
| criterion_main!(benches); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.