Skip to content

Vec2

Defined in: Vec2.ts:11

Immutable 2D vector. All operations return new instances.

new Vec2(x, y): Vec2

Defined in: Vec2.ts:25

number

The x component.

number

The y component.

Vec2

readonly x: number

Defined in: Vec2.ts:27

The x component.

Vec2Like.x


readonly y: number

Defined in: Vec2.ts:29

The y component.

Vec2Like.y


readonly static DOWN: Vec2

Defined in: Vec2.ts:19

Down direction (0, 1) — screen coordinates.


readonly static LEFT: Vec2

Defined in: Vec2.ts:21

Left direction (-1, 0).


readonly static ONE: Vec2

Defined in: Vec2.ts:15

The one vector (1, 1).


readonly static RIGHT: Vec2

Defined in: Vec2.ts:23

Right direction (1, 0).


readonly static UP: Vec2

Defined in: Vec2.ts:17

Up direction (0, -1) — screen coordinates.


readonly static ZERO: Vec2

Defined in: Vec2.ts:13

The zero vector (0, 0).

add(other): Vec2

Defined in: Vec2.ts:33

Add another vector.

Vec2Like

Vec2


angle(): number

Defined in: Vec2.ts:102

Angle of this vector in radians (atan2).

number


cross(other): number

Defined in: Vec2.ts:58

Cross product (z-component of the 3D cross product).

Vec2Like

number


distance(other): number

Defined in: Vec2.ts:80

Euclidean distance to another vector.

Vec2Like

number


distanceSq(other): number

Defined in: Vec2.ts:87

Squared distance to another vector (avoids sqrt).

Vec2Like

number


dot(other): number

Defined in: Vec2.ts:53

Dot product with another vector.

Vec2Like

number


equals(other, epsilon?): boolean

Defined in: Vec2.ts:114

Check equality with optional epsilon tolerance.

Vec2Like

number = EPSILON

boolean


length(): number

Defined in: Vec2.ts:63

Magnitude of this vector.

number


lengthSq(): number

Defined in: Vec2.ts:68

Squared magnitude (avoids sqrt).

number


lerp(other, t): Vec2

Defined in: Vec2.ts:94

Linear interpolation toward another vector.

Vec2Like

number

Vec2


multiply(other): Vec2

Defined in: Vec2.ts:48

Component-wise multiply with another vector.

Vec2Like

Vec2


normalize(): Vec2

Defined in: Vec2.ts:73

Return a unit vector in the same direction. Returns ZERO for zero-length vectors.

Vec2


rotate(radians): Vec2

Defined in: Vec2.ts:107

Rotate this vector by radians.

number

Vec2


scale(scalar): Vec2

Defined in: Vec2.ts:43

Scale by a scalar.

number

Vec2


sub(other): Vec2

Defined in: Vec2.ts:38

Subtract another vector.

Vec2Like

Vec2


toString(): string

Defined in: Vec2.ts:122

String representation.

string


static distance(a, b): number

Defined in: Vec2.ts:132

Euclidean distance between two vectors.

Vec2Like

Vec2Like

number


static fromAngle(radians, length?): Vec2

Defined in: Vec2.ts:127

Create a unit vector from an angle in radians, optionally scaled.

number

number = 1

Vec2


static lerp(a, b, t): Vec2

Defined in: Vec2.ts:139

Linear interpolation between two vectors.

Vec2Like

Vec2Like

number

Vec2