Convert largest_square to use pos indices.

This makes the code a bit more confusing but no functional change.
This commit is contained in:
2025-09-04 11:09:22 +02:00
parent a066fdb552
commit ed71280dc2

12
main.cc
View File

@@ -180,16 +180,18 @@ namespace {
* This means we only need to look for the first non-clear position along the
* current row.
*/
auto b = pos_x(pos);
auto const pos_x = pos % length_;
auto const pos_y0 = pos - pos_x;
auto b = pos;
// Make sure we don't go looking in the next row.
auto e = std::min(pos_x(pos) + n, length_);
auto const e = std::min(pos + n, pos_y0 + length_);
while (b < e) {
if (grid_[b + pos_y(pos) * length_] != empty) { break; }
if (grid_[b] != empty) { break; }
++b;
}
// Check that this length fits vertically as well.
auto len = b - pos_x(pos);
auto ye = std::min(pos_y(pos) + len, length_);
auto const len = b - pos;
auto const ye = std::min((pos / length_) + len, length_);
return ye - pos_y(pos);
}