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

add

(v1,

v2)

(v1,

v2)

Add two vectors

addInPlace

(v1,

v2)

(v1,

v2)

Add two vectors and store the result in the first vector

clamp

(v,

min,

max)

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

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

(v1,

v2)

Divide a vector by another vector

divInPlace

(v1,

v2)

(v1,

v2)

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

dot

(v1,

v2)

(v1,

v2)

Calculate the dot product of two vectors

length

(v)

(v)

Calculate the length of a vector

Calculate the length squared of a vector

maxComponent

(v)

(v)

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

minComponent

(v)

(v)

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

mul

(v1,

v2)

(v1,

v2)

Multiply two vectors

mulInPlace

(v1,

v2)

(v1,

v2)

Multiply two vectors and store the result in the first vector

normalize

(v)

(v)

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)

(v,

angle)

Rotate a vector by an angle

rotateInPlace

(v,

angle)

(v,

angle)

Rotate a vector by an angle.

scale

(v,

s)

(v,

s)

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

scaleInPlace

(v,

s)

(v,

s)

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

sub

(v1,

v2)

(v1,

v2)

Subtract two vectors

subInPlace

(v1,

v2)

(v1,

v2)

Subtract two vectors and store the result in the first vector

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.

add

(v1,

v2)

(v1,

v2)

Add two vectors

#### Parameters:

#### Returns:

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

A 2d vector

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

Another 2d vector

{{x: number|y: number}}

v1 + v2

addInPlace

(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

clamp

(v,

min,

max)

(v,

min,

max)

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

#### Parameters:

#### Returns:

{{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}}

The clamped vector

clampInPlace

(v,

min,

max)

(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

div

(v1,

v2)

(v1,

v2)

Divide a vector by another vector

#### Parameters:

#### Returns:

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

A 2d vector

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

Another 2d vector

{{x: number|y: number}}

v1 / v2

divInPlace

(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

dot

(v1,

v2)

(v1,

v2)

Calculate the dot product of two vectors

#### Parameters:

#### Returns:

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

A 2d vector

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

Another 2d vector

undefined

length

(v)

(v)

Calculate the length of a vector

#### Parameters:

#### Returns:

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

A 2d vector

{number}

The length of v

lengthSquared

(v)

(v)

Calculate the length squared of a vector

#### Parameters:

#### Returns:

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

A 2d vector

{number}

The length squared of v

maxComponent

(v)

(v)

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

#### Parameters:

#### Returns:

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

A 2d vector

{number}

v.x or v.y, whichever is bigger

minComponent

(v)

(v)

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

#### Parameters:

#### Returns:

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

A 2d vector

{number}

v.x or v.y, whichever is smaller

mul

(v1,

v2)

(v1,

v2)

Multiply two vectors

#### Parameters:

#### Returns:

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

A 2d vector

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

Another 2d vector

{{x: number|y: number}}

v1 * v2

mulInPlace

(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

normalize

(v)

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

#### Returns:

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

A 2d vector

{{x: number|y: number}}

The normalized vector

normalizeIfPossible

(v)

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

#### Returns:

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

A 2d vector

{{x: number|y: number}}

The normalized vector

normalizeInPlace

(v)

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

(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

rotate

(v,

angle)

(v,

angle)

Rotate a vector by an angle

#### Parameters:

#### Returns:

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

A 2d vector

{number}angle

An angle in radians

{{x: number|y: number}}

The rotated vector

rotateInPlace

(v,

angle)

(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

scale

(v,

s)

(v,

s)

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

#### Parameters:

#### Returns:

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

A 2d vector

{number}s

A scale factor

{{x: number|y: number}}

v * s

scaleInPlace

(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

sub

(v1,

v2)

(v1,

v2)

Subtract two vectors

#### Parameters:

#### Returns:

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

A 2d vector

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

Another 2d vector

{{x: number|y: number}}

v1 - v2

subInPlace

(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