Classes


Class Wade_vec2

Class Summary
Constructor Attributes Constructor Name and Description
 
This is a set of functions that operate on 2d vectors.
Method Summary
Method Attributes Method Name and Description
 
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
 
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)
 
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
Class Detail
Wade_vec2()
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.
Method Detail
{{x: number|y: number}} add(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

addInPlace(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

{{x: number|y: number}} clamp(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

clampInPlace(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

{{x: number|y: number}} div(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

divInPlace(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

{{x: number|y: number}} dot(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:
{{x: number|y: number}} The dot product of v1 and v2

{number} length(v)
Calculate the length of a vector
Parameters:
{{x: number|y: number}} v
A 2d vector
Returns:
{number} The length of v

{number} lengthSquared(v)
Calculate the length squared of a vector
Parameters:
{{x: number|y: number}} v
A 2d vector
Returns:
{number} The length squared of v

{{x: number|y: number}} mul(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

mulInPlace(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

{{x: number|y: number}} normalize(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

{{x: number|y: number}} normalizeIfPossible(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

normalizeInPlace(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

normalizeInPlaceIfPossible(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

{{x: number|y: number}} rotate(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

rotateInPlace(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

{{x: number|y: number}} scale(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

scaleInPlace(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

{{x: number|y: number}} sub(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

subInPlace(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

Documentation generated by JsDoc Toolkit 2.4.0 on Tue Jul 12 2016 07:54:41 GMT+0100 (BST)