Is a polygon convex? * @param verts A pointer to point coordinates. * @param count The number of verts measured in points. */
| 51 | * @param count The number of verts measured in points. |
| 52 | */ |
| 53 | static 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 | |
| 75 | static V2F_C4B_T2F* expandBufferAndGetPointer(axstd::pod_vector<V2F_C4B_T2F>& buffer, size_t count) |
| 76 | { |