Skip to main content

Vector3

Defined in: src/lib/math.ts:369

A 3D vector.

Extends

  • BaseVector<Vector3>

Constructors

Constructor

protected new Vector3(_array: Float32Array): Vector3;

Defined in: src/lib/math.ts:46

Parameters

ParameterType
_arrayFloat32Array

Returns

Vector3

Inherited from

BaseVector\<Vector3\>.constructor

Properties

PropertyModifierTypeDefault valueDescriptionInherited fromDefined in
_arrayprotectedFloat32Arrayundefined-Vector2._arraysrc/lib/math.ts:46
_immutableprotectedbooleanfalse-Vector2._immutablesrc/lib/math.ts:44
ONEreadonlyReadonly<Vector3>undefinedA vector with all components set to 1. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying.-src/lib/math.ts:382
ZEROreadonlyReadonly<Vector3>undefinedA vector with all components set to 0. This is a truly immutable constant - any mutation attempt will throw an ImmutableVectorException. Clone before modifying.-src/lib/math.ts:375

Accessors

immutable

Get Signature

get immutable(): boolean;

Defined in: src/lib/math.ts:51

Whether this vector is immutable.

Returns

boolean

Inherited from

BaseVector.immutable

length

Get Signature

get length(): number;

Defined in: src/lib/math.ts:82

Returns

number

Inherited from

BaseVector.length

x

Get Signature

get x(): number;

Defined in: src/lib/math.ts:417

The x coordinate.

Returns

number

Set Signature

set x(value: number): void;

Defined in: src/lib/math.ts:423

Throws

if this vector is immutable.

Parameters
ParameterType
valuenumber
Returns

void


y

Get Signature

get y(): number;

Defined in: src/lib/math.ts:431

The y coordinate.

Returns

number

Set Signature

set y(value: number): void;

Defined in: src/lib/math.ts:437

Throws

if this vector is immutable.

Parameters
ParameterType
valuenumber
Returns

void


z

Get Signature

get z(): number;

Defined in: src/lib/math.ts:445

The z coordinate.

Returns

number

Set Signature

set z(value: number): void;

Defined in: src/lib/math.ts:451

Throws

if this vector is immutable.

Parameters
ParameterType
valuenumber
Returns

void

Methods

_createInstance()

protected _createInstance(array: Float32Array\<ArrayBufferLike\> | number[]): Vector3;

Defined in: src/lib/math.ts:476

Parameters

ParameterType
arrayFloat32Array<ArrayBufferLike> | number[]

Returns

Vector3

Inherit Doc

Overrides

BaseVector._createInstance

_throwIfImmutable()

protected _throwIfImmutable(operation: string): void;

Defined in: src/lib/math.ts:62

Throws an error if this vector is immutable.

Parameters

ParameterTypeDescription
operationstringDescription of the attempted operation for the error message.

Returns

void

Throws

if this vector is immutable.

Inherited from

BaseVector._throwIfImmutable

[iterator]()

iterator: Generator<number, void, unknown>;

Defined in: src/lib/math.ts:350

Make this vector iterable for destructuring.

Returns

Generator<number, void, unknown>

Inherited from

BaseVector.[iterator]

add()

add(other: Vector3): Vector3;

Defined in: src/lib/math.ts:132

Add another vector to this vector.

Parameters

ParameterTypeDescription
otherVector3The vector to add to this vector.

Returns

Vector3

A new vector with the result of the addition.

Throws

if the index is out of bounds.

Inherited from

BaseVector.add

at()

at(index: number): number;

Defined in: src/lib/math.ts:94

Get the value at the given index.

Parameters

ParameterTypeDescription
indexnumberThe index to get the value at.

Returns

number

The value at the given index.

Throws

if the index is out of bounds.

Inherited from

BaseVector.at

clone()

clone(): Vector3;

Defined in: src/lib/math.ts:313

Clone this vector.

Returns

Vector3

A new vector with the same values.

Inherited from

BaseVector.clone

cross()

cross(other: Vector3): Vector3;

Defined in: src/lib/math.ts:463

Calculate the cross product of this vector and another vector.

Parameters

ParameterTypeDescription
otherVector3The vector to calculate the cross product with.

Returns

Vector3

A new vector with the result of the cross product.


distance()

distance(other: Vector3): number;

Defined in: src/lib/math.ts:304

Calculate the distance between this vector and another vector.

