[−][src]Struct splines::spline::Spline
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 getNone
.Spline::clamped_sample
: behaves likeSpline::sample
but will return either the first or last key if out of bound; it will returnNone
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]
T: PartialOrd,
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]
I: Iterator<Item = Key<T, V>>,
T: PartialOrd,
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
. This will remove dynamic allocations.
pub fn keys(&self) -> &[Key<T, V>]
[src]
Retrieve the keys of a spline.
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]
T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
V: Interpolate<T>,
Sample a spline at a given time.
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 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]
T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
V: Interpolate<T>,
Sample a spline at a given time with clamping.
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.
Trait Implementations
impl<T: Clone, V: Clone> Clone for Spline<T, V>
[src]
fn clone(&self) -> Spline<T, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T: Debug, V: Debug> Debug for Spline<T, V>
[src]
Auto Trait Implementations
impl<T, V> Send for Spline<T, V> where
T: Send,
V: Send,
T: Send,
V: Send,
impl<T, V> Sync for Spline<T, V> where
T: Sync,
V: Sync,
T: Sync,
V: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,