API reference

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

C

classVector

@codexo/exojs / math / stable

Concrete mutable 2D vector with full AbstractVector arithmetic and Collidable collision support (treated as a point collider). `Vector.temp` provides a shared scratch instance for intermediate calculations - never store the reference across frames. `Vector.zero` and `Vector.one` are read-only sentinel constants. The four static factory methods (`add`, `subtract`, `multiply`, `divide`) always allocate a new `Vector`. Instance methods mutate in place and return `this` for chaining.

9
props
30
methods
0
events
Import
import { Vector } from '@codexo/exojs'

Concrete mutable 2D vector with full AbstractVector arithmetic and Collidable collision support (treated as a point collider).

`Vector.temp` provides a shared scratch instance for intermediate calculations - never store the reference across frames. `Vector.zero` and `Vector.one` are read-only sentinel constants.

The four static factory methods (`add`, `subtract`, `multiply`, `divide`) always allocate a new `Vector`. Instance methods mutate in place and return `this` for chaining.

Constructors1
new(x: number, y: number): Vector
Methods30
add(x: number, y: number): this
Add (x, y) to this vector. When y is omitted it defaults to x. Mutates in place and returns this for chaining.
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(vector: Vector): this
cross(vector: T): number
2D cross product (scalar z-component of the 3D cross product) of this vector with vector. A positive value means vector is to the left of this vector.
destroy(): void
distanceTo(vector: T): number
Euclidean distance from this vector's tip to vector's tip.
divide(x: number, y: number): this
Divide components by (x, y). Division is skipped silently when either divisor is zero to avoid NaN. Mutates in place and returns this for chaining.
dot(x: number, y: number): number
Dot product of this vector with (x, y).
equals(__namedParameters: Partial<T>): boolean
Return true when this vector matches all supplied components. Omitting a component skips that comparison, so v.equals({ x: 0 }) checks only the X component.
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.
getNormals(): Vector[]
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.
invert(): this
Negate both components. Mutates in place and returns this for chaining.
max(): number
Return the larger of the two components.
min(): number
Return the smaller of the two components.
multiply(x: number, y: number): this
Multiply components by (x, y). When y is omitted it defaults to x (uniform scale). Mutates in place and returns this for chaining.
normalize(): this
Scale this vector to unit length. No-op when the vector is zero. Mutates in place and returns this for chaining.
perp(): this
Rotate this vector 90° counter-clockwise (left perpendicular): (-y, x). Mutates in place and returns this for chaining.
rperp(): this
Rotate this vector 90° clockwise (right perpendicular): (y, -x). Mutates in place and returns this for chaining.
set(x: number, y: number): this
Set both components. When y is omitted it defaults to x (uniform assignment). Mutates in place and returns this for chaining.
subtract(x: number, y: number): this
Subtract (x, y) from this vector. When y is omitted it defaults to x. Mutates in place and returns this for chaining.
Apply a 3×3 affine matrix to this vector (translation + linear transform). Mutates in place and returns this for chaining.
Apply the inverse of matrix to this vector. Useful for converting a world-space point into the local space defined by matrix. Mutates in place and returns this for chaining.
add(v1: Vector, v2: Vector): Vector
Return a new Vector equal to v1 + v2. Does not mutate either operand.
divide(v1: Vector, v2: Vector): Vector
Return a new Vector equal to the component-wise quotient of v1 / v2. Does not mutate either operand.
multiply(v1: Vector, v2: Vector): Vector
Return a new Vector equal to the component-wise product of v1 and v2. Does not mutate either operand.
subtract(v1: Vector, v2: Vector): Vector
Return a new Vector equal to v1 - v2. Does not mutate either operand.
Properties9
x: number
y: number
one: Vector
zero: Vector
angle: number
Angle of this vector in radians, measured from the positive X-axis (the same convention as PolarVector.phi). Setting this rotates the vector to the new angle while preserving its length. Mutates in place.
length: number
Euclidean magnitude of this vector. Setting rescales the vector to magnitude while preserving its angle. Mutates in place.
lengthSq: number
Squared Euclidean magnitude. Avoids the sqrt - prefer this over length when only relative comparisons are needed.
temp: Vector
Source