Parameters

ParameterTypeDescription
otherVector3The vector to calculate the distance to.

Returns

number

The distance between this vector and the other vector.

Throws

if the index is out of bounds.

Inherited from

BaseVector.distance

div()

div(other: Vector3): Vector3;

Defined in: src/lib/math.ts:199

Divide this vector by another vector.

Parameters

ParameterTypeDescription
otherVector3The vector to divide this vector by.

Returns

Vector3

A new vector with the result of the division.

Throws

if the index is out of bounds.

Throws

if the divisor is zero.

Inherited from

BaseVector.div

dot()

dot(other: Vector3): number;

Defined in: src/lib/math.ts:226

Calculate the dot product of this vector and another vector.

Parameters

ParameterTypeDescription
otherVector3The vector to calculate the dot product with.

Returns

number

The dot product of this vector and the other vector.

Throws

if the index is out of bounds.

Inherited from

BaseVector.dot

equals()

equals(other: Vector3, epsilon: number): boolean;

Defined in: src/lib/math.ts:325

Check if this vector is equal to another vector. (Approximately)

Parameters

ParameterTypeDefault valueDescription
otherVector3undefinedThe vector to check equality with.
epsilonnumber1e-6The epsilon to use for the comparison.

Returns

boolean

True if the vectors are equal, false otherwise.

Inherited from

BaseVector.equals

freeze()

freeze(): Readonly\<T\>;

Defined in: src/lib/math.ts:77

Mark this vector as immutable. Once frozen, any attempt to modify the vector will throw an ImmutableVectorException.

Note: The underlying Float32Array is not itself frozen; only this wrapper instance is. All mutation methods check the immutable flag and will throw.

Returns

Readonly<T>

This vector, frozen and typed as Readonly<T>.

Inherited from

BaseVector.freeze

magnitude()

magnitude(): number;

Defined in: src/lib/math.ts:246

Calculate the magnitude of this vector.

Returns

number

The magnitude of this vector.

Throws

if the index is out of bounds.

Inherited from

BaseVector.magnitude

mul()

mul(other: Vector3): Vector3;

Defined in: src/lib/math.ts:176

Multiply this vector by another vector.

Parameters

ParameterTypeDescription
otherVector3The vector to multiply this vector by.

Returns

Vector3

A new vector with the result of the multiplication.

Throws

if the index is out of bounds.

Inherited from

BaseVector.mul

normalize()

normalize(): Vector3;

Defined in: src/lib/math.ts:265

Normalize this vector.

Returns

Vector3

A new vector with the result of the normalization.

Throws

if the index is out of bounds.

Inherited from

BaseVector.normalize

scale()

scale(scalar: number): Vector3;

Defined in: src/lib/math.ts:283

Scale this vector by a scalar.

Parameters

ParameterTypeDescription
scalarnumberThe scalar to scale this vector by.

Returns

Vector3

A new vector with the result of the scaling.

Throws

if the index is out of bounds.

Inherited from

BaseVector.scale

setAt()

setAt(index: number, value: number): void;

Defined in: src/lib/math.ts:112

Set the value at the given index.

Parameters

ParameterTypeDescription
indexnumberThe index to set the value at.
valuenumberThe value to set at the given index.

Returns

void

Throws

if the index is out of bounds.

Throws

if this vector is immutable.

Inherited from

BaseVector.setAt

sub()

sub(other: Vector3): Vector3;

Defined in: src/lib/math.ts:154

Subtract another vector from this vector.

Parameters

ParameterTypeDescription
otherVector3The vector to subtract from this vector.

Returns

Vector3

A new vector with the result of the subtraction.

Throws

if the index is out of bounds.

Inherited from

BaseVector.sub

create()

static create(
x: number,
y: number,
z: number): Vector3;

Defined in: src/lib/math.ts:410

Create a vector from individual coordinates.

Parameters

ParameterTypeDescription
xnumberThe x coordinate.
ynumberThe y coordinate.
znumberThe z coordinate.

Returns

Vector3

A new vector.


fromRaw()

static fromRaw(array: Float32Array): Vector3;

Defined in: src/lib/math.ts:393

Create a vector from a raw Float32Array.

Parameters

ParameterTypeDescription
arrayFloat32ArrayThe Float32Array to create the vector from (must have length 3).

Returns

Vector3

A new vector.

Throws

if the array is invalid (not length 3 or contains invalid values).