Skip to content

Commit ea15c85

Browse files
mweatherleymockersf
authored andcommitted
Expose the output curve type in with_derivative (#18826)
# Objective I was wrong about how RPITIT works when I wrote this stuff initially, and in order to actually give people access to all the traits implemented by the output (e.g. Debug and so on) it's important to expose the real output type, even if it makes the trait uglier and less comprehensible. (☹️) ## Solution Expose the curve output type of the `CurveWithDerivative` trait and its double-derivative companion. I also added a bunch of trait derives to `WithDerivative<T>`, since I think that was just an oversight.
1 parent 033f29d commit ea15c85

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

crates/bevy_math/src/common_traits.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ impl VectorSpace for f32 {
8080
///
8181
/// [vector spaces]: VectorSpace
8282
#[derive(Debug, Clone, Copy)]
83+
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
84+
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
8385
pub struct Sum<V, W>(pub V, pub W);
8486

8587
impl<V, W> Mul<f32> for Sum<V, W>
@@ -424,6 +426,9 @@ pub trait HasTangent {
424426
}
425427

426428
/// A value with its derivative.
429+
#[derive(Debug, Clone, Copy)]
430+
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
431+
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
427432
pub struct WithDerivative<T>
428433
where
429434
T: HasTangent,
@@ -436,6 +441,9 @@ where
436441
}
437442

438443
/// A value together with its first and second derivatives.
444+
#[derive(Debug, Clone, Copy)]
445+
#[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))]
446+
#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))]
439447
pub struct WithTwoDerivatives<T>
440448
where
441449
T: HasTangent,

crates/bevy_math/src/curve/derivatives/mod.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,28 @@ use bevy_reflect::{FromReflect, Reflect};
3737
/// derivatives to be extracted along with values.
3838
///
3939
/// This is implemented by implementing [`SampleDerivative`].
40-
pub trait CurveWithDerivative<T>: SampleDerivative<T>
40+
pub trait CurveWithDerivative<T>: SampleDerivative<T> + Sized
4141
where
4242
T: HasTangent,
4343
{
4444
/// This curve, but with its first derivative included in sampling.
45-
fn with_derivative(self) -> impl Curve<WithDerivative<T>>;
45+
///
46+
/// Notably, the output type is a `Curve<WithDerivative<T>>`.
47+
fn with_derivative(self) -> SampleDerivativeWrapper<Self>;
4648
}
4749

4850
/// Trait for curves that have a well-defined notion of second derivative,
4951
/// allowing for two derivatives to be extracted along with values.
5052
///
5153
/// This is implemented by implementing [`SampleTwoDerivatives`].
52-
pub trait CurveWithTwoDerivatives<T>: SampleTwoDerivatives<T>
54+
pub trait CurveWithTwoDerivatives<T>: SampleTwoDerivatives<T> + Sized
5355
where
5456
T: HasTangent,
5557
{
5658
/// This curve, but with its first two derivatives included in sampling.
57-
fn with_two_derivatives(self) -> impl Curve<WithTwoDerivatives<T>>;
59+
///
60+
/// Notably, the output type is a `Curve<WithTwoDerivatives<T>>`.
61+
fn with_two_derivatives(self) -> SampleTwoDerivativesWrapper<Self>;
5862
}
5963

6064
/// A trait for curves that can sample derivatives in addition to values.
@@ -210,7 +214,7 @@ where
210214
T: HasTangent,
211215
C: SampleDerivative<T>,
212216
{
213-
fn with_derivative(self) -> impl Curve<WithDerivative<T>> {
217+
fn with_derivative(self) -> SampleDerivativeWrapper<Self> {
214218
SampleDerivativeWrapper(self)
215219
}
216220
}
@@ -220,7 +224,7 @@ where
220224
T: HasTangent,
221225
C: SampleTwoDerivatives<T> + CurveWithDerivative<T>,
222226
{
223-
fn with_two_derivatives(self) -> impl Curve<WithTwoDerivatives<T>> {
227+
fn with_two_derivatives(self) -> SampleTwoDerivativesWrapper<Self> {
224228
SampleTwoDerivativesWrapper(self)
225229
}
226230
}

0 commit comments

Comments
 (0)