API reference

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

C

classObservableVector

@codexo/exojs / math / stable

An AbstractVector subclass that notifies an owner whenever its components change. Used internally by Rectangle, `SceneNode`, View and other types to invalidate cached state (normals, transforms) on mutation. Instead of a per-instance callback closure, the vector holds a reference to its `owner` plus a numeric `channel` and calls `owner._onObservableChange(channel)` on change. This keeps hot per-node vectors closure-free - a `SceneNode` carries four of these, so dropping the bound closures saves four allocations per node. Pass `owner = null` for a plain, non-reactive vector. Setting individual components (`x`, `y`) notifies only when the value actually changes. Batch mutations via `set()` notify at most once per call. Deliberately has no `clone()`. A clone is a value, not a second notification channel into this vector's owner, so it would have to hand back a plain `Vector` - and importing `Vector` here closes a module-evaluation cycle (`Vector` imports `Rectangle`, which constructs at module scope). Copy explicitly instead: `new Vector(v.x, v.y)`.

5
props
20
methods
0
events
Import
import { ObservableVector } from '@codexo/exojs'

An AbstractVector subclass that notifies an owner whenever its components change. Used internally by Rectangle, `SceneNode`, View and other types to invalidate cached state (normals, transforms) on mutation.

Instead of a per-instance callback closure, the vector holds a reference to its `owner` plus a numeric `channel` and calls `owner._onObservableChange(channel)` on change. This keeps hot per-node vectors closure-free - a `SceneNode` carries four of these, so dropping the bound closures saves four allocations per node. Pass `owner = null` for a plain, non-reactive vector.

Setting individual components (`x`, `y`) notifies only when the value actually changes. Batch mutations via `set()` notify at most once per call.

Deliberately has no `clone()`. A clone is a value, not a second notification channel into this vector's owner, so it would have to hand back a plain `Vector` - and importing `Vector` here closes a module-evaluation cycle (`Vector` imports `Rectangle`, which constructs at module scope). Copy explicitly instead: `new Vector(v.x, v.y)`.

Methods20
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.
copy(vector: AbstractVector): 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.
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.
scale(x: number, y: number): this
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.
Properties5
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.
x: number
y: number
Source