Trait ColorComponent

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

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>(self) -> U
where U: ColorComponent,

Convert from one type to another

Source

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

Linearly interpolate between start and end values.

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 ColorComponent for f32

Source§

const ZERO: f32 = 0f32

Source§

const HALF: f32 = 0.5f32

Source§

const MAX: f32 = 1f32

Source§

fn as_f32(self) -> f32

Source§

fn from_f32(x: f32) -> f32

Source§

impl ColorComponent for f64

Source§

const ZERO: f64 = 0f64

Source§

const HALF: f64 = 0.5f64

Source§

const MAX: f64 = 1f64

Source§

fn as_f32(self) -> f32

Source§

fn from_f32(x: f32) -> f64

Source§

impl ColorComponent for u8

Source§

const ZERO: u8 = 0u8

Source§

const HALF: u8 = 127u8

Source§

const MAX: u8 = 255u8

Source§

fn as_f32(self) -> f32

Source§

fn from_f32(x: f32) -> u8

Implementors§