MCPcopy Create free account
hub / github.com/comaps/comaps / CalcSum

Method CalcSum

generator/cells_merger.cpp:61–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61void 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

Callers

nothing calls this directly

Calls 10

GetFunction · 0.85
TryGetFunction · 0.85
SetBottomLeftMethod · 0.80
GetBottomLeftMethod · 0.80
SetBottomRightMethod · 0.80
GetBottomRightMethod · 0.80
SetTopLeftMethod · 0.80
GetTopLeftMethod · 0.80
SetTopRightMethod · 0.80
GetTopRightMethod · 0.80

Tested by

no test coverage detected