API reference

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

C

classPolygon

@codexo/exojs / math / stable

Mutable convex polygon defined by a world-space offset `(x, y)` and an array of local-space vertex Vectors. Implements Collidable with full SAT collision response. Edge vectors are recomputed whenever `setPoints` is called; normals are cached lazily and invalidated on any positional or point mutation. `Polygon.temp` is a shared scratch instance.

6
props
13
methods
0
events
Import
import { Polygon } from '@codexo/exojs'

Mutable convex polygon defined by a world-space offset `(x, y)` and an array of local-space vertex Vectors. Implements Collidable with full SAT collision response.

Edge vectors are recomputed whenever `setPoints` is called; normals are cached lazily and invalidated on any positional or point mutation.

`Polygon.temp` is a shared scratch instance.

Constructors1
Methods13
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.
copy(polygon: Polygon): this
destroy(): void
equals(__namedParameters: Partial<Polygon>): boolean
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.
Returns the edge normals for this polygon. The returned array is cached and reused across calls - the same array reference is returned on consecutive calls when the polygon has not changed. The cache is invalidated automatically when setPoints, setPosition, set, or copy mutate the polygon. This matches the Circle.getNormals() and Sprite.getNormals() behaviour introduced in 0.6.19.
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.
Replace this polygon's vertex array with newPoints. Reuses existing Vector instances where possible to avoid allocation. Recomputes edge vectors and invalidates the normal cache. Returns this for chaining.
setPosition(x: number, y: number): this
Properties6
The precomputed edge vectors (each edge is points[i+1] - points[i]). Updated automatically by setPoints. Read-only - mutating the returned array directly will desync the internal state.
x: number
y: number
Source