Debian Codegraph @

src/color_difference.rs

raw symbols SCIP
1 //! Algorithms for calculating the difference between colors.
2 //!
3 //! ## Selecting an algorithm
4 //!
5 //! Different distance/difference algorithms and formulas are good for different
6 //! situations. Some are faster but less accurate and some may only be suitable
7 //! for certain color spaces. This table may help navigating the options a bit
8 //! by summarizing the difference between the traits in this module.
9 //!
10 //! **Disclaimer:** _This is not an actual benchmark! It's always best to test
11 //! and evaluate the differences in an actual application, when possible._
12 //!
13 //! Property explanations:
14 //! - **Complexity:** Low complexity options are generally faster than high
15 //! complexity options.
16 //! - **Accuracy:** How the numerical difference compares to the perceived
17 //! difference. May differ with the color space.
18 //!
19 //! | Trait | Complexity | Accuracy | Notes |
20 //! |-------|------------|----------|-------|
21 //! | [`Ciede2000`] | High | High for small differences, lower for large differences | The de-facto standard, but requires complex calculations to compensate for increased errors in certain areas of the CIE L\*a\*b\* (CIELAB) space.
22 //! | [`ImprovedCiede2000`] | High | High for small differences, lower for large differences | A general improvement of [`Ciede2000`], using a formula by Huang et al.
23 //! | [`DeltaE`] | Usually low | Medium to high | The formula differs between color spaces and may not always be the best. Other formulas, such as [`Ciede2000`], may be preferred for some spaces.
24 //! | [`ImprovedDeltaE`] | Usually low to medium | Medium to high | A general improvement of [`DeltaE`], using a formula by Huang et al.
25 //! | [`EuclideanDistance`] | Low | Medium to high for perceptually uniform spaces, otherwise low | Can be good enough for perceptually uniform spaces or as a "quick and dirty" check.
26 //! | [`HyAb`] | Low | High accuracy for medium to large differences. Less accurate than CIEDE2000 for small differences, but still performs well and is much less computationally expensive. | Similar to Euclidean distance, but separates lightness and chroma more. Limited to Cartesian spaces with a lightness axis and a chroma plane.
27 //! | [`Wcag21RelativeContrast`] | Low | Low and only compares lightness | Meant for checking contrasts in computer graphics (such as between text and background colors), assuming sRGB. Mostly useful as a hint or for checking WCAG 2.1 compliance, considering the criticism it has received.
28
29 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, BitAndrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#, BitOrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#, Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#, Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#};
30
31 use craterust-analyzer cargo palette 0.7.6 crate/::{
32 anglerust-analyzer cargo palette 0.7.6 angle/::RealAnglerust-analyzer cargo palette 0.7.6 angle/RealAngle#,
33 bool_maskrust-analyzer cargo palette 0.7.6 bool_mask/::{HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#, LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#},
34 convertrust-analyzer cargo palette 0.7.6 convert/::IntoColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#,
35 numrust-analyzer cargo palette 0.7.6 num/::{
36 Absrust-analyzer cargo palette 0.7.6 num/Abs#, Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#, Exprust-analyzer cargo palette 0.7.6 num/Exp#, Hypotrust-analyzer cargo palette 0.7.6 num/Hypot#, MinMaxrust-analyzer cargo palette 0.7.6 num/MinMax#, Onerust-analyzer cargo palette 0.7.6 num/One#, PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp#, Powfrust-analyzer cargo palette 0.7.6 num/Powf#, 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#,
37 Trigonometryrust-analyzer cargo palette 0.7.6 num/Trigonometry#, Zerorust-analyzer cargo palette 0.7.6 num/Zero#,
38 },
39 white_pointrust-analyzer cargo palette 0.7.6 white_point/::D65rust-analyzer cargo palette 0.7.6 white_point/D65#,
40 Labrust-analyzer cargo palette 0.7.6 lab/Lab#, Lchrust-analyzer cargo palette 0.7.6 lch/Lch#, LinLumarust-analyzer cargo palette 0.7.6 luma/LinLuma#,
41 };
42
43 /// A trait for calculating the color difference between two colors.
44 #[deprecated(
45 since = "0.7.2",
46 note = "replaced by `palette::color_difference::Ciede2000`"
47 )]
48 pub trait ColorDifferencerust-analyzer cargo palette 0.7.6 color_difference/ColorDifference# {
49 /// The type of the calculated color difference.
50 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/ColorDifference#Scalar#;
51
52 /// Return the difference or distance between two colors.
53 #[must_use]
54 fn get_color_differencerust-analyzer cargo palette 0.7.6 color_difference/ColorDifference#get_color_difference().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/ColorDifference#Scalar#;
55 }
56
57 /// Calculate the CIEDE2000 Δ*E\** (Delta E) color difference between two
58 /// colors.
59 ///
60 /// CIEDE2000 is a formula by the CIE that calculates a distance metric, Δ*E\**
61 /// (also known as Delta E), as an estimate of perceived color distance or
62 /// difference. CIEDE2000 is an improvement over Δ*E* (see [`DeltaE`]) for CIE
63 /// L\*a\*b\* and CIE L\*C\*h° (see [`Lab`] and [`Lch`]).
64 ///
65 /// There is a "just noticeable difference" between two colors when the Δ*E\**
66 /// is roughly greater than 1. Thus, the color difference is more suited for
67 /// calculating small distances between colors as opposed to large differences.
68 #[doc(alias = "ColorDifference")]
69 pub trait Ciede2000rust-analyzer cargo palette 0.7.6 color_difference/Ciede2000# {
70 /// The type for the Δ*E\** (Delta E).
71 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#;
72
73 /// Calculate the CIEDE2000 Δ*E\** (Delta E) color difference between `self` and `other`.
74 #[must_use]
75 fn differencerust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#difference().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#;
76 }
77
78 /// Calculate the CIEDE2000 Δ*E'* (improved IEDE2000 Δ*E\**) color difference.
79 ///
80 /// The "improved CIEDE2000" uses the output of [`Ciede2000`] and enhances it
81 /// according to *Power functions improving the performance of color-difference
82 /// formulas* by Huang et al.
83 pub trait ImprovedCiede2000rust-analyzer cargo palette 0.7.6 color_difference/ImprovedCiede2000#: Ciede2000rust-analyzer cargo palette 0.7.6 color_difference/Ciede2000# {
84 /// Calculate the CIEDE2000 Δ*E'* (improved IEDE2000 Δ*E\**) color
85 /// difference between `self` and `other`.
86 #[must_use]
87 fn improved_differencerust-analyzer cargo palette 0.7.6 color_difference/ImprovedCiede2000#improved_difference().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#;
88 }
89
90 impl<C> ImprovedCiede2000rust-analyzer cargo palette 0.7.6 color_difference/ImprovedCiede2000# for C
91 where
92 C: Ciede2000rust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#,
93 C::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#: Realrust-analyzer cargo palette 0.7.6 num/Real# + Mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#<C::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#, Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Mul#Output# = C::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#> + Powfrust-analyzer cargo palette 0.7.6 num/Powf#,
94 {
95 #[inline]
96 fn improved_differencerust-analyzer cargo palette 0.7.6 color_difference/impl#[C][ImprovedCiede2000]improved_difference().(self, other: Selfrust-analyzer cargo palette 0.7.6 color_difference/impl#[C][ImprovedCiede2000]) -> Selfrust-analyzer cargo palette 0.7.6 color_difference/impl#[C][ImprovedCiede2000]::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar# {
97 // Coefficients from "Power functions improving the performance of
98 // color-difference formulas" by Huang et al.
99 // https://opg.optica.org/oe/fulltext.cfm?uri=oe-23-1-597&id=307643
100 C::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(1.43) 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().self.differencerust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#difference().(other).powfrust-analyzer cargo palette 0.7.6 num/Powf#powf().(C::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Ciede2000#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.7))
101 }
102 }
103
104 /// Container of components necessary to calculate CIEDE color difference
105 pub(craterust-analyzer cargo palette 0.7.6 crate/) struct LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#<T> {
106 /// Lab color lightness
107 pub lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#l.: T,
108 /// Lab color a* value
109 pub arust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#a.: T,
110 /// Lab color b* value
111 pub brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b.: T,
112 /// Lab color chroma value
113 pub chromarust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#chroma.: T,
114 }
115
116 impl<Wp, T> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Labrust-analyzer cargo palette 0.7.6 lab/Lab#<Wp, T>> for LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#<T>
117 where
118 T: Hypotrust-analyzer cargo palette 0.7.6 num/Hypot# + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
119 {
120 #[inline]
121 fn fromrust-analyzer cargo palette 0.7.6 color_difference/impl#[`LabColorDiff<T>`][`From<Lab<Wp, T>>`]from().(color: Labrust-analyzer cargo palette 0.7.6 lab/Lab#<Wp, T>) -> Selfrust-analyzer cargo palette 0.7.6 color_difference/impl#[`LabColorDiff<T>`][`From<Lab<Wp, T>>`] {
122 // Color difference calculation requires Lab and chroma components. This
123 // function handles the conversion into those components which are then
124 // passed to `get_ciede_difference()` where calculation is completed.
125 LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff# {
126 lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#l.: color.lrust-analyzer cargo palette 0.7.6 lab/Lab#l.,
127 arust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#a.: color.arust-analyzer cargo palette 0.7.6 lab/Lab#a..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
128 brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b.: color.brust-analyzer cargo palette 0.7.6 lab/Lab#b..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
129 chromarust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#chroma.: color.arust-analyzer cargo palette 0.7.6 lab/Lab#a..hypotrust-analyzer cargo palette 0.7.6 num/Hypot#hypot().(color.brust-analyzer cargo palette 0.7.6 lab/Lab#b.),
130 }
131 }
132 }
133
134 impl<Wp, T> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Lchrust-analyzer cargo palette 0.7.6 lch/Lch#<Wp, T>> for LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#<T>
135 where
136 T: Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
137 Lchrust-analyzer cargo palette 0.7.6 lch/Lch#<Wp, T>: IntoColorUnclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#<Labrust-analyzer cargo palette 0.7.6 lab/Lab#<Wp, T>>,
138 {
139 #[inline]
140 fn fromrust-analyzer cargo palette 0.7.6 color_difference/impl#[`LabColorDiff<T>`][`From<Lch<Wp, T>>`]from().(color: Lchrust-analyzer cargo palette 0.7.6 lch/Lch#<Wp, T>) -> Selfrust-analyzer cargo palette 0.7.6 color_difference/impl#[`LabColorDiff<T>`][`From<Lch<Wp, T>>`] {
141 let chroma = color.chromarust-analyzer cargo palette 0.7.6 lch/Lch#chroma..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().();
142 let Labrust-analyzer cargo palette 0.7.6 lab/Lab# { lrust-analyzer cargo palette 0.7.6 lab/Lab#l., arust-analyzer cargo palette 0.7.6 lab/Lab#a., brust-analyzer cargo palette 0.7.6 lab/Lab#b., .. } = color.into_color_unclampedrust-analyzer cargo palette 0.7.6 convert/from_into_color_unclamped/IntoColorUnclamped#into_color_unclamped().();
143
144 LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff# { lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#l., arust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#a., brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b., chromarust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#chroma. }
145 }
146 }
147
148 /// Calculate the CIEDE2000 color difference for two colors in Lab color space.
149 /// There is a "just noticeable difference" between two colors when the delta E
150 /// is roughly greater than 1. Thus, the color difference is more suited for
151 /// calculating small distances between colors as opposed to large differences.
152 #[rustfmt::skip]
153 pub(craterust-analyzer cargo palette 0.7.6 crate/) fn get_ciede2000_differencerust-analyzer cargo palette 0.7.6 color_difference/get_ciede2000_difference().<T>(this: LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#<T>, other: LabColorDiffrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#<T>) -> T
154 where
155 T: Realrust-analyzer cargo palette 0.7.6 num/Real#
156 + RealAnglerust-analyzer cargo palette 0.7.6 angle/RealAngle#
157 + Onerust-analyzer cargo palette 0.7.6 num/One#
158 + Zerorust-analyzer cargo palette 0.7.6 num/Zero#
159 + Trigonometryrust-analyzer cargo palette 0.7.6 num/Trigonometry#
160 + Absrust-analyzer cargo palette 0.7.6 num/Abs#
161 + Sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#
162 + Powirust-analyzer cargo palette 0.7.6 num/Powi#
163 + Exprust-analyzer cargo palette 0.7.6 num/Exp#
164 + Arithmeticsrust-analyzer cargo palette 0.7.6 num/Arithmetics#
165 + PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp#
166 + Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#,
167 T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#: LazySelectrust-analyzer cargo palette 0.7.6 bool_mask/LazySelect#<T> + BitAndrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#Output# = T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#> + BitOrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#Output# = T::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask#>
168 {
169 let c_bar = (this.chromarust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#chroma. 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().other.chromarust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#chroma.) 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0);
170 let c_bar_pow_seven = c_bar.powirust-analyzer cargo palette 0.7.6 num/Powi#powi().(7);
171 let twenty_five_pow_seven = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(6103515625.0);
172 let pi_over_180 = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::f64rust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/::constsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/::PIrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/PI. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().180.0);
173
174 let g = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.5)
175 *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::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().(c_bar_pow_seven.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().(c_bar_pow_seven 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().&twenty_five_pow_seven)).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().());
176 let a_one_prime = this.arust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#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().(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/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().&g);
177 let a_two_prime = other.arust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#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().(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/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().g);
178 let c_one_prime = (a_one_prime.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().&a_one_prime 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().this.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b..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().&this.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b.).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().();
179 let c_two_prime = (a_two_prime.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().&a_two_prime 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().other.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b..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().&other.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b.).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().();
180
181 let calc_h_prime = |b: T, a_prime: T| -> T {
182 lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! {
183 if b.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) &rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitAnd#bitand(). a_prime.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) => T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(),
184 else => {
185 let result = T::radians_to_degreesrust-analyzer cargo palette 0.7.6 angle/RealAngle#radians_to_degrees().(b.atan2rust-analyzer cargo palette 0.7.6 num/Trigonometry#atan2().(a_prime));
186 lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! {
187 if result.ltrust-analyzer cargo palette 0.7.6 num/PartialCmp#lt().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) => result.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(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(360.0),
188 else => result.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
189 }
190 },
191 }
192 };
193 let h_one_prime = calc_h_prime(this.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b., a_one_prime);
194 let h_two_prime = calc_h_prime(other.brust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#b., a_two_prime);
195
196 let h_prime_diff = h_two_prime.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().&h_one_prime;
197 let h_prime_abs_diff = h_prime_diff.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().().absrust-analyzer cargo palette 0.7.6 num/Abs#abs().();
198
199 let delta_h_prime: T = lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! {
200 if c_one_prime.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#bitor(). c_two_prime.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) => T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().(),
201 if h_prime_abs_diff.lt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#lt_eq().(&T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(180.0)) => h_prime_diff.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
202 if h_two_prime.lt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#lt_eq().(&h_one_prime) => h_prime_diff.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(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(360.0),
203 else => h_prime_diff.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(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(360.0),
204 };
205
206 let delta_big_h_prime = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0)
207 *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_one_prime.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().&c_two_prime).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().()
208 *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().(delta_h_prime 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0) 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().&pi_over_180).sinrust-analyzer cargo palette 0.7.6 num/Trigonometry#sin().();
209 let h_prime_sum = h_one_prime 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().h_two_prime;
210 let h_bar_prime = lazy_selectrust-analyzer cargo palette 0.7.6 macros/lazy_select/lazy_select!! {
211 if c_one_prime.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) |rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/BitOr#bitor(). c_two_prime.eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#eq().(&T::zerorust-analyzer cargo palette 0.7.6 num/Zero#zero().()) => h_prime_sum.clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().(),
212 if h_prime_abs_diff.gtrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt().(&T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(180.0)) => {
213 (h_prime_sum.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(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(360.0)) /rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#div(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0)
214 },
215 else => h_prime_sum.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(). T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0),
216 };
217
218 let l_bar = (this.lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#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/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().&other.lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0);
219 let c_bar_prime = (c_one_prime.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().&c_two_prime) 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0);
220
221 let t: T = T::onerust-analyzer cargo palette 0.7.6 num/One#one().()
222 -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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.17) 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().((h_bar_prime.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(30.0)) 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().&pi_over_180).cosrust-analyzer cargo palette 0.7.6 num/Trigonometry#cos().()
223 +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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.24) 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().((h_bar_prime.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0)) 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().&pi_over_180).cosrust-analyzer cargo palette 0.7.6 num/Trigonometry#cos().()
224 +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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.32) 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().((h_bar_prime.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(3.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(6.0)) 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().&pi_over_180).cosrust-analyzer cargo palette 0.7.6 num/Trigonometry#cos().()
225 -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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.20) 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().((h_bar_prime.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(4.0) 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(63.0)) 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().&pi_over_180).cosrust-analyzer cargo palette 0.7.6 num/Trigonometry#cos().();
226 let s_l = T::onerust-analyzer cargo palette 0.7.6 num/One#one().()
227 +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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.015) 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_bar.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(50.0)) 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_bar.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(50.0)))
228 /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_bar.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(50.0)) 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_bar 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(50.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(20.0)).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().());
229 let s_c = 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/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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.045) 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_bar_prime;
230 let s_h = 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/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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.015) 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_bar_prime 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;
231
232 let delta_theta = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(30.0)
233 *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/Neg#neg().(((h_bar_prime.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(275.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(25.0))
234 *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().((h_bar_prime 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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(275.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().T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(25.0))))
235 .exprust-analyzer cargo palette 0.7.6 num/Exp#exp().();
236 let c_bar_prime_pow_seven = c_bar_prime.powirust-analyzer cargo palette 0.7.6 num/Powi#powi().(7);
237 let r_c: T = T::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0)
238 *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_bar_prime_pow_seven.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().(c_bar_prime_pow_seven 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().twenty_five_pow_seven)).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().();
239 let r_t = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Neg#neg().r_c 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::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(2.0) 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().delta_theta 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().pi_over_180).sinrust-analyzer cargo palette 0.7.6 num/Trigonometry#sin().();
240
241 let k_l = T::onerust-analyzer cargo palette 0.7.6 num/One#one().();
242 let k_c = T::onerust-analyzer cargo palette 0.7.6 num/One#one().();
243 let k_h = T::onerust-analyzer cargo palette 0.7.6 num/One#one().();
244 let delta_l_prime = other.lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#l. 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().this.lrust-analyzer cargo palette 0.7.6 color_difference/LabColorDiff#l.;
245 let delta_c_prime = c_two_prime 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().c_one_prime;
246
247 ((delta_l_prime.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_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().&s_l)) 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().(delta_l_prime 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_l 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_l))
248 +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().(delta_c_prime.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_c.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_c)) 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().(delta_c_prime.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_c.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_c))
249 +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().(delta_big_h_prime.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_h.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_h)) 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().(delta_big_h_prime.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_h.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_h))
250 +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().(r_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().delta_c_prime 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().delta_big_h_prime) 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_c 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_c 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_h 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_h))
251 .sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().()
252 }
253
254 /// Calculate the distance between two colors as if they were coordinates in
255 /// Euclidean space.
256 ///
257 /// Euclidean distance is not always a good measurement of visual color
258 /// difference, depending on the color space. Some spaces, like [`Lab`] and
259 /// [`Oklab`][crate::Oklab], will give a fairly uniform result, while other
260 /// spaces, such as [`Rgb`][crate::rgb::Rgb], will give much less uniform
261 /// results. Despite that, it's still appropriate for some applications.
262 pub trait EuclideanDistancerust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
263 /// The type for the distance value.
264 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#Scalar#;
265
266 /// Calculate the Euclidean distance from `self` to `other`.
267 #[must_use]
268 fn distancerust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#distance().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#Scalar#
269 where
270 Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#Scalar#: Sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#,
271 {
272 self.distance_squaredrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#distance_squared().(other).sqrtrust-analyzer cargo palette 0.7.6 num/Sqrt#sqrt().()
273 }
274
275 /// Calculate the squared Euclidean distance from `self` to `other`.
276 ///
277 /// This is typically a faster option than [`Self::distance`] for some
278 /// cases, such as when comparing two distances.
279 #[must_use]
280 fn distance_squaredrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#distance_squared().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/EuclideanDistance#Scalar#;
281 }
282
283 /// Calculate and check the WCAG 2.1 relative contrast and relative luminance.
284 ///
285 /// W3C's Web Content Accessibility Guidelines (WCAG) 2.1 suggest a method to
286 /// calculate accessible contrast ratios of text and background colors for those
287 /// with low vision or color vision deficiencies, and for contrast of colors
288 /// used in user interface graphics objects.
289 ///
290 /// These criteria come with a couple of caveats:
291 /// * sRGB is assumed as the presentation color space, which is why it's only
292 /// implemented for a limited set of [`Rgb`][crate::rgb::Rgb] and
293 /// [`Luma`][crate::Luma] spaces.
294 /// * The contrast ratio is not considered entirely consistent with the
295 /// perceived contrast. WCAG 3.x is supposed to provide a better measurement.
296 ///
297 /// Because of the inconsistency with perceived contrast, these methods are more
298 /// suitable as hints and for mechanical verification of standards compliance,
299 /// than for accurate analysis. Remember to not only rely on the numbers, but to
300 /// also test your interfaces with actual people in actual situations for the
301 /// best results.
302 ///
303 /// The following example checks the contrast ratio of two colors in sRGB
304 /// format:
305 ///
306 /// ```rust
307 /// use std::str::FromStr;
308 /// use palette::{Srgb, color_difference::Wcag21RelativeContrast};
309 /// # fn main() -> Result<(), palette::rgb::FromHexError> {
310 ///
311 /// // the rustdoc "DARK" theme background and text colors
312 /// let background: Srgb<f32> = Srgb::from(0x353535).into_format();
313 /// let foreground = Srgb::from_str("#ddd")?.into_format();
314 ///
315 /// assert!(background.has_enhanced_contrast_text(foreground));
316 /// # Ok(())
317 /// # }
318 /// ```
319 pub trait Wcag21RelativeContrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
320 /// The scalar type used for luminance and contrast.
321 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#: Realrust-analyzer cargo palette 0.7.6 num/Real#
322 + Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#<Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#, Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#Output# = Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#>
323 + Divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#<Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#, Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Div#Output# = Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#>
324 + PartialCmprust-analyzer cargo palette 0.7.6 num/PartialCmp#
325 + MinMaxrust-analyzer cargo palette 0.7.6 num/MinMax#;
326
327 /// Returns the WCAG 2.1 [relative
328 /// luminance](https://www.w3.org/TR/WCAG21/#dfn-relative-luminance) of
329 /// `self`.
330 ///
331 /// The relative luminance is a value between 0 and 1, where 0 is the
332 /// darkest black and 1 is the lightest white. This is the same as clamped
333 /// [`LinLuma`], meaning that the typical implementation of this method
334 /// would be `self.into_color()`.
335 #[must_use]
336 fn relative_luminancerust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_luminance().(self) -> LinLumarust-analyzer cargo palette 0.7.6 luma/LinLuma#<D65rust-analyzer cargo palette 0.7.6 white_point/D65#, Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#>;
337
338 /// Returns the WCAG 2.1 relative luminance contrast between `self` and
339 /// `other`.
340 ///
341 /// A return value of, for example, 4 represents a contrast ratio of 4:1
342 /// between the lightest and darkest of the two colors. The range is from
343 /// 1:1 to 21:1, and a higher contrast ratio is generally desirable.
344 ///
345 /// This method is independent of the order of the colors, so
346 /// `a.relative_contrast(b)` and `b.relative_contrast(a)` would return the
347 /// same value.
348 #[must_use]
349 #[inline]
350 fn relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# {
351 let (min_luma, max_luma) = self
352 .relative_luminancerust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_luminance().()
353 .lumarust-analyzer cargo palette 0.7.6 luma/luma/Luma#luma.
354 .min_maxrust-analyzer cargo palette 0.7.6 num/MinMax#min_max().(other.relative_luminancerust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_luminance().().lumarust-analyzer cargo palette 0.7.6 luma/luma/Luma#luma.);
355
356 (Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.05) 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().max_luma) 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().(Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(0.05) 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().min_luma)
357 }
358
359 /// Verify the contrast between two colors satisfies SC 1.4.3. Contrast is
360 /// at least 4.5:1 (Level AA).
361 ///
362 /// This applies for meaningful text, such as body text. Font sizes of 18
363 /// points or lager, or 14 points when bold, are considered large and can be
364 /// checked with
365 /// [`has_min_contrast_large_text`][Wcag21RelativeContrast::has_min_contrast_large_text]
366 /// instead.
367 ///
368 /// [Success Criterion 1.4.3 Contrast (Minimum) (Level
369 /// AA)](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum)
370 #[must_use]
371 #[inline]
372 fn has_min_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_text().(self, other: Self) -> <Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# as HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#>::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# {
373 self.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(other)
374 .gt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt_eq().(&Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(4.5))
375 }
376
377 /// Verify the contrast between two colors satisfies SC 1.4.3 for large
378 /// text. Contrast is at least 3:1 (Level AA).
379 ///
380 /// This applies for meaningful large text, such as headings. Font sizes of
381 /// 18 points or lager, or 14 points when bold, are considered large.
382 ///
383 /// [Success Criterion 1.4.3 Contrast (Minimum) (Level
384 /// AA)](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum)
385 #[must_use]
386 #[inline]
387 fn has_min_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_large_text().(self, other: Self) -> <Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# as HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#>::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# {
388 self.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(other)
389 .gt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt_eq().(&Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(3.0))
390 }
391
392 /// Verify the contrast between two colors satisfies SC 1.4.6. Contrast is
393 /// at least 7:1 (Level AAA).
394 ///
395 /// This applies for meaningful text, such as body text. Font sizes of 18
396 /// points or lager, or 14 points when bold, are considered large and can be
397 /// checked with
398 /// [`has_enhanced_contrast_large_text`][Wcag21RelativeContrast::has_enhanced_contrast_large_text]
399 /// instead.
400 ///
401 /// [Success Criterion 1.4.6 Contrast (Enhanced) (Level
402 /// AAA)](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced)
403 #[must_use]
404 #[inline]
405 fn has_enhanced_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_text().(self, other: Self) -> <Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# as HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#>::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# {
406 self.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(other)
407 .gt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt_eq().(&Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(7.0))
408 }
409
410 /// Verify the contrast between two colors satisfies SC 1.4.6 for large
411 /// text. Contrast is at least 4.5:1 (Level AAA).
412 ///
413 /// This applies for meaningful large text, such as headings. Font sizes of
414 /// 18 points or lager, or 14 points when bold, are considered large.
415 ///
416 /// [Success Criterion 1.4.6 Contrast (Enhanced) (Level
417 /// AAA)](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced)
418 #[must_use]
419 #[inline]
420 fn has_enhanced_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_large_text().(self, other: Self) -> <Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# as HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#>::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# {
421 self.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(other)
422 .gt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt_eq().(&Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(4.5))
423 }
424
425 /// Verify the contrast between two colors satisfies SC 1.4.11 for graphical
426 /// objects. Contrast is at least 3:1 (Level AA).
427 ///
428 /// This applies for any graphical object that aren't text, such as
429 /// meaningful images and interactive user interface elements.
430 ///
431 /// [Success Criterion 1.4.11 Non-text Contrast (Level
432 /// AA)](https://www.w3.org/WAI/WCAG21/Understanding/non-text-contrast.html)
433 #[must_use]
434 #[inline]
435 fn has_min_contrast_graphicsrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_graphics().(self, other: Self) -> <Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar# as HasBoolMaskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#>::Maskrust-analyzer cargo palette 0.7.6 bool_mask/HasBoolMask#Mask# {
436 self.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(other)
437 .gt_eqrust-analyzer cargo palette 0.7.6 num/PartialCmp#gt_eq().(&Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#Scalar#::from_f64rust-analyzer cargo palette 0.7.6 num/Real#from_f64().(3.0))
438 }
439 }
440
441 /// Calculate a combination of Euclidean and Manhattan/City-block distance
442 /// between two colors.
443 ///
444 /// The HyAB distance was suggested as an alternative to CIEDE2000 for large
445 /// color differences in [Distance metrics for very large color
446 /// differences](http://markfairchild.org/PDFs/PAP40.pdf) (in [Color Res Appl.
447 /// 2019;1–16](https://doi.org/10.1002/col.22451)) by Saeedeh Abasi, Mohammad
448 /// Amani Tehran and Mark D. Fairchild. It's originally meant for [CIE L\*a\*b\*
449 /// (CIELAB)][crate::Lab], but this trait is also implemented for other color
450 /// spaces that have similar semantics, although **without the same quality
451 /// guarantees**.
452 ///
453 /// The hybrid distance is the sum of the absolute lightness difference and the
454 /// distance on the chroma plane. This makes the lightness and chroma
455 /// differences more independent from each other, which is meant to correspond
456 /// more to how humans perceive the two qualities.
457 pub trait HyAbrust-analyzer cargo palette 0.7.6 color_difference/HyAb# {
458 /// The type for the distance value.
459 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/HyAb#Scalar#;
460
461 /// Calculate the hybrid distance between `self` and `other`.
462 ///
463 /// This returns the sum of the absolute lightness difference and the
464 /// distance on the chroma plane.
465 #[must_use]
466 fn hybrid_distancerust-analyzer cargo palette 0.7.6 color_difference/HyAb#hybrid_distance().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/HyAb#Scalar#;
467 }
468
469 /// Calculate the Δ*E* color difference between two colors.
470 ///
471 /// This represents the original Δ*E* formula for a color space. It's often a
472 /// Euclidean distance for perceptually uniform color spaces and may not always
473 /// be the best option. See the [`color_difference`](self) module for more
474 /// details and options.
475 pub trait DeltaErust-analyzer cargo palette 0.7.6 color_difference/DeltaE# {
476 /// The type for the distance value.
477 type Scalarrust-analyzer cargo palette 0.7.6 color_difference/DeltaE#Scalar#;
478
479 /// Calculate the Δ*E* color difference metric for `self` and `other`,
480 /// according to the color space's specification.
481 #[must_use]
482 fn delta_erust-analyzer cargo palette 0.7.6 color_difference/DeltaE#delta_e().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/DeltaE#Scalar#;
483 }
484
485 /// Calculate the Δ*E'* (improved Δ*E*) color difference between two colors.
486 ///
487 /// The Δ*E'* uses the output of [`DeltaE`] and enhances it according to *Power
488 /// functions improving the performance of color-difference formulas* by Huang
489 /// et al. Only spaces with specified coefficients implement this trait.
490 pub trait ImprovedDeltaErust-analyzer cargo palette 0.7.6 color_difference/ImprovedDeltaE#: DeltaErust-analyzer cargo palette 0.7.6 color_difference/DeltaE# {
491 /// Calculate the Δ*E'* (improved Δ*E*) color difference metric for `self`
492 /// and `other`, according to the color space's specification and later
493 /// improvements by Huang et al.
494 #[must_use]
495 fn improved_delta_erust-analyzer cargo palette 0.7.6 color_difference/ImprovedDeltaE#improved_delta_e().(self, other: Self) -> Self::Scalarrust-analyzer cargo palette 0.7.6 color_difference/DeltaE#Scalar#;
496 }
497
498 #[cfg(feature = "approx")]
499 #[cfg(test)]
500 mod testrust-analyzer cargo palette 0.7.6 color_difference/test/ {
501 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#;
502
503 use superrust-analyzer cargo palette 0.7.6 color_difference/::{HyAbrust-analyzer cargo palette 0.7.6 color_difference/HyAb#, Wcag21RelativeContrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#};
504 use craterust-analyzer cargo palette 0.7.6 crate/::{FromColorrust-analyzer cargo palette 0.7.6 convert/from_into_color/FromColor#, Labrust-analyzer cargo palette 0.7.6 lab/Lab#, Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#};
505
506 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
507 fn relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/test/relative_contrast().() {
508 let white = Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::newrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]new().(1.0f32, 1.0, 1.0);
509 let black = 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);
510
511 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(white.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(white), 1.0);
512 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(white.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(black), 21.0);
513 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(
514 white.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(black),
515 black.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(white)
516 );
517
518 let c1 = 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().("#600").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().();
519
520 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(white), 13.41, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
521 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(black), 1.56, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
522
523 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(c1.has_min_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_text().(white));
524 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(c1.has_min_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_large_text().(white));
525 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(c1.has_enhanced_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_text().(white));
526 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(c1.has_enhanced_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_large_text().(white));
527 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(c1.has_min_contrast_graphicsrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_graphics().(white));
528
529 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().c1.has_min_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_text().(black));
530 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().c1.has_min_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_large_text().(black));
531 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().c1.has_enhanced_contrast_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_text().(black));
532 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().c1.has_enhanced_contrast_large_textrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_enhanced_contrast_large_text().(black));
533 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().c1.has_min_contrast_graphicsrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#has_min_contrast_graphics().(black));
534
535 let c1 = 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().("#066").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().();
536
537 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(white), 6.79, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
538 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(black), 3.09, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
539
540 let c1 = 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().("#9f9").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().();
541
542 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(white), 1.22, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
543 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(c1.relative_contrastrust-analyzer cargo palette 0.7.6 color_difference/Wcag21RelativeContrast#relative_contrast().(black), 17.11, epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.01);
544 }
545
546 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
547 fn hyabrust-analyzer cargo palette 0.7.6 color_difference/test/hyab().() {
548 // From https://github.com/Evercoder/culori/blob/cd1fe08a12fa9ddfcf6b2e82914733d23ac117d0/test/difference.test.js#L186
549 let red = Labrust-analyzer cargo palette 0.7.6 lab/Lab#::<_, f64>::from_colorrust-analyzer cargo palette 0.7.6 convert/from_into_color/impl#[U][`FromColor<T>`]from_color().(Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::fromrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, u8>`][`From<u32>`]from().(0xff0000).into_linearrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_linear().());
550 let green = Labrust-analyzer cargo palette 0.7.6 lab/Lab#::<_, f64>::from_colorrust-analyzer cargo palette 0.7.6 convert/from_into_color/impl#[U][`FromColor<T>`]from_color().(Srgbrust-analyzer cargo palette 0.7.6 rgb/Srgb#::fromrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, u8>`][`From<u32>`]from().(0x008000).into_linearrust-analyzer cargo palette 0.7.6 rgb/rgb/impl#[`Rgb<S, T>`]into_linear().());
551 assert_relative_eqrust-analyzer cargo approx 0.5.1 macros/assert_relative_eq!!(
552 red.hybrid_distancerust-analyzer cargo palette 0.7.6 lab/impl#[`Lab<Wp, T>`][HyAb]hybrid_distance().(green),
553 139.93576718451553,
554 epsilonrust-analyzer cargo approx 0.5.1 impl#[`Relative<A, B>`]epsilon(). = 0.000001
555 );
556 }
557 }