diff options
author | Nicholas Johnson <nick@nicholasjohnson.ch> | 2024-04-21 00:00:00 +0000 |
---|---|---|
committer | Nicholas Johnson <nick@nicholasjohnson.ch> | 2024-04-21 00:00:00 +0000 |
commit | d901633c75773ffaa8a1eb01cc9539e3f79b3924613e5c89d5f4b0236acf5d7e (patch) | |
tree | 82747f52a12bb7be42497458bde8f25b2d04c959a249ac0fd0cba30da9c6c742 /src | |
parent | 6d65c8d93c02ae7de7bf6bfb59c1ab2bbc9c0679aa98ce580f24c0ed27d7273c (diff) | |
download | hitomezashi-rs-d901633c75773ffaa8a1eb01cc9539e3f79b3924613e5c89d5f4b0236acf5d7e.tar.gz hitomezashi-rs-d901633c75773ffaa8a1eb01cc9539e3f79b3924613e5c89d5f4b0236acf5d7e.zip |
Implement input validation
Diffstat (limited to 'src')
-rw-r--r-- | src/hitomezashi.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/hitomezashi.rs b/src/hitomezashi.rs index 9ec8758..8e2a773 100644 --- a/src/hitomezashi.rs +++ b/src/hitomezashi.rs @@ -36,6 +36,10 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option<f64>) { // skew=0.5 generates the most random-looking patterns let skew: f64 = skew.unwrap_or(0.5); + assert!(width >= 1, "Width must be a positive number!"); + assert!(height >= 1, "Height must be a positive number!"); + assert!(skew >= 0.0 && skew <= 1.0, "Skew must be between zero and one inclusive!"); + let mut rng = rand::thread_rng(); let brn = Bernoulli::new(skew).unwrap(); |