From 2f3ee8f3028eeaa40bd2058415aa93e454c29e8f Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Sat, 11 Apr 2020 18:24:22 +0100 Subject: [PATCH] use square root instead of constants --- src/main.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70678d3..f5b6447 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,3 @@ -const IMAGE_DIMENSION_SD: usize = 8; -const IMAGE_DIMENSION_HD: usize = 16; - #[derive(Debug, Eq, PartialEq)] struct Colour { red: u8, @@ -114,7 +111,6 @@ struct Game { name: String, version: f64, room_format: u8, - hd: bool, palettes: Vec, variables: Vec, } @@ -310,14 +306,10 @@ fn test_image_from_string() { } fn image_to_string(image: Image) -> String { - image_to_string_opts(image, false) -} - -fn image_to_string_opts(image: Image, hd: bool) -> String { let mut string = String::new(); - let chunk_size = if hd {IMAGE_DIMENSION_HD} else {IMAGE_DIMENSION_SD}; - for line in image.pixels.chunks(chunk_size) { + let sqrt = (room.tiles.len() as f64).sqrt() as usize; // 8 for SD, 16 for HD + for line in image.pixels.chunks(sqrt) { for pixel in line { string.push_str(&format!("{}", *pixel)); }