Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Validate m_rand is > 0
Browse files Browse the repository at this point in the history
Resolves: #45
  • Loading branch information
Jake-Shadle committed Sep 25, 2019
1 parent 0b83409 commit 4495f49
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ impl<'a> SessionBuilder<'a> {
min: 0.0,
max: 1.0,
value: self.params.cauchy_dispersion,
name: "cauchy_dispersion",
name: "cauchy-dispersion",
}));
}

Expand All @@ -665,7 +665,7 @@ impl<'a> SessionBuilder<'a> {
min: 0.0,
max: 1.0,
value: self.params.backtrack_percent,
name: "backtrack_percent",
name: "backtrack-percent",
}));
}

Expand All @@ -674,7 +674,7 @@ impl<'a> SessionBuilder<'a> {
min: 0.0,
max: 1.0,
value: self.params.guide_alpha,
name: "guide_alpha",
name: "guide-alpha",
}));
}

Expand All @@ -684,11 +684,20 @@ impl<'a> SessionBuilder<'a> {
min: 1.0,
max: 1024.0,
value: max_count as f32,
name: "max_thread_count",
name: "max-thread-count",
}));
}
}

if self.params.random_sample_locations == 0 {
return Err(Error::InvalidRange(errors::InvalidRange {
min: 1.0,
max: 1024.0,
value: self.params.random_sample_locations as f32,
name: "m-rand",
}));
}

Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/multires_stochastic_texture_synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ impl Generator {
k_neighs: &[SignedCoord2D],
example_maps: &[ImageBuffer<'_>],
valid_samples_mask: &[SamplingMethod],
m: u32,
m_rand: u32,
m_seed: u64,
) -> &'a [CandidateStruct] {
let mut candidate_count = 0;
Expand Down Expand Up @@ -589,7 +589,7 @@ impl Generator {
let mut rng = Pcg32::seed_from_u64(m_seed);

//random candidates
for _ in 0..m {
for _ in 0..m_rand {
let rand_map = (rng.gen_range(0, example_maps.len())) as u32;
let dims = example_maps[rand_map as usize].dimensions();
let dims = Dims {
Expand Down

0 comments on commit 4495f49

Please sign in to comment.