Trait enterpolation::Curve

source ·
pub trait Curve<R>: Generator<R>where
    R: Real,{
    // Required method
    fn domain(&self) -> [R; 2];

    // Provided methods
    fn take(self, samples: usize) -> Take<Self, R>
       where Self: Sized,
             R: FromPrimitive { ... }
    fn slice<B>(self, bounds: B) -> Slice<Self, R>
       where Self: Sized,
             B: RangeBounds<R> { ... }
    fn clamp(self) -> Clamp<Self>
       where Self: Sized { ... }
}
Expand description

Specialized Generator which takes a real number as input.

Required Methods§

source

fn domain(&self) -> [R; 2]

The domain in which the curve uses interpolation.

Not all Curves may extrapolate in a safe way.

Provided Methods§

source

fn take(self, samples: usize) -> Take<Self, R>where Self: Sized, R: FromPrimitive,

Takes equidistant samples of the curve.

Examples
let linear = Linear::builder()
                .elements([0.0,5.0,3.0])
                .knots([0.0,1.0,2.0])
                .build()?;
let results = [0.0,1.0,2.0,3.0,4.0,5.0,4.6,4.2,3.8,3.4,3.0];    // take 11 samples
for (value,result) in linear.take(results.len()).zip(results.iter().copied()){
    assert_f64_near!(value, result);
}
Panics

Panics if given size of samples is 0 or if samples - 1 can not be converted to the type R.

source

fn slice<B>(self, bounds: B) -> Slice<Self, R>where Self: Sized, B: RangeBounds<R>,

Take a slice of a curve.

A slice of a curve maps its domain onto the given range.

Examples
let linear = Linear::builder()
                .elements([0.0,5.0,3.0])
                .knots([0.0,1.0,2.0])
                .build()?;
let sliced_linear = linear.slice(0.5..1.5);
let results = [2.5,5.0,4.0];
for (value,result) in sliced_linear.take(results.len()).zip(results.iter().copied()){
    assert_f64_near!(value, result);
}
source

fn clamp(self) -> Clamp<Self>where Self: Sized,

Clamp the input of a curve to its domain.

Examples
let linear = Linear::builder()
                .elements([0.0,3.0])
                .knots([0.0,1.0])
                .build()?
                .clamp();
let expected = [[-1.0,0.0],[0.0,0.0],[0.5,1.5],[1.0,3.0],[2.0,3.0]];
for [input,result] in expected {
    assert_f64_near!(linear.gen(input), result);
}

Implementations on Foreign Types§

source§

impl<C: Curve<R> + ?Sized, R> Curve<R> for &Cwhere R: Real,

source§

fn domain(&self) -> [R; 2]

Implementors§

source§

impl<A, B, R> Curve<R> for Composite<A, B>where A: Curve<R>, B: Generator<A::Output>, R: Real,

source§

impl<C, R> Curve<R> for Weights<C>where C: Curve<R>, C::Output: IntoWeight, R: Real,

source§

impl<F, R> Curve<R> for FuncEase<F>where F: Fn(R) -> R, R: Real,

source§

impl<G, H, R> Curve<R> for Stack<G, H>where G: Curve<R>, H: Curve<R>, R: Real,

source§

impl<G, R> Curve<R> for Clamp<G>where G: Curve<R>, R: Real,

source§

impl<G, R> Curve<R> for Slice<G, R>where G: Curve<R>, R: Real,

source§

impl<G, R> Curve<R> for TransformInput<G, R, R>where G: Curve<R>, R: Real,

source§

impl<G, R> Curve<R> for Weighted<G>where G: Curve<R>, G::Output: Project, R: Real,

source§

impl<K, E, S, R> Curve<R> for BSpline<K, E, S>where E: DiscreteGenerator, S: Space<E::Output>, E::Output: Merge<R> + Copy, R: Real + Debug, K: SortedGenerator<Output = R>,

source§

impl<R> Curve<R> for Identitywhere R: Real,

source§

impl<R> Curve<R> for Plateau<R>where R: Real + FromPrimitive,

source§

impl<R, E, S> Curve<R> for Bezier<R, E, S>where E: DiscreteGenerator, E::Output: Merge<R> + Copy, S: Space<E::Output>, R: Real,

source§

impl<R, K, E, F> Curve<R> for Linear<K, E, F>where K: SortedGenerator<Output = R>, E: DiscreteGenerator, E::Output: Merge<R> + Debug, F: Curve<R, Output = R>, R: Real + Debug,