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 {
|
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();
|
||||||
|
|
Loading…
Reference in New Issue