diff --git a/palette/src/alpha/alpha.rs b/palette/src/alpha/alpha.rs index 0db96f389..83f757e5c 100644 --- a/palette/src/alpha/alpha.rs +++ b/palette/src/alpha/alpha.rs @@ -19,7 +19,7 @@ use crate::{ }; /// An alpha component wrapper for colors. -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[repr(C)] pub struct Alpha { @@ -44,6 +44,23 @@ impl Alpha { } } +impl PartialEq for Alpha +where + T: PartialEq, + C: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.color == other.color && self.alpha == other.alpha + } +} + +impl Eq for Alpha +where + T: Eq, + C: Eq, +{ +} + impl, C2, T: Component> FromColorUnclamped for Alpha where C1::Color: IntoColorUnclamped, diff --git a/palette/src/blend/pre_alpha.rs b/palette/src/blend/pre_alpha.rs index 9460d20f8..ac08a8520 100644 --- a/palette/src/blend/pre_alpha.rs +++ b/palette/src/blend/pre_alpha.rs @@ -27,7 +27,7 @@ use crate::{clamp, Alpha, Blend, ComponentWise, Mix, Pixel}; /// /// Note that converting to and from premultiplied alpha will cause the alpha /// component to be clamped to [0.0, 1.0]. -#[derive(Clone, Copy, PartialEq, Debug)] +#[derive(Clone, Copy, Debug)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[repr(C)] pub struct PreAlpha { @@ -40,6 +40,23 @@ pub struct PreAlpha { pub alpha: T, } +impl PartialEq for PreAlpha +where + T: Float + PartialEq, + C: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.color == other.color && self.alpha == other.alpha + } +} + +impl Eq for PreAlpha +where + T: Float + Eq, + C: Eq, +{ +} + impl From> for PreAlpha where C: ComponentWise, diff --git a/palette/src/hsl.rs b/palette/src/hsl.rs index 6de171116..4f7d83d28 100644 --- a/palette/src/hsl.rs +++ b/palette/src/hsl.rs @@ -35,7 +35,7 @@ pub type Hsla = Alpha, T>; /// /// See [HSV](crate::Hsv) for a very similar color space, with brightness /// instead of lightness. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -158,6 +158,23 @@ where } } +impl PartialEq for Hsl +where + T: FloatComponent + PartialEq, + S: RgbStandard, +{ + fn eq(&self, other: &Self) -> bool { + self.hue == other.hue && self.saturation == other.saturation && self.lightness == other.lightness + } +} + +impl Eq for Hsl +where + T: FloatComponent + Eq, + S: RgbStandard, +{ +} + ///[`Hsla`](crate::Hsla) implementations. impl Alpha, A> where diff --git a/palette/src/hsv.rs b/palette/src/hsv.rs index d5222bbba..70bca9f8b 100644 --- a/palette/src/hsv.rs +++ b/palette/src/hsv.rs @@ -32,7 +32,7 @@ pub type Hsva = Alpha, T>; /// _lightness_. The difference is that, for example, red (100% R, 0% G, 0% B) /// and white (100% R, 100% G, 100% B) has the same brightness (or value), but /// not the same lightness. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -155,6 +155,23 @@ where } } +impl PartialEq for Hsv +where + T: FloatComponent + PartialEq, + S: RgbStandard, +{ + fn eq(&self, other: &Self) -> bool { + self.hue == other.hue && self.saturation == other.saturation && self.value == other.value + } +} + +impl Eq for Hsv +where + T: FloatComponent + Eq, + S: RgbStandard, +{ +} + ///[`Hsva`](crate::Hsva) implementations. impl Alpha, A> where diff --git a/palette/src/hues.rs b/palette/src/hues.rs index c116e5767..f3d27c148 100644 --- a/palette/src/hues.rs +++ b/palette/src/hues.rs @@ -119,6 +119,8 @@ macro_rules! make_hues { } } + impl Eq for $name {} + impl Add<$name> for $name { type Output = $name; diff --git a/palette/src/hwb.rs b/palette/src/hwb.rs index fd5d0750a..e4231bc0b 100644 --- a/palette/src/hwb.rs +++ b/palette/src/hwb.rs @@ -33,7 +33,7 @@ pub type Hwba = Alpha, T>; /// /// It is very intuitive for humans to use and many color-pickers are based on /// the HWB color system -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -161,6 +161,25 @@ where } } +impl PartialEq for Hwb +where + T: FloatComponent + PartialEq, + S: RgbStandard, +{ + fn eq(&self, other: &Self) -> bool { + self.hue == other.hue + && self.whiteness == other.whiteness + && self.blackness == other.blackness + } +} + +impl Eq for Hwb +where + T: FloatComponent + Eq, + S: RgbStandard, +{ +} + ///[`Hwba`](crate::Hwba) implementations. impl Alpha, A> where diff --git a/palette/src/lab.rs b/palette/src/lab.rs index d3d6665be..ba4a15f58 100644 --- a/palette/src/lab.rs +++ b/palette/src/lab.rs @@ -33,7 +33,7 @@ pub type Laba = Alpha, T>; /// /// The parameters of L\*a\*b\* are quite different, compared to many other /// color spaces, so manipulating them manually may be unintuitive. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -152,6 +152,23 @@ where } } +impl PartialEq for Lab +where + T: FloatComponent + PartialEq, + Wp: WhitePoint, +{ + fn eq(&self, other: &Self) -> bool { + self.l == other.l && self.a == other.a && self.b == other.b + } +} + +impl Eq for Lab +where + T: FloatComponent + Eq, + Wp: WhitePoint, +{ +} + ///[`Laba`](crate::Laba) implementations. impl Alpha, A> where diff --git a/palette/src/lch.rs b/palette/src/lch.rs index cdd9ebade..61cdf158f 100644 --- a/palette/src/lch.rs +++ b/palette/src/lch.rs @@ -28,7 +28,7 @@ pub type Lcha = Alpha, T>; /// it's a cylindrical color space, like [HSL](crate::Hsl) and /// [HSV](crate::Hsv). This gives it the same ability to directly change /// the hue and colorfulness of a color, while preserving other visual aspects. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -151,6 +151,23 @@ where } } +impl PartialEq for Lch +where + T: FloatComponent + PartialEq, + Wp: WhitePoint, +{ + fn eq(&self, other: &Self) -> bool { + self.l == other.l && self.chroma == other.chroma && self.hue == other.hue + } +} + +impl Eq for Lch +where + T: FloatComponent + Eq, + Wp: WhitePoint, +{ +} + ///[`Lcha`](crate::Lcha) implementations. impl Alpha, A> where diff --git a/palette/src/luma/luma.rs b/palette/src/luma/luma.rs index 3ca45b2da..e43f506e8 100644 --- a/palette/src/luma/luma.rs +++ b/palette/src/luma/luma.rs @@ -33,7 +33,7 @@ pub type Lumaa = Alpha, T>; /// perceived to be. It's basically the `Y` component of [CIE /// XYZ](crate::Xyz). The lack of any form of hue representation limits /// the set of operations that can be performed on it. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -166,6 +166,23 @@ where } } +impl PartialEq for Luma +where + T: Component + PartialEq, + S: LumaStandard, +{ + fn eq(&self, other: &Self) -> bool { + self.luma == other.luma + } +} + +impl Eq for Luma +where + T: Component + Eq, + S: LumaStandard, +{ +} + ///[`Lumaa`](crate::luma::Lumaa) implementations. impl Alpha, A> where diff --git a/palette/src/rgb/rgb.rs b/palette/src/rgb/rgb.rs index 7d4eb6b88..d08e8ed98 100644 --- a/palette/src/rgb/rgb.rs +++ b/palette/src/rgb/rgb.rs @@ -43,7 +43,7 @@ pub type Rgba = Alpha, T>; /// linear, meaning that gamma correction is required when converting to and /// from a displayable RGB, such as sRGB. See the [`pixel`](crate::encoding::pixel) /// module for encoding formats. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -154,6 +154,23 @@ impl Rgb { } } +impl PartialEq for Rgb +where + T: Component + PartialEq, + S: RgbStandard, +{ + fn eq(&self, other: &Self) -> bool { + self.red == other.red && self.green == other.green && self.blue == other.blue + } +} + +impl Eq for Rgb +where + T: Component + Eq, + S: RgbStandard, +{ +} + /// Convenience functions to convert between a packed `u32` and `Rgb`. /// /// ``` diff --git a/palette/src/xyz.rs b/palette/src/xyz.rs index 17d379eb3..ec6991ed3 100644 --- a/palette/src/xyz.rs +++ b/palette/src/xyz.rs @@ -32,7 +32,7 @@ pub type Xyza = Alpha, T>; /// /// Conversions and operations on this color space depend on the defined white /// point -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -157,6 +157,23 @@ where } } +impl PartialEq for Xyz +where + T: FloatComponent + PartialEq, + Wp: WhitePoint, +{ + fn eq(&self, other: &Self) -> bool { + self.x == other.x && self.y == other.y && self.z == other.z + } +} + +impl Eq for Xyz +where + T: FloatComponent + Eq, + Wp: WhitePoint, +{ +} + ///[`Xyza`](crate::Xyza) implementations. impl Alpha, A> where diff --git a/palette/src/yxy.rs b/palette/src/yxy.rs index 96f5af5b2..5388dcb5e 100644 --- a/palette/src/yxy.rs +++ b/palette/src/yxy.rs @@ -28,7 +28,7 @@ pub type Yxya = Alpha, T>; /// for the color spaces are a plot of this color space's x and y coordinates. /// /// Conversions and operations on this color space depend on the white point. -#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)] +#[derive(Debug, Pixel, FromColorUnclamped, WithAlpha)] #[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))] #[palette( palette_internal, @@ -150,6 +150,23 @@ where } } +impl PartialEq for Yxy +where + T: FloatComponent + PartialEq, + Wp: WhitePoint, +{ + fn eq(&self, other: &Self) -> bool { + self.luma == other.luma && self.x == other.x && self.y == other.y + } +} + +impl Eq for Yxy +where + T: FloatComponent + Eq, + Wp: WhitePoint, +{ +} + ///[`Yxya`](crate::Yxya) implementations. impl Alpha, A> where