Centroid (mean of vertex positions). Recomputed whenever the vertex set changes.
Read-only view of the current vertex list. Use addPoint/offset/rotate to mutate.
Append a single vertex at (x, y). Mutates and returns this.
New Polygon with the same vertices.
SAT collision against otherPolygon. Both polygons must be convex — SAT silently misses collisions for concave shapes. Pass a non-zero velocity to also compute whether the polygons would intersect after that displacement. Warns and returns a no-collision result if either polygon has zero edges.
Stroke the polygon to context, shifted by offset. Coordinates are truncated to integers (via | 0) for crisp lines.
Translate every vertex by (x, y). Mutates and returns this.
StaticfromTrace an outline around the opaque pixels of canvas via four directional sweeps (top, right, bottom, left). detail is the pixel stride (≥ 2) between scanline samples — higher = faster but coarser. angle is the simplification threshold in radians: vertices whose turn angle wraps to within ±angle of straight are dropped. Throws if fewer than 3 vertices survive.
Convex shapes only. The sweep ignores anything an outer-perimeter ray can't reach: holes (donuts), inward bays (a "C" opening sideways), or any row/column with multiple disjoint opaque spans. For those inputs the result is either a broken polygon or simply the outer hull, and Polygon.collide relies on convexity anyway.
StaticfromStaticfrom
Convex 2D polygon. The collision API (Polygon.collide) uses SAT, which is mathematically defined only for convex polygons — feeding it a concave polygon silently produces wrong results.