Skip to content

Commit 001c49a

Browse files
committed
Use normal constructors for EasingCurve, FunctionCurve, ConstantCurve
1 parent a8c610a commit 001c49a

File tree

9 files changed

+90
-106
lines changed

9 files changed

+90
-106
lines changed

crates/bevy_animation/src/animation_curves.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
//! `Curve<Vec3>` that we want to use to animate something. That could be defined in
88
//! a number of different ways, but let's imagine that we've defined it [using a function]:
99
//!
10-
//! # use bevy_math::curve::{Curve, Interval, function_curve};
10+
//! # use bevy_math::curve::{Curve, Interval, FunctionCurve};
1111
//! # use bevy_math::vec3;
12-
//! let wobble_curve = function_curve(
12+
//! let wobble_curve = FunctionCurve::new(
1313
//! Interval::UNIT,
1414
//! |t| { vec3(t.cos(), 0.0, 0.0) },
1515
//! );
@@ -25,10 +25,10 @@
2525
//! the adaptor [`TranslationCurve`], which wraps any `Curve<Vec3>` and turns it into an
2626
//! [`AnimationCurve`] that will use the given curve to animate the entity's translation:
2727
//!
28-
//! # use bevy_math::curve::{Curve, Interval, function_curve};
28+
//! # use bevy_math::curve::{Curve, Interval, FunctionCurve};
2929
//! # use bevy_math::vec3;
3030
//! # use bevy_animation::animation_curves::*;
31-
//! # let wobble_curve = function_curve(
31+
//! # let wobble_curve = FunctionCurve::new(
3232
//! # Interval::UNIT,
3333
//! # |t| vec3(t.cos(), 0.0, 0.0)
3434
//! # );
@@ -37,11 +37,11 @@
3737
//! And finally, this `AnimationCurve` needs to be added to an [`AnimationClip`] in order to
3838
//! actually animate something. This is what that looks like:
3939
//!
40-
//! # use bevy_math::curve::{Curve, Interval, function_curve};
40+
//! # use bevy_math::curve::{Curve, Interval, FunctionCurve};
4141
//! # use bevy_animation::{AnimationClip, AnimationTargetId, animation_curves::*};
4242
//! # use bevy_core::Name;
4343
//! # use bevy_math::vec3;
44-
//! # let wobble_curve = function_curve(
44+
//! # let wobble_curve = FunctionCurve::new(
4545
//! # Interval::UNIT,
4646
//! # |t| { vec3(t.cos(), 0.0, 0.0) },
4747
//! # );
@@ -71,7 +71,7 @@
7171
//! Animation of arbitrary components can be accomplished using [`AnimatableProperty`] in
7272
//! conjunction with [`AnimatableCurve`]. See the documentation [there] for details.
7373
//!
74-
//! [using a function]: bevy_math::curve::function_curve
74+
//! [using a function]: bevy_math::curve::FunctionCurve
7575
//! [translation component of a `Transform`]: bevy_transform::prelude::Transform::translation
7676
//! [`AnimationClip`]: crate::AnimationClip
7777
//! [there]: AnimatableProperty

