Trait CurveResampleExt

Source
pub trait CurveResampleExt<T>: Curve<T> {
    // Provided methods
    fn resample<I>(
        &self,
        segments: usize,
        interpolation: I,
    ) -> Result<SampleCurve<T, I>, ResamplingError>
       where I: Fn(&T, &T, f32) -> T { ... }
    fn resample_auto(
        &self,
        segments: usize,
    ) -> Result<SampleAutoCurve<T>, ResamplingError>
       where T: StableInterpolate { ... }
    fn resample_uneven<I>(
        &self,
        sample_times: impl IntoIterator<Item = f32>,
        interpolation: I,
    ) -> Result<UnevenSampleCurve<T, I>, ResamplingError>
       where I: Fn(&T, &T, f32) -> T { ... }
    fn resample_uneven_auto(
        &self,
        sample_times: impl IntoIterator<Item = f32>,
    ) -> Result<UnevenSampleAutoCurve<T>, ResamplingError>
       where T: StableInterpolate { ... }
}
Expand description

Extension trait implemented by curves, allowing access to generic resampling methods as well as those based on stable interpolation.

This trait is automatically implemented for all curves.

For more information, see the module-level documentation.

Provided Methods§

Source

fn resample<I>( &self, segments: usize, interpolation: I, ) -> Result<SampleCurve<T, I>, ResamplingError>
where I: Fn(&T, &T, f32) -> T,

Resample this Curve to produce a new one that is defined by interpolation over equally spaced sample values, using the provided interpolation to interpolate between adjacent samples. The curve is interpolated on segments segments between samples. For example, if segments is 1, only the start and end points of the curve are used as samples; if segments is 2, a sample at the midpoint is taken as well, and so on.

The interpolation takes two values by reference together with a scalar parameter and produces an owned value. The expectation is that interpolation(&x, &y, 0.0) and interpolation(&x, &y, 1.0) are equivalent to x and y respectively.

§Errors

If segments is zero or if this curve has unbounded domain, then a ResamplingError is returned.

§Example
let quarter_rotation = FunctionCurve::new(interval(0.0, 90.0).unwrap(), |t| Rot2::degrees(t));
// A curve which only stores three data points and uses `nlerp` to interpolate them:
let resampled_rotation = quarter_rotation.resample(3, |x, y, t| x.nlerp(*y, t));
Source

fn resample_auto( &self, segments: usize, ) -> Result<SampleAutoCurve<T>, ResamplingError>

Resample this Curve to produce a new one that is defined by interpolation over equally spaced sample values, using automatic interpolation to interpolate between adjacent samples. The curve is interpolated on segments segments between samples. For example, if segments is 1, only the start and end points of the curve are used as samples; if segments is 2, a sample at the midpoint is taken as well, and so on.

§Errors

If segments is zero or if this curve has unbounded domain, a ResamplingError is returned.

Source

fn resample_uneven<I>( &self, sample_times: impl IntoIterator<Item = f32>, interpolation: I, ) -> Result<UnevenSampleCurve<T, I>, ResamplingError>
where I: Fn(&T, &T, f32) -> T,

Resample this Curve to produce a new one that is defined by interpolation over samples taken at a given set of times. The given interpolation is used to interpolate adjacent samples, and the sample_times are expected to contain at least two valid times within the curve’s domain interval.

Redundant sample times, non-finite sample times, and sample times outside of the domain are filtered out. With an insufficient quantity of data, a ResamplingError is returned.

The domain of the produced curve stretches between the first and last sample times of the iterator.

The interpolation takes two values by reference together with a scalar parameter and produces an owned value. The expectation is that interpolation(&x, &y, 0.0) and interpolation(&x, &y, 1.0) are equivalent to x and y respectively.

§Errors

If sample_times doesn’t contain at least two distinct times after filtering, a ResamplingError is returned.

Source

fn resample_uneven_auto( &self, sample_times: impl IntoIterator<Item = f32>, ) -> Result<UnevenSampleAutoCurve<T>, ResamplingError>

Resample this Curve to produce a new one that is defined by automatic interpolation over samples taken at the given set of times. The given sample_times are expected to contain at least two valid times within the curve’s domain interval.

Redundant sample times, non-finite sample times, and sample times outside of the domain are simply filtered out. With an insufficient quantity of data, a ResamplingError is returned.

The domain of the produced UnevenSampleAutoCurve stretches between the first and last sample times of the iterator.

§Errors

If sample_times doesn’t contain at least two distinct times after filtering, a ResamplingError is returned.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<C, T> CurveResampleExt<T> for C
where C: Curve<T> + ?Sized,