Image.invert()
This commit is contained in:
parent
a3ae353830
commit
3ce85fcb5e
12
src/image.rs
12
src/image.rs
|
@ -4,6 +4,10 @@ pub struct Image {
|
|||
}
|
||||
|
||||
impl Image {
|
||||
pub fn invert(&mut self) {
|
||||
self.pixels = self.pixels.iter().map(|pixel| 1 - pixel).collect();
|
||||
}
|
||||
|
||||
/// flip image vertically
|
||||
pub fn flip(&mut self) {
|
||||
let mut pixels = Vec::with_capacity(64);
|
||||
|
@ -159,6 +163,14 @@ mod test {
|
|||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invert() {
|
||||
let mut output = crate::mock::image::chequers_1();
|
||||
output.invert();
|
||||
let expected = crate::mock::image::chequers_2();
|
||||
assert_eq!(output, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flip() {
|
||||
let mut image = crate::mock::image::asymmetrical();
|
||||
|
|
Loading…
Reference in New Issue