| 1 | //! Types for the Okhsl color space. |
| 2 | |
| 3 | pub use alpharust-analyzer cargo palette 0.7.6 okhsl/alpha/::Okhslarust-analyzer cargo palette 0.7.6 okhsl/alpha/Okhsla#; |
| 4 | |
| 5 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 6 | anglerust-analyzer cargo palette 0.7.6 angle/::FromAnglerust-analyzer cargo palette 0.7.6 angle/FromAngle#, |
| 7 | convertrust-analyzer cargo palette 0.7.6 convert/::{FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#, IntoColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#}, |
| 8 | numrust-analyzer cargo palette 0.7.6 num/::{Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#, Cbrtrust-analyzer cargo palette 0.7.6 num/Cbrt#, Hypotrust-analyzer cargo palette 0.7.6 num/Hypot#, IsValidDivisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#, MinMaxrust-analyzer cargo palette 0.7.6 num/MinMax#, Onerust-analyzer cargo palette 0.7.6 num/One#, Powirust-analyzer cargo palette 0.7.6 num/Powi#, Realrust-analyzer cargo palette 0.7.6 num/Real#, Sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#, Zerorust-analyzer cargo palette 0.7.6 num/Zero#}, |
| 9 | ok_utilsrust-analyzer cargo palette 0.7.6 ok_utils/::{toerust-analyzer cargo palette 0.7.6 ok_utils/toe()., ChromaValuesrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#}, |
| 10 | stimulusrust-analyzer cargo palette 0.7.6 stimulus/::{FromStimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#, Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#}, |
| 11 | white_pointrust-analyzer cargo palette 0.7.6 white_point/::D65rust-analyzer cargo palette 0.7.6 white_point/D65#, |
| 12 | GetHuerust-analyzer cargo palette 0.7.6 GetHue#, HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#, LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#, Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#, OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#, |
| 13 | }; |
| 14 | |
| 15 | pub use selfrust-analyzer cargo palette 0.7.6 okhsl/::propertiesrust-analyzer cargo palette 0.7.6 okhsl/properties/::Iterrust-analyzer cargo palette 0.7.6 okhsl/properties/Iter#; |
| 16 | |
| 17 | #[cfg(feature = "random")] |
| 18 | pub use selfrust-analyzer cargo palette 0.7.6 okhsl/::randomrust-analyzer cargo palette 0.7.6 okhsl/random/::UniformOkhslrust-analyzer cargo palette 0.7.6 okhsl/random/UniformOkhsl#; |
| 19 | |
| 20 | mod alpharust-analyzer cargo palette 0.7.6 okhsl/alpha/; |
| 21 | mod propertiesrust-analyzer cargo palette 0.7.6 okhsl/properties/; |
| 22 | #[cfg(feature = "random")] |
| 23 | mod randomrust-analyzer cargo palette 0.7.6 okhsl/random/; |
| 24 | #[cfg(test)] |
| 25 | #[cfg(feature = "approx")] |
| 26 | mod visual_eqrust-analyzer cargo palette 0.7.6 okhsl/visual_eq/; |
| 27 | |
| 28 | /// A Hue/Saturation/Lightness representation of [`Oklab`] in the `sRGB` color space. |
| 29 | /// |
| 30 | /// Allows |
| 31 | /// * changing hue/chroma/saturation, while keeping perceived lightness constant (like HSLuv) |
| 32 | /// * changing lightness/chroma/saturation, while keeping perceived hue constant |
| 33 | /// * changing the perceived saturation (more or less) proportionally with the numerical |
| 34 | /// amount of change (unlike HSLuv) |
| 35 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, ArrayCastrust-analyzer cargo palette_derive 0.7.6 ArrayCast:, FromColorUnclampedrust-analyzer cargo palette_derive 0.7.6 FromColorUnclamped:, WithAlpharust-analyzer cargo palette_derive 0.7.6 WithAlpha:)] |
| 36 | #[cfg_attr(feature = "serializing", derive(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:))] |
| 37 | #[palette( |
| 38 | palette_internal, |
| 39 | white_point = "D65", |
| 40 | component = "T", |
| 41 | skip_derives(Oklab) |
| 42 | )] |
| 43 | #[repr(C)] |
| 44 | pub struct Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T = f32> { |
| 45 | /// The hue of the color, in degrees of a circle. |
| 46 | /// |
| 47 | /// For fully saturated, bright colors |
| 48 | /// * 0° corresponds to a kind of magenta-pink (RBG #ff0188), |
| 49 | /// * 90° to a kind of yellow (RBG RGB #ffcb00) |
| 50 | /// * 180° to a kind of cyan (RBG #00ffe1) and |
| 51 | /// * 240° to a kind of blue (RBG #00aefe). |
| 52 | /// |
| 53 | /// For s == 0 or v == 0, the hue is irrelevant. |
| 54 | #[paletterust-analyzer cargo palette_derive 0.7.6 palette:(unsafe_same_layout_as = "T")] |
| 55 | pub huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue.: OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>, |
| 56 | |
| 57 | /// The saturation (freedom of black or white) of the color. |
| 58 | /// |
| 59 | /// * `0.0` corresponds to pure mixture of black and white without any color. |
| 60 | /// The black to white relation depends on v. |
| 61 | /// * `1.0` to a fully saturated color without any white. |
| 62 | /// |
| 63 | /// For v == 0 the saturation is irrelevant. |
| 64 | pub saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation.: T, |
| 65 | |
| 66 | /// The relative luminance of the color, where |
| 67 | /// * `0.0` corresponds to pure black |
| 68 | /// * `1.0` corresponds to white |
| 69 | /// |
| 70 | /// This luminance is visually similar to [Cielab](crate::Lab)'s luminance for a |
| 71 | /// `D65` reference white point. |
| 72 | /// |
| 73 | /// `Okhsv`'s `value` component goes from black to non-black |
| 74 | /// -- a maximally bright color in the `sRGB` gamut. |
| 75 | /// |
| 76 | /// `Okhsl`'s `lightness` component goes from black to white in the `sRGB` color space. |
| 77 | pub lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.: T, |
| 78 | } |
| 79 | |
| 80 | impl<T> Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> { |
| 81 | /// Create an Okhsl color. |
| 82 | pub fn newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().<H: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>>>(hue: H, saturation: T, lightness: T) -> Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] { |
| 83 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] { |
| 84 | huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue.: hue.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 85 | saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., |
| 86 | lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness., |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /// Create an `Okhsl` color. This is the same as `Okhsl::new` without the |
| 91 | /// generic hue type. It's temporary until `const fn` supports traits. |
| 92 | pub const fn new_construst-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new_const().(hue: OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>, saturation: T, lightness: T) -> Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] { |
| 93 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] { |
| 94 | huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue., |
| 95 | saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., |
| 96 | lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness., |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /// Convert into another component type. |
| 101 | pub fn into_formatrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]into_format().<U>(self) -> Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<U> |
| 102 | where |
| 103 | U: FromStimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#<T> + FromAnglerust-analyzer cargo palette 0.7.6 angle/FromAngle#<T>, |
| 104 | { |
| 105 | Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl# { |
| 106 | huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue.: self.huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue..into_formatrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_format().(), |
| 107 | saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation.: U::from_stimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#from_stimulus().(self.saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation.), |
| 108 | lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.: U::from_stimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#from_stimulus().(self.lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.), |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | /// Convert from another component type. |
| 113 | pub fn from_formatrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]from_format().<U>(color: Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<U>) -> Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] |
| 114 | where |
| 115 | T: FromStimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#<U> + FromAnglerust-analyzer cargo palette 0.7.6 angle/FromAngle#<U>, |
| 116 | { |
| 117 | color.into_formatrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]into_format().() |
| 118 | } |
| 119 | |
| 120 | /// Convert to a `(h, s, l)` tuple. |
| 121 | pub fn into_componentsrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]into_components().(self) -> (OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>, T, T) { |
| 122 | (self.huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue., self.saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., self.lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.) |
| 123 | } |
| 124 | |
| 125 | /// Convert from a `(h, s, l)` tuple. |
| 126 | pub fn from_componentsrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]from_components().<H: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>>>((hue, saturation, lightness): (H, T, T)) -> Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`] { |
| 127 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(hue, saturation, lightness) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | impl<T> Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> |
| 132 | where |
| 133 | T: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 134 | { |
| 135 | /// Return the `saturation` value minimum. |
| 136 | pub fn min_saturationrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]min_saturation().() -> T { |
| 137 | T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().() |
| 138 | } |
| 139 | |
| 140 | /// Return the `saturation` value maximum. |
| 141 | pub fn max_saturationrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]max_saturation().() -> T { |
| 142 | T::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().() |
| 143 | } |
| 144 | |
| 145 | /// Return the `lightness` value minimum. |
| 146 | pub fn min_lightnessrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]min_lightness().() -> T { |
| 147 | T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().() |
| 148 | } |
| 149 | |
| 150 | /// Return the `lightness` value maximum. |
| 151 | pub fn max_lightnessrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]max_lightness().() -> T { |
| 152 | T::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().() |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | impl_reference_component_methods_huerust-analyzer cargo palette 0.7.6 macros/reference_component/impl_reference_component_methods_hue!!(Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#, [saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.]); |
| 157 | impl_struct_of_arrays_methods_huerust-analyzer cargo palette 0.7.6 macros/struct_of_arrays/impl_struct_of_arrays_methods_hue!!(Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#, [saturation, lightness]); |
| 158 | |
| 159 | /// # See |
| 160 | /// See [`srgb_to_okhsl`](https://bottosson.github.io/posts/colorpicker/#hsl-2) |
| 161 | impl<T> FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#<Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#<T>> for Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> |
| 162 | where |
| 163 | T: Realrust-analyzer cargo palette 0.7.6 num/Real# |
| 164 | + Onerust-analyzer cargo palette 0.7.6 num/One# |
| 165 | + Zerorust-analyzer cargo palette 0.7.6 num/Zero# |
| 166 | + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics# |
| 167 | + Powirust-analyzer cargo palette 0.7.6 num/Powi# |
| 168 | + Sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt# |
| 169 | + Hypotrust-analyzer cargo palette 0.7.6 num/Hypot# |
| 170 | + MinMaxrust-analyzer cargo palette 0.7.6 num/MinMax# |
| 171 | + Cbrtrust-analyzer cargo palette 0.7.6 num/Cbrt# |
| 172 | + IsValidDivisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#<Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# = bool> |
| 173 | + HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#<Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# = bool> |
| 174 | + PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# |
| 175 | + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#, |
| 176 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#<T>: GetHuerust-analyzer cargo palette 0.7.6 GetHue#<Huerust-analyzer cargo palette 0.7.6 GetHue#Hue# = OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>> + IntoColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#<LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#<T>>, |
| 177 | { |
| 178 | fn from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(lab: Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#<T>) -> Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`] { |
| 179 | // refer to the SRGB reference-white-based lightness L_r as l for consistency with HSL |
| 180 | let l = toerust-analyzer cargo palette 0.7.6 ok_utils/toe().(lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().()); |
| 181 | let chroma = lab.get_chromarust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]get_chroma().(); |
| 182 | |
| 183 | // Not part of the reference implementation. Added to prevent |
| 184 | // https://github.com/Ogeon/palette/issues/368 and other cases of NaN. |
| 185 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().chroma.is_valid_divisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#is_valid_divisor().() || lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#eq().T::onerust-analyzer cargo palette 0.7.6 num/One#one().() || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l..is_valid_divisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#is_valid_divisor().() { |
| 186 | return Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), l); |
| 187 | } |
| 188 | |
| 189 | let hue = lab.get_huerust-analyzer cargo palette 0.7.6 GetHue#get_hue().(); |
| 190 | let cs = ChromaValuesrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#::from_normalizedrust-analyzer cargo palette 0.7.6 ok_utils/impl#[`ChromaValues<T>`]from_normalized().(lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l., lab.arust-analyzer cargo palette 0.7.6 oklab/Oklab#a. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().&chroma, lab.brust-analyzer cargo palette 0.7.6 oklab/Oklab#b. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().&chroma); |
| 191 | |
| 192 | // Inverse of the interpolation in okhsl_to_srgb: |
| 193 | |
| 194 | let mid = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.8); |
| 195 | let mid_inv = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.25); |
| 196 | |
| 197 | let s = if chroma rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#lt().cs.midrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#mid. { |
| 198 | let k_1 = mid.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().cs.zerorust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#zero.; |
| 199 | let k_2 = T::onerust-analyzer cargo palette 0.7.6 num/One#one().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().k_1.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().cs.midrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#mid.; |
| 200 | |
| 201 | let t = chroma.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().(k_1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().k_2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().chroma); |
| 202 | t rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().mid |
| 203 | } else { |
| 204 | let k_0 = cs.midrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#mid..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(); |
| 205 | let k_1 = (T::onerust-analyzer cargo palette 0.7.6 num/One#one().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().&mid) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().(cs.midrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#mid..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().mid_inv).powirust-analyzer cargo palette 0.7.6 num/Powi#powi().(2) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().cs.zerorust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#zero.; |
| 206 | let k_2 = T::onerust-analyzer cargo palette 0.7.6 num/One#one().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().k_1.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().(cs.maxrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#max. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().cs.midrust-analyzer cargo palette 0.7.6 ok_utils/ChromaValues#mid.); |
| 207 | |
| 208 | let t = (chroma.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().&k_0) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div().(k_1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().k_2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().(chroma rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().k_0)); |
| 209 | mid.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().(T::onerust-analyzer cargo palette 0.7.6 num/One#one().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Sub#sub().mid) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#mul().t |
| 210 | }; |
| 211 | |
| 212 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(hue, s, l) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | impl<T> HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask# for Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> |
| 217 | where |
| 218 | T: HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#, |
| 219 | { |
| 220 | type Maskrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][HasBoolMask]Mask# = T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#; |
| 221 | } |
| 222 | |
| 223 | impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> |
| 224 | where |
| 225 | T: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#, |
| 226 | OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 227 | { |
| 228 | fn defaultrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][Default]default().() -> Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> { |
| 229 | Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().( |
| 230 | OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(), |
| 231 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][Default]::min_saturationrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]min_saturation().(), |
| 232 | Selfrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][Default]::min_lightnessrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]min_lightness().(), |
| 233 | ) |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | #[cfg(feature = "bytemuck")] |
| 238 | unsafe impl<T> bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.25.2 zeroable/Zeroable# for Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> where T: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Zeroablerust-analyzer cargo bytemuck 1.25.2 zeroable/Zeroable# {} |
| 239 | |
| 240 | #[cfg(feature = "bytemuck")] |
| 241 | unsafe impl<T> bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Podrust-analyzer cargo bytemuck 1.25.2 pod/Pod# for Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#<T> where T: bytemuckrust-analyzer cargo bytemuck 1.25.2 crate/::Podrust-analyzer cargo bytemuck 1.25.2 pod/Pod# {} |
| 242 | |
| 243 | #[cfg(test)] |
| 244 | mod testsrust-analyzer cargo palette 0.7.6 okhsl/tests/ { |
| 245 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 246 | convertrust-analyzer cargo palette 0.7.6 convert/::{FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#, IntoColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#}, |
| 247 | encodingrust-analyzer cargo palette 0.7.6 encoding/, |
| 248 | rgbrust-analyzer cargo palette 0.7.6 rgb/::Rgbrust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#, |
| 249 | Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#, Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#, Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#, |
| 250 | }; |
| 251 | |
| 252 | test_convert_into_from_xyzrust-analyzer cargo palette 0.7.6 macros/convert/test_convert_into_from_xyz!!(Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#); |
| 253 | |
| 254 | #[cfg(feature = "approx")] |
| 255 | mod conversionrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/ { |
| 256 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 257 | |
| 258 | use craterust-analyzer cargo palette 0.7.6 crate/::{ |
| 259 | convertrust-analyzer cargo palette 0.7.6 convert/::FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#, |
| 260 | visualrust-analyzer cargo palette 0.7.6 visual/::{VisualColorrust-analyzer cargo palette 0.7.6 visual/VisualColor#, VisuallyEqualrust-analyzer cargo palette 0.7.6 visual/VisuallyEqual#}, |
| 261 | LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#, Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#, Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#, Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#, |
| 262 | }; |
| 263 | |
| 264 | #[cfg_attr(miri, ignore)] |
| 265 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 266 | fn test_roundtrip_okhsl_oklab_is_originalrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/test_roundtrip_okhsl_oklab_is_original().() { |
| 267 | let colors = [ |
| 268 | ( |
| 269 | "red", |
| 270 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(1.0, 0.0, 0.0)), |
| 271 | ), |
| 272 | ( |
| 273 | "green", |
| 274 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.0, 1.0, 0.0)), |
| 275 | ), |
| 276 | ( |
| 277 | "cyan", |
| 278 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.0, 1.0, 1.0)), |
| 279 | ), |
| 280 | ( |
| 281 | "magenta", |
| 282 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(1.0, 0.0, 1.0)), |
| 283 | ), |
| 284 | ( |
| 285 | "black", |
| 286 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.0, 0.0, 0.0)), |
| 287 | ), |
| 288 | ( |
| 289 | "grey", |
| 290 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.5, 0.5, 0.5)), |
| 291 | ), |
| 292 | ( |
| 293 | "yellow", |
| 294 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(1.0, 1.0, 0.0)), |
| 295 | ), |
| 296 | ( |
| 297 | "blue", |
| 298 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.0, 0.0, 1.0)), |
| 299 | ), |
| 300 | ( |
| 301 | "white", |
| 302 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(1.0, 1.0, 1.0)), |
| 303 | ), |
| 304 | ]; |
| 305 | |
| 306 | // unlike in okhwb we are using f64 here, which actually works. |
| 307 | // So we can afford a small tolerance. |
| 308 | // For some reason the roundtrip of Okhsl seems to produce a greater |
| 309 | // divergence than the round trip of Okhsv (1e-8 vs 1e-10) |
| 310 | const EPSILONrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/EPSILON.: f64 = 1e-8; |
| 311 | |
| 312 | for (name, color) in colors { |
| 313 | let rgb: Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#<u8> = Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::<f64>::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(color).into_formatrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_format().(); |
| 314 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 315 | "\n\ |
| 316 | roundtrip of {} (#{:x} / {:?})\n\ |
| 317 | =================================================", |
| 318 | name, rgb, color |
| 319 | ); |
| 320 | |
| 321 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Color is white: {}", color.is_whiterust-analyzer cargo palette 0.7.6 oklab/visual_eq/impl#[`Oklab<T>`][`VisualColor<T>`]is_white().(EPSILONrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/EPSILON.)); |
| 322 | |
| 323 | let okhsl = Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(color); |
| 324 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Okhsl: {:?}", okhsl); |
| 325 | let roundtrip_color = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Okhsl<T>>`]from_color_unclamped().(okhsl); |
| 326 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 327 | Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::visually_eqrust-analyzer cargo palette 0.7.6 oklab/visual_eq/impl#[`Oklab<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(roundtrip_color, color, EPSILONrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/EPSILON.), |
| 328 | "'{}' failed.\n{:?}\n!=\n{:?}", |
| 329 | name, |
| 330 | roundtrip_color, |
| 331 | color |
| 332 | ); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 337 | fn test_bluerust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/test_blue().() { |
| 338 | let lab = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::newrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]new().( |
| 339 | 0.45201371519623734_f64, |
| 340 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.03245697990291002, |
| 341 | -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.3115281336419824, |
| 342 | ); |
| 343 | let okhsl = Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::<f64>::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(lab); |
| 344 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 345 | abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/abs_diff_eq!!( |
| 346 | okhsl.huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue..into_raw_degreesrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_raw_degrees().(), |
| 347 | 360.0 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). 0.7334778365225699, |
| 348 | epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-10 |
| 349 | ), |
| 350 | "{}\n!=\n{}", |
| 351 | okhsl.huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue..into_raw_degreesrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_raw_degrees().(), |
| 352 | 360.0 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). 0.7334778365225699 |
| 353 | ); |
| 354 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 355 | abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/abs_diff_eq!!(okhsl.saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., 0.9999999897262261, epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-8), |
| 356 | "{}\n!=\n{}", |
| 357 | okhsl.saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., |
| 358 | 0.9999999897262261 |
| 359 | ); |
| 360 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 361 | abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/abs_diff_eq!!(okhsl.lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness., 0.366565335813274, epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-10), |
| 362 | "{}\n!=\n{}", |
| 363 | okhsl.lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness., |
| 364 | 0.366565335813274 |
| 365 | ); |
| 366 | } |
| 367 | |
| 368 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 369 | fn test_srgb_to_okhslrust-analyzer cargo palette 0.7.6 okhsl/tests/conversion/test_srgb_to_okhsl().() { |
| 370 | let red_hex = "#834941"; |
| 371 | let rgb: Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#<f64> = Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::from_strrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, u8>`][FromStr]from_str().(red_hex).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().into_formatrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_format().(); |
| 372 | let lin_rgb = LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::<f64>::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S1, T>`][`FromColorUnclamped<Rgb<S2, T>>`]from_color_unclamped().(rgb); |
| 373 | let oklab = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(lin_rgb); |
| 374 | printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!( |
| 375 | "RGB: {:?}\n\ |
| 376 | LinRgb: {:?}\n\ |
| 377 | Oklab: {:?}", |
| 378 | rgb, lin_rgb, oklab |
| 379 | ); |
| 380 | let okhsl = Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(oklab); |
| 381 | |
| 382 | // test data from Ok Color picker |
| 383 | assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!( |
| 384 | okhsl.huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue..into_raw_degreesrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_raw_degrees().(), |
| 385 | 360.0 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). 0.07992730371382328, |
| 386 | epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-10, |
| 387 | max_relativerust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]max_relative(). = 1e-13 |
| 388 | ); |
| 389 | assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(okhsl.saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., 0.4629217183454986, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-10); |
| 390 | assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(okhsl.lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness., 0.3900998146147427, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-10); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 395 | fn test_okhsl_to_srgbrust-analyzer cargo palette 0.7.6 okhsl/tests/test_okhsl_to_srgb().() { |
| 396 | let okhsl = Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(0.0_f32, 0.5, 0.5); |
| 397 | let rgb = Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`][`FromColorUnclamped<crate::Okhsl<T>>`]from_color_unclamped().(okhsl); |
| 398 | let rgb8: Rgbrust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#<encodingrust-analyzer cargo palette 0.7.6 encoding/::Srgbrust-analyzer cargo palette 0.7.6 encoding/srgb/Srgb#, u8> = rgb.into_formatrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_format().(); |
| 399 | let hex_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:x}", rgb8); |
| 400 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hex_str, "aa5a74"); |
| 401 | } |
| 402 | |
| 403 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 404 | fn test_okhsl_to_srgb_saturated_blackrust-analyzer cargo palette 0.7.6 okhsl/tests/test_okhsl_to_srgb_saturated_black().() { |
| 405 | let okhsl = Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(0.0_f32, 1.0, 0.0); |
| 406 | let rgb = Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`][`FromColorUnclamped<crate::Okhsl<T>>`]from_color_unclamped().(okhsl); |
| 407 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(rgb, Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(0.0, 0.0, 0.0)); |
| 408 | } |
| 409 | |
| 410 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 411 | fn test_oklab_to_okhsl_saturated_whiterust-analyzer cargo palette 0.7.6 okhsl/tests/test_oklab_to_okhsl_saturated_white().() { |
| 412 | // Minimized check for the case in |
| 413 | // https://github.com/Ogeon/palette/issues/368. It ended up resulting in |
| 414 | // an Oklab value where a or b was larger than 0, which bypassed the |
| 415 | // chroma check. |
| 416 | let oklab = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::newrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]new().(1.0, 1.0, 0.0); |
| 417 | let okhsl: Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl# = oklab.into_color_unclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/impl#[T][`IntoColorUnclamped<U>`]into_color_unclamped().(); |
| 418 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(okhsl, Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(0.0, 0.0, 1.0)); |
| 419 | } |
| 420 | |
| 421 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 422 | fn test_oklab_to_okhsl_saturated_blackrust-analyzer cargo palette 0.7.6 okhsl/tests/test_oklab_to_okhsl_saturated_black().() { |
| 423 | // Minimized check for the case in |
| 424 | // https://github.com/Ogeon/palette/issues/368. This wasn't the reported |
| 425 | // case, but another variant of it. |
| 426 | let oklab = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::newrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]new().(0.0, 1.0, 0.0); |
| 427 | let okhsl: Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl# = oklab.into_color_unclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/impl#[T][`IntoColorUnclamped<U>`]into_color_unclamped().(); |
| 428 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(okhsl, Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#::newrust-analyzer cargo palette 0.7.6 okhsl/impl#[`Okhsl<T>`]new().(0.0, 0.0, 0.0)); |
| 429 | } |
| 430 | |
| 431 | struct_of_arrays_testsrust-analyzer cargo palette 0.7.6 macros/struct_of_arrays/struct_of_arrays_tests!!( |
| 432 | Okhslrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#[huerust-analyzer cargo palette 0.7.6 okhsl/Okhsl#hue., saturationrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#saturation., lightnessrust-analyzer cargo palette 0.7.6 okhsl/Okhsl#lightness.], |
| 433 | superrust-analyzer cargo palette 0.7.6 okhsl/::Okhslarust-analyzer cargo palette 0.7.6 okhsl/alpha/Okhsla#::newrust-analyzer cargo palette 0.7.6 okhsl/alpha/impl#[`Alpha<Okhsl<T>, A>`]new().(0.1f32, 0.2, 0.3, 0.4), |
| 434 | superrust-analyzer cargo palette 0.7.6 okhsl/::Okhslarust-analyzer cargo palette 0.7.6 okhsl/alpha/Okhsla#::newrust-analyzer cargo palette 0.7.6 okhsl/alpha/impl#[`Alpha<Okhsl<T>, A>`]new().(0.2, 0.3, 0.4, 0.5), |
| 435 | superrust-analyzer cargo palette 0.7.6 okhsl/::Okhslarust-analyzer cargo palette 0.7.6 okhsl/alpha/Okhsla#::newrust-analyzer cargo palette 0.7.6 okhsl/alpha/impl#[`Alpha<Okhsl<T>, A>`]new().(0.3, 0.4, 0.5, 0.6) |
| 436 | ); |
| 437 | } |