Convert largest_square to use pos indices.
This makes the code a bit more confusing but no functional change.
This commit is contained in:
12
main.cc
12
main.cc
@@ -180,16 +180,18 @@ namespace {
|
|||||||
* This means we only need to look for the first non-clear position along the
|
* This means we only need to look for the first non-clear position along the
|
||||||
* current row.
|
* 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.
|
// 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) {
|
while (b < e) {
|
||||||
if (grid_[b + pos_y(pos) * length_] != empty) { break; }
|
if (grid_[b] != empty) { break; }
|
||||||
++b;
|
++b;
|
||||||
}
|
}
|
||||||
// Check that this length fits vertically as well.
|
// Check that this length fits vertically as well.
|
||||||
auto len = b - pos_x(pos);
|
auto const len = b - pos;
|
||||||
auto ye = std::min(pos_y(pos) + len, length_);
|
auto const ye = std::min((pos / length_) + len, length_);
|
||||||
return ye - pos_y(pos);
|
return ye - pos_y(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user