Vector2

Reference

class Vector2
module:
x: number
y: number
static new(x, y)

Create a new Vector2

Parameters:
  • x (number) – x component

  • y (number) – y component

set(x, y)

Set values

Parameters:
  • x (number) – x component

  • y (number) – y component

get()

Get values

Returns:

x, y component

Return type:

array

sqrMagnitude()

Return the squared magnitude of the vector

Returns:

squared magnitude

Return type:

number

clone()

Create a clone of the vector

Returns:

a new vector

Return type:

Vector2

normalized()

Return the normalized version of this vector

Returns:

the normalized vector

Return type:

Vector2

normalize()

Normalize the vector

static dot(lhs, rhs)

Calculate dot product of 2 vectors

Parameters:
Returns:

the result

Return type:

number

static angle(from, to)

Calculate angle between 2 vectors

Parameters:
Returns:

the angle in degrees

Return type:

number

magnitude()

Calculate the magnitude of the vector

Returns:

the magnitude

Return type:

number

div(d)

Divide this vector by another one. Result is stored in this vector.

Parameters:

d (Vector2) – the divisor

Returns:

returns itself

Return type:

Vector2

mul(d)

Multiply this vector with another one. Result is stored in this vector.

Parameters:

d (Vector2) – the factor

Returns:

returns itself

Return type:

Vector2

add(b)

Adds another vector to this vector. Result is stored in this vector

Parameters:

b (Vector2) – the summand

Returns:

returns itself

Return type:

Vector2

sub(b)

Subtract another vector from this vector. Result is stored in this vector

Parameters:

b (Vector2) – the subtrahend

Returns:

returns itself

Return type:

Vector2

Examples