[go: up one dir, main page]

Curve

Trait Curve 

Source
pub trait Curve<R>: Signal<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 Signal 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.eval(input), result);
}

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.

Implementations on Foreign Types§

Source§

impl<C: Curve<R> + ?Sized, R> Curve<R> for &C
where 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: Signal<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: Chain, S: Space<E::Output>, E::Output: Merge<R> + Copy, R: Real + Debug, K: SortedChain<Output = R>,

Source§

impl<R> Curve<R> for Identity
where 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: Chain, 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: SortedChain<Output = R>, E: Chain, E::Output: Merge<R> + Debug, F: Curve<R, Output = R>, R: Real + Debug,