Constructors

Fields Summary

Wade_vec2

This is a set of functions that operate on 2d vectors. 2d vectors are objects with x and y properties.

Functions Summary

wade.vec2.add (v1, v2)

Add two vectors
wade.vec2.addInPlace (v1, v2)

Add two vectors and store the result in the first vector
wade.vec2.clamp (v, min, max)

Clamp a vector, that is force both its components to be between a minimum value and a maximum value
wade.vec2.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.
wade.vec2.div (v1, v2)

Divide a vector by another vector
wade.vec2.divInPlace (v1, v2)

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

Calculate the dot product of two vectors
wade.vec2.equal (v1, v2, tolerance)

Check whether two vectors are equal (i.e. both x and y have the same values), optionally accounting for some tolerance in the comparisons
wade.vec2.length (v)

Calculate the length of a vector
wade.vec2.lengthSquared (v)

Calculate the length squared of a vector
wade.vec2.maxComponent (v)

Get the larger value of the x and y components of a vector
wade.vec2.minComponent (v)

Get the smaller value of the x and y components of a vector
wade.vec2.mul (v1, v2)

Multiply two vectors
wade.vec2.mulInPlace (v1, v2)

Multiply two vectors and store the result in the first vector
wade.vec2.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
wade.vec2.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
wade.vec2.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.
wade.vec2.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
wade.vec2.rotate (v, angle)

Rotate a vector by an angle
wade.vec2.rotateInPlace (v, angle)

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

Scale a vector (that is, multiply the vector by a scalar)
wade.vec2.scaleInPlace (v, s)

Scale a vector (that is, multiply the vector by a scalar). Unlike the 'scale' function, this one modifies the original vector.
wade.vec2.sub (v1, v2)

Subtract two vectors
wade.vec2.subInPlace (v1, v2)

Subtract two vectors and store the result in the first vector

Fields Details

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.
^

Function Details

wade.vec2.add (v1, v2)

Add two vectors

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


Returns {x: number, y: number} : v1 + v2

^
wade.vec2.addInPlace (v1, v2)

Add two vectors and store the result in the first vector

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector

^
wade.vec2.clamp (v, min, max)

Clamp a vector, that is force both its components to be between a minimum value and a maximum value

{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

^
wade.vec2.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.

{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

^
wade.vec2.div (v1, v2)

Divide a vector by another vector

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


Returns {x: number, y: number} : v1 / v2

^
wade.vec2.divInPlace (v1, v2)

Divide a vector by another vector and store the result in the first vector

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector

^
wade.vec2.dot (v1, v2)

Calculate the dot product of two vectors

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


Returns : number The dot product of v1 and v2

^
wade.vec2.equal (v1, v2, tolerance)

Check whether two vectors are equal (i.e. both x and y have the same values), optionally accounting for some tolerance in the comparisons

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


number tolerance (optional, defaults to 0): How different the x and y components can be before the comparison returns false


Returns boolean : Whether v1 and v2 have the same value

^
wade.vec2.length (v)

Calculate the length of a vector

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


Returns number : The length of v

^
wade.vec2.lengthSquared (v)

Calculate the length squared of a vector

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


Returns number : The length squared of v

^
wade.vec2.maxComponent (v)

Get the larger value of the x and y components of a vector

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


Returns number : v.x or v.y, whichever is bigger

^
wade.vec2.minComponent (v)

Get the smaller value of the x and y components of a vector

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


Returns number : v.x or v.y, whichever is smaller

^
wade.vec2.mul (v1, v2)

Multiply two vectors

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


Returns {x: number, y: number} : v1 * v2

^
wade.vec2.mulInPlace (v1, v2)

Multiply two vectors and store the result in the first vector

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector

^
wade.vec2.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

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


Returns {x: number, y: number} : The normalized vector

^
wade.vec2.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

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


Returns {x: number, y: number} : The normalized vector

^
wade.vec2.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.

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

^
wade.vec2.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

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

^
wade.vec2.rotate (v, angle)

Rotate a vector by an angle

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


number angle : An angle in radians


Returns {x: number, y: number} : The rotated vector

^
wade.vec2.rotateInPlace (v, angle)

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

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


number angle : An angle in radians

^
wade.vec2.scale (v, s)

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

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


number s : A scale factor


Returns {x: number, y: number} : v * s

^
wade.vec2.scaleInPlace (v, s)

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

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


number s : A scale factor

^
wade.vec2.sub (v1, v2)

Subtract two vectors

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector


Returns {x: number, y: number} : v1 - v2

^
wade.vec2.subInPlace (v1, v2)

Subtract two vectors and store the result in the first vector

{x: number, y: number} v1 : A 2d vector


{x: number, y: number} v2 : Another 2d vector

^