[−][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
.
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(&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.
pub fn add(&mut self, key: Key<T, V>) where
T: PartialOrd,
[src]
T: PartialOrd,
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]
F: FnOnce(&Key<T, V>) -> Key<T, V>,
T: PartialOrd,
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<T: Clone, V: Clone> Clone for Spline<T, V>
[src]
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]
impl<T, V> Serialize for Spline<T, V> where
T: Serialize,
V: Serialize,
[src]
T: Serialize,
V: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, T, V> Deserialize<'de> for Spline<T, V> where
T: Deserialize<'de>,
V: Deserialize<'de>,
[src]
T: Deserialize<'de>,
V: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<T, V> Send for Spline<T, V> where
T: Send,
V: Send,
T: Send,
V: Send,
impl<T, V> Unpin for Spline<T, V> where
T: Unpin,
V: Unpin,
T: Unpin,
V: Unpin,
impl<T, V> Sync for Spline<T, V> where
T: Sync,
V: Sync,
T: Sync,
V: Sync,
impl<T, V> UnwindSafe for Spline<T, V> where
T: UnwindSafe,
V: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
impl<T, V> RefUnwindSafe for Spline<T, V> where
T: RefUnwindSafe,
V: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
Blanket Implementations
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, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> 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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
[src]
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
[src]
fn is_in_subset(&self) -> bool
[src]
unsafe fn to_subset_unchecked(&self) -> SS
[src]
fn from_subset(element: &SS) -> SP
[src]
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,