Skip to content

Commit 5d1c746

Browse files
committed
Create filter trait.
1 parent 142ab84 commit 5d1c746

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/bin/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate clap;
55

66
use clap::{Arg, App, AppSettings};
77

8-
use geometrify::RandomPointGenerator;
8+
use geometrify::{RandomPointGenerator, Filter};
99
use geometrify::geometrify::Geometrify;
1010

1111
use image::open;
@@ -67,7 +67,7 @@ fn main() {
6767
);
6868

6969

70-
let outputbuf = filter.apply(sourcebuf);
70+
let outputbuf = filter.apply(&sourcebuf);
7171

7272
outputbuf
7373
.save(&Path::new(matches.value_of("OUTPUT").expect("expected output file")))

src/geometrify.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{Point, BoundingBox, PointGenerator};
1+
use super::{Point, BoundingBox, PointGenerator, Filter};
22
use image::{Rgba, RgbaImage, Pixel};
33

44
use pbr::ProgressBar;
@@ -287,8 +287,10 @@ impl Geometrify {
287287

288288
result
289289
}
290+
}
290291

291-
pub fn apply(&mut self, image: RgbaImage) -> RgbaImage {
292+
impl Filter for Geometrify {
293+
fn apply(&mut self, image: &RgbaImage) -> RgbaImage {
292294
let mut progress = ProgressBar::new(self.iterations as u64);
293295
progress.format("|#--|");
294296

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ extern crate pbr;
55

66
pub mod geometrify;
77

8+
9+
use image::RgbaImage;
810
use rand::Rng;
911

1012
#[derive(Clone, Copy, Debug)]
@@ -54,6 +56,10 @@ impl PointGenerator for RandomPointGenerator {
5456
}
5557
}
5658

59+
pub trait Filter {
60+
fn apply(&mut self, image: &RgbaImage) -> RgbaImage;
61+
}
62+
5763
#[cfg(test)]
5864
mod tests {
5965
#[test]

0 commit comments

Comments
 (0)