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 gooey::animation::{BinaryLerp, ImmediateLerp, LinearInterpolate};
use gooey::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.

Implementations on Foreign Types§

source§

impl LinearInterpolate for u64

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 u32

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 bool

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 isize

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 Color

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 i8

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 Angle

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 UPx

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 i16

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 f32

source§

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

Implementors§