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

Rename Bezier to CubicBezier for clarity #9554

Merged
merged 1 commit into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions benches/benches/bevy_math/bezier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn easing(c: &mut Criterion) {
}

fn cubic_2d(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec2(0.0, 0.0),
vec2(0.0, 1.0),
vec2(1.0, 0.0),
Expand All @@ -27,7 +27,7 @@ fn cubic_2d(c: &mut Criterion) {
}

fn cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand All @@ -40,7 +40,7 @@ fn cubic(c: &mut Criterion) {
}

fn cubic_vec3(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3(0.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(1.0, 0.0, 0.0),
Expand All @@ -53,7 +53,7 @@ fn cubic_vec3(c: &mut Criterion) {
}

fn build_pos_cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand All @@ -66,7 +66,7 @@ fn build_pos_cubic(c: &mut Criterion) {
}

fn build_accel_cubic(c: &mut Criterion) {
let bezier = Bezier::new([[
let bezier = CubicBezier::new([[
vec3a(0.0, 0.0, 0.0),
vec3a(0.0, 1.0, 0.0),
vec3a(1.0, 0.0, 0.0),
Expand Down
18 changes: 9 additions & 9 deletions crates/bevy_math/src/cubic_splines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Point for Vec3A {}
impl Point for Vec2 {}
impl Point for f32 {}

/// A spline composed of a series of cubic Bezier curves.
/// A spline composed of a single cubic Bezier curve.
///
/// Useful for user-drawn curves with local control, or animation easing. See
/// [`CubicSegment::new_bezier`] for use in easing.
Expand All @@ -53,22 +53,22 @@ impl Point for f32 {}
/// vec2(5.0, 3.0),
/// vec2(9.0, 8.0),
/// ]];
/// let bezier = Bezier::new(points).to_curve();
/// let bezier = CubicBezier::new(points).to_curve();
/// let positions: Vec<_> = bezier.iter_positions(100).collect();
/// ```
pub struct Bezier<P: Point> {
pub struct CubicBezier<P: Point> {
control_points: Vec<[P; 4]>,
}

impl<P: Point> Bezier<P> {
/// Create a new Bezier curve from sets of control points.
impl<P: Point> CubicBezier<P> {
/// Create a new cubic Bezier curve from sets of control points.
pub fn new(control_points: impl Into<Vec<[P; 4]>>) -> Self {
Self {
control_points: control_points.into(),
}
}
}
impl<P: Point> CubicGenerator<P> for Bezier<P> {
impl<P: Point> CubicGenerator<P> for CubicBezier<P> {
#[inline]
fn to_curve(&self) -> CubicCurve<P> {
let char_matrix = [
Expand Down Expand Up @@ -340,7 +340,7 @@ impl CubicSegment<Vec2> {
/// example, the ubiquitous "ease-in-out" is defined as `(0.25, 0.1), (0.25, 1.0)`.
pub fn new_bezier(p1: impl Into<Vec2>, p2: impl Into<Vec2>) -> Self {
let (p0, p3) = (Vec2::ZERO, Vec2::ONE);
let bezier = Bezier::new([[p0, p1.into(), p2.into(), p3]]).to_curve();
let bezier = CubicBezier::new([[p0, p1.into(), p2.into(), p3]]).to_curve();
bezier.segments[0].clone()
}

Expand Down Expand Up @@ -553,7 +553,7 @@ impl<P: Point> CubicCurve<P> {
mod tests {
use glam::{vec2, Vec2};

use crate::cubic_splines::{Bezier, CubicGenerator, CubicSegment};
use crate::cubic_splines::{CubicBezier, CubicGenerator, CubicSegment};

/// How close two floats can be and still be considered equal
const FLOAT_EQ: f32 = 1e-5;
Expand All @@ -568,7 +568,7 @@ mod tests {
vec2(5.0, 3.0),
vec2(9.0, 8.0),
]];
let bezier = Bezier::new(points).to_curve();
let bezier = CubicBezier::new(points).to_curve();
for i in 0..=N_SAMPLES {
let t = i as f32 / N_SAMPLES as f32; // Check along entire length
assert!(bezier.position(t).distance(cubic_manual(t, points[0])) <= FLOAT_EQ);
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ pub use rects::*;
pub mod prelude {
#[doc(hidden)]
pub use crate::{
cubic_splines::{BSpline, Bezier, CardinalSpline, CubicGenerator, CubicSegment, Hermite},
cubic_splines::{
BSpline, CardinalSpline, CubicBezier, CubicGenerator, CubicSegment, Hermite,
},
BVec2, BVec3, BVec4, EulerRot, IRect, IVec2, IVec3, IVec4, Mat2, Mat3, Mat4, Quat, Ray,
Rect, URect, UVec2, UVec3, UVec4, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles, Vec4,
Vec4Swizzles,
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/cubic_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn setup(
]];

// Make a CubicCurve
let bezier = Bezier::new(points).to_curve();
let bezier = CubicBezier::new(points).to_curve();

// Spawning a cube to experiment on
commands.spawn((
Expand Down