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: ColorComponent>(self) -> U { ... }
    fn lerp(start: Self, end: Self, t: f32) -> Self { ... }
}
Expand description

A trait representing a color component in a color.

Required Associated Constants§

source

const ZERO: Self

Min value (black)

source

const HALF: Self

Half value (gray)

source

const MAX: Self

Max value (white)

Required Methods§

source

fn as_f32(self) -> f32

Convert into an f32

source

fn from_f32(value: f32) -> Self

Convert from an f32

Provided Methods§

source

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

Convert from one type to another

source

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§

source§

impl ColorComponent for f32

source§

const ZERO: Self = 0f32

source§

const HALF: Self = 0.5f32

source§

const MAX: Self = 1f32

source§

fn as_f32(self) -> f32

source§

fn from_f32(x: f32) -> Self

source§

impl ColorComponent for f64

source§

const ZERO: Self = 0f64

source§

const HALF: Self = 0.5f64

source§

const MAX: Self = 1f64

source§

fn as_f32(self) -> f32

source§

fn from_f32(x: f32) -> Self

source§

impl ColorComponent for u8

source§

const ZERO: Self = 0u8

source§

const HALF: Self = 127u8

source§

const MAX: Self = 255u8

source§

fn as_f32(self) -> f32

source§

fn from_f32(x: f32) -> Self

Implementors§