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

Function isConvex

core/2d/DrawNode.cpp:53–73  ·  view source on GitHub ↗

Is a polygon convex? * @param verts A pointer to point coordinates. * @param count The number of verts measured in points. */

Source from the content-addressed store, hash-verified

51 * @param count The number of verts measured in points.
52 */
53static bool isConvex(const Vec2* verts, int count)
54{
55 bool isPositive = false, isNegative = false;
56 for (unsigned int i = 0; i < count; i++)
57 {
58 auto& A = verts[i];
59 auto& B = verts[(i + 1) % count];
60 auto& C = verts[(i + 2) % count];
61
62 double crossProduct = (B.x - A.x) * (C.y - B.y) - (B.y - A.y) * (C.x - B.x);
63
64 if (crossProduct > 0)
65 isPositive = true;
66 else if (crossProduct < 0)
67 isNegative = true;
68
69 if (isPositive && isNegative)
70 return false; // is concave
71 }
72 return true; // is convex
73}
74
75static V2F_C4B_T2F* expandBufferAndGetPointer(axstd::pod_vector<V2F_C4B_T2F>& buffer, size_t count)
76{

Callers 1

_drawPolygonMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected