cushy::animation

Trait LinearInterpolate

Source
pub trait LinearInterpolate: PartialEq {
    // Required method
    fn lerp(&self, target: &Self, percent: f32) -> Self;
}
Expand description

Performs a linear interpolation between two values.

This trait can be derived for structs and fieldless enums.

Note: for fields that don’t implement LinerarInterpolate the wrappers BinaryLerp and ImmediateLerp can be used.

use cushy::animation::{BinaryLerp, ImmediateLerp, LinearInterpolate};
use cushy::kludgine::Color;

#[derive(LinearInterpolate, PartialEq, Debug)]
struct Struct(Color, BinaryLerp<&'static str>, ImmediateLerp<&'static str>);

let from = Struct(Color::BLACK, "hello".into(), "hello".into());
let to = Struct(Color::WHITE, "world".into(), "world".into());

assert_eq!(
    from.lerp(&to, 0.41),
    Struct(Color::DIMGRAY, "hello".into(), "world".into())
);
assert_eq!(
    from.lerp(&to, 0.663),
    Struct(Color::DARKGRAY, "world".into(), "world".into())
);

#[derive(LinearInterpolate, PartialEq, Debug)]
enum Enum {
    A,
    B,
    C,
}
assert_eq!(Enum::A.lerp(&Enum::B, 0.4), Enum::A);
assert_eq!(Enum::A.lerp(&Enum::C, 0.1), Enum::A);
assert_eq!(Enum::A.lerp(&Enum::C, 0.4), Enum::B);
assert_eq!(Enum::A.lerp(&Enum::C, 0.9), Enum::C);

Required Methods§

Source

fn lerp(&self, target: &Self, percent: f32) -> Self

Interpolate linearly between self and target using percent.

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 LinearInterpolate for bool

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for f32

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for f64

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for i8

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for i16

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for i32

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for i64

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for i128

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for isize

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for u8

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for u16

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for u32

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for u64

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for u128

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for usize

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for Duration

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for Angle

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for Fraction

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for Lp

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for Px

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl LinearInterpolate for UPx

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl<Unit> LinearInterpolate for Point<Unit>
where Unit: LinearInterpolate,

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl<Unit> LinearInterpolate for Rect<Unit>
where Unit: LinearInterpolate,

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Source§

impl<Unit> LinearInterpolate for Size<Unit>
where Unit: LinearInterpolate,

Source§

fn lerp(&self, target: &Self, percent: f32) -> Self

Implementors§