|
|
|
@ -5,22 +5,11 @@ |
|
|
|
|
|
|
|
|
|
using std::vector; |
|
|
|
|
|
|
|
|
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x, size_t w, size_t h) { |
|
|
|
|
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"); |
|
|
|
|
|
|
|
|
|
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=size_t(col), .y=size_t(row)}); |
|
|
|
|
} |
|
|
|
|
inline void add_neighbors(PointList &neighbors, Matrix &closed, size_t y, size_t x) { |
|
|
|
|
for(matrix::in_box it{closed, x, y, 1}; it.next();) { |
|
|
|
|
if(closed[it.y][it.x] == 0) { |
|
|
|
|
closed[it.y][it.x] = 1; |
|
|
|
|
neighbors.push_back({.x=it.x, .y=it.y}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -56,7 +45,7 @@ void Pathing::compute_paths(Matrix &walls) { |
|
|
|
|
|
|
|
|
|
// Second pass: Add border to open
|
|
|
|
|
for(auto sp : starting_pixels) { |
|
|
|
|
add_neighbors(open_pixels, closed, sp.y, sp.x, $width, $height); |
|
|
|
|
add_neighbors(open_pixels, closed, sp.y, sp.x); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Third pass: Iterate filling in the open list
|
|
|
|
@ -65,7 +54,7 @@ void Pathing::compute_paths(Matrix &walls) { |
|
|
|
|
PointList next_open; |
|
|
|
|
for(auto sp : open_pixels) { |
|
|
|
|
$paths[sp.y][sp.x] = counter; |
|
|
|
|
add_neighbors(next_open, closed, sp.y, sp.x, $width, $height); |
|
|
|
|
add_neighbors(next_open, closed, sp.y, sp.x); |
|
|
|
|
} |
|
|
|
|
open_pixels = next_open; |
|
|
|
|
} |
|
|
|
|