pub trait ColorComponent: Copy {
    const ZERO: Self;
    const HALF: Self;
    const MAX: Self;

    // Required methods
    fn as_f32(self) -> f32;
    fn from_f32(value: f32) -> Self;

    // Provided methods
    fn convert<U>(self) -> U
       where U: ColorComponent { ... }
    fn lerp(start: Self, end: Self, t: f32) -> Self { ... }
}
Expand description

A trait representing a color component in a color.

Required Associated Constants§

const ZERO: Self

Min value (black)

const HALF: Self

Half value (gray)

const MAX: Self

Max value (white)

Required Methods§

fn as_f32(self) -> f32

Convert into an f32

fn from_f32(value: f32) -> Self

Convert from an f32

Provided Methods§

fn convert<U>(self) -> U
where U: ColorComponent,

Convert from one type to another

fn lerp(start: Self, end: Self, t: f32) -> Self

Linearly interpolate between start and end values.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl ColorComponent for f32

§

const ZERO: f32 = 0f32

§

const HALF: f32 = 0.5f32

§

const MAX: f32 = 1f32

§

fn as_f32(self) -> f32

§

fn from_f32(x: f32) -> f32

§

impl ColorComponent for f64

§

const ZERO: f64 = 0f64

§

const HALF: f64 = 0.5f64

§

const MAX: f64 = 1f64

§

fn as_f32(self) -> f32

§

fn from_f32(x: f32) -> f64

§

impl ColorComponent for u8

§

const ZERO: u8 = 0u8

§

const HALF: u8 = 127u8

§

const MAX: u8 = 255u8

§

fn as_f32(self) -> f32

§

fn from_f32(x: f32) -> u8

Implementors§