Class: Vector

Vector


new Vector()

The Vector object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
Prefer Vector.create for new instances.

Source:

Members


x :Number

Type:
Source:

y :Number

Type:
Source:

Methods


<static> create( [x] [, y])

Create a vecotr instance. This is prefered than new Vector() since
the instance may come from the pool.

Parameters:
Name Type Argument Description
x number <optional>

Position of the point on the x axis

y number <optional>

Position of the point on the y axis

Source:
Returns:

Vector instance

Type
Vector

<static> recycle(vector)

Recycle a Vector instance into the pool for later use.

Parameters:
Name Type Description
vector Vector

Vector instance to be recycled.

Source:
See:

add(x [, y])

Add to vector values.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to add to self.

y number <optional>

Number to add to y.

Source:
Returns:

Self for chaining.

Type
Vector

angle( [vector])

Get angle vector angle or angle between two vectors.

Parameters:
Name Type Argument Description
vector Vector <optional>

Target vector to calculate with, angle of self is returned when it is not provided.

Source:
Returns:

Angle between self and target.

Type
number

angleFromOrigin(vector)

Get angle between two vectors from origin.

Parameters:
Name Type Description
vector Vector

The vector to calculate angle from.

Source:
Returns:

Angle.

Type
number

clone()

Clone this vector.

Source:
Returns:

The cloned vector.

Type
Vector

copy(v)

Copy values from another vector.

Parameters:
Name Type Description
v Vector

Vector to copy from.

Source:
Returns:

Self for chaining.

Type
Vector

distance(vector)

Get distance of two vectors.

Parameters:
Name Type Description
vector Vector

Target vector to calculate distance from.

Source:
Returns:

Distance.

Type
number

divide(x [, y])

Divide self by another vector or 2 numbers.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to divide.

y number <optional>

Number to divide by.

Source:
Returns:

Self for chaining.

Type
Vector

dot( [vector])

Dot operation with another vector.

Parameters:
Name Type Argument Description
vector Vector <optional>

Vector to dot with.

Source:
Returns:

Result of dot operation.

Type
number

dotNormalized( [vector])

Get normalized dot of vector.

Parameters:
Name Type Argument Description
vector Vector <optional>

Vector to dot with

Source:
Returns:

Result of the dot operation.

Type
number

equals(vector)

Returns true if the given point is equal to this point

Parameters:
Name Type Description
vector Vector

Vector to compare to.

Source:
Returns:

Whether the two vectors are equal

Type
boolean

length()

Get length of vector.

Source:
Returns:

Length of this vector.

Type
number

limit(vector)

Limit vector values.

Parameters:
Name Type Description
vector Vector

Clamp this vector to a limitation(vector)

Source:
Returns:

Self for chaining.

Type
Vector

multiply(x [, y])

Multiply self with another vector or 2 numbers.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to multiply.

y number <optional>

Number to multiply to y.

Source:
Returns:

Self for chaining.

Type
Vector

normalize()

Normalize vector.

Source:
Returns:

Self for chaining

Type
Vector

perp()

Change this vector to be perpendicular to what it was before. (Effectively
roatates it 90 degrees in a clockwise direction)

Source:
Returns:

Self for chaining.

Type
Vector

project(other)

Project this vector on to another vector.

Parameters:
Name Type Description
other Vector

The vector to project onto

Source:
Returns:

Self for chaining.

Type
Vector

projectN(other)

Project this vector onto a vector of unit length. This is slightly more efficient
than project when dealing with unit vectors.

Parameters:
Name Type Description
other Vector

The unit vector to project onto

Source:
Returns:

Self for chaining.

Type
Vector

reflect(axis)

Reflect this vector on an arbitrary axis.

Parameters:
Name Type Description
axis Vector

The vector representing the axis

Source:
Returns:

Self for chaining.

Type
Vector

reflectN(axis)

Reflect this vector on an arbitrary axis (represented by a unit vector). This is
slightly more efficient than reflect when dealing with an axis that is a unit vector.

Parameters:
Name Type Description
axis Vector

The unit vector representing the axis

Source:
Returns:

Self for chaining.

Type
Vector

reverse()

Reverse this vector

Source:
Returns:

Self for chaining.

Type
Vector

rotate(angle)

Rotate vector in radians.

Parameters:
Name Type Description
angle number

Angle to rotate.

Source:
Returns:

Self for chaining.

Type
Vector

round()

Round vector values.

Source:
Returns:

Self for chaining

Type
Vector

set( [x] [, y])

Set vector values.

Parameters:
Name Type Argument Default Description
x number <optional>
0

Position of the point on the x axis

y number <optional>
0

Position of the point on the y axis

Source:
Returns:

Vector itself for chaining.

Type
Vector

sign(vector)

Check whether the direction from self to other vector is clockwise.

Parameters:
Name Type Description
vector Vector

Vector to calculate from

Source:
Returns:

Result (1 = CW, -1 = CCW)

Type
number

squaredDistance(vector)

Get squared euclidian distance of two vectors.

Parameters:
Name Type Description
vector Vector

Target vector to calculate distance from.

Source:
Returns:

Squared distance value.

Type
number

squaredLength()

Get squared length of vector.

Source:
Returns:

Squared length of this vector.

Type
number

subtract(x [, y])

Subtract from vector values.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to subtract from.

y number <optional>

Number to subtract from y.

Source:
Returns:

Self for chaining.

Type
Vector

Class: Vector

Vector


new Vector( [x] [, y])

