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

Commit

Permalink
Fix --m-rand (#46)
Browse files Browse the repository at this point in the history
* Validate m_rand is > 0

Resolves: #45

* Update CHANGELOG
  • Loading branch information
Jake-Shadle authored and mergify[bot] committed Sep 25, 2019
1 parent 0b83409 commit cd3ca52
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Validate that the `--m-rand` / `random_sample_locations` parameter is > 0. [#45](https://github.com/EmbarkStudios/texture-synthesis/issues/45)

## [0.6.0]
### Added
- Added support for the alpha channel during generation, which was previously ignored
Expand Down
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 cd3ca52

Please sign in to comment.