Skip to main content

HSV

Struct HSV 

Source
pub struct HSV {
    pub h: f32,
    pub s: f32,
    pub v: f32,
}
Expand description

HSV color.

FieldRangeDescription
h0..360Hue angle (wraps at 360)
s0..1Saturation
v0..1Value (brightness)

§Why no arithmetic?

HSV does not implement ChannelArray, [Add], [Sub], [Mul], or lerp. Hue is an angle on a circle — componentwise interpolation between 350° and 10° would pass through 180° instead of the short arc through 0°. This produces incorrect visual results.

To manipulate HSV colors, convert to RGBA, do your math there, then convert back:

use optic_color::*;

let hsv = HSV::new(350.0, 0.8, 0.9);
let mut rgba: RGBA = hsv.into();
rgba = rgba.lighten(0.1);

For hue-aware interpolation between two colors, use Gradient with [GradientColorSpace::Hsv].

Fields§

§h: f32§s: f32§v: f32

Implementations§

Source§

impl HSV

Source

pub fn new(h: f32, s: f32, v: f32) -> Self

Construct an HSV color with clamping.

Hue is clamped to 0..360, saturation and value to 0..1.

Source

pub fn to_rgba_alpha(self, alpha: f32) -> RGBA

Convert to RGBA with a custom alpha, without going through ToRgba.

Equivalent to self.to_rgba().with_alpha(alpha).

Trait Implementations§

Source§

impl Clone for HSV

Source§

fn clone(&self) -> HSV

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for HSV

Source§

impl Debug for HSV

Source§

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

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

impl From<HSV> for RGBA

Source§

fn from(hsv: HSV) -> Self

Converts to this type from the input type.
Source§

impl From<RGBA> for HSV

Source§

fn from(rgba: RGBA) -> Self

Converts to this type from the input type.
Source§

impl FromRgba for HSV

Source§

fn from_rgba(rgba: RGBA) -> Self

Source§

impl ToRgba for HSV

Source§

fn to_rgba(self) -> RGBA

Convert to RGBA.

Auto Trait Implementations§

§

impl Freeze for HSV

§

impl RefUnwindSafe for HSV

§

impl Send for HSV

§

impl Sync for HSV

§

impl Unpin for HSV

§

impl UnsafeUnpin for HSV

§

impl UnwindSafe for HSV

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> ColorInfo for T
where T: ToRgba,

Source§

fn luminance(self) -> f32

Relative luminance per ITU-R BT.709. Read more
Source§

fn is_light(self) -> bool

Returns true if the luminance is greater than 0.5.
Source§

fn contrast_ratio(self, other: impl ToRgba) -> f32

Compute the WCAG contrast ratio against another color. Read more
Source§

fn to_hex(self) -> String

Encode as a hex string: #RRGGBBAA.
Source§

fn to_bytes(self) -> (u8, u8, u8, u8)

Convert to 8-bit byte channels: (r, g, b, a) in 0..255.
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.