drawPolygon method
Draw a closed polygon provided in counter-clockwise order.
This implementation uses drawSegment to draw each side of the polygon.
Implementation
void drawPolygon(List<Vector2> vertices, Color3i color) {
final vertexCount = vertices.length;
if (vertexCount == 1) {
drawSegment(vertices[0], vertices[0], color);
return;
}
for (var i = 0; i < vertexCount - 1; i += 1) {
drawSegment(vertices[i], vertices[i + 1], color);
}
if (vertexCount > 2) {
drawSegment(vertices[vertexCount - 1], vertices[0], color);
}
}