arcade2d
Interface

Shape

geometry/shape.types.ts:23

The common contract every pure shape in the geometry package implements — Circle, Rectangle, and Polygon. It exists so code can treat shapes uniformly (measure them, test containment, test overlap, copy them) without switching on the concrete type, which is what the collision and spatial-query layers built on top of geometry need.

Every shape is positionless: its geometry lives in its own local space, and where it sits in the world is the owner's responsibility (a transform / WorldObject). Queries that involve two shapes therefore take a offset — the position of the other shape's local origin relative to this shape's — rather than absolute coordinates.

Note the two-level surface: shapes expose idiomatic conveniences beyond this contract (a circle's diameter, a rectangle's right/bottomLeft), while these methods are the uniform, polymorphic core shared by all of them.

Methods

#
clone(): Shape

Returns an independent copy of this shape.

Returns

Shape
#
containsPoint(point: PointPrimitive): boolean

Whether a point lies inside the shape. The point is expressed in the shape's own local space. Edge behaviour is shape-specific — see each implementation.

Parameters

Returns

boolean
#
getArea(): number

The unsigned area the shape encloses, in square local units.

Returns

number
#
getBoundingBox(): Rectangle

The smallest axis-aligned Rectangle that fully contains the shape, as a positionless size (width × height).

Returns

Rectangle
#
getPerimeter(): number

The length of the shape's outline (a circle's circumference, a polygon's perimeter including the closing edge).

Returns

number
#
intersects(other: Shape, offset: PointPrimitive): boolean

Whether this shape overlaps other. Shapes that touch at a single point or edge count as intersecting. Assumes convex shapes; results for a concave Polygon are undefined.

Parameters

Returns

boolean
ESC