|
|
|
@ -15,8 +15,7 @@ void dump_map(const std::string &msg, Matrix &map) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
|
inline void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
|
size_t h = closed.size(); |
|
|
|
|
size_t w = closed[0].size(); |
|
|
|
|
vector<size_t> rows{j - 1, j, j + 1}; |
|
|
|
@ -35,15 +34,15 @@ void add_neighbors(PairList &neighbors, Matrix &closed, size_t j, size_t i) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
|
size_t h = input_map.size(); |
|
|
|
|
size_t w = input_map[0].size(); |
|
|
|
|
void Map::make_paths() { |
|
|
|
|
size_t h = m_input_map.size(); |
|
|
|
|
size_t w = m_input_map[0].size(); |
|
|
|
|
|
|
|
|
|
// Initialize the new array with every pixel at limit distance
|
|
|
|
|
// NOTE: this is normally ones() * limit
|
|
|
|
|
limit = limit == 0 ? h * w : limit; |
|
|
|
|
int limit = m_limit == 0 ? h * w : m_limit; |
|
|
|
|
Matrix new_arr = Matrix(h, MatrixRow(w, limit)); |
|
|
|
|
Matrix closed = walls_map; |
|
|
|
|
Matrix closed = m_walls_map; |
|
|
|
|
PairList starting_pixels; |
|
|
|
|
PairList open_pixels; |
|
|
|
|
|
|
|
|
@ -51,7 +50,7 @@ Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
|
for(size_t counter = 0; counter < h * w; counter++) { |
|
|
|
|
size_t i = counter % w; |
|
|
|
|
size_t j = counter / w; |
|
|
|
|
if(input_map[j][i] == 0) { |
|
|
|
|
if(m_input_map[j][i] == 0) { |
|
|
|
|
new_arr[j][i] = 0; |
|
|
|
|
closed[j][i] = 1; |
|
|
|
|
starting_pixels.push_back({.j=j,.i=i}); |
|
|
|
@ -79,5 +78,5 @@ Matrix dijkstra_map(Matrix &input_map, Matrix &walls_map, int limit) { |
|
|
|
|
new_arr[sp.j][sp.i] = counter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return new_arr; |
|
|
|
|
m_paths = new_arr; |
|
|
|
|
} |
|
|
|
|