Skip to main content

Class: Vec2Math

Defined in: src/sdk/math/VecMath.ts:9

2D vector mathematical operations.

Constructors​

Constructor​

new Vec2Math(): Vec2Math

Returns​

Vec2Math

Methods​

abs()​

static abs(v1): number

Defined in: src/sdk/math/VecMath.ts:134

Gets the magnitude of a vector.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe vector to get the magnitude for.

Returns​

number

the vector's magnitude.


add()​

static add(v1, v2, out): Float64Array

Defined in: src/sdk/math/VecMath.ts:74

Add one vector to another.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe first vector.
v2ReadonlyFloat64ArrayThe second vector.
outFloat64ArrayThe vector to write the results to.

Returns​

Float64Array

the vector sum.


copy()​

static copy(from, to): Float64Array

Defined in: src/sdk/math/VecMath.ts:209

Copies one vector to another.

Parameters​

ParameterTypeDescription
fromReadonlyFloat64ArrayThe vector from which to copy.
toFloat64ArrayThe vector to which to copy.

Returns​

Float64Array

The changed vector.


create()​

Call Signature​

static create(): Float64Array

Defined in: src/sdk/math/VecMath.ts:14

Creates a 2D vector initialized to [0, 0].

Returns​

Float64Array

A new 2D vector initialized to [0, 0].

Call Signature​

static create(x, y): Float64Array

Defined in: src/sdk/math/VecMath.ts:21

Creates a 2D vector with specified x- and y- components.

Parameters​
ParameterTypeDescription
xnumberThe x-component of the new vector.
ynumberThe y-component of the new vector.
Returns​

Float64Array

A new 2D vector with the specified components.


det()​

static det(v1, v2): number

Defined in: src/sdk/math/VecMath.ts:111

Gets the determinant of two vectors.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe first vector.
v2ReadonlyFloat64ArrayThe second vector.

Returns​

number

The determinant of the vectors.


distance()​

static distance(vec1, vec2): number

Defined in: src/sdk/math/VecMath.ts:180

Gets the Euclidean distance between two vectors.

Parameters​

ParameterTypeDescription
vec1ReadonlyFloat64ArrayThe first vector.
vec2ReadonlyFloat64ArrayThe second vector.

Returns​

number

the Euclidean distance between the two vectors.


dot()​

static dot(v1, v2): number

Defined in: src/sdk/math/VecMath.ts:101

Gets the dot product of two vectors.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe first vector.
v2ReadonlyFloat64ArrayThe second vector.

Returns​

number

The dot product of the vectors.


equals()​

static equals(vec1, vec2): boolean

Defined in: src/sdk/math/VecMath.ts:190

Checks if two vectors are equal.

Parameters​

ParameterTypeDescription
vec1ReadonlyFloat64ArrayThe first vector.
vec2ReadonlyFloat64ArrayThe second vector.

Returns​

boolean

Whether the two vectors are equal.


isFinite()​

static isFinite(vec): boolean

Defined in: src/sdk/math/VecMath.ts:199

Checks if a vector is finite. A vector is considered finite if all of its components are finite.

Parameters​

ParameterTypeDescription
vecReadonlyFloat64ArrayThe vector to check.

Returns​

boolean

Whether the specified vector is finite.


multScalar()​

static multScalar(v1, scalar, out): Float64Array

Defined in: src/sdk/math/VecMath.ts:122

Multiplies a vector by a scalar.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe vector to multiply.
scalarnumberThe scalar to apply.
outFloat64ArrayThe vector to write the results to.

Returns​

Float64Array

The scaled vector.


normal()​

static normal(v1, out, counterClockwise): Float64Array

Defined in: src/sdk/math/VecMath.ts:159

Gets the normal of the supplied vector.

Parameters​

ParameterTypeDefault valueDescription
v1ReadonlyFloat64ArrayundefinedThe vector to get the normal for.
outFloat64ArrayundefinedThe vector to write the results to.
counterClockwisebooleanfalseWhether or not to get the counterclockwise normal.

Returns​

Float64Array

the normal vector.


normalize()​

static normalize(v1, out): Float64Array

Defined in: src/sdk/math/VecMath.ts:144

Normalizes the vector to a unit vector.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe vector to normalize.
outFloat64ArrayThe vector to write the results to.

Returns​

Float64Array

the normalized vector.


pointWithinPolygon()​

static pointWithinPolygon(polygon, point): undefined | boolean

Defined in: src/sdk/math/VecMath.ts:220

Checks if a point is within a polygon.

Parameters​

ParameterTypeDescription
polygonReadonly<Omit<Float64Array, "set" | "sort" | "copyWithin">>[]The polygon to check against.
pointFloat64ArrayThe point to test.

Returns​

undefined | boolean

True if the point is within or on the polygon, false otherwise.

Throws​

An error if first and last points in a polygon are not the same.


set()​

static set(x, y, vec): Float64Array

Defined in: src/sdk/math/VecMath.ts:48

Sets the components of a vector.

Parameters​

ParameterTypeDescription
xnumberthe new x-component.
ynumberthe new y-component.
vecFloat64Arraythe vector to change.

Returns​

Float64Array

the vector after it has been changed.


setFromPolar()​

static setFromPolar(r, theta, vec): Float64Array

Defined in: src/sdk/math/VecMath.ts:61

Sets the polar components of a vector.

Parameters​

ParameterTypeDescription
rnumberthe new length (magnitude).
thetanumberthe new polar angle theta, in radians.
vecFloat64Arraythe vector to change.

Returns​

Float64Array

the vector after it has been changed.


sub()​

static sub(v1, v2, out): Float64Array

Defined in: src/sdk/math/VecMath.ts:88

Subtracts one vector from another.

Parameters​

ParameterTypeDescription
v1ReadonlyFloat64ArrayThe first vector.
v2ReadonlyFloat64ArrayThe second vector.
outFloat64ArrayThe vector to write the results to.

Returns​

Float64Array

the vector difference.


theta()​

static theta(vec): number

Defined in: src/sdk/math/VecMath.ts:37

Gets the polar angle theta of a vector in radians.

Parameters​

ParameterTypeDescription
vecReadonlyFloat64Arraya vector.

Returns​

number

the polar angle theta of the vector.