Polygon

open class Polygon(val vertices: List<FlatPoint>) : Composite

Closed loop of straight edges through a cycle of vertices.

The closed sibling of Polyline: N vertices make N edges, the last edge closing back to the first vertex implicitly. Starting vertex and traversal direction are data — the rounded identity of equals distinguishes both. Counter-clockwise winding is the documented convention but is not enforced; to read the actual winding, test signedArea's sign. Convexity is not required: self-intersecting (a pentagram) and self-touching (revisiting a vertex mid-loop — a figure-eight, a slit) loops are legal; only consecutive coincident vertices are rejected at construction.

Throws

When fewer than 3 vertices are given, a vertex lies at infinity, or two consecutive vertices coincide at the SCALE quantum — including the last and first, whose implicit closing edge would collapse.

Constructors

Link copied to clipboard
constructor(vertices: List<FlatPoint>)

Validates the vertex list and throws on degenerate input.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The area centroid — the balance point of the enclosed region — as a finite FlatPoint.

Link copied to clipboard

The edges, one Segment per consecutive vertex pair — N for N vertices, the last edge wrapping back to the first vertex.

Link copied to clipboard

Whether this polygon is inside-out — wound clockwise, its solid region the closed complement of the loop's bounded one.

Link copied to clipboard

The signed area of the loop — raw; positive when the winding is counter-clockwise, negative when clockwise.

Link copied to clipboard

The open Polyline over the same walk.

Link copied to clipboard

The points the loop passes through — finite FlatPoints in traversal order, closing implicitly.

Functions

Link copied to clipboard
infix fun Polygon.collide(collider: Polygon): Penetration?

Polygon collide Polygon => Penetration?
Returns the penetration where this polygon reaches into collider's solid region, or null when the two are clear of each other, touching included.

Link copied to clipboard
infix operator fun Polygon.contains(point: FlatPoint): Boolean

Polygon contains FlatPoint => Boolean
Returns whether the point lies within the polygon's solid region, boundary included.

infix operator fun Polygon.contains(point: RoundPoint): Boolean

Polygon contains RoundPoint => Boolean
Returns whether the point lies within the polygon's solid region, boundary included.

Link copied to clipboard
open fun copy(polygon: Polygon): Polygon

Returns this object rebuilt around the replacement geometry polygon — the hook the shape-preserving operations return through.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Rounded identity over the vertex cycle: equal when the vertex lists match pairwise at the SCALE quantum.

Link copied to clipboard
infix fun Polygon.escape(boundary: Polygon): Penetration?

Polygon escape Polygon => Penetration?
Returns the penetration where this polygon reaches out of boundary's solid region, or null when it lies within, touching included.

Link copied to clipboard
infix fun Polygon.gap(other: Polygon): Segment?

Polygon gap Polygon => Segment?
Returns the shortest segment from this polygon to other — from a point of one boundary to the nearest point of the other's — or null when their solid regions share any point, touching included.

Link copied to clipboard
open override fun hashCode(): Int

Returns the hash of the rounded vertices, consistent with equals.

Link copied to clipboard
infix fun Polygon.intersects(other: Polygon): Boolean

Polygon intersects Polygon => Boolean
Returns whether the two solid regions share any point — touching boundaries count.

infix fun Polygon.intersects(segment: Segment): Boolean

Polygon intersects Segment => Boolean
Returns whether the segment touches the polygon's boundary or lies within its solid region.

infix fun Polygon.intersects(line: Line): Boolean

Polygon intersects Line => Boolean
Returns whether the line reaches the polygon's solid region.

Link copied to clipboard
open override fun toString(): String

Returns the vertices — raw components, full stored precision.

Link copied to clipboard

Returns the vertices rounded at the SCALE quantum — the debug-output convention of every shape.