# B.Math.Vector2()

Represents a 2D vector.

To create the object use B.Math.makeVector2().

## CONSTANTS:

ZERO = {x: 0.0, y: 0.0}

Zero vector.

INF = {x: Infinity, y: Infinity}

Positive infinity point.

N_INF = {x: -Infinity, y: -Infinity}

Negative infinity point.

X = {x: 1.0, y: 0.0}

Positive direction along X-axis.

Y = {x: 0.0, y: 1.0}

Positive direction along Y-axis.

N_X = {x: -1.0, y: 0.0}

Negative direction along X-axis.

N_Y = {x: 0.0, y: -1.0}

Negative direction along Y-axis.

{number} x

X component.

{number} y

Y component.

## METHODS:

clone()

Clones this vector to a new vector.

### RETURNS:

this

copy(v)

Copies a given vector into this vector.

### RETURNS:

this

set(x, y)

Sets this vector from separated components.

{number} x

{number} y

### RETURNS:

this

get(index)

Gets an element by its index.

{number} index

{number}

### THROWS:

{Error}

if the index is out of range

fromArray(array, offset)

Sets this vector from a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

toArray(array, offset)

Sets this vector to a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

length()

Calculates the length of this vector.

### RETURNS:

{number}

length

lengthSq()

Calculates the squared length of this vector.

### RETURNS:

{number}

squared length

normalize()

Normalizes this vector.

### RETURNS:

this

negate()

Inverts this vector.

### RETURNS:

this

clamp(minVal, maxVal)

Clamps components of this vector.

### PARAMETERS:

{number} [minVal] = 0.0

{number} [maxVal] = 1.0

### RETURNS:

this

Adds a vector or a scalar to this vector.

### PARAMETERS:

{number | B.Math.Vector2} v

### RETURNS:

this

Adds two given vectors and sets the result to this.

### RETURNS:

this

sub(v)

Subtracts a vector or a scalar from this vector.

### PARAMETERS:

{number | B.Math.Vector2} v

### RETURNS:

this

subVectors(a, b)

Subtracts two given vectors and sets the result to this.

### RETURNS:

this

mul(v)

Multiplies this vector by a given vector or a scalar.

### PARAMETERS:

{number | B.Math.Vector2} v

### RETURNS:

this

mulVectors(a, b)

Multiplies two given vectors and sets the result to this.

### RETURNS:

this

div(v)

Divides this vector by a given vector or a scalar.

### PARAMETERS:

{number | B.Math.Vector2} v

### RETURNS:

this

divVectors(a, b)

Divides two given vectors and sets the result to this.

### RETURNS:

this

dot(v)

Calculates the dot product of this vector and another vector.

### RETURNS:

{number}

dot product

angleTo(v)

Calculates the angle in radians between this vector and another vector.

### RETURNS:

{number}

angle

distanceTo(v)

Calculates the distance between this vector and another vector.

### RETURNS:

{number}

distance

distanceToSq(v)

Calculates the squared distance between this vector and another vector.

### RETURNS:

{number}

squared distance

equal(v)

Checks for strict equality of this vector and another vector.

{boolean}