VertexLoop
A sequence of vertices forming an open or closed loop
Provides utilities for geometric operations like centroid, area, and bounds. Can be subclassed for specific geometric primitives.
Constructor
VertexLoop(vertices: Points2D, closed: bool = True)
Initialize a vertex loop
Parameters
-
vertices - List of (x, y) tuples
-
closed - Whether the loop is closed (connects last to first)
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: Optional[Point2D] = None
) -> VertexLoop
Rotate vertices in-place by angle_degrees around center
Parameters
-
angle_degrees - Rotation angle in degrees (positive = counter-clockwise)
-
center - Center of rotation (default is origin) Returns self for method chaining.
scale
scale(sx: float, sy: Optional[float] = None) -> VertexLoop
Scale vertices in-place by (sx, sy)
translate
translate(dx: float, dy: float) -> VertexLoop
Translate vertices in-place by (dx, dy)
Properties
closed- Whether this loop is closed
vertices- Get vertices as list of tuples