JSDoc: Module: vec2

# Module: vec2

2 Dimensional Vector

Source:
  - vec2.js, line 3

### Methods

#### (static) add(out, a, b) → {vec2}

Adds two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 84

##### Returns:

out

Type
  vec2

#### (static) angle(a, b) → {Number}

Get the angle between two 2D vectors

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | The first operand
`b` | vec2 | The second operand

Source:
  - vec2.js, line 478

##### Returns:

The angle in radians

Type
  Number

#### (static) ceil(out, a) → {vec2}

Math.ceil the components of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to ceil

Source:
  - vec2.js, line 139

##### Returns:

out

Type
  vec2

#### (static) clone(a) → {vec2}

Creates a new vec2 initialized with values from an existing vector

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | vector to clone

Source:
  - vec2.js, line 28

##### Returns:

a new 2D vector

Type
  vec2

#### (static) copy(out, a) → {vec2}

Copy the values from one vec2 to another

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the source vector

Source:
  - vec2.js, line 56

##### Returns:

out

Type
  vec2

#### (static) create() → {vec2}

Creates a new, empty vec2

Source:
  - vec2.js, line 13

##### Returns:

a new 2D vector

Type
  vec2

#### (static) cross(out, a, b) → {vec3}

Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec3 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 344

##### Returns:

out

Type
  vec3

#### (static) dist()

Alias for vec2.distance

Source:
  - vec2.js, line 572

#### (static) distance(a, b) → {Number}

Calculates the euclidian distance between two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 235

##### Returns:

distance between a and b

Type
  Number

#### (static) div()

Alias for vec2.divide

Source:
  - vec2.js, line 566

#### (static) divide(out, a, b) → {vec2}

Divides two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 126

##### Returns:

out

Type
  vec2

#### (static) dot(a, b) → {Number}

Calculates the dot product of two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 331

##### Returns:

dot product of a and b

Type
  Number

#### (static) equals(a, b) → {Boolean}

Returns whether or not the vectors have approximately the same elements in the same position.

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | The first vector.
`b` | vec2 | The second vector.

Source:
  - vec2.js, line 537

##### Returns:

True if the vectors are equal, false otherwise.

Type
  Boolean

#### (static) exactEquals(a, b) → {Boolean}

Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | The first vector.
`b` | vec2 | The second vector.

Source:
  - vec2.js, line 526

##### Returns:

True if the vectors are equal, false otherwise.

Type
  Boolean

#### (static) floor(out, a) → {vec2}

Math.floor the components of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to floor

Source:
  - vec2.js, line 152

##### Returns:

out

Type
  vec2

#### (static) forEach(a, stride, offset, count, fn, argopt) → {Array}

Perform some operation over an array of vec2s.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`a` | Array |  | the array of vectors to iterate over
`stride` | Number |  | Number of elements between the start of each vec2. If 0 assumes tightly packed
`offset` | Number |  | Number of elements to skip at the beginning of the array
`count` | Number |  | Number of vec2s to iterate over. If 0 iterates over entire array
`fn` | function |  | Function to call for each vector in the array
`arg` | Object | <optional> | additional argument to pass to fn

Source:
  - vec2.js, line 598

##### Returns:

a

Type
  Array

#### (static) fromValues(x, y) → {vec2}

Creates a new vec2 initialized with the given values

##### Parameters:

Name | Type | Description
--- | --- | ---
`x` | Number | X component
`y` | Number | Y component

Source:
  - vec2.js, line 42

##### Returns:

a new 2D vector

Type
  vec2

#### (static) inverse(out, a) → {vec2}

Returns the inverse of the components of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to invert

Source:
  - vec2.js, line 298

##### Returns:

out

Type
  vec2

#### (static) len()

Alias for vec2.length

Source:
  - vec2.js, line 548

#### (static) length(a) → {Number}

Calculates the length of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | vector to calculate length of

Source:
  - vec2.js, line 260

##### Returns:

length of a

Type
  Number

#### (static) lerp(out, a, b, t) → {vec2}

Performs a linear interpolation between two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand
`t` | Number | interpolation amount, in the range [0-1], between the two inputs

Source:
  - vec2.js, line 360

##### Returns:

out

Type
  vec2

#### (static) max(out, a, b) → {vec2}

Returns the maximum of two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 180

##### Returns:

out

Type
  vec2

