Skip to content

Documentation / base / ObservableVector2

Class: ObservableVector2 ​

Defined in: libs/base/src/math/vector.ts:500

Observable 2 dimentional vector

Extends ​

Indexable ​

[index: number]: number

Constructors ​

Constructor ​

new ObservableVector2(x, y): ObservableVector2

Defined in: libs/base/src/math/vector.ts:92

Creates a new Vector2 initialized with values.

Parameters ​

x ​

number

The x component.

y ​

number

The y component.

Returns ​

ObservableVector2

Inherited from ​

Vector2.constructor

Constructor ​

new ObservableVector2(elements): ObservableVector2

Defined in: libs/base/src/math/vector.ts:97

Creates a new Vector2 initialized with values in an array.

Parameters ​

elements ​

number[]

Array that contains the x, y values.

Returns ​

ObservableVector2

Inherited from ​

Vector2.constructor

Constructor ​

new ObservableVector2(array): ObservableVector2

Defined in: libs/base/src/math/vector.ts:102

Creates a new Vector2 initialized with values in a Float32Array.

Parameters ​

array ​

Float32Array<ArrayBuffer>

Float32Array object that contains the x, y values.

Returns ​

ObservableVector2

Inherited from ​

Vector2.constructor

Constructor ​

new ObservableVector2(buffer, offset): ObservableVector2

Defined in: libs/base/src/math/vector.ts:108

Creates a new Vector2 placed on a given ArrayBuffer object.

Parameters ​

buffer ​

ArrayBuffer

The array buffer object.

offset ​

number

The byte offset of the buffer where the vector placed at.

Returns ​

ObservableVector2

Inherited from ​

Vector2.constructor

Constructor ​

new ObservableVector2(): ObservableVector2

Defined in: libs/base/src/math/vector.ts:112

Creates a new Vector2 filled with zero values.

Returns ​

ObservableVector2

Inherited from ​

Vector2.constructor

Accessors ​

magnitude ​

Get Signature ​

get magnitude(): number

Defined in: libs/base/src/math/vector.ts:151

Get the length of the vector.

Returns ​

number

Inherited from ​

Vector2.magnitude


magnitudeSq ​

Get Signature ​

get magnitudeSq(): number

Defined in: libs/base/src/math/vector.ts:155

Get the squared length of the vector.

Returns ​

number

Inherited from ​

Vector2.magnitudeSq


callback ​

Get Signature ​

get callback(): () => void

Defined in: libs/base/src/math/vector.ts:504

The callback function which will be executed when the value changed

Returns ​

() => void

Set Signature ​

set callback(cb): void

Defined in: libs/base/src/math/vector.ts:507

Parameters ​
cb ​

() => void

Returns ​

void


x ​

Get Signature ​

get x(): number

Defined in: libs/base/src/math/vector.ts:518

Get the x component value.

Returns ​

number

Set Signature ​

set x(val): void

Defined in: libs/base/src/math/vector.ts:521

Get the x component value.

Parameters ​
val ​

number

Returns ​

void

Overrides ​

Vector2.x


y ​

Get Signature ​

get y(): number

Defined in: libs/base/src/math/vector.ts:531

Get the y component value.

Returns ​

number

Set Signature ​

set y(val): void

Defined in: libs/base/src/math/vector.ts:534

Get the y component value.

Parameters ​
val ​

number

Returns ​

void

Overrides ​

Vector2.y

Methods ​

equalsTo() ​

equalsTo(other, epsl?): boolean

Defined in: libs/base/src/math/vector.ts:32

Check if all data is close enough to another

Parameters ​

other ​

Float32Array<ArrayBuffer>

The data to be compared with.

epsl? ​

number

Returns ​

boolean

true if close enough, otherwise false.

Inherited from ​

Vector2.equalsTo


toString() ​

toString(): string

Defined in: libs/base/src/math/vector.ts:52

Convert this to string object.

Returns ​

string

Inherited from ​

Vector2.toString


isNaN() ​

isNaN(): boolean

Defined in: libs/base/src/math/vector.ts:61

Check the data for the presence of NaN.

Returns ​

boolean

true if NaN is present, otherwise false.

Inherited from ​

Vector2.isNaN


setRandom() ​

setRandom(minValue, maxValue): void

Defined in: libs/base/src/math/vector.ts:75

Generate random vector

Parameters ​

minValue ​

number

Minimum value of any component of the vector

maxValue ​

number

Maximum value of any component of the vector

Returns ​

void

Inherited from ​

