Rectangle

Rectangle represents an axis-aligned rectangle defined by a position (x, y) and a size (width, height). It is used for bounding boxes and area checks.

import { Rectangle } from "angry-pixel";

const rect = new Rectangle(0, 0, 32, 32);

Properties

PropertyTypeDescription
xnumberThe x coordinate.
ynumberThe y coordinate.
widthnumberThe width.
heightnumberThe height.
positionVector2The position as a vector.
centerVector2The center point (read-only).

Methods

MethodDescription
set(x, y, width, height)Sets all four values at once.
copy(rectangle)Copies the values from another rectangle.
equals(rectangle)Returns true if both rectangles have the same values.
intersects(rectangle)Returns true if this rectangle overlaps another.
contains(rectangle)Returns true if this rectangle fully contains another rectangle.
contains(vector)Returns true if this rectangle contains a point.
const area = new Rectangle(0, 0, 100, 100);
const point = new Vector2(50, 50);

area.contains(point); // true