Polygon
geometry/polygon.ts:21Defines a polygon as a pure shape: an ordered ring of vertices in the polygon's own local coordinate space. The polygon has no world position of its own — its vertices are intrinsic shape data, and where the polygon sits in the world is the responsibility of whatever owns it (e.g. a transform). All queries therefore operate in this local space.
The polygon is implicitly closed: the last vertex connects back to the first. Polygons are immutable value objects — the vertex tuple is read-only and derived measurements are computed on demand. Measurements assume a simple (non-self-intersecting) ring; results are undefined otherwise.
The engine uses screen-space coordinates, so y increases downward.
Constructors
Properties
points: TPointTuple Methods
containsPoint(point: PointPrimitive): boolean Determines whether a point lies inside this polygon using a ray-casting
test. The point is expressed in the polygon's local space. Points exactly
on an edge may return either result and should not be relied upon. Always
false for polygons with fewer than three vertices.
Parameters
-
pointPointPrimitive
Returns
boolean getArea(): number Returns the unsigned area enclosed by this polygon, computed via the
shoelace formula. A polygon with fewer than three vertices has an area of
0.
Returns
number getBoundingBox(): Rectangle Returns the size of this polygon's bounding box as a pure Rectangle. Because shapes are positionless, only the extents' width and height are returned; use Polygon.getBounds for the local min/max corners.
Returns
Rectangle getBounds(): PolygonBounds Returns the local-space axis-aligned extents of this polygon. An empty polygon yields zero extents at the origin.
Returns
PolygonBounds getCenter(): Readonly Returns the center of this polygon's bounding box, in local space. This is not the area centroid — see Polygon.getCentroid for the mass-weighted center.
The returned primitive is frozen.
Returns
Readonly getCentroid(): Readonly Returns the area centroid (center of mass) of this polygon, in local space. For polygons with fewer than three vertices, or a degenerate (zero-area) ring, this falls back to the bounding-box center.
The returned primitive is frozen.
Returns
Readonly getPerimeter(): number Returns the total length of this polygon's perimeter, including the
closing edge from the last vertex back to the first. A polygon with fewer
than two vertices has a perimeter of 0.
Returns
number