#### (static) min(out, a, b) → {vec2}

Returns the minimum of two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 166

##### Returns:

out

Type
  vec2

#### (static) mul()

Alias for vec2.multiply

Source:
  - vec2.js, line 560

#### (static) multiply(out, a, b) → {vec2}

Multiplies two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 112

##### Returns:

out

Type
  vec2

#### (static) negate(out, a) → {vec2}

Negates the components of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to negate

Source:
  - vec2.js, line 285

##### Returns:

out

Type
  vec2

#### (static) normalize(out, a) → {vec2}

Normalize a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to normalize

Source:
  - vec2.js, line 311

##### Returns:

out

Type
  vec2

#### (static) random(out, scaleopt) → {vec2}

Generates a random vector with the given scale

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`out` | vec2 |  | the receiving vector
`scale` | Number | <optional> | Length of the resulting vector. If ommitted, a unit vector will be returned

Source:
  - vec2.js, line 375

##### Returns:

out

Type
  vec2

#### (static) rotate(out, a, b, c) → {vec2}

Rotate a 2D vector

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | The receiving vec2
`a` | vec2 | The vec2 point to rotate
`b` | vec2 | The origin of the rotation
`c` | Number | The angle of rotation

Source:
  - vec2.js, line 458

##### Returns:

out

Type
  vec2

#### (static) round(out, a) → {vec2}

Math.round the components of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | vector to round

Source:
  - vec2.js, line 193

##### Returns:

out

Type
  vec2

#### (static) scale(out, a, b) → {vec2}

Scales a vec2 by a scalar number

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the vector to scale
`b` | Number | amount to scale the vector by

Source:
  - vec2.js, line 207

##### Returns:

out

Type
  vec2

#### (static) scaleAndAdd(out, a, b, scale) → {vec2}

Adds two vec2's after scaling the second operand by a scalar value

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand
`scale` | Number | the amount to scale b by before adding

Source:
  - vec2.js, line 222

##### Returns:

out

Type
  vec2

#### (static) set(out, x, y) → {vec2}

Set the components of a vec2 to the given values

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`x` | Number | X component
`y` | Number | Y component

Source:
  - vec2.js, line 70

##### Returns:

out

Type
  vec2

#### (static) sqrDist()

Alias for vec2.squaredDistance

Source:
  - vec2.js, line 578

#### (static) sqrLen()

Alias for vec2.squaredLength

Source:
  - vec2.js, line 584

#### (static) squaredDistance(a, b) → {Number}

Calculates the squared euclidian distance between two vec2's

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 248

##### Returns:

squared distance between a and b

Type
  Number

#### (static) squaredLength(a) → {Number}

Calculates the squared length of a vec2

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | vector to calculate squared length of

Source:
  - vec2.js, line 272

##### Returns:

squared length of a

Type
  Number

#### (static) str(a) → {String}

Returns a string representation of a vector

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | vec2 | vector to represent as a string

Source:
  - vec2.js, line 515

##### Returns:

string representation of the vector

Type
  String

#### (static) sub()

Alias for vec2.subtract

Source:
  - vec2.js, line 554

#### (static) subtract(out, a, b) → {vec2}

Subtracts vector b from vector a

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the first operand
`b` | vec2 | the second operand

Source:
  - vec2.js, line 98

##### Returns:

out

Type
  vec2

#### (static) transformMat2(out, a, m) → {vec2}

Transforms the vec2 with a mat2

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the vector to transform
`m` | mat2 | matrix to transform with

Source:
  - vec2.js, line 391

##### Returns:

out

Type
  vec2

#### (static) transformMat2d(out, a, m) → {vec2}

Transforms the vec2 with a mat2d

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the vector to transform
`m` | mat2d | matrix to transform with

Source:
  - vec2.js, line 407

##### Returns:

out

Type
  vec2

#### (static) transformMat3(out, a, m) → {vec2}

Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the vector to transform
`m` | mat3 | matrix to transform with

Source:
  - vec2.js, line 424

##### Returns:

out

Type
  vec2

#### (static) transformMat4(out, a, m) → {vec2}

Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

##### Parameters:

Name | Type | Description
--- | --- | ---
`out` | vec2 | the receiving vector
`a` | vec2 | the vector to transform
`m` | mat4 | matrix to transform with

Source:
  - vec2.js, line 442

##### Returns:

out

Type
  vec2