pub trait Vary:
Lerp
+ ZDiv
+ Sized
+ Clone {
type Iter: Iterator<Item = Self>;
type Diff: Clone;
// Required methods
fn vary(self, step: Self::Diff, max: Option<u32>) -> Self::Iter;
fn dv_dt(&self, other: &Self, recip_dt: f32) -> Self::Diff;
fn step(&self, delta: &Self::Diff) -> Self;
// Provided method
fn vary_to(self, other: Self, n: u32) -> Self::Iter { ... }
}Expand description
A trait for types that can be linearly interpolated and distributed between two endpoints.
This trait is designed particularly for varyings: types that are meant to be interpolated across the face of a polygon when rendering, but the methods are useful for various purposes.
Required Associated Types§
Required Methods§
Sourcefn vary(self, step: Self::Diff, max: Option<u32>) -> Self::Iter
fn vary(self, step: Self::Diff, max: Option<u32>) -> Self::Iter
Returns an iterator that yields values such that the first value
equals self, and each subsequent value is offset by step from its
predecessor using the step method. If max is Some(n),
stops after n steps, otherwise infinite.
§Examples
use retrofire_core::math::Vary;
let mut iter = 0.0f32.vary(0.2, Some(5));
assert_eq!(iter.next(), Some(0.0));
assert_eq!(iter.next(), Some(0.2));
assert_eq!(iter.next(), Some(0.4));
assert_eq!(iter.next(), Some(0.6));
assert_eq!(iter.next(), Some(0.8));
assert_eq!(iter.next(), None);Provided Methods§
Sourcefn vary_to(self, other: Self, n: u32) -> Self::Iter
fn vary_to(self, other: Self, n: u32) -> Self::Iter
Linearly distributes n values between self and other inclusive.
The first and last items emitted are self and other respectively.
If n = 1, the only item emitted is self. If n = 0, emits nothing.
§Examples
use retrofire_core::math::Vary;
let mut v = 2.0.vary_to(8.0, 3);
assert_eq!(v.next(), Some(2.0));
assert_eq!(v.next(), Some(5.0));
assert_eq!(v.next(), Some(8.0));
assert_eq!(v.next(), None);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.