crates/bevy_gizmos/src/curves.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ where
3333
/// # use bevy_color::palettes::basic::{RED};
3434
/// fn system(mut gizmos: Gizmos) {
3535
/// let domain = Interval::UNIT;
36-
/// let curve = function_curve(domain, |t| Vec2::from(t.sin_cos()));
36+
/// let curve = FunctionCurve::new(domain, |t| Vec2::from(t.sin_cos()));
3737
/// gizmos.curve_2d(curve, (0..=100).map(|n| n as f32 / 100.0), RED);
3838
/// }
3939
/// # bevy_ecs::system::assert_is_system(system);
@@ -67,7 +67,7 @@ where
6767
/// # use bevy_color::palettes::basic::{RED};
6868
/// fn system(mut gizmos: Gizmos) {
6969
/// let domain = Interval::UNIT;
70-
/// let curve = function_curve(domain, |t| {
70+
/// let curve = FunctionCurve::new(domain, |t| {
7171
/// let (x,y) = t.sin_cos();
7272
/// Vec3::new(x, y, t)
7373
/// });
@@ -104,7 +104,7 @@ where
104104
/// # use bevy_color::{Mix, palettes::basic::{GREEN, RED}};
105105
/// fn system(mut gizmos: Gizmos) {
106106
/// let domain = Interval::UNIT;
107-
/// let curve = function_curve(domain, |t| Vec2::from(t.sin_cos()));
107+
/// let curve = FunctionCurve::new(domain, |t| Vec2::from(t.sin_cos()));
108108
/// gizmos.curve_gradient_2d(
109109
/// curve,
110110
/// (0..=100).map(|n| n as f32 / 100.0)
@@ -147,7 +147,7 @@ where
147147
/// # use bevy_color::{Mix, palettes::basic::{GREEN, RED}};
148148
/// fn system(mut gizmos: Gizmos) {
149149
/// let domain = Interval::UNIT;
150-
/// let curve = function_curve(domain, |t| {
150+
/// let curve = FunctionCurve::new(domain, |t| {
151151
/// let (x,y) = t.sin_cos();
152152
/// Vec3::new(x, y, t)
153153
/// });

