palette/okhwb/
properties.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use crate::hues::OklabHueIter;
use crate::num::{Arithmetics, PartialCmp, Real};
use crate::stimulus::Stimulus;
use crate::white_point::D65;
use crate::{
    bool_mask::{LazySelect, Select},
    FromColor, OklabHue, Xyz,
};

use super::Okhwb;

impl_is_within_bounds_hwb!(Okhwb where T: Stimulus);
impl_clamp_hwb!(Okhwb where T: Stimulus);

impl_mix_hue!(Okhwb {
    whiteness,
    blackness
});
impl_lighten_hwb!(Okhwb where T: Stimulus);
impl_hue_ops!(Okhwb, OklabHue);

impl_color_add!(Okhwb, [hue, whiteness, blackness]);
impl_color_sub!(Okhwb, [hue, whiteness, blackness]);

impl_array_casts!(Okhwb<T>, [T; 3]);
impl_simd_array_conversion_hue!(Okhwb, [whiteness, blackness]);
impl_struct_of_array_traits_hue!(Okhwb, OklabHueIter, [whiteness, blackness]);

#[allow(deprecated)]
impl<T> crate::RelativeContrast for Okhwb<T>
where
    T: Real + Arithmetics + PartialCmp,
    T::Mask: LazySelect<T>,
    Xyz<D65, T>: FromColor<Self>,
{
    type Scalar = T;

    #[inline]
    fn get_contrast_ratio(self, other: Self) -> T {
        let xyz1 = Xyz::from_color(self);
        let xyz2 = Xyz::from_color(other);

        crate::contrast_ratio(xyz1.y, xyz2.y)
    }
}

impl_eq_hue!(Okhwb, OklabHue, [hue, whiteness, blackness]);