Skip to content
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

[Merged by Bors] - Add Beziers to bevy_math #7653

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bevy_ecs = { path = "../crates/bevy_ecs" }
bevy_reflect = { path = "../crates/bevy_reflect" }
bevy_tasks = { path = "../crates/bevy_tasks" }
bevy_utils = { path = "../crates/bevy_utils" }
bevy_math = { path = "../crates/bevy_math" }

[profile.release]
opt-level = 3
Expand Down Expand Up @@ -50,3 +51,8 @@ harness = false
name = "iter"
path = "benches/bevy_tasks/iter.rs"
harness = false

[[bench]]
name = "bezier"
path = "benches/bevy_math/bezier.rs"
harness = false
95 changes: 95 additions & 0 deletions benches/benches/bevy_math/bezier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
aevyrie marked this conversation as resolved.
Show resolved Hide resolved

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::new([
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
vec3(1.0, 1.0, 1.0),
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
vec3(1.0, 1.0, 1.0),
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
vec3(1.0, 1.0, 1.0),
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
vec3(1.0, 1.0, 1.0),
]);
c.bench_function("fifteen_degree_position", |b| {
b.iter(|| bezier.position(black_box(0.5)));
});
}

fn quadratic(c: &mut Criterion) {
let bezier = QuadraticBezier3d::new([
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 1.0, 1.0),
]);
c.bench_function("quadratic_position", |b| {
b.iter(|| bezier.position(black_box(0.5)));
});
}

fn quadratic_vec3(c: &mut Criterion) {
let bezier = Bezier::new([
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 1.0, 1.0),
]);
c.bench_function("quadratic_position_Vec3", |b| {
b.iter(|| bezier.position(black_box(0.5)));
});
}

fn cubic(c: &mut Criterion) {
let bezier = CubicBezier3d::new([
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
vec3a(1.0, 1.0, 1.0),
]);
c.bench_function("cubic_position", |b| {
b.iter(|| bezier.position(black_box(0.5)));
});
}

fn cubic_vec3(c: &mut Criterion) {
let bezier = Bezier::new([
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
vec3(1.0, 1.0, 1.0),
]);
c.bench_function("cubic_position_Vec3", |b| {
b.iter(|| bezier.position(black_box(0.5)));
});
}

criterion_group!(
benches,
easing,
fifteen_degree,
quadratic,
quadratic_vec3,
cubic,
cubic_vec3
);
criterion_main!(benches);
Loading