diff options
author | Nicholas Johnson <nick@nicholasjohnson.ch> | 2024-04-20 00:00:00 +0000 |
---|---|---|
committer | Nicholas Johnson <nick@nicholasjohnson.ch> | 2024-04-20 00:00:00 +0000 |
commit | 50ba16d9f8d69103b2343424ff6b7e9835d8c318393359573eeb1d8049189aee (patch) | |
tree | f494de478c84f56a6160a964299b70378aea56553198cadd0f14e778e2d59e5e /src | |
parent | eaf3969ee6d74911b8540cacc2d0219482209b98fe625e4322d8a4d869ffab76 (diff) | |
download | hitomezashi-rs-50ba16d9f8d69103b2343424ff6b7e9835d8c318393359573eeb1d8049189aee.tar.gz hitomezashi-rs-50ba16d9f8d69103b2343424ff6b7e9835d8c318393359573eeb1d8049189aee.zip |
Replace hardcoded lengths with capacity() calls
Diffstat (limited to 'src')
-rw-r--r-- | src/hitomezashi.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/hitomezashi.rs b/src/hitomezashi.rs index 155f0b7..b39cace 100644 --- a/src/hitomezashi.rs +++ b/src/hitomezashi.rs @@ -43,19 +43,19 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option<f64>) { let mut row_bits: Vec<bool> = Vec::with_capacity(height - 1); - for _ in 0..(height - 1) { + for _ in 0..row_bits.capacity() { row_bits.push(brn.sample(&mut rng)); } let mut col_bits: Vec<bool> = Vec::with_capacity(width - 1); - for _ in 0..(width - 1) { + for _ in 0..col_bits.capacity() { col_bits.push(brn.sample(&mut rng)); } let mut alt_bits: Vec<bool> = Vec::with_capacity(width); - for col in 0..width { + for col in 0..alt_bits.capacity() { alt_bits.push(col % 2 == 1); } @@ -64,7 +64,7 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option<f64>) { above_bits.push(init_bit); - for col in 0..(width - 1) { + for col in 0..(above_bits.capacity() - 1) { /* each square in the first row is derived from the square to its left. the column bits * represent whether there's a stitch between the two squares. if there's a stitch, the squares * are different, otherwise they are the same. */ @@ -72,7 +72,7 @@ pub fn hitomezashi(width: usize, height: usize, skew: Option<f64>) { above_bits.push(above_bits[col] ^ col_bits[col]); } - print_square(above_bits[width - 1]); + print_square(above_bits[above_bits.capacity() - 1]); println!(); // height-1 because the first row has already been printed |