Skip to content

Commit a2dc29a

Browse files
committed
Move iterations/samples parameter away from apply method.
1 parent fc75b66 commit a2dc29a

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

src/bin/cli.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,23 @@ fn main() {
5050

5151

5252
let pointgen = Box::new(RandomPointGenerator::new());
53-
let mut filter = Geometrify::new(pointgen);
54-
55-
56-
let outputbuf = filter.apply(
57-
sourcebuf,
53+
let mut filter = Geometrify::new(
54+
pointgen,
5855
matches
5956
.value_of("iterations")
6057
.unwrap_or("100")
61-
.parse::<i32>()
58+
.parse::<u32>()
6259
.expect("invalid iterations parameter"),
6360
matches
6461
.value_of("samples")
6562
.unwrap_or("50")
66-
.parse::<i32>()
63+
.parse::<u32>()
6764
.expect("invalid samples parameter"),
6865
);
6966

67+
68+
let outputbuf = filter.apply(sourcebuf);
69+
7070
outputbuf
7171
.save(&Path::new(matches.value_of("OUTPUT").expect("expected output file")))
7272
.expect("Can't save image");

src/lib.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,25 @@ impl PointGenerator for RandomPointGenerator {
150150

151151
pub struct Geometrify {
152152
point_gen: Box<RandomPointGenerator>,
153+
iterations: u32,
154+
samples: u32,
153155
}
154156

155157
impl Geometrify {
156-
pub fn new(point_gen: Box<RandomPointGenerator>) -> Geometrify {
157-
Geometrify { point_gen: point_gen }
158+
pub fn new(point_gen: Box<RandomPointGenerator>, iterations: u32, samples: u32) -> Geometrify {
159+
Geometrify {
160+
point_gen: point_gen,
161+
iterations: iterations,
162+
samples: samples,
163+
}
164+
}
165+
166+
pub fn set_iterations(&mut self, iterations: u32) {
167+
self.iterations = iterations
168+
}
169+
170+
pub fn set_samples(&mut self, samples: u32) {
171+
self.samples = samples
158172
}
159173

160174
fn calculate_color(image: &RgbaImage, primitive: &Primitive) -> Rgba<u8> {
@@ -321,20 +335,16 @@ impl Geometrify {
321335
result
322336
}
323337

324-
pub fn apply(&mut self,
325-
image: RgbaImage,
326-
number_of_iterations: i32,
327-
number_of_samples: i32)
328-
-> RgbaImage {
329-
let mut progress = ProgressBar::new(number_of_iterations as u64);
338+
pub fn apply(&mut self, image: RgbaImage) -> RgbaImage {
339+
let mut progress = ProgressBar::new(self.iterations as u64);
330340
progress.format("|#--|");
331341

332342
let mut destination = RgbaImage::new(image.width(), image.height());
333343

334-
for _ in 0..number_of_iterations {
344+
for _ in 0..self.iterations {
335345
let difference_lut = Geometrify::calculate_difference_lut(&image, &destination);
336346

337-
let primitives = (0..number_of_samples)
347+
let primitives = (0..self.samples)
338348
.map(|_| self.generate_primitive(image.width(), image.height()))
339349
.map(
340350
|mut p| {

0 commit comments

Comments
 (0)