Iterators are now working far more reliably and have more extensive tests that randomize inputs and fuzz them to check they keep working.

This commit is contained in:
Zed A. Shaw 2024-12-15 19:38:16 -05:00
parent 8e470df554
commit 70cd963e5c
11 changed files with 318 additions and 84 deletions

View file

@ -6,17 +6,20 @@
using std::vector;
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) {
vector<size_t> rows{y - 1, y, y + 1};
vector<size_t> cols{x - 1, x, x + 1};
dbc::check(h == closed.size(), "given height and closed height don't match");
dbc::check(w == closed[0].size(), "given width and closed width don't match");
for(size_t row : rows) {
for(size_t col : cols) {
if((0 <= row && row < h) &&
(0 <= col && col < w) &&
closed[row][col] == 0)
{
vector<int> rows{int(y) - 1, int(y), int(y) + 1};
vector<int> cols{int(x) - 1, int(x), int(x) + 1};
for(int row : rows) {
for(int col : cols) {
if(row < 0 || row >= int(h)) continue;
if(col < 0 || col >= int(w)) continue;
if(closed[row][col] == 0) {
closed[row][col] = 1;
neighbors.push_back({.x=col, .y=row});
neighbors.push_back({.x=size_t(col), .y=size_t(row)});
}
}
}
@ -27,6 +30,12 @@ inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t
*/
void Pathing::compute_paths(Matrix &walls) {
INVARIANT();
dbc::check(walls[0].size() == $width,
fmt::format("Pathing::compute_paths called with walls.width={} but paths $width={}", walls[0].size(), $width));
dbc::check(walls.size() == $height,
fmt::format("Pathing::compute_paths called with walls.height={} but paths $height={}", walls[0].size(), $height));
// Initialize the new array with every pixel at limit distance
matrix::assign($paths, WALL_PATH_LIMIT);