rename apply to map just like the image crate, one more test
This commit is contained in:
parent
1508a03717
commit
1728b9b2c4
2 changed files with 17 additions and 2 deletions
|
@ -65,7 +65,7 @@ where
|
||||||
P: Send + Sync,
|
P: Send + Sync,
|
||||||
{
|
{
|
||||||
type Unit = P;
|
type Unit = P;
|
||||||
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(mut self, f: F) -> Self {
|
||||||
self.par_pixels_mut().for_each(|p| *p = f(p));
|
self.par_pixels_mut().for_each(|p| *p = f(p));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -186,4 +186,19 @@ mod tests {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod effects {
|
||||||
|
use crate::Bendable;
|
||||||
|
|
||||||
|
use super::super::{Pixel, RgbImage};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn fill_with_funny_number() {
|
||||||
|
let image = RgbImage::new(8, 16);
|
||||||
|
let new_image = image.clone().map(|p| p.map(|_channel| 42u8));
|
||||||
|
assert_ne!(image.clone(), new_image);
|
||||||
|
assert_eq!(42, new_image.get_pixel(1, 2).channels()[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ pub trait Bendable: TryFromDataBytes + IntoDataBytes {
|
||||||
) -> Result<Self, <Self as TryFromDataBytes>::Error> {
|
) -> Result<Self, <Self as TryFromDataBytes>::Error> {
|
||||||
Self::try_from_bytes(b.into_bytes(), format)
|
Self::try_from_bytes(b.into_bytes(), format)
|
||||||
}
|
}
|
||||||
fn apply<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self;
|
fn map<F: Fn(&Self::Unit) -> Self::Unit + Sync>(self, f: F) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait IntoDataBytes: Sized {
|
pub trait IntoDataBytes: Sized {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue