Struct Hsl

Source
#[repr(C)]
pub struct Hsl<T, A = Deg<T>> { /* private fields */ }
Expand description

The HSL device-dependent polar color model

hsl-diagram

HSL is defined by a hue (base color), saturation (color richness) and value (whiteness). Like HSV, HSL is modeled as a cylinder, however the underlying space is two cones stacked bottom-to-bottom. /// This causes some level of distortion and a degeneracy at S=0 or L={0,1}. Thus, while easy to reason about, it is not good for perceptual uniformity. It does an okay job with averaging colors or doing other math, but prefer the CIE spaces for uniform gradients.

Hsl takes two type parameters: the cartesian channel scalar, and an angular channel scalar.

Hsl is in the same color space and encoding as the parent RGB space, it is merely a geometric transformation and distortion.

For an undistorted device-dependent polar color model, look at Hsi.

Implementations§

Source§

impl<T, A> Hsl<T, A>

Source

pub fn new(hue: A, saturation: T, lightness: T) -> Self

Construct an Hsl instance from hue, saturation and lightness

Source

pub fn color_cast<TOut, AOut>(&self) -> Hsl<TOut, AOut>

Convert the internal channel scalar format

Source

pub fn hue(&self) -> A

Returns the hue scalar

Source

pub fn saturation(&self) -> T

Returns the saturation scalar

Source

pub fn lightness(&self) -> T

Returns the lightness scalar

Source

pub fn hue_mut(&mut self) -> &mut A

Returns a mutable reference to the hue scalar

Source

pub fn saturation_mut(&mut self) -> &mut T

Returns a mutable reference to the saturation scalar

Source

pub fn lightness_mut(&mut self) -> &mut T

Returns a mutable reference to the lightness scalar

Source

pub fn set_hue(&mut self, val: A)

Set the hue channel value

Source

pub fn set_saturation(&mut self, val: T)

Set the saturation channel value

Source

pub fn set_lightness(&mut self, val: T)

Set the lightness channel value

Trait Implementations§

Source§

impl<T, A> AbsDiffEq for Hsl<T, A>

Source§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of ApproxEq::abs_diff_eq.
Source§

impl<T, A> Bounded for Hsl<T, A>

Source§

fn normalize(self) -> Self

Return a value clipped inside the normalized range
Source§

fn is_normalized(&self) -> bool

Return true if the value is normalized
Source§

impl<T: Clone, A: Clone> Clone for Hsl<T, A>

Source§

fn clone(&self) -> Hsl<T, A>

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<T, A> Color for Hsl<T, A>

Source§

type Tag = HslTag

The unique tag unit struct identifying the color type
Source§

type ChannelsTuple = (A, T, T)

A tuple of types for each channel in the color
Source§

fn num_channels() -> u32

Return how many channels the color has
Source§

fn to_tuple(self) -> Self::ChannelsTuple

Convert a color into a tuple of channels
Source§

impl<T: Debug, A: Debug> Debug for Hsl<T, A>

Source§

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

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

impl<T, A> Default for Hsl<T, A>

Source§

fn default() -> Self

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

impl<T, A> Display for Hsl<T, A>

Source§

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

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

impl<T, A> EncodableColor for Hsl<T, A>

Source§

fn encoded_as<E>(self, encoding: E) -> EncodedColor<Self, E>
where E: ColorEncoding,

Specify what encoding the color has. This does not actually encode anything Read more
Source§

fn linear(self) -> EncodedColor<Self, LinearEncoding>

Specify that the color is linear
Source§

fn srgb_encoded(self) -> EncodedColor<Self, SrgbEncoding>

Specify that the color is sRGB encoded Read more
Source§

fn gamma_encoded<T: Float>( self, gamma: T, ) -> EncodedColor<Self, GammaEncoding<T>>

Specify that the color is gamma encoded with a given gamma
Source§

impl<T, A> From<Hsl<T, A>> for Rgb<T>

Source§

fn from(from: Hsl<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for Hsl<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> FromColor<Hsl<T, A>> for Rgb<T>

Source§

fn from_color(from: &Hsl<T, A>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for Hsl<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T, A> FromTuple for Hsl<T, A>

Source§

fn from_tuple(values: Self::ChannelsTuple) -> Self

Construct Self from a tuple of channel values
Source§

impl<T: Hash, A: Hash> Hash for Hsl<T, A>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, A> Invert for Hsl<T, A>

Source§

fn invert(self) -> Self

Invert Self
Source§

impl<T, A> Lerp for Hsl<T, A>

Source§

type Position = <A as Lerp>::Position

The type of the pos argument
Source§

fn lerp(&self, right: &Self, pos: Self::Position) -> Self

Interpolate between self and right Read more
Source§

impl<T: PartialEq, A: PartialEq> PartialEq for Hsl<T, A>

Source§

fn eq(&self, other: &Hsl<T, A>) -> 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<T: PartialOrd, A: PartialOrd> PartialOrd for Hsl<T, A>

Source§

fn partial_cmp(&self, other: &Hsl<T, A>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T, A> PolarColor for Hsl<T, A>

Source§

type Angular = A

The angular channel’s scalar type
Source§

type Cartesian = T

The remaining channels’ scalar types
Source§

impl<T, A> RelativeEq for Hsl<T, A>

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of ApproxEq::relative_eq.
Source§

impl<T, A> UlpsEq for Hsl<T, A>

Source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
Source§

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
Source§

fn ulps_ne(&self, other: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of ApproxEq::ulps_eq.
Source§

impl<T: Copy, A: Copy> Copy for Hsl<T, A>

Source§

impl<T, A> StructuralPartialEq for Hsl<T, A>

Auto Trait Implementations§

§

impl<T, A> Freeze for Hsl<T, A>
where A: Freeze, T: Freeze,

§

impl<T, A> RefUnwindSafe for Hsl<T, A>

§

impl<T, A> Send for Hsl<T, A>
where A: Send, T: Send,

§

impl<T, A> Sync for Hsl<T, A>
where A: Sync, T: Sync,

§

impl<T, A> Unpin for Hsl<T, A>
where A: Unpin, T: Unpin,

§

impl<T, A> UnwindSafe for Hsl<T, A>
where A: UnwindSafe, T: UnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.