Parameters:
Name Type Argument Default Description
x Number <optional>
0

X coordinate

y Number <optional>
0

Y coordinate

Source:

Members


x :Number

Type:
Source:

y :Number

Type:
Source:

Methods


<static> create( [x] [, y])

Create a vecotr instance. This is prefered than new Vector() since
the instance may come from the pool.

Parameters:
Name Type Argument Description
x number <optional>

Position of the point on the x axis

y number <optional>

Position of the point on the y axis

Source:
Returns:

Vector instance

Type
Vector

<static> recycle(vector)

Recycle a Vector instance into the pool for later use.

Parameters:
Name Type Description
vector Vector

Vector instance to be recycled.

Source:
See:

add(x [, y])

Add to vector values.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to add to self.

y number <optional>

Number to add to y.

Source:
Returns:

Self for chaining.

Type
Vector

angle( [vector])

Get angle vector angle or angle between two vectors.

Parameters:
Name Type Argument Description
vector Vector <optional>

Target vector to calculate with, angle of self is returned when it is not provided.

Source:
Returns:

Angle between self and target.

Type
number

angleFromOrigin(vector)

Get angle between two vectors from origin.

Parameters:
Name Type Description
vector Vector

The vector to calculate angle from.

Source:
Returns:

Angle.

Type
number

clone()

Clone this vector.

Source:
Returns:

The cloned vector.

Type
Vector

copy(v)

Copy values from another vector.

Parameters:
Name Type Description
v Vector

Vector to copy from.

Source:
Returns:

Self for chaining.

Type
Vector

distance(vector)

Get distance of two vectors.

Parameters:
Name Type Description
vector Vector

Target vector to calculate distance from.

Source:
Returns:

Distance.

Type
number

divide(x [, y])

Divide self by another vector or 2 numbers.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to divide.

y number <optional>

Number to divide by.

Source:
Returns:

Self for chaining.

Type
Vector

dot( [vector])

Dot operation with another vector.

Parameters:
Name Type Argument Description
vector Vector <optional>

Vector to dot with.

Source:
Returns:

Result of dot operation.

Type
number

dotNormalized( [vector])

Get normalized dot of vector.

Parameters:
Name Type Argument Description
vector Vector <optional>

Vector to dot with

Source:
Returns:

Result of the dot operation.

Type
number

equals(vector)

Returns true if the given point is equal to this point

Parameters:
Name Type Description
vector Vector

Vector to compare to.

Source:
Returns:

Whether the two vectors are equal

Type
boolean

length()

Get length of vector.

Source:
Returns:

Length of this vector.

Type
number

limit(vector)

Limit vector values.

Parameters:
Name Type Description
vector Vector

Clamp this vector to a limitation(vector)

Source:
Returns:

Self for chaining.

Type
Vector

multiply(x [, y])

Multiply self with another vector or 2 numbers.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to multiply.

y number <optional>

Number to multiply to y.

Source:
Returns:

Self for chaining.

Type
Vector

normalize()

Normalize vector.

Source:
Returns:

Self for chaining

Type
Vector

perp()

Change this vector to be perpendicular to what it was before. (Effectively
roatates it 90 degrees in a clockwise direction)

Source:
Returns:

Self for chaining.

Type
Vector

project(other)

Project this vector on to another vector.

Parameters:
Name Type Description
other Vector

The vector to project onto

Source:
Returns:

Self for chaining.

Type
Vector

projectN(other)

Project this vector onto a vector of unit length. This is slightly more efficient
than project when dealing with unit vectors.

Parameters:
Name Type Description
other Vector

The unit vector to project onto

Source:
Returns:

Self for chaining.

Type
Vector

reflect(axis)

Reflect this vector on an arbitrary axis.

Parameters:
Name Type Description
axis Vector

The vector representing the axis

Source:
Returns:

Self for chaining.

Type
Vector

reflectN(axis)

Reflect this vector on an arbitrary axis (represented by a unit vector). This is
slightly more efficient than reflect when dealing with an axis that is a unit vector.

Parameters:
Name Type Description
axis Vector

The unit vector representing the axis

Source:
Returns:

Self for chaining.

Type
Vector

reverse()

Reverse this vector

Source:
Returns:

Self for chaining.

Type
Vector

rotate(angle)

Rotate vector in radians.

Parameters:
Name Type Description
angle number

Angle to rotate.

Source:
Returns:

Self for chaining.

Type
Vector

round()

Round vector values.

Source:
Returns:

Self for chaining

Type
Vector

set( [x] [, y])

Set vector values.

Parameters:
Name Type Argument Default Description
x number <optional>
0

Position of the point on the x axis

y number <optional>
0

Position of the point on the y axis

Source:
Returns:

Vector itself for chaining.

Type
Vector

sign(vector)

Check whether the direction from self to other vector is clockwise.

Parameters:
Name Type Description
vector Vector

Vector to calculate from

Source:
Returns:

Result (1 = CW, -1 = CCW)

Type
number

squaredDistance(vector)

Get squared euclidian distance of two vectors.

Parameters:
Name Type Description
vector Vector

Target vector to calculate distance from.

Source:
Returns:

Squared distance value.

Type
number

squaredLength()

Get squared length of vector.

Source:
Returns:

Squared length of this vector.

Type
number

subtract(x [, y])

Subtract from vector values.

Parameters:
Name Type Argument Description
x number | Vector

Number or Vector to subtract from.

y number <optional>

Number to subtract from y.

Source:
Returns:

Self for chaining.

Type
Vector