API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classRectangle

@codexo/exojs / math / stable

Mutable axis-aligned rectangle defined by a top-left origin `(x, y)` and dimensions `(width, height)`. Implements Collidable with full SAT collision response for rectangles and polygons, and specialised algorithms for circle and ellipse intersections. `Rectangle.temp` is a shared scratch instance. Edge normals are lazily computed and cached; they are invalidated when position or size mutates. Position and size are reactive components, so EVERY mutation - the accessors here, `set`/`copy`, and a write one level down such as `rect.size.width = 5` - funnels through a single internal notification. Pass `onChange` to be told about all of them: an owner that hands out its live rectangle uses it to run whatever invalidation a direct write implies - a camera's viewport rectangle bumps the camera's update counter this way. clone deliberately does not carry the callback over - a copy is a value, not a second owner. See ReadonlyRectangle for the read-only view engine APIs hand out when they return a live internal rectangle.

12
props
15
methods
0
events
Import
import { Rectangle } from '@codexo/exojs'

Mutable axis-aligned rectangle defined by a top-left origin `(x, y)` and dimensions `(width, height)`. Implements Collidable with full SAT collision response for rectangles and polygons, and specialised algorithms for circle and ellipse intersections.

`Rectangle.temp` is a shared scratch instance. Edge normals are lazily computed and cached; they are invalidated when position or size mutates.

Position and size are reactive components, so EVERY mutation - the accessors here, `set`/`copy`, and a write one level down such as `rect.size.width = 5` - funnels through a single internal notification. Pass `onChange` to be told about all of them: an owner that hands out its live rectangle uses it to run whatever invalidation a direct write implies - a camera's viewport rectangle bumps the camera's update counter this way. clone deliberately does not carry the callback over - a copy is a value, not a second owner.

See ReadonlyRectangle for the read-only view engine APIs hand out when they return a live internal rectangle.

Constructors1
new(x: number, y: number, width: number, height: number, onChange: () => void | null): Rectangle
Methods15
clone(): this
Compute a full CollisionResponse between this shape and target. Returns null in two cases: - the shapes do not overlap, **or** - the specific shape-pair combination does not support response generation (e.g. Line against any shape, Ellipse against Ellipse or Polygon). Use intersectsWith for a universal boolean overlap check that works across all supported shape pairs.
contains(x: number, y: number): boolean
Returns true if the point (x, y) is inside this shape.
containsRect(rect: Rectangle): boolean
Return true when rect is entirely within this rectangle (all four edges inside).
copy(rectangle: Rectangle): this
destroy(): void
equals(__namedParameters: Partial<Rectangle>): boolean
getBounds(out?: Rectangle): Rectangle
The axis-aligned bounding box of this object. Pass out to write into a rectangle you own - every implementer honours it, so this form is always safe to retain and never allocates. Without out, the math shape values (Rectangle, Circle, Polygon, ...) return a **fresh** rectangle, while a node or view that maintains a cached box (see SceneNode.getBounds) returns that cached instance, which the next invalidation overwrites.
Return the outward-facing edge normals used by the SAT solver. The array should be cached and reused across calls.
Test whether this shape overlaps target using a fast boolean algorithm (no penetration depth or normal computed). Prefer this over collidesWith when only the yes/no result is needed.
set(x: number, y: number, width: number, height: number): this
setPosition(x: number, y: number): this
setSize(width: number, height: number): this
Apply a 3×3 affine matrix to all four corners of this rectangle, then return the axis-aligned bounding box of the transformed corners written into result. Defaults to mutating this in place. Returns result.
Properties12
bottom: number
height: number
left: number
position: AbstractVector
right: number
top: number
width: number
x: number
y: number
temp: Rectangle
Source