pub struct Spline<T, V>(/* private fields */);
Expand description
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.
Implementations§
Source§impl<T, V> Spline<T, V>
impl<T, V> Spline<T, V>
Sourcepub fn from_vec(keys: Vec<Key<T, V>>) -> Selfwhere
T: PartialOrd,
pub fn from_vec(keys: Vec<Key<T, V>>) -> Selfwhere
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).
Sourcepub fn from_iter<I>(iter: I) -> Self
pub fn from_iter<I>(iter: I) -> Self
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
.
Sourcepub 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>,
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>,
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.
Sourcepub fn sample(&self, t: T) -> Option<V>where
T: Additive + One + Trigo + Mul<T, Output = T> + Div<T, Output = T> + PartialOrd,
V: Interpolate<T>,
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>,
Sample a spline at a given time.
Sourcepub 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>,
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>,
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.
Sourcepub 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>,
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>,
Sample a spline at a given time with clamping.
Sourcepub fn add(&mut self, key: Key<T, V>)where
T: PartialOrd,
pub fn add(&mut self, key: Key<T, V>)where
T: PartialOrd,
Add a key into the spline.
Sourcepub fn replace<F>(&mut self, index: usize, f: F) -> Option<Key<T, V>>
pub fn replace<F>(&mut self, index: usize, f: F) -> Option<Key<T, V>>
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.
Trait Implementations§
Source§impl<'a, T, V> IntoIterator for &'a Spline<T, V>
impl<'a, T, V> IntoIterator for &'a Spline<T, V>
Auto Trait Implementations§
impl<T, V> Freeze for Spline<T, V>
impl<T, V> RefUnwindSafe for Spline<T, V>where
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<T, V> Send for Spline<T, V>
impl<T, V> Sync for Spline<T, V>
impl<T, V> Unpin for Spline<T, V>
impl<T, V> UnwindSafe for Spline<T, V>where
T: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)