Vec2

Vec2

A two component vector.

Constructor

new Vec2()

Instantiates a Vec2 object.
Source:

Methods

add(that) → {Vec2}

Adds the vector with the provided vector argument, returning a new Vec2 object representing the sum.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The vector to add.
Source:
Returns:
The sum of the two vectors.
Type
Vec2

cross(that) → {number}

Calculates and returns 2D cross product of the vector and the provided vector argument. This value represents the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values as 0.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The other vector argument.
Source:
Returns:
The 2D cross product.
Type
number

divScalar(that) → {Vec2}

Divides the vector with the provided scalar argument, returning a new Vec2 object representing the scaled vector.
Parameters:
Name Type Description
that number The scalar to divide the vector by.
Source:
Returns:
The scaled vector.
Type
Vec2

dot(that) → {number}

Calculates and returns the dot product of the vector and the provided vector argument.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The other vector argument.
Source:
Returns:
The dot product.
Type
number

equals(that, epsilon) → {boolean}

Returns true if the vector components match those of a provided vector. An optional epsilon value may be provided.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The vector to test equality with.
epsilon number The epsilon value. Optional.
Source:
Returns:
Whether or not the vector components match.
Type
boolean

length(length) → {number|Vec2}

If no argument is provided, this function returns the scalar length of the vector. If an argument is provided, this method will return a new Vec2 scaled to the provided length.
Parameters:
Name Type Description
length number The length to scale the vector to. Optional.
Source:
Returns:
Either the length, or new scaled vector.
Type
number | Vec2

lengthSquared() → {number}

Returns the squared length of the vector.
Source:
Returns:
The squared length of the vector.
Type
number

multScalar(that) → {Vec2}

Multiplies the vector with the provided scalar argument, returning a new Vec2 object representing the scaled vector.
Parameters:
Name Type Description
that number The scalar to multiply the vector by.
Source:
Returns:
The scaled vector.
Type
Vec2

negate() → {Vec2}

Returns a new Vec2 with each component negated.
Source:
Returns:
The negated vector.
Type
Vec2

normalize() → {Vec2}

Returns a new Vec2 of unit length.
Source:
Returns:
The vector of unit length.
Type
Vec2

sub(that) → {Vec2}

Subtracts the provided vector argument from the vector, returning a new Vec2 object representing the difference.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The vector to subtract.
Source:
Returns:
The difference of the two vectors.
Type
Vec2

toArray() → {Array}

Returns an array representation of the vector.
Source:
Returns:
The vector as an array.
Type
Array

toString() → {String}

Returns a string representation of the vector.
Source:
Returns:
The string representation of the vector.
Type
String

unsignedAngle(that) → {number}

Returns the unsigned angle between this angle and the argument in radians.
Parameters:
Name Type Description
that Vec2 | Vec3 | Vec4 | Array The vector to measure the angle from.
Source:
Returns:
The unsigned angle in radians.
Type
number

(static) random() → {Vec2}

Returns a random Vec2 of unit length.
Source:
Returns:
A random vector of unit length.
Type
Vec2