@@ -107,29 +107,36 @@ void TopologyClassifier::accountTopology(uint16_t bitmask, uint16_t minRow, uint
107107 return ;
108108 }
109109
110+ // Calculate total active digits in the cluster mask
111+ int firedDigits = 0 ;
112+ for (int r = minRow; r <= maxRow; ++r) {
113+ for (int c = minCol; c <= maxCol; ++c) {
114+ if (hasDigit (r, c)) firedDigits++;
115+ }
116+ }
117+
118+ // Square and rectangles: all pixels fired
119+ if (firedDigits == spanRow * spanCol && spanRow == spanCol) {
120+ newTopo.mTopology = Topologies::kSquare ;
121+ mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
122+ return ;
123+ }
124+ if (firedDigits == spanRow * spanCol && spanRow != spanCol) {
125+ newTopo.mTopology = Topologies::kRectangle ;
126+ mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
127+ return ;
128+ }
129+
110130 // Corner occupancy
111- const bool hasTopLeft = hasDigit (minRow, minCol);
112- const bool hasTopRight = hasDigit (minRow, maxCol);
113- const bool hasBottomLeft = hasDigit (maxRow, minCol);
114- const bool hasBottomRight = hasDigit (maxRow, maxCol);
131+ const bool hasBottomLeft = hasDigit (minRow, minCol);
132+ const bool hasBottomRight = hasDigit (minRow, maxCol);
133+ const bool hasTopLeft = hasDigit (maxRow, minCol);
134+ const bool hasTopRight = hasDigit (maxRow, maxCol);
115135
116- // Diagonal and square
136+ // Diagonal and triangles
117137 if (spanRow == spanCol) {
118138
119- if ((hasTopLeft && hasBottomRight && !hasTopRight && !hasBottomLeft) ||
120- (!hasTopLeft && !hasBottomRight && hasTopRight && hasBottomLeft)) {
121- newTopo.mTopology = Topologies::kDiagonal ;
122- mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
123- return ;
124- }
125-
126- if (hasTopLeft && hasTopRight && hasBottomLeft && hasBottomRight) {
127- newTopo.mTopology = Topologies::kSquare ;
128- mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
129- return ;
130- }
131-
132- // Triangles (exactly one missing corner)
139+ // Triangles
133140 const int nCorners = hasTopLeft + hasTopRight + hasBottomLeft + hasBottomRight;
134141 if (nCorners == 3 ) {
135142 const int missing = !hasTopLeft ? 0 : !hasTopRight ? 1 : !hasBottomLeft ? 2 : 3 ;
@@ -143,21 +150,28 @@ void TopologyClassifier::accountTopology(uint16_t bitmask, uint16_t minRow, uint
143150 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
144151 return ;
145152 }
153+
154+ if ((firedDigits == spanRow && hasTopLeft && hasBottomRight && !hasTopRight && !hasBottomLeft) ||
155+ (firedDigits == spanRow && hasTopRight && hasBottomLeft && !hasTopLeft && !hasBottomRight)) {
156+ newTopo.mTopology = Topologies::kDiagonal ;
157+ mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
158+ return ;
159+ }
146160 }
147161
148162 // Snake: 3 x 2
149163 if (spanRow == 3 && spanCol == 2 ) {
150- const bool hasMiddleMin = hasDigit (minRow + 1 , minCol );
151- const bool hasMiddleMax = hasDigit (minRow + 1 , maxCol );
164+ const bool hasMiddleMin = hasDigit (minRow, minCol + 1 );
165+ const bool hasMiddleMax = hasDigit (minRow, maxCol + 1 );
152166
153167 if (hasMiddleMin && hasMiddleMax) {
154- if (hasTopLeft && hasBottomRight) {
168+ if (! hasTopLeft && ! hasBottomRight && hasTopRight && hasBottomLeft ) {
155169 newTopo.mTopology = Topologies::kSnake ;
156170 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
157171 return ;
158172 }
159173
160- if (! hasTopLeft && ! hasBottomRight) {
174+ if (hasTopLeft && hasBottomRight && !hasTopRight && !hasBottomLeft ) {
161175 newTopo.mTopology = Topologies::kSnakeRefl ;
162176 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
163177 return ;
@@ -167,17 +181,17 @@ void TopologyClassifier::accountTopology(uint16_t bitmask, uint16_t minRow, uint
167181
168182 // Snake rotated by 90 degrees: 2 x 3
169183 if (spanRow == 2 && spanCol == 3 ) {
170- const bool hasMiddleLeft = hasDigit (minRow, minCol + 1 );
171- const bool hasMiddleRight = hasDigit (maxRow, minCol + 1 );
184+ const bool hasMiddleLeft = hasDigit (minRow + 1 , minCol );
185+ const bool hasMiddleRight = hasDigit (maxRow + 1 , minCol );
172186
173187 if (hasMiddleLeft && hasMiddleRight) {
174- if (hasTopLeft && hasBottomRight) {
188+ if (! hasTopLeft && ! hasBottomRight && hasTopRight && hasBottomLeft ) {
175189 newTopo.mTopology = Topologies::kSnakeRot90 ;
176190 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
177191 return ;
178192 }
179193
180- if (! hasTopLeft && ! hasBottomRight) {
194+ if (hasTopLeft && hasBottomRight && !hasTopRight && !hasBottomLeft ) {
181195 newTopo.mTopology = Topologies::kSnakeRot90Refl ;
182196 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
183197 return ;
@@ -190,7 +204,6 @@ void TopologyClassifier::accountTopology(uint16_t bitmask, uint16_t minRow, uint
190204 mTopologyCache [packKey (spanRow, spanCol, bitmask)] = newTopo;
191205 return ;
192206 }
193- // Insert in map
194207}
195208
196209
0 commit comments