Debian Codegraph @

src/okhsv.rs

raw symbols SCIP
1 //! Types for the Okhsv color space.
2
3 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#;
4
5 pub use alpharust-analyzer cargo palette 0.7.6 okhsv/alpha/::Okhsvarust-analyzer cargo palette 0.7.6 okhsv/alpha/Okhsva#;
6 #[cfg(feature = "random")]
7 pub use randomrust-analyzer cargo palette 0.7.6 okhsv/random/::UniformOkhsvrust-analyzer cargo palette 0.7.6 okhsv/random/UniformOkhsv#;
8
9 use craterust-analyzer cargo palette 0.7.6 crate/::{
10 anglerust-analyzer cargo palette 0.7.6 angle/::FromAnglerust-analyzer cargo palette 0.7.6 angle/FromAngle#,
11 bool_maskrust-analyzer cargo palette 0.7.6 bool_mask/::LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#,
12 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#},
13 numrust-analyzer cargo palette 0.7.6 num/::{
14 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#, Trigonometryrust-analyzer cargo palette 0.7.6 num/Trigonometry#, Zerorust-analyzer cargo palette 0.7.6 num/Zero#,
15 },
16 ok_utilsrust-analyzer cargo palette 0.7.6 ok_utils/::{selfrust-analyzer cargo palette 0.7.6 ok_utils/, LCrust-analyzer cargo palette 0.7.6 ok_utils/LC#, STrust-analyzer cargo palette 0.7.6 ok_utils/ST#},
17 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#},
18 white_pointrust-analyzer cargo palette 0.7.6 white_point/::D65rust-analyzer cargo palette 0.7.6 white_point/D65#,
19 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#, Okhwbrust-analyzer cargo palette 0.7.6 okhwb/Okhwb#, Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#, OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#,
20 };
21
22 pub use selfrust-analyzer cargo palette 0.7.6 okhsv/::propertiesrust-analyzer cargo palette 0.7.6 okhsv/properties/::Iterrust-analyzer cargo palette 0.7.6 okhsv/properties/Iter#;
23
24 mod alpharust-analyzer cargo palette 0.7.6 okhsv/alpha/;
25 mod propertiesrust-analyzer cargo palette 0.7.6 okhsv/properties/;
26 #[cfg(feature = "random")]
27 mod randomrust-analyzer cargo palette 0.7.6 okhsv/random/;
28 #[cfg(test)]
29 #[cfg(feature = "approx")]
30 mod visual_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/;
31
32 /// A Hue/Saturation/Value representation of [`Oklab`] in the `sRGB` color space.
33 ///
34 /// Allows
35 /// * changing lightness/chroma/saturation while keeping perceived Hue constant
36 /// (like HSV promises but delivers only partially)
37 /// * finding the strongest color (maximum chroma) at s == 1 (like HSV)
38 #[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:)]
39 #[cfg_attr(feature = "serializing", derive(Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:))]
40 #[palette(
41 palette_internal,
42 white_point = "D65",
43 component = "T",
44 skip_derives(Oklab, Okhwb)
45 )]
46 #[repr(C)]
47 pub struct Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T = f32> {
48 /// The hue of the color, in degrees of a circle.
49 ///
50 /// For fully saturated, bright colors
51 /// * 0° corresponds to a kind of magenta-pink (RBG #ff0188),
52 /// * 90° to a kind of yellow (RBG RGB #ffcb00)
53 /// * 180° to a kind of cyan (RBG #00ffe1) and
54 /// * 240° to a kind of blue (RBG #00aefe).
55 ///
56 /// For s == 0 or v == 0, the hue is irrelevant.
57 #[paletterust-analyzer cargo palette_derive 0.7.6 palette:(unsafe_same_layout_as = "T")]
58 pub huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue.: OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>,
59
60 /// The saturation (freedom of whitishness) of the color.
61 ///
62 /// * `0.0` corresponds to pure mixture of black and white without any color.
63 /// The black to white relation depends on v.
64 /// * `1.0` to a fully saturated color without any white.
65 ///
66 /// For v == 0 the saturation is irrelevant.
67 pub saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.: T,
68
69 /// The monochromatic brightness of the color.
70 /// * `0.0` corresponds to pure black
71 /// * `1.0` corresponds to a maximally bright colour -- be it very colorful or very white
72 ///
73 /// `Okhsl`'s `lightness` component goes from black to white.
74 /// `Okhsv`'s `value` component goes from black to non-black -- a maximally bright color..
75 pub valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.: T,
76 }
77
78 impl_tuple_conversion_huerust-analyzer cargo palette 0.7.6 macros/convert/impl_tuple_conversion_hue!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv# as (H, T, T), OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#);
79
80 impl<T> HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask# for Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T>
81 where
82 T: HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#,
83 {
84 type Maskrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][HasBoolMask]Mask# = T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#;
85 }
86
87 impl<T> Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T>
88 where
89 T: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#,
90 OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#,
91 {
92 fn defaultrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][Default]default().() -> Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T> {
93 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(
94 OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(),
95 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][Default]::min_saturationrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]min_saturation().(),
96 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][Default]::min_valuerust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]min_value().(),
97 )
98 }
99 }
100
101 impl<T> Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T>
102 where
103 T: Stimulusrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#,
104 {
105 /// Return the `saturation` value minimum.
106 pub fn min_saturationrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]min_saturation().() -> T {
107 T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()
108 }
109
110 /// Return the `saturation` value maximum.
111 pub fn max_saturationrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]max_saturation().() -> T {
112 T::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().()
113 }
114
115 /// Return the `value` value minimum.
116 pub fn min_valuerust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]min_value().() -> T {
117 T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()
118 }
119
120 /// Return the `value` value maximum.
121 pub fn max_valuerust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]max_value().() -> T {
122 T::max_intensityrust-analyzer cargo palette 0.7.6 stimulus/Stimulus#max_intensity().()
123 }
124 }
125
126 impl_reference_component_methods_huerust-analyzer cargo palette 0.7.6 macros/reference_component/impl_reference_component_methods_hue!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#, [saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation., valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.]);
127 impl_struct_of_arrays_methods_huerust-analyzer cargo palette 0.7.6 macros/struct_of_arrays/impl_struct_of_arrays_methods_hue!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#, [saturation, value]);
128
129 impl<T> Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T> {
130 /// Create an `Okhsv` color.
131 pub fn newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<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, value: T) -> Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`] {
132 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`] {
133 huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue.: hue.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(),
134 saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.,
135 valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.,
136 }
137 }
138
139 /// Create an `Okhsv` color. This is the same as `Okhsv::new` without the
140 /// generic hue type. It's temporary until `const fn` supports traits.
141 pub const fn new_construst-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new_const().(hue: OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>, saturation: T, value: T) -> Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`] {
142 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`] {
143 huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue.,
144 saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.,
145 valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.,
146 }
147 }
148
149 /// Convert into another component type.
150 pub fn into_formatrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]into_format().<U>(self) -> Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<U>
151 where
152 U: FromStimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#<T> + FromAnglerust-analyzer cargo palette 0.7.6 angle/FromAngle#<T>,
153 {
154 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv# {
155 huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue.: self.huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue..into_formatrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_format().(),
156 saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.: U::from_stimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#from_stimulus().(self.saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.),
157 valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.: U::from_stimulusrust-analyzer cargo palette 0.7.6 stimulus/FromStimulus#from_stimulus().(self.valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.),
158 }
159 }
160
161 /// Convert to a `(h, s, v)` tuple.
162 pub fn into_componentsrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]into_components().(self) -> (OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#<T>, T, T) {
163 (self.huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue., self.saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation., self.valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.)
164 }
165
166 /// Convert from a `(h, s, v)` tuple.
167 pub fn from_componentsrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<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, value): (H, T, T)) -> Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`] {
168 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(hue, saturation, value)
169 }
170 }
171
172 /// Converts `lab` to `Okhsv` in the bounds of sRGB.
173 ///
174 /// # See
175 /// See [`srgb_to_okhsv`](https://bottosson.github.io/posts/colorpicker/#hsv-2).
176 /// This implementation differs from srgb_to_okhsv in that it starts with the `lab`
177 /// value and produces hues in degrees, whereas `srgb_to_okhsv` produces degree/360.
178 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 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T>
179 where
180 T: Realrust-analyzer cargo palette 0.7.6 num/Real#
181 + MinMaxrust-analyzer cargo palette 0.7.6 num/MinMax#
182 + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#
183 + Powirust-analyzer cargo palette 0.7.6 num/Powi#
184 + Sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#
185 + Cbrtrust-analyzer cargo palette 0.7.6 num/Cbrt#
186 + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#
187 + Trigonometryrust-analyzer cargo palette 0.7.6 num/Trigonometry#
188 + Zerorust-analyzer cargo palette 0.7.6 num/Zero#
189 + Hypotrust-analyzer cargo palette 0.7.6 num/Hypot#
190 + Onerust-analyzer cargo palette 0.7.6 num/One#
191 + IsValidDivisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#<Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# = bool>
192 + HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#<Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# = bool>
193 + PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#,
194 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>>,
195 {
196 fn from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<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 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`] {
197 if 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::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().() {
198 // the color is pure black
199 return Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().());
200 }
201
202 let chroma = lab.get_chromarust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]get_chroma().();
203 let hue = lab.get_huerust-analyzer cargo palette 0.7.6 GetHue#get_hue().();
204 if chroma.is_valid_divisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#is_valid_divisor().() {
205 let (a_, b_) = (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);
206
207 // For each hue the sRGB gamut can be drawn on a 2-dimensional space.
208 // Let L_r, the lightness in relation to the possible luminance of sRGB, be spread
209 // along the y-axis (bottom is black, top is bright) and Chroma along the x-axis
210 // (left is desaturated, right is colorful). The gamut then takes a triangular shape,
211 // with a concave top side and a cusp to the right.
212 // To use saturation and brightness values, the gamut must be mapped to a square.
213 // The lower point of the triangle is expanded to the lower side of the square.
214 // The left side remains unchanged and the cusp of the triangle moves to the upper right.
215 let cusp = LCrust-analyzer cargo palette 0.7.6 ok_utils/LC#::find_cusprust-analyzer cargo palette 0.7.6 ok_utils/impl#[`LC<T>`]find_cusp().(a_.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(), b_.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
216 let st_max = STrust-analyzer cargo palette 0.7.6 ok_utils/ST#::<T>::fromrust-analyzer cargo palette 0.7.6 ok_utils/impl#[`ST<T>`][`From<LC<T>>`]from().(cusp);
217
218 let s_0 = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.5);
219 let k = 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().s_0.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().st_max.srust-analyzer cargo palette 0.7.6 ok_utils/ST#s.;
220
221 // first we find L_v, C_v, L_vt and C_vt
222 let t = st_max.trust-analyzer cargo palette 0.7.6 ok_utils/ST#t..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().(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/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().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().() 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().&st_max.trust-analyzer cargo palette 0.7.6 ok_utils/ST#t.);
223 let l_v = t.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().&lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l.;
224 let c_v = 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().chroma;
225
226 let l_vt = ok_utilsrust-analyzer cargo palette 0.7.6 ok_utils/::toe_invrust-analyzer cargo palette 0.7.6 ok_utils/toe_inv().(l_v.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().());
227 let c_vt = c_v.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().&l_vt 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().&l_v;
228
229 // we can then use these to invert the step that compensates for the toe and the curved top part of the triangle:
230 let rgb_scale: LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#<T> =
231 Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::newrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]new().(l_vt, a_ 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().&c_vt, b_ 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().c_vt).into_color_unclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#into_color_unclamped().();
232 let lightness_scale_factor = T::cbrtrust-analyzer cargo palette 0.7.6 num/Cbrt#cbrt().(
233 T::onerust-analyzer cargo palette 0.7.6 num/One#one().()
234 /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().T::maxrust-analyzer cargo palette 0.7.6 num/MinMax#max().(
235 T::maxrust-analyzer cargo palette 0.7.6 num/MinMax#max().(rgb_scale.redrust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#red., rgb_scale.greenrust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#green.),
236 T::maxrust-analyzer cargo palette 0.7.6 num/MinMax#max().(rgb_scale.bluerust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#blue., T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()),
237 ),
238 );
239
240 //chroma = chroma / lightness_scale_factor;
241
242 // use L_r instead of L and also scale C by L_r/L
243 let l_r = ok_utilsrust-analyzer cargo palette 0.7.6 ok_utils/::toerust-analyzer cargo palette 0.7.6 ok_utils/toe().(lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l. 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().lightness_scale_factor);
244 //chroma = chroma * l_r / (lab.l / lightness_scale_factor);
245
246 // we can now compute v and s:
247 let v = l_r 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().l_v;
248 let s =
249 (s_0.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().&st_max.trust-analyzer cargo palette 0.7.6 ok_utils/ST#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().&c_v 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().((st_max.trust-analyzer cargo palette 0.7.6 ok_utils/ST#t..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().s_0) 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().st_max.trust-analyzer cargo palette 0.7.6 ok_utils/ST#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().k 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().c_v);
250
251 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(hue, s, v)
252 } else {
253 // the color is totally desaturated.
254 let v = ok_utilsrust-analyzer cargo palette 0.7.6 ok_utils/::toerust-analyzer cargo palette 0.7.6 ok_utils/toe().(lab.lrust-analyzer cargo palette 0.7.6 oklab/Oklab#l.);
255 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(), v)
256 }
257 }
258 }
259 impl<T> FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#<Okhwbrust-analyzer cargo palette 0.7.6 okhwb/Okhwb#<T>> for Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<T>
260 where
261 T: Onerust-analyzer cargo palette 0.7.6 num/One# + Zerorust-analyzer cargo palette 0.7.6 num/Zero# + IsValidDivisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor# + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#,
262 T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#: LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#<T>,
263 {
264 fn from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Okhwb<T>>`]from_color_unclamped().(hwb: Okhwbrust-analyzer cargo palette 0.7.6 okhwb/Okhwb#<T>) -> Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Okhwb<T>>`] {
265 let Okhwbrust-analyzer cargo palette 0.7.6 okhwb/Okhwb# {
266 huerust-analyzer cargo palette 0.7.6 okhwb/Okhwb#hue.,
267 whitenessrust-analyzer cargo palette 0.7.6 okhwb/Okhwb#whiteness.,
268 blacknessrust-analyzer cargo palette 0.7.6 okhwb/Okhwb#blackness.,
269 } = hwb;
270
271 let value = 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().blackness;
272
273 // avoid divide by zero
274 let saturation = lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! {
275 if value.is_valid_divisorrust-analyzer cargo palette 0.7.6 num/IsValidDivisor#is_valid_divisor().() => 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(). (whiteness /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). &value),
276 else => T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(),
277 };
278
279 Selfrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Okhwb<T>>`] {
280 huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue.,
281 saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.,
282 valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.,
283 }
284 }
285 }
286
287 #[cfg(test)]
288 mod testsrust-analyzer cargo palette 0.7.6 okhsv/tests/ {
289 use craterust-analyzer cargo palette 0.7.6 crate/::{convertrust-analyzer cargo palette 0.7.6 convert/::FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#, Clamprust-analyzer cargo palette 0.7.6 Clamp#, IsWithinBoundsrust-analyzer cargo palette 0.7.6 IsWithinBounds#, LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#, Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#, Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#};
290
291 test_convert_into_from_xyzrust-analyzer cargo palette 0.7.6 macros/convert/test_convert_into_from_xyz!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#);
292
293 #[cfg(feature = "approx")]
294 mod conversionrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/ {
295 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#;
296
297 use craterust-analyzer cargo palette 0.7.6 crate/::{
298 convertrust-analyzer cargo palette 0.7.6 convert/::FromColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/FromColorUnclamped#, encodingrust-analyzer cargo palette 0.7.6 encoding/, rgbrust-analyzer cargo palette 0.7.6 rgb/::Rgbrust-analyzer cargo palette 0.7.6 rgb/rgb/Rgb#, visualrust-analyzer cargo palette 0.7.6 visual/::VisuallyEqualrust-analyzer cargo palette 0.7.6 visual/VisuallyEqual#, LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#, Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#,
299 Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#, OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#, Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#,
300 };
301
302 #[cfg_attr(miri, ignore)]
303 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
304 fn test_roundtrip_okhsv_oklab_is_originalrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/test_roundtrip_okhsv_oklab_is_original().() {
305 let colors = [
306 (
307 "red",
308 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)),
309 ),
310 (
311 "green",
312 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)),
313 ),
314 (
315 "cyan",
316 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)),
317 ),
318 (
319 "magenta",
320 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)),
321 ),
322 (
323 "white",
324 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)),
325 ),
326 (
327 "black",
328 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)),
329 ),
330 (
331 "grey",
332 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)),
333 ),
334 (
335 "yellow",
336 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)),
337 ),
338 (
339 "blue",
340 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)),
341 ),
342 ];
343
344 // unlike in okhwb we are using f64 here, which actually works.
345 // So we can afford a small tolerance
346 const EPSILONrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/EPSILON.: f64 = 1e-10;
347
348 for (name, color) in colors {
349 let rgb: 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> =
350 craterust-analyzer cargo palette 0.7.6 crate/::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().();
351 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
352 "\n\
353 roundtrip of {} (#{:x} / {:?})\n\
354 =================================================",
355 name, rgb, color
356 );
357
358 let okhsv = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(color);
359 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Okhsv: {:?}", okhsv);
360 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<Okhsv<T>>`]from_color_unclamped().(okhsv);
361 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
362 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 okhsv/tests/conversion/EPSILON.),
363 "'{}' failed.\n{:?}\n!=\n{:?}",
364 name,
365 roundtrip_color,
366 color
367 );
368 }
369 }
370
371 /// Compares results to results for a run of
372 /// https://github.com/bottosson/bottosson.github.io/blob/3d3f17644d7f346e1ce1ca08eb8b01782eea97af/misc/ok_color.h
373 /// Not to the ideal values, which should be
374 /// hue: as is
375 /// saturation: 1.0
376 /// value: 1.0
377 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
378 fn bluerust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/blue().() {
379 let lin_srgb_blue = 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);
380 let oklab_blue_64 = Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::<f64>::from_color_unclampedrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`][`FromColorUnclamped<Rgb<S, T>>`]from_color_unclamped().(lin_srgb_blue);
381 let okhsv_blue_64 = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(oklab_blue_64);
382
383 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Okhsv f64: {:?}\n", okhsv_blue_64);
384 // HSV values of the reference implementation (in C)
385 // 1 iteration : 264.0520206380550121, 0.9999910912349018, 0.9999999646150918
386 // 2 iterations: 264.0520206380550121, 0.9999999869716002, 0.9999999646150844
387 // 3 iterations: 264.0520206380550121, 0.9999999869716024, 0.9999999646150842
388 #[allow(clippy::excessive_precision)]
389 let expected_hue = OklabHuerust-analyzer cargo palette 0.7.6 hues/OklabHue#::newrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]new().(264.0520206380550121);
390 let expected_saturation = 0.9999910912349018;
391 let expected_value = 0.9999999646150918;
392
393 // compare to the reference implementation values
394 assert_abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/assert_abs_diff_eq!!(okhsv_blue_64.huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue., expected_hue, epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-12);
395 assert_abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/assert_abs_diff_eq!!(
396 okhsv_blue_64.saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation.,
397 expected_saturation,
398 epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-12
399 );
400 assert_abs_diff_eqrust-analyzer cargo approx 0.5.1 macros/assert_abs_diff_eq!!(okhsv_blue_64.valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value., expected_value, epsilonrust-analyzer cargo approx 0.5.1 impl#[`AbsDiff<A, B>`]epsilon(). = 1e-12);
401 }
402
403 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
404 fn test_srgb_to_okhsvrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/test_srgb_to_okhsv().() {
405 let red_hex = "#ff0004";
406 let rgb: Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb# = 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#, _>::from_strrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, u8>`][FromStr]from_str().(red_hex)
407 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
408 .into_formatrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_format().();
409 let okhsv = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<crate::rgb::Rgb<_S, T>>`]from_color_unclamped().(rgb);
410 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(okhsv.saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation., 1.0, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-3);
411 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(okhsv.valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value., 1.0, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-3);
412 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(
413 okhsv.huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue..into_raw_degreesrust-analyzer cargo palette 0.7.6 hues/impl#[`OklabHue<T>`]into_raw_degrees().(),
414 29.0,
415 epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 1e-3,
416 max_relativerust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]max_relative(). = 1e-3
417 );
418 }
419
420 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
421 fn test_okhsv_to_srgbrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/test_okhsv_to_srgb().() {
422 let okhsv = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0_f32, 0.5, 0.5);
423 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::Okhsv<T>>`]from_color_unclamped().(okhsv);
424 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().();
425 let hex_str = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:x}", rgb8);
426 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(hex_str, "7a4355");
427 }
428
429 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
430 fn test_okhsv_to_srgb_saturated_blackrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/test_okhsv_to_srgb_saturated_black().() {
431 let okhsv = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0_f32, 1.0, 0.0);
432 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::Okhsv<T>>`]from_color_unclamped().(okhsv);
433 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_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));
434 }
435
436 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
437 fn black_eq_different_blackrust-analyzer cargo palette 0.7.6 okhsv/tests/conversion/black_eq_different_black().() {
438 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
439 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(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)),
440 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(Oklabrust-analyzer cargo palette 0.7.6 oklab/Oklab#::newrust-analyzer cargo palette 0.7.6 oklab/impl#[`Oklab<T>`]new().(0.0, 0.0, 1.0)),
441 1e-12
442 ));
443 }
444 }
445
446 #[cfg(feature = "approx")]
447 mod visual_eqrust-analyzer cargo palette 0.7.6 okhsv/tests/visual_eq/ {
448 use craterust-analyzer cargo palette 0.7.6 crate/::{visualrust-analyzer cargo palette 0.7.6 visual/::VisuallyEqualrust-analyzer cargo palette 0.7.6 visual/VisuallyEqual#, Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#};
449
450 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
451 fn white_eq_different_whiterust-analyzer cargo palette 0.7.6 okhsv/tests/visual_eq/white_eq_different_white().() {
452 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
453 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(240.0, 0.0, 1.0),
454 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(24.0, 0.0, 1.0),
455 1e-12
456 ));
457 }
458
459 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
460 fn white_ne_grey_or_blackrust-analyzer cargo palette 0.7.6 okhsv/tests/visual_eq/white_ne_grey_or_black().() {
461 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
462 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 0.0),
463 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 1.0),
464 1e-12
465 ));
466 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
467 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 0.3),
468 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 1.0),
469 1e-12
470 ));
471 }
472
473 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
474 fn color_neq_different_colorrust-analyzer cargo palette 0.7.6 okhsv/tests/visual_eq/color_neq_different_color().() {
475 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
476 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(10.0, 0.01, 0.5),
477 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(11.0, 0.01, 0.5),
478 1e-12
479 ));
480 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
481 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(10.0, 0.01, 0.5),
482 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(10.0, 0.02, 0.5),
483 1e-12
484 ));
485 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
486 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(10.0, 0.01, 0.5),
487 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(10.0, 0.01, 0.6),
488 1e-12
489 ));
490 }
491
492 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
493 fn grey_vs_greyrust-analyzer cargo palette 0.7.6 okhsv/tests/visual_eq/grey_vs_grey().() {
494 // greys of different lightness are not equal
495 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
496 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 0.3),
497 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 0.4),
498 1e-12
499 ));
500 // greys of same lightness but different hue are equal
501 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::visually_eqrust-analyzer cargo palette 0.7.6 okhsv/visual_eq/impl#[`Okhsv<T>`][`VisuallyEqual<O, S, T>`]visually_eq().(
502 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(0.0, 0.0, 0.3),
503 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::newrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`]new().(12.0, 0.0, 0.3),
504 1e-12
505 ));
506 }
507 }
508
509 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
510 fn srgb_gamut_containmentrust-analyzer cargo palette 0.7.6 okhsv/tests/srgb_gamut_containment().() {
511 {
512 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("sRGB Red");
513 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().(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));
514 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", oklab);
515 let okhsv: Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<f64> = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(oklab);
516 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", okhsv);
517 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(okhsv.is_within_boundsrust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][IsWithinBounds]is_within_bounds().());
518 }
519
520 {
521 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Double sRGB Red");
522 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().(LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(2.0, 0.0, 0.0));
523 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", oklab);
524 let okhsv: Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<f64> = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(oklab);
525 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", okhsv);
526 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().okhsv.is_within_boundsrust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][IsWithinBounds]is_within_bounds().());
527 let clamped_okhsv = okhsv.clamprust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][Clamp]clamp().();
528 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Clamped: {:?}", clamped_okhsv);
529 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(clamped_okhsv.is_within_boundsrust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][IsWithinBounds]is_within_bounds().());
530 let linsrgb = LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`][`FromColorUnclamped<crate::Okhsv<T>>`]from_color_unclamped().(clamped_okhsv);
531 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Clamped as unclamped Linear sRGB: {:?}", linsrgb);
532 }
533
534 {
535 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("P3 Yellow");
536 // display P3 yellow according to https://colorjs.io/apps/convert/?color=color(display-p3%201%201%200)&precision=17
537 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().(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, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.098273600140966));
538 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", oklab);
539 let okhsv: Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#<f64> = Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#::from_color_unclampedrust-analyzer cargo palette 0.7.6 okhsv/impl#[`Okhsv<T>`][`FromColorUnclamped<Oklab<T>>`]from_color_unclamped().(oklab);
540 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{:?}", okhsv);
541 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().okhsv.is_within_boundsrust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][IsWithinBounds]is_within_bounds().());
542 let clamped_okhsv = okhsv.clamprust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][Clamp]clamp().();
543 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Clamped: {:?}", clamped_okhsv);
544 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(clamped_okhsv.is_within_boundsrust-analyzer cargo palette 0.7.6 okhsv/properties/impl#[`Okhsv<T>`][IsWithinBounds]is_within_bounds().());
545 let linsrgb = LinSrgbrust-analyzer cargo palette 0.7.6 rgb/LinSrgb#::from_color_unclampedrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`][`FromColorUnclamped<crate::Okhsv<T>>`]from_color_unclamped().(clamped_okhsv);
546 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!(
547 "Clamped as unclamped Linear sRGB: {:?}\n\
548 May be different, but should be visually indistinguishable from\n\
549 color.js' gamut mapping red: 1 green: 0.9876530763223166 blue: 0",
550 linsrgb
551 );
552 }
553 }
554
555 struct_of_arrays_testsrust-analyzer cargo palette 0.7.6 macros/struct_of_arrays/struct_of_arrays_tests!!(
556 Okhsvrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#[huerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#hue., saturationrust-analyzer cargo palette 0.7.6 okhsv/Okhsv#saturation., valuerust-analyzer cargo palette 0.7.6 okhsv/Okhsv#value.],
557 superrust-analyzer cargo palette 0.7.6 okhsv/::Okhsvarust-analyzer cargo palette 0.7.6 okhsv/alpha/Okhsva#::newrust-analyzer cargo palette 0.7.6 okhsv/alpha/impl#[`Alpha<Okhsv<T>, A>`]new().(0.1f32, 0.2, 0.3, 0.4),
558 superrust-analyzer cargo palette 0.7.6 okhsv/::Okhsvarust-analyzer cargo palette 0.7.6 okhsv/alpha/Okhsva#::newrust-analyzer cargo palette 0.7.6 okhsv/alpha/impl#[`Alpha<Okhsv<T>, A>`]new().(0.2, 0.3, 0.4, 0.5),
559 superrust-analyzer cargo palette 0.7.6 okhsv/::Okhsvarust-analyzer cargo palette 0.7.6 okhsv/alpha/Okhsva#::newrust-analyzer cargo palette 0.7.6 okhsv/alpha/impl#[`Alpha<Okhsv<T>, A>`]new().(0.3, 0.4, 0.5, 0.6)
560 );
561 }