MCPcopy Create free account
hub / github.com/axmolengine/axmol / getSquareValue

Method getSquareValue

core/2d/AutoPolygon.cpp:230–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230unsigned int AutoPolygon::getSquareValue(unsigned int x, unsigned int y, const Rect& rect, float threshold)
231{
232 /*
233 checking the 2x2 pixel grid, assigning these values to each pixel, if not transparent
234 +---+---+
235 | 1 | 2 |
236 +---+---+
237 | 4 | 8 | <- current pixel (curx,cury)
238 +---+---+
239 */
240 unsigned int sv = 0;
241 // NOTE: due to the way we pick points from texture, rect needs to be smaller, otherwise it goes outside 1 pixel
242 auto fixedRect = Rect(rect.origin, rect.size - Vec2(2, 2));
243
244 Vec2 tl = Vec2(x - 1.0f, y - 1.0f);
245 sv += (fixedRect.containsPoint(tl) && getAlphaByPos(tl) > threshold) ? 1 : 0;
246 Vec2 tr = Vec2(x - 0.0f, y - 1.0f);
247 sv += (fixedRect.containsPoint(tr) && getAlphaByPos(tr) > threshold) ? 2 : 0;
248 Vec2 bl = Vec2(x - 1.0f, y - 0.0f);
249 sv += (fixedRect.containsPoint(bl) && getAlphaByPos(bl) > threshold) ? 4 : 0;
250 Vec2 br = Vec2(x - 0.0f, y - 0.0f);
251 sv += (fixedRect.containsPoint(br) && getAlphaByPos(br) > threshold) ? 8 : 0;
252 AXASSERT(sv != 0 && sv != 15, "square value should not be 0, or 15");
253 return sv;
254}
255
256std::vector<ax::Vec2> AutoPolygon::marchSquare(const Rect& rect, const Vec2& start, float threshold)
257{

Callers

nothing calls this directly

Calls 3

RectClass · 0.70
Vec2Class · 0.70
containsPointMethod · 0.45

Tested by

no test coverage detected