# JSDoc: Class: Vector2

# Class: Vector2

## Vector2(x, y)

#### new Vector2(x, y)

Class representing a 2D vector. A 2D vector is an ordered pair of numbers (labeled x and y), which can be used to represent points in space, directions, etc.

##### Parameters:

Name | Type | Description
--- | --- | ---
`x` | number |
`y` | number |

Source:
  - math/Vector2.js, line 11

### Methods

#### add(v)

Add the content of another vector to this one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 62

#### addScalar(s)

Add a scalar value to booth vector components.

##### Parameters:

Name | Type | Description
--- | --- | ---
`s` | number |

Source:
  - math/Vector2.js, line 73

#### addScaledVector(v, s)

Scale a vector components and add the result to this vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |
`s` | number |

Source:
  - math/Vector2.js, line 97

#### addVectors(a, b)

Add two vectors and store the result in this vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | Vector2 |
`b` | Vector2 |

Source:
  - math/Vector2.js, line 85

#### angle()

Computes the angle in radians with respect to the positive x-axis

Source:
  - math/Vector2.js, line 324

#### ceil()

Round the vector coordinates to integer by ceiling to the bigger integer.

Source:
  - math/Vector2.js, line 239

#### clone()

Create a clone of this vector object.

Source:
  - math/Vector2.js, line 41

#### copy(v)

Copy the content of another vector into this one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 51

#### cross(vector) → {number}

Cross multiplication between this vector and another vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`vector` | Vector2 |

Source:
  - math/Vector2.js, line 282

##### Returns:

Result of the cross multiplication.

Type
  number

#### distanceTo()

Distance between two vector positions.

Source:
  - math/Vector2.js, line 339

#### distanceToSquared()

Distance between two vector positions squared. Faster for comparisons.

Source:
  - math/Vector2.js, line 349

#### divide(v)

Divide the content of another vector from this one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 165

#### divideScalar(s)

Divide a scalar value by booth vector components.

##### Parameters:

Name | Type | Description
--- | --- | ---
`s` | number |

Source:
  - math/Vector2.js, line 176

#### dot(vector) → {number}

Dot multiplication between this vector and another vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`vector` | Vector2 |

Source:
  - math/Vector2.js, line 271

##### Returns:

Result of the dot multiplication.

Type
  number

#### equals(v)

Check if two vectors are equal.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 389

#### floor()

Round the vector coordinates to integer by flooring to the smaller integer.

Source:
  - math/Vector2.js, line 230

#### fromArray(array, offsetopt)

Set vector value from array with a offset.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`array` | array |  |
`offset` | number | <optional> |

Source:
  - math/Vector2.js, line 400

#### length()

Length of the vector.

Source:
  - math/Vector2.js, line 300

#### lengthSq()

Squared length of the vector. Faster for comparions.

Source:
  - math/Vector2.js, line 292

#### manhattanDistanceTo()

Manhattan distance between two vector positions.

Source:
  - math/Vector2.js, line 360

#### manhattanLength()

Manhattan length of the vector.

Source:
  - math/Vector2.js, line 308

#### max(v)

Set the maximum of x and y coordinates between two vectors. X is set as the max between this vector and the other vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 201

#### min(v)

Set the minimum of x and y coordinates between two vectors. X is set as the min between this vector and the other vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 188

#### multiply(v)

Multiply the content of another vector to this one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 142

#### multiplyScalar(s)

Multiply a scalar value by booth vector components.

##### Parameters:

Name | Type | Description
--- | --- | ---
`s` | number |

Source:
  - math/Vector2.js, line 153

#### negate()

Negate the coordinates of this vector.

Source:
  - math/Vector2.js, line 257

#### normalize()

Normalize the vector (make it length one).

Source:
  - math/Vector2.js, line 316

#### rotateAround(center, angle)

Rotate the vector around a central point.

##### Parameters:

Name | Type | Description
--- | --- | ---
`center` | Vector2 |
`angle` | number |

Source:
  - math/Vector2.js, line 431

#### round()

Round the vector coordinates to their closest integer.

Source:
  - math/Vector2.js, line 248

#### set(x, y)

Set vector x and y values.

##### Parameters:

Name | Type | Description
--- | --- | ---
`x` | number |
`y` | number |

Source:
  - math/Vector2.js, line 23

#### setLength()

Scale the vector to have a defined length value.

Source:
  - math/Vector2.js, line 368

#### setScalar()

Set a scalar value into the x and y values.

Source:
  - math/Vector2.js, line 32

#### sub(v)

Subtract the content of another vector to this one.

##### Parameters:

Name | Type | Description
--- | --- | ---
`v` | Vector2 |

Source:
  - math/Vector2.js, line 108

#### subScalar(s)

Subtract a scalar value to booth vector components.

##### Parameters:

Name | Type | Description
--- | --- | ---
`s` | number |

Source:
  - math/Vector2.js, line 119

#### subVectors(a, b)

Subtract two vectors and store the result in this vector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`a` | Vector2 |
`b` | Vector2 |

Source:
  - math/Vector2.js, line 131

#### toArray(array, offsetopt)

Convert this vector to an array.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`array` | array |  |
`offset` | number | <optional> |

Source:
  - math/Vector2.js, line 414