Struct lab::LCh[][src]

pub struct LCh {
    pub l: f32,
    pub c: f32,
    pub h: f32,
}

Struct representing a color in cylindrical CIELCh color space

Fields

l: f32c: f32h: f32

Implementations

impl LCh[src]

pub fn from_rgb(rgb: &[u8; 3]) -> Self[src]

Constructs a new LCh from a three-element array of u8s

Examples

let lch = lab::LCh::from_rgb(&[240, 33, 95]);
assert_eq!(lab::LCh { l: 52.334686, c: 78.15284, h: 0.25873056 }, lch);

pub fn from_rgba(rgba: &[u8; 4]) -> Self[src]

Constructs a new LCh from a four-element array of u8s

The LCh struct does not store alpha channel information, so the last u8 representing alpha is discarded. This convenience method exists in order to easily measure colors already stored in an RGBA array.

Examples

let lch = lab::LCh::from_rgba(&[240, 33, 95, 255]);
assert_eq!(lab::LCh { l: 52.334686, c: 78.15284, h: 0.25873056 }, lch);

pub fn from_lab(lab: Lab) -> Self[src]

Constructs a new LCh from a Lab

Examples

let lab = lab::Lab { l: 52.33686, a: 75.5516, b: 19.998878 };
let lch = lab::LCh::from_lab(lab);
assert_eq!(lab::LCh { l: 52.33686, c: 78.15369, h: 0.25877 }, lch);

let lab = lab::Lab { l: 52.33686, a: 0.0, b: 0.0 };
let lch = lab::LCh::from_lab(lab);
assert_eq!(lab::LCh { l: 52.33686, c: 0.0, h: 0.0 }, lch);

pub fn to_rgb(&self) -> [u8; 3][src]

Returns the LCh’s color in RGB, in a 3-element array

Examples

let mut lch = lab::LCh { l: 52.33686, c: 78.15369, h: 0.25877 };
assert_eq!([240, 33, 95], lch.to_rgb());

lch.h += std::f32::consts::TAU;
assert_eq!([240, 33, 95], lch.to_rgb());

pub fn to_lab(&self) -> Lab[src]

Returns the LCh’s color in Lab

Note that due to imprecision of floating point arithmetic, conversions between Lab and LCh are not stable. A chain of Lab→LCh→Lab or LCh→Lab→LCh operations isn’t guaranteed to give back the source colour.

Examples

let lch = lab::LCh { l: 52.33686, c: 78.15369, h: 0.25877 };
let lab = lch.to_lab();
assert_eq!(lab::Lab { l: 52.33686, a: 75.5516, b: 19.998878 }, lab);

let lch = lab::LCh { l: 52.33686, c: 0.0, h: 0.25877 };
let lab = lch.to_lab();
assert_eq!(lab::Lab { l: 52.33686, a: 0.0, b: 0.0 }, lab);

let inp = lab::Lab { l: 29.52658, a: 58.595745, b: -36.281406 };
let lch = lab::LCh { l: 29.52658, c: 68.91881,  h: -0.5544043 };
let out = lab::Lab { l: 29.52658, a: 58.59575,  b: -36.281406 };
assert_eq!(lch, lab::LCh::from_lab(inp));
assert_eq!(out, lch.to_lab());

Trait Implementations

impl Clone for LCh[src]

impl Copy for LCh[src]

impl Debug for LCh[src]

impl Default for LCh[src]

impl PartialEq<LCh> for LCh[src]

impl StructuralPartialEq for LCh[src]

Auto Trait Implementations

impl RefUnwindSafe for LCh

impl Send for LCh

impl Sync for LCh

impl Unpin for LCh

impl UnwindSafe for LCh

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.