Struct scribl_curves::Lerp [−][src]
Specifies interpolations between two sets of times.
This struct maintains two lists of "key-frame" times, which it uses for mapping times from one
scale to another. The two lists of key-frames must have the same length; the i
th key-frame
of one list is mapped to the i
th key-frame of the other list, and times that fall in between
key-frames are mapped using linear interpolation. There are various different ways that you can
handle times that lie outside the range of key-frames, as illustrated in the examples below.
Examples
let t = |x| Time::from_micros(x); // Create an "identity" lerp that just maps the interval [100, 200] to itself. let mut lerp = Lerp::identity(t(100), t(200)); // Now map time 150 to time 180. The interval [100, 150] will be stretched to cover // [100, 180], and the interval [150, 200] will be squished to [180, 200]. lerp.add_lerp(t(150), t(180)); // The midpoint between 100 and 150 will be mapped to the midpoint between 100 and 180. assert_eq!(lerp.lerp(t(125)), Some(t(140))); // The midpoint between 150 and 200 will be mapped to the midpoint between 180 and 200. assert_eq!(lerp.lerp(t(175)), Some(t(190))); // Adding a lerp is like taking the *composition* of the two mappings. So taking the previous // lerp and then sending 140 to 150 means that the original 125 will get sent to 150. lerp.add_lerp(t(140), t(150)); assert_eq!(lerp.lerp(t(125)), Some(t(150))); assert_eq!(lerp.lerp(t(120)), Some(t(140))); // When we map a time to something outside the current output range, something special happens: // all of the output times will get "squished" to the new time. Currently, the interval // [125, 200] is getting mapped to [150, 200]; after this line, that whole interval will get // mapped to 250. lerp.add_lerp(t(150), t(250)); assert_eq!(lerp.lerp(t(125)), Some(t(250))); assert_eq!(lerp.lerp(t(199)), Some(t(250))); // There are three different ways that elements outside the domain can be handled. // The `lerp` method returns `None` if asked to map something outside its domain. assert_eq!(lerp.lerp(t(201)), None); // The `lerp_clamped` method effectively rounds its input to the nearest end of the domain. assert_eq!(lerp.lerp_clamped(t(201)), t(250)); // The `lerp_extended` method extends the map past the original domain by linear interpolation. assert_eq!(lerp.lerp_extended(t(201)), t(251));
Implementations
impl Lerp
[src]
pub fn identity(start: Time, end: Time) -> Lerp
[src]
Creates a new Lerp
representing the identity mapping on the interval [start, end]
.
That is, start
will be mapped to start
, end
will be mapped to end
, and everything
in between will also be mapped to itself. Times outside the interval [start, end]
will be
treated differently depending on which of the lerping functions you call.
Examples
let t = |x| Time::from_micros(x); assert_eq!(Lerp::identity(t(0), t(10)).lerp(t(5)), Some(t(5))); assert_eq!(Lerp::identity(t(0), t(10)).lerp(t(10)), Some(t(10)));
pub fn first(&self) -> Time
[src]
The first time in the range of the mapping.
Examples
let t = |x| Time::from_micros(x); assert_eq!( Lerp::identity(t(10), t(20)) .with_new_lerp(t(10), t(9)) .first(), t(9) );
pub fn last(&self) -> Time
[src]
The last time in the range of the mapping.
Examples
let t = |x| Time::from_micros(x); assert_eq!( Lerp::identity(t(10), t(20)) .with_new_lerp(t(20), t(25)) .last(), t(25) );
pub fn times(&self) -> &[Time]
[src]
All of the key frames in the range of the mapping.
Examples
let t = |x| Time::from_micros(x); assert_eq!( Lerp::identity(t(10), t(20)) .with_new_lerp(t(15), t(18)) .times(), &[t(10), t(18), t(20)] );
pub fn shifted(&self, shift: TimeDiff) -> Lerp
[src]
Returns a clone of this Lerp
, with all times shifted by shift
.
pub fn lerp(&self, t: Time) -> Option<Time>
[src]
pub fn lerp_clamped(&self, t: Time) -> Time
[src]
pub fn lerp_extended(&self, t: Time) -> Time
[src]
pub fn unlerp(&self, t: Time) -> Option<Time>
[src]
pub fn unlerp_clamped(&self, t: Time) -> Time
[src]
pub fn unlerp_extended(&self, t: Time) -> Time
[src]
pub fn add_lerp(&mut self, time_from: Time, time_to: Time)
[src]
pub fn with_new_lerp(&self, time_from: Time, time_to: Time) -> Lerp
[src]
Trait Implementations
impl Clone for Lerp
[src]
impl Debug for Lerp
[src]
impl<'de> Deserialize<'de> for Lerp
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl From<Lerp> for Lerp
[src]
impl PartialEq<Lerp> for Lerp
[src]
impl Serialize for Lerp
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl StructuralPartialEq for Lerp
[src]
Auto Trait Implementations
impl RefUnwindSafe for Lerp
[src]
impl Send for Lerp
[src]
impl Sync for Lerp
[src]
impl Unpin for Lerp
[src]
impl UnwindSafe for Lerp
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyEq for T where
T: PartialEq<T> + Any,
T: PartialEq<T> + Any,
pub fn equals(&self, other: &(dyn Any + 'static)) -> bool
pub fn as_any(&self) -> &(dyn Any + 'static)
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut 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.
pub 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>,