diff --git a/palette/src/alpha.rs b/palette/src/alpha.rs index 101130b8a..d897a62a3 100644 --- a/palette/src/alpha.rs +++ b/palette/src/alpha.rs @@ -1,4 +1,4 @@ -use core::ops::{Add, Deref, DerefMut, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use core::fmt; use float::Float; @@ -237,6 +237,20 @@ impl> Add for Alpha { } } +impl AddAssign for Alpha { + fn add_assign(&mut self, other: Alpha) { + self.color += other.color; + self.alpha += other.alpha; + } +} + +impl> AddAssign for Alpha { + fn add_assign(&mut self, c: T) { + self.color += c; + self.alpha += c; + } +} + impl Sub for Alpha { type Output = Alpha::Output>; @@ -259,6 +273,20 @@ impl> Sub for Alpha { } } +impl SubAssign for Alpha { + fn sub_assign(&mut self, other: Alpha) { + self.color -= other.color; + self.alpha -= other.alpha; + } +} + +impl> SubAssign for Alpha { + fn sub_assign(&mut self, c: T) { + self.color -= c; + self.alpha -= c; + } +} + impl Mul for Alpha { type Output = Alpha::Output>; @@ -281,6 +309,20 @@ impl> Mul for Alpha { } } +impl MulAssign for Alpha { + fn mul_assign(&mut self, other: Alpha) { + self.color *= other.color; + self.alpha *= other.alpha; + } +} + +impl> MulAssign for Alpha { + fn mul_assign(&mut self, c: T) { + self.color *= c; + self.alpha *= c; + } +} + impl Div for Alpha { type Output = Alpha::Output>; @@ -303,6 +345,20 @@ impl> Div for Alpha { } } +impl DivAssign for Alpha { + fn div_assign(&mut self, other: Alpha) { + self.color /= other.color; + self.alpha /= other.alpha; + } +} + +impl> DivAssign for Alpha { + fn div_assign(&mut self, c: T) { + self.color /= c; + self.alpha /= c; + } +} + impl AsRef

