Struct LCh

Source
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

Source

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

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

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

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

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

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

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§

Source§

impl Clone for LCh

Source§

fn clone(&self) -> LCh

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LCh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LCh

Source§

fn default() -> LCh

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

impl PartialEq for LCh

Source§

fn eq(&self, other: &LCh) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for LCh

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.