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: f32
§c: f32
§h: f32
Implementations§
Source§impl LCh
impl LCh
Sourcepub fn from_rgb(rgb: &[u8; 3]) -> Self
pub fn from_rgb(rgb: &[u8; 3]) -> Self
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);
Sourcepub fn from_rgba(rgba: &[u8; 4]) -> Self
pub fn from_rgba(rgba: &[u8; 4]) -> Self
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);
Sourcepub fn from_lab(lab: Lab) -> Self
pub fn from_lab(lab: Lab) -> Self
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);
Sourcepub fn to_rgb(&self) -> [u8; 3]
pub fn to_rgb(&self) -> [u8; 3]
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());
Sourcepub fn to_lab(&self) -> Lab
pub fn to_lab(&self) -> Lab
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 Copy for LCh
impl StructuralPartialEq for LCh
Auto Trait Implementations§
impl Freeze for LCh
impl RefUnwindSafe for LCh
impl Send for LCh
impl Sync for LCh
impl Unpin for LCh
impl UnwindSafe for LCh
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more