Struct lab::LCh[][src]

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

Struct representing a color in cylindrical CIELCh color space

Fields

l: f32c: f32h: f32

Implementations

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);

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);

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);

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());

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.