# Fields Summary

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

# Functions Summary

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.

Divide a vector by another vector

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

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

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

Multiply two vectors

Multiply two vectors and store the result in the first vector

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

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

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.

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

Rotate a vector by an angle

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

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

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

Subtract two vectors

Subtract two vectors and store the result in the first vector

# Fields 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

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

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

Returns {x: number, y: number} : 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

^

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

^

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

^

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

^

Calculate the length of a vector

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

Returns number : The length of v

^

Calculate the length squared of a vector

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

Returns number : The length squared of 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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^

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

^