Rectangle
geometry/rectangle.ts:13 Extends Polygon<[PointPrimitive, PointPrimitive, PointPrimitive, PointPrimitive]>
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
Properties
points: [PointPrimitive, PointPrimitive, PointPrimitive, PointPrimitive] Accessors
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
-
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 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
-
otherRectangle -
offsetPointPrimitive
Returns
boolean