From 50ba16d9f8d69103b2343424ff6b7e9835d8c318393359573eeb1d8049189aee Mon Sep 17 00:00:00 2001 From: Nicholas Johnson Date: Sat, 20 Apr 2024 00:00:00 +0000 Subject: Replace hardcoded lengths with capacity() calls --- src/hitomezashi.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') 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) { let mut row_bits: Vec = 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 = 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 = 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) { 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) { 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 -- cgit v1.2.3