| 59 | } |
| 60 | |
| 61 | void CellsMerger::CalcSum() |
| 62 | { |
| 63 | // Bottom left |
| 64 | for (int32_t x = 0; x <= m_maxX; ++x) |
| 65 | { |
| 66 | for (int32_t y = 0; y <= m_maxY; ++y) |
| 67 | { |
| 68 | if (!Has(x, y)) |
| 69 | continue; |
| 70 | auto & cell = Get(x, y); |
| 71 | cell.SetBottomLeft(std::min({TryGet(x - 1, y).GetBottomLeft(), TryGet(x, y - 1).GetBottomLeft(), |
| 72 | TryGet(x - 1, y - 1).GetBottomLeft()}) + |
| 73 | 1); |
| 74 | } |
| 75 | } |
| 76 | // Bottom right |
| 77 | for (int32_t x = m_maxX; x >= 0; --x) |
| 78 | { |
| 79 | for (int32_t y = 0; y <= m_maxY; ++y) |
| 80 | { |
| 81 | if (!Has(x, y)) |
| 82 | continue; |
| 83 | auto & cell = Get(x, y); |
| 84 | cell.SetBottomRight(std::min({TryGet(x + 1, y).GetBottomRight(), TryGet(x, y - 1).GetBottomRight(), |
| 85 | TryGet(x + 1, y - 1).GetBottomRight()}) + |
| 86 | 1); |
| 87 | } |
| 88 | } |
| 89 | // Top left |
| 90 | for (int32_t x = 0; x <= m_maxX; ++x) |
| 91 | { |
| 92 | for (int32_t y = m_maxY; y >= 0; --y) |
| 93 | { |
| 94 | if (!Has(x, y)) |
| 95 | continue; |
| 96 | auto & cell = Get(x, y); |
| 97 | cell.SetTopLeft( |
| 98 | std::min({TryGet(x - 1, y).GetTopLeft(), TryGet(x, y + 1).GetTopLeft(), TryGet(x - 1, y + 1).GetTopLeft()}) + |
| 99 | 1); |
| 100 | } |
| 101 | } |
| 102 | // Top right |
| 103 | for (int32_t x = m_maxX; x >= 0; --x) |
| 104 | { |
| 105 | for (int32_t y = m_maxY; y >= 0; --y) |
| 106 | { |
| 107 | if (!Has(x, y)) |
| 108 | continue; |
| 109 | auto & cell = Get(x, y); |
| 110 | cell.SetTopRight(std::min({TryGet(x + 1, y).GetTopRight(), TryGet(x, y + 1).GetTopRight(), |
| 111 | TryGet(x + 1, y + 1).GetTopRight()}) + |
| 112 | 1); |
| 113 | } |
| 114 | } |
| 115 | for (auto & pair : m_matrix) |
| 116 | pair.second.CalcSum(); |
| 117 | } |
| 118 |
nothing calls this directly
no test coverage detected