VertexPolygon
Arbitrary polygon as a VertexLoop
Creates a polygon from arbitrary vertices. Optionally redistributes vertices to achieve a specific num_vertices count for morphing compatibility.
Constructor
VertexPolygon(
vertices: Points2D,
closed: bool = True,
auto_close: bool = True,
num_vertices: int | None = None
)
Create a polygon from arbitrary vertices
Parameters
-
vertices - List of (x, y) tuples defining the polygon
-
closed - Whether the polygon is closed
-
auto_close - If True and closed=True, ensures last vertex equals first
-
num_vertices - If provided, redistributes vertices to this count (important for morphing!)
Methods
area
area()
Calculate the signed area of the loop
bounds
bounds()
Calculate bounding box (min_x, min_y, max_x, max_y)
centroid
centroid()
Calculate the centroid (geometric center) of the vertices
is_clockwise
is_clockwise()
Check if the loop has clockwise winding (negative area)
reverse
reverse()
Return a new VertexLoop with reversed vertex order
rotate
rotate(
angle_degrees: float,
center: Point2D | None = None
) -> VertexLoop
Rotate all vertices by angle_degrees around center (default: origin). Returns self for chaining.
scale
scale(sx: float, sy: float | None = None) -> VertexLoop
Scale all vertices by (sx, sy). If sy is None, uses sx for both axes. Returns self for chaining.
translate
translate(dx: float, dy: float) -> VertexLoop
Translate all vertices by (dx, dy). Returns self for chaining.
Properties
closed- Whether this loop is closed
vertices- Get vertices as list of tuples