arcade2d
Class

Rectangle

geometry/rectangle.ts:13

Defines an axis-aligned rectangle as a pure shape, described by its width and height. Like every shape it is positionless; its local space is anchored at the top-left corner 0,0 and extends to width,height. Because the engine uses screen-space coordinates, "top" is the smaller y.

width and height are expected to be non-negative; the edge accessors and containment tests assume this.

Constructors

#
constructor(width: number, height: number): Rectangle

Parameters

  • width number
  • height number

Properties

readonly #
height: number

The height of the rectangle.

readonly #
width: number

The width of the rectangle.

Accessors

readonly #
bottom: number

The y coordinate of the bottom edge.

readonly #
bottomLeft: Readonly

The bottom-left corner.

readonly #
bottomRight: Readonly

The bottom-right corner.

readonly #
left: number

The x coordinate of the left edge (always 0 in local space).

readonly #
top: number

The y coordinate of the top edge (always 0 in local space).

readonly #
topLeft: Readonly

The top-left corner (the local origin).

readonly #
topRight: Readonly

The top-right corner.

Methods

#
containsPoint(point: PointPrimitive): boolean

Determines whether a point lies within this rectangle. The point is expressed in the rectangle's local space (origin at the top-left corner). Points on an edge are treated as contained.

Parameters

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
#
intersects(other: Rectangle, offset: PointPrimitive): boolean

Determines whether this rectangle overlaps another rectangle. Rectangles that touch only at an edge or corner are considered intersecting.

Parameters

Returns

boolean
ESC