Vary

Trait Vary 

Source
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§

Source

type Iter: Iterator<Item = Self>

The iterator returned by the vary method.

Source

type Diff: Clone

The difference type of Self.

Required Methods§

Source

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);
Source

fn dv_dt(&self, other: &Self, recip_dt: f32) -> Self::Diff

Returns, conceptually, (other - self) / dt.

Source

fn step(&self, delta: &Self::Diff) -> Self

Returns the result of offsetting self by delta, conceptually self + delta.

Provided Methods§

Source

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.

Implementations on Foreign Types§

Source§

impl Vary for ()

Source§

type Iter = Iter<()>

Source§

type Diff = ()

Source§

fn vary(self, _: Self::Diff, n: Option<u32>) -> Self::Iter

Source§

fn dv_dt(&self, _: &Self, _: f32)

Source§

fn step(&self, _: &Self::Diff)

Source§

impl<T: Vary, U: Vary> Vary for (T, U)

Source§

type Iter = Iter<(T, U)>

Source§

type Diff = (<T as Vary>::Diff, <U as Vary>::Diff)

Source§

fn vary(self, step: Self::Diff, n: Option<u32>) -> Self::Iter

Source§

fn dv_dt(&self, other: &Self, recip_dt: f32) -> Self::Diff

Source§

fn step(&self, (d0, d1): &Self::Diff) -> Self

Implementors§

Source§

impl<V: Clone> Vary for V
where Self: Affine<Diff: Linear<Scalar = f32> + Clone> + ZDiv,

Source§

type Iter = Iter<V>

Source§

type Diff = <V as Affine>::Diff