diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-02-17 00:13:22 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-02-17 00:13:22 +0100 |
commit | a9e8a7ff0e993d946c719b0bea8735483f0e6a2d (patch) | |
tree | ffdceb3ad119d206ba1453d63ee9adb872c0f648 | |
parent | fa4483dc336deafea36768e1e8a804e9d0ae823d (diff) |
Speed up computeBounds
-rw-r--r-- | board.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -160,15 +160,13 @@ const vector<int>& Board::getEdgeCells() const { Bounds Board::computeBounds() const { Bounds bounds; - for (int y = 1; y < BSZ - 1; y++) { - for (int x = 1; x < BSZ - 1; x++) { - int idx = BSZ * y + x; - if (bd[idx] != 0 || checkEdge(idx)) { - bounds.left = min(bounds.left, x); - bounds.right = max(bounds.right, x); - bounds.top = min(bounds.top, y); - bounds.bottom = max(bounds.bottom, y); - } + for (int idx : edgeCells) { + int x = idx % BSZ, y = idx / BSZ; + if (bd[idx] != 0 || checkEdge(idx)) { + bounds.left = min(bounds.left, x); + bounds.right = max(bounds.right, x); + bounds.top = min(bounds.top, y); + bounds.bottom = max(bounds.bottom, y); } } |