Fix bug in largest_square: y direction
We were not taking into account that the largest_square may be constrained by the y position as well as the x. i.e. is there enough vertical space for the square. This commit adds that check. We were working before because C++ is not memory safe, and we weren't running debug builds.
This commit is contained in:
4
main.cc
4
main.cc
@@ -137,7 +137,9 @@ struct Grid {
|
|||||||
if (grid_[b + y(pos) * length_] != '.') { break; }
|
if (grid_[b + y(pos) * length_] != '.') { break; }
|
||||||
++b;
|
++b;
|
||||||
}
|
}
|
||||||
return b - x(pos);
|
auto len = b - x(pos);
|
||||||
|
auto ye = std::min(y(pos) + len, length_);
|
||||||
|
return ye - y(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the next position to check. n is the size of the square we just
|
/** Get the next position to check. n is the size of the square we just
|
||||||
|
|||||||
Reference in New Issue
Block a user