diff --git a/CHANGELOG.md b/CHANGELOG.md index 17cb141..011b04a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,10 +3,6 @@ Game store page: https://crispypin.itch.io/marble-machinations ## [unreleased] -## v0.3.1 - 2025-04-05 -### fixed -- broken area calculation causing crash when completing a level with a machine wider than it is tall - ## v0.3.0 - 2025-04-04 ### added - score number: bounding area diff --git a/Cargo.lock b/Cargo.lock index 0481cd8..d4c39b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 4 +version = 3 [[package]] name = "aho-corasick" @@ -213,7 +213,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "marble-machinations" -version = "0.3.1" +version = "0.3.0" dependencies = [ "arboard", "raylib", diff --git a/Cargo.toml b/Cargo.toml index d7d32d7..e184723 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "marble-machinations" -version = "0.3.1" +version = "0.3.0" edition = "2021" default-run = "marble-machinations" diff --git a/src/marble_engine/grid.rs b/src/marble_engine/grid.rs index 63f2f64..1e0bc8d 100644 --- a/src/marble_engine/grid.rs +++ b/src/marble_engine/grid.rs @@ -124,9 +124,9 @@ impl Grid { } pub fn used_bounds_area(&self) -> usize { - let row_clear = |y| { - for x in 0..self.width { - if !self.get_unchecked((x, y).into()).is_blank() { + let row_clear = |a, max, f: fn(usize, usize) -> (usize, usize)| { + for b in 0..max { + if !self.get_unchecked(f(a, b).into()).is_blank() { return false; } } @@ -134,37 +134,29 @@ impl Grid { }; let mut height = self.height; for y in 0..self.height { - if row_clear(y) { + if row_clear(y, self.width, |y, x| (x, y)) { height -= 1; } else { break; } } for y in (0..self.height).rev() { - if row_clear(y) { + if row_clear(y, self.width, |y, x| (x, y)) { height -= 1; } else { break; } } - let col_clear = |x| { - for y in 0..self.height { - if !self.get_unchecked((x, y).into()).is_blank() { - return false; - } - } - true - }; let mut width = self.width; for x in 0..self.width { - if col_clear(x) { + if row_clear(x, self.height, |x, y| (x, y)) { width -= 1; } else { break; } } for x in (0..self.width).rev() { - if col_clear(x) { + if row_clear(x, self.width, |x, y| (x, y)) { width -= 1; } else { break;