for Alpha where C: Pixel, diff --git a/palette/src/blend/pre_alpha.rs b/palette/src/blend/pre_alpha.rs index 43569f657..2d103d511 100644 --- a/palette/src/blend/pre_alpha.rs +++ b/palette/src/blend/pre_alpha.rs @@ -1,4 +1,4 @@ -use core::ops::{Add, Deref, DerefMut, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Deref, DerefMut, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use approx::{AbsDiffEq, RelativeEq, UlpsEq}; use float::Float; @@ -197,7 +197,7 @@ where impl Add for PreAlpha { type Output = PreAlpha; - fn add(self, other: PreAlpha) -> PreAlpha { + fn add(self, other: PreAlpha) -> Self::Output { PreAlpha { color: self.color + other.color, alpha: self.alpha + other.alpha, @@ -208,7 +208,7 @@ impl Add for PreAlpha { impl> Add for PreAlpha { type Output = PreAlpha; - fn add(self, c: T) -> PreAlpha { + fn add(self, c: T) -> Self::Output { PreAlpha { color: self.color + c, alpha: self.alpha + c, @@ -216,10 +216,24 @@ impl> Add for PreAlpha { } } +impl AddAssign for PreAlpha { + fn add_assign(&mut self, other: PreAlpha) { + self.color += other.color; + self.alpha += other.alpha; + } +} + +impl> AddAssign for PreAlpha { + fn add_assign(&mut self, c: T) { + self.color += c; + self.alpha += c; + } +} + impl Sub for PreAlpha { type Output = PreAlpha; - fn sub(self, other: PreAlpha) -> PreAlpha { + fn sub(self, other: PreAlpha) -> Self::Output { PreAlpha { color: self.color - other.color, alpha: self.alpha - other.alpha, @@ -230,7 +244,7 @@ impl Sub for PreAlpha { impl> Sub for PreAlpha { type Output = PreAlpha; - fn sub(self, c: T) -> PreAlpha { + fn sub(self, c: T) -> Self::Output { PreAlpha { color: self.color - c, alpha: self.alpha - c, @@ -238,10 +252,25 @@ impl> Sub for PreAlpha { } } +impl SubAssign for PreAlpha { + fn sub_assign(&mut self, other: PreAlpha) { + self.color -= other.color; + self.alpha -= other.alpha; + } +} + +impl> SubAssign for PreAlpha { + fn sub_assign(&mut self, c: T) { + self.color -= c; + self.alpha -= c; + } +} + + impl Mul for PreAlpha { type Output = PreAlpha; - fn mul(self, other: PreAlpha) -> PreAlpha { + fn mul(self, other: PreAlpha) -> Self::Output { PreAlpha { color: self.color * other.color, alpha: self.alpha * other.alpha, @@ -252,7 +281,7 @@ impl Mul for PreAlpha { impl> Mul for PreAlpha { type Output = PreAlpha; - fn mul(self, c: T) -> PreAlpha { + fn mul(self, c: T) -> Self::Output { PreAlpha { color: self.color * c, alpha: self.alpha * c, @@ -260,10 +289,24 @@ impl> Mul for PreAlpha { } } +impl MulAssign for PreAlpha { + fn mul_assign(&mut self, other: PreAlpha) { + self.color *= other.color; + self.alpha *= other.alpha; + } +} + +impl> MulAssign for PreAlpha { + fn mul_assign(&mut self, c: T) { + self.color *= c; + self.alpha *= c; + } +} + impl Div for PreAlpha { type Output = PreAlpha; - fn div(self, other: PreAlpha) -> PreAlpha { + fn div(self, other: PreAlpha) -> Self::Output { PreAlpha { color: self.color / other.color, alpha: self.alpha / other.alpha, @@ -274,7 +317,7 @@ impl Div for PreAlpha { impl> Div for PreAlpha { type Output = PreAlpha; - fn div(self, c: T) -> PreAlpha { + fn div(self, c: T) -> Self::Output { PreAlpha { color: self.color / c, alpha: self.alpha / c, @@ -282,6 +325,20 @@ impl> Div for PreAlpha { } } +impl DivAssign for PreAlpha { + fn div_assign(&mut self, other: PreAlpha) { + self.color /= other.color; + self.alpha /= other.alpha; + } +} + +impl> DivAssign for PreAlpha { + fn div_assign(&mut self, c: T) { + self.color /= c; + self.alpha /= c; + } +} + impl AsRef

for PreAlpha where C: Pixel, diff --git a/palette/src/hsl.rs b/palette/src/hsl.rs index 7ade6277b..b0256d6de 100644 --- a/palette/src/hsl.rs +++ b/palette/src/hsl.rs @@ -3,7 +3,7 @@ use float::Float; use core::any::TypeId; use core::marker::PhantomData; -use core::ops::{Add, Sub}; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use encoding::{Linear, Srgb}; @@ -435,7 +435,7 @@ where { type Output = Hsl; - fn add(self, other: Hsl) -> Hsl { + fn add(self, other: Hsl) -> Self::Output { Hsl { hue: self.hue + other.hue, saturation: self.saturation + other.saturation, @@ -452,7 +452,7 @@ where { type Output = Hsl; - fn add(self, c: T) -> Hsl { + fn add(self, c: T) -> Self::Output { Hsl { hue: self.hue + c, saturation: self.saturation + c, @@ -462,6 +462,30 @@ where } } +impl AddAssign> for Hsl + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, other: Hsl) { + self.hue += other.hue; + self.saturation += other.saturation; + self.lightness += other.lightness; + } +} + +impl AddAssign for Hsl + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, c: T) { + self.hue += c; + self.saturation += c; + self.lightness += c; + } +} + impl Sub> for Hsl where T: Component + Float, @@ -469,7 +493,7 @@ where { type Output = Hsl; - fn sub(self, other: Hsl) -> Hsl { + fn sub(self, other: Hsl) -> Self::Output { Hsl { hue: self.hue - other.hue, saturation: self.saturation - other.saturation, @@ -486,7 +510,7 @@ where { type Output = Hsl; - fn sub(self, c: T) -> Hsl { + fn sub(self, c: T) -> Self::Output { Hsl { hue: self.hue - c, saturation: self.saturation - c, @@ -496,6 +520,30 @@ where } } +impl SubAssign> for Hsl + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, other: Hsl) { + self.hue -= other.hue; + self.saturation -= other.saturation; + self.lightness -= other.lightness; + } +} + +impl SubAssign for Hsl + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, c: T) { + self.hue -= c; + self.saturation -= c; + self.lightness -= c; + } +} + impl AsRef

for Hsl where T: Component + Float, diff --git a/palette/src/hsv.rs b/palette/src/hsv.rs index 26fca96ac..fd147f868 100644 --- a/palette/src/hsv.rs +++ b/palette/src/hsv.rs @@ -3,7 +3,7 @@ use float::Float; use core::any::TypeId; use core::marker::PhantomData; -use core::ops::{Add, Sub}; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use encoding::{Linear, Srgb}; @@ -446,7 +446,7 @@ where { type Output = Hsv; - fn add(self, other: Hsv) -> Hsv { + fn add(self, other: Hsv) -> Self::Output { Hsv { hue: self.hue + other.hue, saturation: self.saturation + other.saturation, @@ -463,7 +463,7 @@ where { type Output = Hsv; - fn add(self, c: T) -> Hsv { + fn add(self, c: T) -> Self::Output{ Hsv { hue: self.hue + c, saturation: self.saturation + c, @@ -473,6 +473,30 @@ where } } +impl AddAssign> for Hsv + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, other: Hsv) { + self.hue += other.hue; + self.saturation += other.saturation; + self.value += other.value; + } +} + +impl AddAssign for Hsv + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, c: T) { + self.hue += c; + self.saturation += c; + self.value += c; + } +} + impl Sub> for Hsv where T: Component + Float, @@ -480,7 +504,7 @@ where { type Output = Hsv; - fn sub(self, other: Hsv) -> Hsv { + fn sub(self, other: Hsv) -> Self::Output { Hsv { hue: self.hue - other.hue, saturation: self.saturation - other.saturation, @@ -497,7 +521,7 @@ where { type Output = Hsv; - fn sub(self, c: T) -> Hsv { + fn sub(self, c: T) -> Self::Output { Hsv { hue: self.hue - c, saturation: self.saturation - c, @@ -507,6 +531,30 @@ where } } +impl SubAssign> for Hsv + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, other: Hsv) { + self.hue -= other.hue; + self.saturation -= other.saturation; + self.value -= other.value; + } +} + +impl SubAssign for Hsv + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, c: T) { + self.hue -= c; + self.saturation -= c; + self.value -= c; + } +} + impl AsRef

for Hsv where T: Component + Float, diff --git a/palette/src/hues.rs b/palette/src/hues.rs index 4df9f77cf..b716317f1 100644 --- a/palette/src/hues.rs +++ b/palette/src/hues.rs @@ -2,7 +2,7 @@ use float::Float; use core::f64::consts::PI; use core::cmp::PartialEq; -use core::ops::{Add, Sub}; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use cast; @@ -150,6 +150,34 @@ macro_rules! make_hues { } } + impl AddAssign<$name> for $name { + #[inline] + fn add_assign(&mut self, other: $name) { + self.0 += other.0; + } + } + + impl AddAssign for $name { + #[inline] + fn add_assign(&mut self, other: T) { + self.0 += other; + } + } + + impl AddAssign<$name> for f32 { + #[inline] + fn add_assign(&mut self, other: $name) { + *self += other.0; + } + } + + impl AddAssign<$name> for f64 { + #[inline] + fn add_assign(&mut self, other: $name){ + *self += other.0; + } + } + impl Sub<$name> for $name { type Output = $name; @@ -185,6 +213,34 @@ macro_rules! make_hues { $name(self - other.0) } } + + impl SubAssign<$name> for $name { + #[inline] + fn sub_assign(&mut self, other: $name) { + self.0 -= other.0; + } + } + + impl SubAssign for $name { + #[inline] + fn sub_assign(&mut self, other: T) { + self.0 -= other; + } + } + + impl SubAssign<$name> for f32 { + #[inline] + fn sub_assign(&mut self, other: $name) { + *self -= other.0; + } + } + + impl SubAssign<$name> for f64 { + #[inline] + fn sub_assign(&mut self, other: $name){ + *self -= other.0; + } + } )+) } diff --git a/palette/src/hwb.rs b/palette/src/hwb.rs index c04816c99..d8f375a88 100644 --- a/palette/src/hwb.rs +++ b/palette/src/hwb.rs @@ -3,7 +3,7 @@ use float::Float; use core::any::TypeId; use core::marker::PhantomData; -use core::ops::{Add, Sub}; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use encoding::Srgb; @@ -363,7 +363,7 @@ where { type Output = Hwb; - fn add(self, other: Hwb) -> Hwb { + fn add(self, other: Hwb) -> Self::Output { Hwb { hue: self.hue + other.hue, whiteness: self.whiteness + other.whiteness, @@ -380,7 +380,7 @@ where { type Output = Hwb; - fn add(self, c: T) -> Hwb { + fn add(self, c: T) -> Self::Output { Hwb { hue: self.hue + c, whiteness: self.whiteness + c, @@ -390,6 +390,30 @@ where } } +impl AddAssign> for Hwb + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, other: Hwb) { + self.hue += other.hue; + self.whiteness += other.whiteness; + self.blackness += other.blackness; + } +} + +impl AddAssign for Hwb + where + T: Component + Float + AddAssign, + S: RgbSpace, +{ + fn add_assign(&mut self, c: T) { + self.hue += c; + self.whiteness += c; + self.blackness += c; + } +} + impl Sub> for Hwb where T: Component + Float, @@ -397,7 +421,7 @@ where { type Output = Hwb; - fn sub(self, other: Hwb) -> Hwb { + fn sub(self, other: Hwb) -> Self::Output { Hwb { hue: self.hue - other.hue, whiteness: self.whiteness - other.whiteness, @@ -414,7 +438,7 @@ where { type Output = Hwb; - fn sub(self, c: T) -> Hwb { + fn sub(self, c: T) -> Self::Output { Hwb { hue: self.hue - c, whiteness: self.whiteness - c, @@ -424,6 +448,31 @@ where } } + +impl SubAssign> for Hwb + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, other: Hwb) { + self.hue -= other.hue; + self.whiteness -= other.whiteness; + self.blackness -= other.blackness; + } +} + +impl SubAssign for Hwb + where + T: Component + Float + SubAssign, + S: RgbSpace, +{ + fn sub_assign(&mut self, c: T) { + self.hue -= c; + self.whiteness -= c; + self.blackness -= c; + } +} + impl AsRef

for Hwb where T: Component + Float, diff --git a/palette/src/lab.rs b/palette/src/lab.rs index 65ec364f6..8ae7af8d3 100644 --- a/palette/src/lab.rs +++ b/palette/src/lab.rs @@ -1,7 +1,7 @@ use float::Float; use core::marker::PhantomData; -use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use white_point::{D65, WhitePoint}; @@ -352,7 +352,7 @@ where { type Output = Lab; - fn add(self, other: Lab) -> Lab { + fn add(self, other: Lab) -> Self::Output { Lab { l: self.l + other.l, a: self.a + other.a, @@ -369,7 +369,7 @@ where { type Output = Lab; - fn add(self, c: T) -> Lab { + fn add(self, c: T) -> Self::Output { Lab { l: self.l + c, a: self.a + c, @@ -379,6 +379,30 @@ where } } +impl AddAssign> for Lab + where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, other: Lab) { + self.l += other.l; + self.a += other.a; + self.b += other.b; + } +} + +impl AddAssign for Lab + where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, c: T) { + self.l += c; + self.a += c; + self.b += c; + } +} + impl Sub> for Lab where T: Component + Float, @@ -386,7 +410,7 @@ where { type Output = Lab; - fn sub(self, other: Lab) -> Lab { + fn sub(self, other: Lab) -> Self::Output { Lab { l: self.l - other.l, a: self.a - other.a, @@ -403,7 +427,7 @@ where { type Output = Lab; - fn sub(self, c: T) -> Lab { + fn sub(self, c: T) -> Self::Output { Lab { l: self.l - c, a: self.a - c, @@ -413,6 +437,30 @@ where } } +impl SubAssign> for Lab + where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, other: Lab) { + self.l -= other.l; + self.a -= other.a; + self.b -= other.b; + } +} + +impl SubAssign for Lab + where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, c: T) { + self.l -= c; + self.a -= c; + self.b -= c; + } +} + impl Mul> for Lab where T: Component + Float, @@ -420,7 +468,7 @@ where { type Output = Lab; - fn mul(self, other: Lab) -> Lab { + fn mul(self, other: Lab) -> Self::Output { Lab { l: self.l * other.l, a: self.a * other.a, @@ -437,7 +485,7 @@ where { type Output = Lab; - fn mul(self, c: T) -> Lab { + fn mul(self, c: T) -> Self::Output { Lab { l: self.l * c, a: self.a * c, @@ -447,6 +495,30 @@ where } } +impl MulAssign> for Lab + where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, other: Lab) { + self.l *= other.l; + self.a *= other.a; + self.b *= other.b; + } +} + +impl MulAssign for Lab + where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, c: T) { + self.l *= c; + self.a *= c; + self.b *= c; + } +} + impl Div> for Lab where T: Component + Float, @@ -454,7 +526,7 @@ where { type Output = Lab; - fn div(self, other: Lab) -> Lab { + fn div(self, other: Lab) -> Self::Output { Lab { l: self.l / other.l, a: self.a / other.a, @@ -471,7 +543,7 @@ where { type Output = Lab; - fn div(self, c: T) -> Lab { + fn div(self, c: T) -> Self::Output { Lab { l: self.l / c, a: self.a / c, @@ -481,6 +553,30 @@ where } } +impl DivAssign> for Lab + where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, other: Lab) { + self.l /= other.l; + self.a /= other.a; + self.b /= other.b; + } +} + +impl DivAssign for Lab + where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, c: T) { + self.l /= c; + self.a /= c; + self.b /= c; + } +} + impl AsRef

for Lab where T: Component + Float, diff --git a/palette/src/lch.rs b/palette/src/lch.rs index c9386ecf0..13b06bf67 100644 --- a/palette/src/lch.rs +++ b/palette/src/lch.rs @@ -1,7 +1,7 @@ use float::Float; use core::marker::PhantomData; -use core::ops::{Add, Sub}; +use core::ops::{Add, AddAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use white_point::{D65, WhitePoint}; @@ -337,7 +337,7 @@ where { type Output = Lch; - fn add(self, other: Lch) -> Lch { + fn add(self, other: Lch) -> Self::Output { Lch { l: self.l + other.l, chroma: self.chroma + other.chroma, @@ -354,7 +354,7 @@ where { type Output = Lch; - fn add(self, c: T) -> Lch { + fn add(self, c: T) -> Self::Output { Lch { l: self.l + c, chroma: self.chroma + c, @@ -364,6 +364,30 @@ where } } +impl AddAssign> for Lch +where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, other: Lch) { + self.l += other.l; + self.chroma += other.chroma; + self.hue += other.hue; + } +} + +impl AddAssign for Lch + where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, c: T) { + self.l += c; + self.chroma += c; + self.hue += c; + } +} + impl Sub> for Lch where T: Component + Float, @@ -371,7 +395,7 @@ where { type Output = Lch; - fn sub(self, other: Lch) -> Lch { + fn sub(self, other: Lch) -> Self::Output { Lch { l: self.l - other.l, chroma: self.chroma - other.chroma, @@ -388,7 +412,7 @@ where { type Output = Lch; - fn sub(self, c: T) -> Lch { + fn sub(self, c: T) -> Self::Output { Lch { l: self.l - c, chroma: self.chroma - c, @@ -398,6 +422,30 @@ where } } +impl SubAssign> for Lch +where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, other: Lch) { + self.l -= other.l; + self.chroma -= other.chroma; + self.hue -= other.hue; + } +} + +impl SubAssign for Lch +where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, c: T) { + self.l -= c; + self.chroma -= c; + self.hue -= c; + } +} + impl AsRef

for Lch where T: Component + Float, diff --git a/palette/src/luma/luma.rs b/palette/src/luma/luma.rs index bb5824ee3..b8e9bae12 100644 --- a/palette/src/luma/luma.rs +++ b/palette/src/luma/luma.rs @@ -1,6 +1,6 @@ use core::fmt; use core::marker::PhantomData; -use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use approx::{AbsDiffEq, RelativeEq, UlpsEq}; @@ -412,6 +412,26 @@ where } } +impl AddAssign> for Luma +where + T: Component + AddAssign, + S: LumaStandard, +{ + fn add_assign(&mut self, other: Luma) { + self.luma += other.luma; + } +} + +impl AddAssign for Luma +where + T: Component + AddAssign, + S: LumaStandard, +{ + fn add_assign(&mut self, c: T) { + self.luma += c; + } +} + impl Sub> for Luma where T: Component + Sub, @@ -444,6 +464,26 @@ where } } +impl SubAssign> for Luma +where + T: Component + SubAssign, + S: LumaStandard, +{ + fn sub_assign(&mut self, other: Luma) { + self.luma -= other.luma; + } +} + +impl SubAssign for Luma +where + T: Component + SubAssign, + S: LumaStandard, +{ + fn sub_assign(&mut self, c: T) { + self.luma -= c; + } +} + impl Mul> for Luma where T: Component + Mul, @@ -476,6 +516,26 @@ where } } +impl MulAssign> for Luma +where + T: Component + MulAssign, + S: LumaStandard, +{ + fn mul_assign(&mut self, other: Luma) { + self.luma *= other.luma; + } +} + +impl MulAssign for Luma +where + T: Component + MulAssign, + S: LumaStandard, +{ + fn mul_assign(&mut self, c: T) { + self.luma *= c; + } +} + impl Div> for Luma where T: Component + Div, @@ -508,6 +568,26 @@ where } } +impl DivAssign> for Luma +where + T: Component + DivAssign, + S: LumaStandard, +{ + fn div_assign(&mut self, other: Luma) { + self.luma /= other.luma; + } +} + +impl DivAssign for Luma +where + T: Component + DivAssign, + S: LumaStandard, +{ + fn div_assign(&mut self, c: T) { + self.luma /= c; + } +} + impl AsRef

for Luma where T: Component, diff --git a/palette/src/rgb/rgb.rs b/palette/src/rgb/rgb.rs index 35ca9eb3a..c5b71fcef 100644 --- a/palette/src/rgb/rgb.rs +++ b/palette/src/rgb/rgb.rs @@ -1,7 +1,7 @@ use core::any::TypeId; use core::fmt; use core::marker::PhantomData; -use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use approx::{AbsDiffEq, RelativeEq, UlpsEq}; use float::Float; @@ -420,6 +420,30 @@ where } } +impl AddAssign> for Rgb +where + S: RgbStandard, + T: Component + AddAssign, +{ + fn add_assign(&mut self, other: Rgb) { + self.red += other.red; + self.green += other.green; + self.blue += other.blue; + } +} + +impl AddAssign for Rgb +where + S: RgbStandard, + T: Component + AddAssign, +{ + fn add_assign(&mut self, c: T) { + self.red += c; + self.green += c; + self.blue += c; + } +} + impl Sub> for Rgb where S: RgbStandard, @@ -456,6 +480,30 @@ where } } +impl SubAssign> for Rgb +where + S: RgbStandard, + T: Component + SubAssign, +{ + fn sub_assign(&mut self, other: Rgb) { + self.red -= other.red; + self.green -= other.green; + self.blue -= other.blue; + } +} + +impl SubAssign for Rgb +where + S: RgbStandard, + T: Component + SubAssign, +{ + fn sub_assign(&mut self, c: T) { + self.red -= c; + self.green -= c; + self.blue -= c; + } +} + impl Mul> for Rgb where S: RgbStandard, @@ -492,6 +540,30 @@ where } } +impl MulAssign> for Rgb +where + S: RgbStandard, + T: Component + MulAssign, +{ + fn mul_assign(&mut self, other: Rgb) { + self.red *= other.red; + self.green *= other.green; + self.blue *= other.blue; + } +} + +impl MulAssign for Rgb +where + S: RgbStandard, + T: Component + MulAssign, +{ + fn mul_assign(&mut self, c: T) { + self.red *= c; + self.green *= c; + self.blue *= c; + } +} + impl Div> for Rgb where S: RgbStandard, @@ -528,6 +600,30 @@ where } } +impl DivAssign> for Rgb +where + S: RgbStandard, + T: Component + DivAssign, +{ + fn div_assign(&mut self, other: Rgb) { + self.red /= other.red; + self.green /= other.green; + self.blue /= other.blue; + } +} + +impl DivAssign for Rgb +where + S: RgbStandard, + T: Component + DivAssign, +{ + fn div_assign(&mut self, c: T) { + self.red /= c; + self.green /= c; + self.blue /= c; + } +} + impl From> for Rgb where S: RgbStandard, diff --git a/palette/src/xyz.rs b/palette/src/xyz.rs index 84ab59859..46da956fa 100644 --- a/palette/src/xyz.rs +++ b/palette/src/xyz.rs @@ -1,7 +1,7 @@ use float::Float; use core::marker::PhantomData; -use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use encoding::pixel::RawPixel; use luma::LumaStandard; @@ -359,7 +359,7 @@ where { type Output = Xyz; - fn add(self, other: Xyz) -> Xyz { + fn add(self, other: Xyz) -> Self::Output { Xyz { x: self.x + other.x, y: self.y + other.y, @@ -376,7 +376,7 @@ where { type Output = Xyz; - fn add(self, c: T) -> Xyz { + fn add(self, c: T) -> Self::Output { Xyz { x: self.x + c, y: self.y + c, @@ -386,6 +386,30 @@ where } } +impl AddAssign> for Xyz +where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, other: Xyz) { + self.x += other.x; + self.y += other.y; + self.z += other.z; + } +} + +impl AddAssign for Xyz +where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, c: T) { + self.x += c; + self.y += c; + self.z += c; + } +} + impl Sub> for Xyz where T: Component + Float, @@ -393,7 +417,7 @@ where { type Output = Xyz; - fn sub(self, other: Xyz) -> Xyz { + fn sub(self, other: Xyz) -> Self::Output { Xyz { x: self.x - other.x, y: self.y - other.y, @@ -410,7 +434,7 @@ where { type Output = Xyz; - fn sub(self, c: T) -> Xyz { + fn sub(self, c: T) -> Self::Output { Xyz { x: self.x - c, y: self.y - c, @@ -420,6 +444,30 @@ where } } +impl SubAssign> for Xyz +where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, other: Xyz) { + self.x -= other.x; + self.y -= other.y; + self.z -= other.z; + } +} + +impl SubAssign for Xyz +where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, c: T) { + self.x -= c; + self.y -= c; + self.z -= c; + } +} + impl Mul> for Xyz where T: Component + Float, @@ -427,7 +475,7 @@ where { type Output = Xyz; - fn mul(self, other: Xyz) -> Xyz { + fn mul(self, other: Xyz) -> Self::Output { Xyz { x: self.x * other.x, y: self.y * other.y, @@ -444,7 +492,7 @@ where { type Output = Xyz; - fn mul(self, c: T) -> Xyz { + fn mul(self, c: T) -> Self::Output { Xyz { x: self.x * c, y: self.y * c, @@ -454,6 +502,30 @@ where } } +impl MulAssign> for Xyz +where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, other: Xyz) { + self.x *= other.x; + self.y *= other.y; + self.z *= other.z; + } +} + +impl MulAssign for Xyz +where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, c: T) { + self.x *= c; + self.y *= c; + self.z *= c; + } +} + impl Div> for Xyz where T: Component + Float, @@ -461,7 +533,7 @@ where { type Output = Xyz; - fn div(self, other: Xyz) -> Xyz { + fn div(self, other: Xyz) -> Self::Output { Xyz { x: self.x / other.x, y: self.y / other.y, @@ -478,7 +550,7 @@ where { type Output = Xyz; - fn div(self, c: T) -> Xyz { + fn div(self, c: T) -> Self::Output { Xyz { x: self.x / c, y: self.y / c, @@ -488,6 +560,30 @@ where } } +impl DivAssign> for Xyz +where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, other: Xyz) { + self.x /= other.x; + self.y /= other.y; + self.z /= other.z; + } +} + +impl DivAssign for Xyz +where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, c: T) { + self.x /= c; + self.y /= c; + self.z /= c; + } +} + impl AsRef

for Xyz where T: Component + Float, diff --git a/palette/src/yxy.rs b/palette/src/yxy.rs index 01f51feee..005920e90 100644 --- a/palette/src/yxy.rs +++ b/palette/src/yxy.rs @@ -1,7 +1,7 @@ use float::Float; use core::marker::PhantomData; -use core::ops::{Add, Div, Mul, Sub}; +use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use clamp; use encoding::pixel::RawPixel; @@ -325,7 +325,7 @@ where { type Output = Yxy; - fn add(self, other: Yxy) -> Yxy { + fn add(self, other: Yxy) -> Self::Output { Yxy { x: self.x + other.x, y: self.y + other.y, @@ -342,7 +342,7 @@ where { type Output = Yxy; - fn add(self, c: T) -> Yxy { + fn add(self, c: T) -> Self::Output { Yxy { x: self.x + c, y: self.y + c, @@ -352,6 +352,30 @@ where } } +impl AddAssign> for Yxy +where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, other: Yxy) { + self.x += other.x; + self.y += other.y; + self.luma += other.luma; + } +} + +impl AddAssign for Yxy +where + T: Component + Float + AddAssign, + Wp: WhitePoint, +{ + fn add_assign(&mut self, c: T) { + self.x += c; + self.y += c; + self.luma += c; + } +} + impl Sub> for Yxy where T: Component + Float, @@ -359,7 +383,7 @@ where { type Output = Yxy; - fn sub(self, other: Yxy) -> Yxy { + fn sub(self, other: Yxy) -> Self::Output { Yxy { x: self.x - other.x, y: self.y - other.y, @@ -376,7 +400,7 @@ where { type Output = Yxy; - fn sub(self, c: T) -> Yxy { + fn sub(self, c: T) -> Self::Output { Yxy { x: self.x - c, y: self.y - c, @@ -386,6 +410,30 @@ where } } +impl SubAssign> for Yxy + where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, other: Yxy) { + self.x -= other.x; + self.y -= other.y; + self.luma -= other.luma; + } +} + +impl SubAssign for Yxy + where + T: Component + Float + SubAssign, + Wp: WhitePoint, +{ + fn sub_assign(&mut self, c: T) { + self.x -= c; + self.y -= c; + self.luma -= c; + } +} + impl Mul> for Yxy where T: Component + Float, @@ -393,7 +441,7 @@ where { type Output = Yxy; - fn mul(self, other: Yxy) -> Yxy { + fn mul(self, other: Yxy) -> Self::Output { Yxy { x: self.x * other.x, y: self.y * other.y, @@ -410,7 +458,7 @@ where { type Output = Yxy; - fn mul(self, c: T) -> Yxy { + fn mul(self, c: T) -> Self::Output { Yxy { x: self.x * c, y: self.y * c, @@ -420,6 +468,30 @@ where } } +impl MulAssign> for Yxy + where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, other: Yxy) { + self.x *= other.x; + self.y *= other.y; + self.luma *= other.luma; + } +} + +impl MulAssign for Yxy + where + T: Component + Float + MulAssign, + Wp: WhitePoint, +{ + fn mul_assign(&mut self, c: T) { + self.x *= c; + self.y *= c; + self.luma *= c; + } +} + impl Div> for Yxy where T: Component + Float, @@ -427,7 +499,7 @@ where { type Output = Yxy; - fn div(self, other: Yxy) -> Yxy { + fn div(self, other: Yxy) -> Self::Output { Yxy { x: self.x / other.x, y: self.y / other.y, @@ -444,7 +516,7 @@ where { type Output = Yxy; - fn div(self, c: T) -> Yxy { + fn div(self, c: T) -> Self::Output { Yxy { x: self.x / c, y: self.y / c, @@ -454,6 +526,30 @@ where } } +impl DivAssign> for Yxy + where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, other: Yxy) { + self.x /= other.x; + self.y /= other.y; + self.luma /= other.luma; + } +} + +impl DivAssign for Yxy + where + T: Component + Float + DivAssign, + Wp: WhitePoint, +{ + fn div_assign(&mut self, c: T) { + self.x /= c; + self.y /= c; + self.luma /= c; + } +} + impl AsRef

for Yxy where T: Component + Float,