crates/bevy_gltf/src/loader.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ async fn load_gltf<'a, 'b, 'c>(
275275
#[cfg(feature = "bevy_animation")]
276276
let (animations, named_animations, animation_roots) = {
277277
use bevy_animation::{animation_curves::*, gltf_curves::*, VariableCurve};
278-
use bevy_math::curve::{constant_curve, Interval, UnevenSampleAutoCurve};
278+
use bevy_math::curve::{ConstantCurve, Interval, UnevenSampleAutoCurve};
279279
use bevy_math::{Quat, Vec4};
280280
use gltf::animation::util::ReadOutputs;
281281
let mut animations = vec![];
@@ -313,7 +313,7 @@ async fn load_gltf<'a, 'b, 'c>(
313313
let translations: Vec<Vec3> = tr.map(Vec3::from).collect();
314314
if keyframe_timestamps.len() == 1 {
315315
#[allow(clippy::unnecessary_map_on_constructor)]
316-
Some(constant_curve(Interval::EVERYWHERE, translations[0]))
316+
Some(ConstantCurve::new(Interval::EVERYWHERE, translations[0]))
317317
.map(TranslationCurve)
318318
.map(VariableCurve::new)
319319
} else {
@@ -348,7 +348,7 @@ async fn load_gltf<'a, 'b, 'c>(
348348
rots.into_f32().map(Quat::from_array).collect();
349349
if keyframe_timestamps.len() == 1 {
350350
#[allow(clippy::unnecessary_map_on_constructor)]
351-
Some(constant_curve(Interval::EVERYWHERE, rotations[0]))
351+
Some(ConstantCurve::new(Interval::EVERYWHERE, rotations[0]))
352352
.map(RotationCurve)
353353
.map(VariableCurve::new)
354354
} else {
@@ -385,7 +385,7 @@ async fn load_gltf<'a, 'b, 'c>(
385385
let scales: Vec<Vec3> = scale.map(Vec3::from).collect();
386386
if keyframe_timestamps.len() == 1 {
387387
#[allow(clippy::unnecessary_map_on_constructor)]
388-
Some(constant_curve(Interval::EVERYWHERE, scales[0]))
388+
Some(ConstantCurve::new(Interval::EVERYWHERE, scales[0]))
389389
.map(ScaleCurve)
390390
.map(VariableCurve::new)
391391
} else {
@@ -419,7 +419,7 @@ async fn load_gltf<'a, 'b, 'c>(
419419
let weights: Vec<f32> = weights.into_f32().collect();
420420
if keyframe_timestamps.len() == 1 {
421421
#[allow(clippy::unnecessary_map_on_constructor)]
422-
Some(constant_curve(Interval::EVERYWHERE, weights))
422+
Some(ConstantCurve::new(Interval::EVERYWHERE, weights))
423423
.map(WeightsCurve)
424424
.map(VariableCurve::new)
425425
} else {

crates/bevy_math/src/curve/easing.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
//!
44
//! [easing functions]: EaseFunction
55
6-
use crate::{Dir2, Dir3, Dir3A, Quat, Rot2, VectorSpace};
7-
8-
use super::{function_curve, Curve, Interval};
6+
use crate::{
7+
curve::{FunctionCurve, Interval},
8+
Curve, Dir2, Dir3, Dir3A, Quat, Rot2, VectorSpace,
9+
};
910

1011
// TODO: Think about merging `Ease` with `StableInterpolate`
1112

@@ -28,13 +29,13 @@ pub trait Ease: Sized {
2829

2930
impl<V: VectorSpace> Ease for V {
3031
fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve<Self> {
31-
function_curve(Interval::EVERYWHERE, move |t| V::lerp(start, end, t))
32+
FunctionCurve::new(Interval::EVERYWHERE, move |t| V::lerp(start, end, t))
3233
}
3334
}
3435

3536
impl Ease for Rot2 {
3637
fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve<Self> {
37-
function_curve(Interval::EVERYWHERE, move |t| Rot2::slerp(start, end, t))
38+
FunctionCurve::new(Interval::EVERYWHERE, move |t| Rot2::slerp(start, end, t))
3839
}
3940
}
4041

@@ -44,15 +45,15 @@ impl Ease for Quat {
4445
let end_adjusted = if dot < 0.0 { -end } else { end };
4546
let difference = end_adjusted * start.inverse();
4647
let (axis, angle) = difference.to_axis_angle();
47-
function_curve(Interval::EVERYWHERE, move |s| {
48+
FunctionCurve::new(Interval::EVERYWHERE, move |s| {
4849
Quat::from_axis_angle(axis, angle * s) * start
4950
})
5051
}
5152
}
5253

5354
impl Ease for Dir2 {
5455
fn interpolating_curve_unbounded(start: Self, end: Self) -> impl Curve<Self> {
55-
function_curve(Interval::EVERYWHERE, move |t| Dir2::slerp(start, end, t))
56+
FunctionCurve::new(Interval::EVERYWHERE, move |t| Dir2::slerp(start, end, t))
5657
}
5758
}
5859

@@ -71,20 +72,6 @@ impl Ease for Dir3A {
7172
}
7273
}
7374

74-
/// Given a `start` and `end` value, create a curve parametrized over [the unit interval]
75-
/// that connects them, using the given [ease function] to determine the form of the
76-
/// curve in between.
77-
///
78-
/// [the unit interval]: Interval::UNIT
79-
/// [ease function]: EaseFunction
80-
pub fn easing_curve<T: Ease + Clone>(start: T, end: T, ease_fn: EaseFunction) -> EasingCurve<T> {
81-
EasingCurve {
82-
start,
83-
end,
84-
ease_fn,
85-
}
86-
}
87-
8875
/// A [`Curve`] that is defined by
8976
///
9077
/// - an initial `start` sample value at `t = 0`
@@ -104,6 +91,22 @@ pub struct EasingCurve<T> {
10491
ease_fn: EaseFunction,
10592
}
10693

94+
impl<T> EasingCurve<T> {
95+
/// Given a `start` and `end` value, create a curve parametrized over [the unit interval]
96+
/// that connects them, using the given [ease function] to determine the form of the
97+
/// curve in between.
98+
///
99+
/// [the unit interval]: Interval::UNIT
100+
/// [ease function]: EaseFunction
101+
pub fn new(start: T, end: T, ease_fn: EaseFunction) -> Self {
102+
Self {
103+
start,
104+
end,
105+
ease_fn,
106+
}
107+
}
108+
}
109+
107110
impl<T> Curve<T> for EasingCurve<T>
108111
where
109112
T: Ease + Clone,

0 commit comments

Comments
 (0)