Skip to content

Commit 42b9fe0

Browse files
author
jnickg
committed
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
1 parent b7b4d9f commit 42b9fe0

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

src/color.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -382,19 +382,6 @@ impl<T: $($bound+)*> Pixel for $ident<T> {
382382
}
383383
}
384384

385-
fn map2_without_alpha<F>(&self, other: &Self, f: F) -> $ident<T> where F: FnMut(T, T) -> T {
386-
let mut this = (*self).clone();
387-
this.apply2_without_alpha(other, f);
388-
this
389-
}
390-
391-
fn apply2_without_alpha<F>(&mut self, other: &$ident<T>, mut f: F) where F: FnMut(T, T) -> T {
392-
const ALPHA: usize = $channels - $alphas;
393-
for (a, &b) in self.0[..ALPHA].iter_mut().zip(other.0[..ALPHA].iter()) {
394-
*a = f(*a, b)
395-
}
396-
}
397-
398385
fn invert(&mut self) {
399386
Invert::invert(self)
400387
}

src/traits.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,21 @@ pub trait Pixel: Copy + Clone {
377377
/// of this pixel and ```other``` pairwise.
378378
fn map2_without_alpha<F>(&self, other: &Self, f: F) -> Self
379379
where
380-
F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel;
380+
F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel
381+
{
382+
let mut this = *self;
383+
this.apply2_with_alpha(other, f, |x, _| x);
384+
this
385+
}
381386

382387
/// Apply the function ```f``` to each channel except the alpha channel,
383388
/// of this pixel and ```other``` pairwise. Works in place.
384389
fn apply2_without_alpha<F>(&mut self, other: &Self, f: F)
385390
where
386-
F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel;
391+
F: FnMut(Self::Subpixel, Self::Subpixel) -> Self::Subpixel
392+
{
393+
self.apply2_with_alpha(other, f, |x, _| x);
394+
}
387395

388396
/// Invert this pixel
389397
fn invert(&mut self);

0 commit comments

Comments
 (0)