Constructors

- Wade.vec2

Constructor Summary

This is a set of functions that operate on 2d vectors.

Functions Summary

add
(v1,
v2)
Add two vectors
addInPlace
(v1,
v2)
Add two vectors and store the result in the first vector
clamp
(v,
min,
max)
Clamp a vector, that is force both its components to be between a minimum value and a maximum value
clampInPlace
(v,
min,
max)
Clamp a vector, that is force both its components to be between a minimum value and a maximum value.
div
(v1,
v2)
Divide a vector by another vector
divInPlace
(v1,
v2)
Divide a vector by another vector and store the result in the first vector
dot
(v1,
v2)
Calculate the dot product of two vectors
length
(v)
Calculate the length of a vector
Calculate the length squared of a vector
Get the larger value of the x and y components of a vector
Get the smaller value of the x and y components of a vector
mul
(v1,
v2)
Multiply two vectors
mulInPlace
(v1,
v2)
Multiply two vectors and store the result in the first vector
Normalize a vector (so that its length is 1).
Normalize a vector (so that its length is 1).
Normalize a vector (so that its length is 1).
Normalize a vector (so that its length is 1).
rotate
(v,
angle)
Rotate a vector by an angle
rotateInPlace
(v,
angle)
Rotate a vector by an angle.
scale
(v,
s)
Scale a vector (that is, multiply the vector by a scalar)
scaleInPlace
(v,
s)
Scale a vector (that is, multiply the vector by a scalar).
sub
(v1,
v2)
Subtract two vectors
subInPlace
(v1,
v2)
Subtract two vectors and store the result in the first vector

Constructor Details

()
This is a set of functions that operate on 2d vectors. 2d vectors are objects with x and y properties. Because of the weakly-typed nature of JavaScript, 2d vectors can have any other properties as well as x and y, but all the functions in wade.vec2d that return 2d vectors will ignore the other properties, and just return objects with x and y properties.

Function Details


(v1,
v2)
Add two vectors

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

Returns:


{{x: number|y: number}}
v1 + v2

(v1,
v2)
Add two vectors and store the result in the first vector

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

(v,
min,
max)
Clamp a vector, that is force both its components to be between a minimum value and a maximum value

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}min
The minimum value for either component of the vector
{number}max
The maximum value for either component of the vector

Returns:


{{x: number|y: number}}
The clamped vector

(v,
min,
max)
Clamp a vector, that is force both its components to be between a minimum value and a maximum value. Unlike the 'clamp' function, this one modifies the original vector.

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}min
The minimum value for either component of the vector
{number}max
The maximum value for either component of the vector

(v1,
v2)
Divide a vector by another vector

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

Returns:


{{x: number|y: number}}
v1 / v2

(v1,
v2)
Divide a vector by another vector and store the result in the first vector

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

(v1,
v2)
Calculate the dot product of two vectors

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

Returns:


undefined

(v)
Calculate the length of a vector

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{number}
The length of v

(v)
Calculate the length squared of a vector

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{number}
The length squared of v

(v)
Get the larger value of the x and y components of a vector

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{number}
v.x or v.y, whichever is bigger

(v)
Get the smaller value of the x and y components of a vector

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{number}
v.x or v.y, whichever is smaller

(v1,
v2)
Multiply two vectors

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

Returns:


{{x: number|y: number}}
v1 * v2

(v1,
v2)
Multiply two vectors and store the result in the first vector

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

(v)
Normalize a vector (so that its length is 1). Note that if the length of the vector is very close to 0, this operation may fail and return a vector whose components are NaN

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{{x: number|y: number}}
The normalized vector

(v)
Normalize a vector (so that its length is 1). Note that if the length of the vector is very close to 0, this operation will just return the original vector

Parameters:


{{x: number|y: number}}v
A 2d vector

Returns:


{{x: number|y: number}}
The normalized vector

(v)
Normalize a vector (so that its length is 1). Note that if the length of the vector is very close to 0, this operation may fail and return a vector whose components are NaN. Unlike the 'normalize' function, this one modifies the original vector.

Parameters:


{{x: number|y: number}}v
A 2d vector

(v)
Normalize a vector (so that its length is 1). Note that if the length of the vector is very close to 0, this operation will just return the original vector. Unlike the 'normalizeIfPossible' function, this one modifies the original vector

Parameters:


{{x: number|y: number}}v
A 2d vector

(v,
angle)
Rotate a vector by an angle

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}angle
An angle in radians

Returns:


{{x: number|y: number}}
The rotated vector

(v,
angle)
Rotate a vector by an angle. Unlike the 'rotate' function, this one modifies the original vector.

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}angle
An angle in radians

(v,
s)
Scale a vector (that is, multiply the vector by a scalar)

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}s
A scale factor

Returns:


{{x: number|y: number}}
v * s

(v,
s)
Scale a vector (that is, multiply the vector by a scalar). Unlike the 'scale' function, this one modifies the original vector.

Parameters:


{{x: number|y: number}}v
A 2d vector
{number}s
A scale factor

(v1,
v2)
Subtract two vectors

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector

Returns:


{{x: number|y: number}}
v1 - v2

(v1,
v2)
Subtract two vectors and store the result in the first vector

Parameters:


{{x: number|y: number}}v1
A 2d vector
{{x: number|y: number}}v2
Another 2d vector