[][src]Struct splines::spline::Spline

pub struct Spline<T, V>(_);

Spline curve used to provide interpolation between control points (keys).

Splines are made out of control points (Key). When creating a Spline with Spline::from_vec or Spline::from_iter, the keys don’t have to be sorted (they are sorted automatically by the sampling value).

You can sample from a spline with several functions:

  • Spline::sample: allows you to sample from a spline. If not enough keys are available for the required interpolation mode, you get None.
  • Spline::clamped_sample: behaves like Spline::sample but will return either the first or last key if out of bound; it will return None if not enough key.

Methods

impl<T, V> Spline<T, V>[src]

pub fn from_vec(keys: Vec<Key<T, V>>) -> Self where
    T: PartialOrd
[src]

Create a new spline out of keys. The keys don’t have to be sorted even though it’s recommended to provide ascending sorted ones (for performance purposes).

pub fn from_iter<I>(iter: I) -> Self where
    I: Iterator<Item = Key<T, V>>,
    T: PartialOrd
[src]

Create a new spline by consuming an Iterater<Item = Key<T>>. They keys don’t have to be sorted.

Note on iterators

It’s valid to use any iterator that implements Iterator<Item = Key<T>>. However, you should use Spline::from_vec if you are passing a Vec.

pub fn keys(&self) -> &[Key<T, V>][src]

Retrieve the keys of a spline.

pub fn len(&self) -> usize[src]

Number of keys.

pub fn is_empty(&self) -> bool[src]

Check whether the spline has no key.

pub fn sample_with_key(
    &self,
    t: T
) -> Option<(V, &Key<T, V>, Option<&Key<T, V>>)> where
    T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
    V: Interpolate<T>, 
[src]

Sample a spline at a given time, returning the interpolated value along with its associated key.

The current implementation, based on immutability, cannot perform in constant time. This means that sampling’s processing complexity is currently O(log n). It’s possible to achieve O(1) performance by using a slightly different spline type. If you are interested by this feature, an implementation for a dedicated type is foreseen yet not started yet.

Return

None if you try to sample a value at a time that has no key associated with. That can also happen if you try to sample between two keys with a specific interpolation mode that makes the sampling impossible. For instance, Interpolation::CatmullRom requires four keys. If you’re near the beginning of the spline or its end, ensure you have enough keys around to make the sampling.

pub fn sample(&self, t: T) -> Option<V> where
    T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
    V: Interpolate<T>, 
[src]

Sample a spline at a given time.

pub fn clamped_sample_with_key(
    &self,
    t: T
) -> Option<(V, &Key<T, V>, Option<&Key<T, V>>)> where
    T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
    V: Interpolate<T>, 
[src]

Sample a spline at a given time with clamping, returning the interpolated value along with its associated key.

Return

If you sample before the first key or after the last one, return the first key or the last one, respectively. Otherwise, behave the same way as Spline::sample.

Error

This function returns None if you have no key.

pub fn clamped_sample(&self, t: T) -> Option<V> where
    T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
    V: Interpolate<T>, 
[src]

Sample a spline at a given time with clamping.

pub fn add(&mut self, key: Key<T, V>) where
    T: PartialOrd
[src]

Add a key into the spline.

pub fn remove(&mut self, index: usize) -> Option<Key<T, V>>[src]

Remove a key from the spline.

pub fn replace<F>(&mut self, index: usize, f: F) -> Option<Key<T, V>> where
    F: FnOnce(&Key<T, V>) -> Key<T, V>,
    T: PartialOrd
[src]

Update a key and return the key already present.

The key is updated — if present — with the provided function.

Notes

That function makes sense only if you want to change the interpolator (i.e. Key::t) of your key. If you just want to change the interpolation mode or the carried value, consider using the Spline::get_mut method instead as it will be way faster.

pub fn get(&self, index: usize) -> Option<&Key<T, V>>[src]

Get a key at a given index.

pub fn get_mut(&mut self, index: usize) -> Option<KeyMut<T, V>>[src]

Mutably get a key at a given index.

Trait Implementations

impl<'a, T, V> IntoIterator for &'a Spline<T, V>[src]

type Item = &'a Key<T, V>

The type of the elements being iterated over.

type IntoIter = Iter<'a, T, V>

Which kind of iterator are we turning this into?

impl<T: Clone, V: Clone> Clone for Spline<T, V>[src]

impl<T: Debug, V: Debug> Debug for Spline<T, V>[src]

impl<T, V> Serialize for Spline<T, V> where
    T: Serialize,
    V: Serialize
[src]

impl<'de, T, V> Deserialize<'de> for Spline<T, V> where
    T: Deserialize<'de>,
    V: Deserialize<'de>, 
[src]

Auto Trait Implementations

impl<T, V> Send for Spline<T, V> where
    T: Send,
    V: Send

impl<T, V> Sync for Spline<T, V> where
    T: Sync,
    V: Sync

impl<T, V> Unpin for Spline<T, V> where
    T: Unpin,
    V: Unpin

impl<T, V> UnwindSafe for Spline<T, V> where
    T: UnwindSafe,
    V: UnwindSafe

impl<T, V> RefUnwindSafe for Spline<T, V> where
    T: RefUnwindSafe,
    V: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<SS, SP> SupersetOf<SS> for SP where
    SS: SubsetOf<SP>, 

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]