From 220f39feec96c99d0739def7643b6cd09227706e Mon Sep 17 00:00:00 2001 From: jnickg Date: Tue, 11 Jun 2024 14:59:42 -0700 Subject: [PATCH] Switch {map, apply}2_without_alpha Pixel functions to trait defaults - This makes their implementations parallel with {map, apply}_without_alpha implementations - Per PR feedback in #2239 --- src/color.rs | 13 ------------- src/traits.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/color.rs b/src/color.rs index 37249f1b62..496c7b320f 100644 --- a/src/color.rs +++ b/src/color.rs @@ -389,19 +389,6 @@ impl Pixel for $ident { } } - fn map2_without_alpha(&self, other: &Self, f: F) -> $ident where F: FnMut(T, T) -> T { - let mut this = (*self).clone(); - this.apply2_without_alpha(other, f); - this - } - - fn apply2_without_alpha(&mut self, other: &$ident, mut f: F) where F: FnMut(T, T) -> T { - const ALPHA: usize = $channels - $alphas; - for (a, &b) in self.0[..ALPHA].iter_mut().zip(other.0[..ALPHA].iter()) { - *a = f(*a, b) - } - } - fn invert(&mut self) { Invert::invert(self) } diff --git a/src/traits.rs b/src/traits.rs index 8af918b515..62e0779a68 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -375,13 +375,21 @@ pub trait Pixel: Copy + Clone { /// of this pixel and ```other``` pairwise. fn map2_without_alpha(&self, other: &Self, f: F) -> Self where - F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel; + F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel, + { + let mut this = *self; + this.apply2_with_alpha(other, f, |x, _| x); + this + } /// Apply the function ```f``` to each channel except the alpha channel, /// of this pixel and ```other``` pairwise. Works in place. fn apply2_without_alpha(&mut self, other: &Self, f: F) where - F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel; + F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel, + { + self.apply2_with_alpha(other, f, |x, _| x); + } /// Invert this pixel fn invert(&mut self);