Struct lab::LCh [−][src]
Expand description
Struct representing a color in cylindrical CIELCh color space
Fields
l: f32
c: f32
h: f32
Implementations
Constructs a new LCh
from a three-element array of u8
s
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 u8
s
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
Auto Trait Implementations
impl RefUnwindSafe for LCh
impl UnwindSafe for LCh
Blanket Implementations
Mutably borrows from an owned value. Read more