Vector2.setRandom


clone() ​

clone(): Vector2

Defined in: libs/base/src/math/vector.ts:133

Creates a new Vector2 initialized with values from this vector.

Returns ​

Vector2

The new Vector2.

Inherited from ​

Vector2.clone


setAndNormalize() ​

setAndNormalize(x, y): ObservableVector2

Defined in: libs/base/src/math/vector.ts:175

Set component values and then normalize the vector.

Parameters ​

x ​

number

The x component value.

y ​

number

The y component value.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.setAndNormalize


subBy() ​

subBy(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:184

Subtract a vector from this vector.

Parameters ​

other ​

Vector2

The vector that will be subtract.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.subBy


addBy() ​

addBy(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:193

Add a vector to this vector.

Parameters ​

other ​

Vector2

The vector that will be added.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.addBy


combineBy() ​

combineBy(other, t0, t1): ObservableVector2

Defined in: libs/base/src/math/vector.ts:204

Combine a vector to this vector.

Parameters ​

other ​

Vector2

The vector that will be added.

t0 ​

number

Scale factor for this vector

t1 ​

number

Scale factor for other vector

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.combineBy


mulBy() ​

mulBy(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:213

Multiply this vector by a vector.

Parameters ​

other ​

Vector2

The vector that will be multiplied by.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.mulBy


divBy() ​

divBy(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:222

Divide this vector by a vector.

Parameters ​

other ​

Vector2

The vector that will be divide by.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.divBy


scaleBy() ​

scaleBy(f): ObservableVector2

Defined in: libs/base/src/math/vector.ts:231

Scale this vector by a scalar number.

Parameters ​

f ​

number

amount to scale this vector by.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.scaleBy


inplaceNormalize() ​

inplaceNormalize(): ObservableVector2

Defined in: libs/base/src/math/vector.ts:239

Normalize this vector inplace.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.inplaceNormalize


inplaceInverse() ​

inplaceInverse(): ObservableVector2

Defined in: libs/base/src/math/vector.ts:247

Inverse this vector inplace.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.inplaceInverse


inplaceMin() ​

inplaceMin(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:256

Set the component values to the minimum of this vector and another vector.

Parameters ​

other ​

Vector2

The vector that to be compared with.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.inplaceMin


inplaceMax() ​

inplaceMax(other): ObservableVector2

Defined in: libs/base/src/math/vector.ts:265

Set the component values to the maximum of this vector and another vector.

Parameters ​

other ​

Vector2

The vector that to be compared with.

Returns ​

ObservableVector2

self

Inherited from ​

Vector2.inplaceMax


zero() ​

static zero(): Vector2

Defined in: libs/base/src/math/vector.ts:273

Creates a new Vector2 initialized with zero values.

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.zero


one() ​

static one(): Vector2

Defined in: libs/base/src/math/vector.ts:280

Creates a new Vector2 initialized with one.

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.one


axisPX() ​

static axisPX(): Vector2

Defined in: libs/base/src/math/vector.ts:287

Creates a new Vector2 pointing in the positive direction of the X axis, i.e. vec2(1, 0)

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.axisPX


axisNX() ​

static axisNX(): Vector2

Defined in: libs/base/src/math/vector.ts:294

Creates a new Vector2 pointing in the negative direction of the X axis, i.e. vec2(-1, 0)

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.axisNX


axisPY() ​

static axisPY(): Vector2

Defined in: libs/base/src/math/vector.ts:301

Creates a new Vector2 pointing in the positive direction of the Y axis, i.e. vec2(0, 1)

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.axisPY


axisNY() ​

static axisNY(): Vector2

Defined in: libs/base/src/math/vector.ts:308

Creates a new Vector2 pointing in the negative direction of the Y axis, i.e. vec2(0, -1)

Returns ​

Vector2

The new vector

Inherited from ​

Vector2.axisNY


distance() ​

static distance(v1, v2): number

Defined in: libs/base/src/math/vector.ts:317

Calculates the distance between two Vector2's.

Parameters ​

v1 ​

Vector2

The first vector.

v2 ​

Vector2

The second vector.

Returns ​

number

distance between v1 and v2

Inherited from ​

Vector2.distance


distanceSq() ​

static distanceSq(v1, v2): number

Defined in: libs/base/src/math/vector.ts:326

Calculates the squared distance between two Vector2's.

Parameters ​

v1 ​

Vector2

The first vector.

v2 ​

Vector2

The second vector.

Returns ​

number

squared distance between v1 and v2

Inherited from ​

Vector2.distanceSq


normalize() ​

static normalize(v, result?): Vector2

Defined in: libs/base/src/math/vector.ts:337

Normalize a Vector2

Parameters ​

v ​

Vector2

The input vector

result? ​

Vector2

The output vector (can be the same vector as v). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.normalize


inverse() ​

static inverse(v, result?): Vector2

Defined in: libs/base/src/math/vector.ts:349

Inverse a Vector2

Parameters ​

v ​

Vector2

The input vector

result? ​

Vector2

The output vector (can be the same vector as v). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.inverse


sub() ​

static sub(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:361

Subtract two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.sub


add() ​

static add(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:373

Add two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.add


combine() ​

static combine(a, b, t0, t1, result?): Vector2

Defined in: libs/base/src/math/vector.ts:387

Combine two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

t0 ​

number

Scale factor for the first operand

t1 ​

number

Scale factor for the second operand

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.combine


lerp() ​

static lerp(a, b, t, result?): Vector2

Defined in: libs/base/src/math/vector.ts:400

Linearly interpolate between two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

t ​

number

The interpolation factor. The result is equal to a when t = 0 and equal to b when t = 1.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.lerp


mul() ​

static mul(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:412

Multiply two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.mul


div() ​

static div(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:424

Divide two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.div


scale() ​

static scale(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:436

Scale a Vector2 by a scalar number.

Parameters ​

a ​

Vector2

The vector to be scaled.

b ​

number

The scalar number.

result? ​

Vector2

The output vector (can be the same vector as a). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.scale


min() ​

static min(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:448

Calculates the minimum of two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.min


max() ​

static max(a, b, result?): Vector2

Defined in: libs/base/src/math/vector.ts:460

Calculates the maximum of two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.max


abs() ​

static abs(a, result?): Vector2

Defined in: libs/base/src/math/vector.ts:471

Calculates the absolute values of a Vector2.

Parameters ​

a ​

Vector2

The input vector.

result? ​

Vector2

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns ​

Vector2

The output vector

Inherited from ​

Vector2.abs


dot() ​

static dot(a, b): number

Defined in: libs/base/src/math/vector.ts:482

Calculates the dot product of two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

Returns ​

number

dot product of a and b

Inherited from ​

Vector2.dot


cross() ​

static cross(a, b): number

Defined in: libs/base/src/math/vector.ts:491

Calculates the cross product of two Vector2's.

Parameters ​

a ​

Vector2

The first operand.

b ​

Vector2

The second operand.

Returns ​

number

z component of the cross product of the two vectors.

Inherited from ​

Vector2.cross


setCallback() ​

setCallback(cb): ObservableVector2

Defined in: libs/base/src/math/vector.ts:511

Set callback

Parameters ​

cb ​

() => void

Returns ​

ObservableVector2


setXY() ​

setXY(x, y): ObservableVector2

Defined in: libs/base/src/math/vector.ts:544

Set component values.

Parameters ​

x ​

number

The x component value.

y ​

number

The y component value.

Returns ​

ObservableVector2

self

Overrides ​

Vector2.setXY


copyWithin() ​

copyWithin(target, start, end?): ObservableVector2

Defined in: libs/base/src/math/vector.ts:556

Inherited from Float32Array.copyWithin

Parameters ​

target ​

number

start ​

number

end? ​

number

Returns ​

ObservableVector2

Overrides ​

Vector2.copyWithin


fill() ​

fill(value, start?, end?): ObservableVector2

Defined in: libs/base/src/math/vector.ts:564

Inherited from Float32Array.fill

Parameters ​

value ​

number

start? ​

number

end? ​

number

Returns ​

ObservableVector2

Overrides ​

Vector2.fill


reverse() ​

reverse(): ObservableVector2

Defined in: libs/base/src/math/vector.ts:572

Inherited from Float32Array.reverse

Returns ​

ObservableVector2

Overrides ​

Vector2.reverse


set() ​

set(array, offset?): void

Defined in: libs/base/src/math/vector.ts:580

Inherited from Float32Array.set

Parameters ​

array ​

ArrayLike<number>

offset? ​

number

Returns ​

void

Overrides ​

Vector2.set


sort() ​

sort(compareFn?): ObservableVector2

Defined in: libs/base/src/math/vector.ts:587

Inherited from Float32Array.sort

Parameters ​

compareFn? ​

(a, b) => number

Returns ​

ObservableVector2

Overrides ​

Vector2.sort

Released under the MIT License.