Image.invert()

This commit is contained in:
Max Bradbury 2020-07-20 21:05:25 +01:00
parent a3ae353830
commit 3ce85fcb5e
1 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,10 @@ pub struct Image {
} }
impl Image { impl Image {
pub fn invert(&mut self) {
self.pixels = self.pixels.iter().map(|pixel| 1 - pixel).collect();
}
/// flip image vertically /// flip image vertically
pub fn flip(&mut self) { pub fn flip(&mut self) {
let mut pixels = Vec::with_capacity(64); let mut pixels = Vec::with_capacity(64);
@ -159,6 +163,14 @@ mod test {
assert_eq!(output, expected); 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] #[test]
fn flip() { fn flip() {
let mut image = crate::mock::image::asymmetrical(); let mut image = crate::mock::image::asymmetrical();