npm package: @ishoa/vector2
Description: A Vector representing X and Y values in 2D space
Author: Shane Coates
Latest version: 1.0.2

<a name="Vector2"></a>

## Vector2

A simple Vector2 object

A Vector representing X and Y values in 2D space

* [Vector2](#Vector2)
    * [new Vector2(x, y)](#new_Vector2_new)
    * [.add(vector)](#add) ⇒ [<code>Vector2</code>](#Vector2)
    * [.addScalar(scalar)](#addScalar) ⇒ [<code>Vector2</code>](#Vector2)
    * [.addVectors(vector1, vector2)](#addVectors) ⇒ [<code>Vector2</code>](#Vector2)
    * [.angle()](#angle) ⇒ <code>Number</code>
    * [.angleBetween(vector)](#angleBetween) ⇒ <code>Number</code>
    * [.angleTo(vector)](#angleTo) ⇒ <code>Number</code>
    * [.cartesianToPolar(x, y)](#cartesianToPolar) ⇒ <code>Object</code>
    * [.clone()](#clone) ⇒ [<code>Vector2</code>](#Vector2)
    * [.cross()](#cross) ⇒ <code>Number</code>
    * [.distanceTo(vector2)](#distanceTo) ⇒ <code>Number</code>
    * [.divide(vector)](#divide) ⇒ [<code>Vector2</code>](#Vector2)
    * [.divideScalar(scalar)](#divideScalar) ⇒ [<code>Vector2</code>](#Vector2)
    * [.dot(vector)](#dot) ⇒ <code>Number</code>
    * [.length(x, y)](#length) ⇒ <code>Number</code>
    * [.limit(value)](#limit) ⇒ [<code>Vector2</code>](#Vector2)
    * [.mag()](#mag) ⇒ <code>Number</code>
    * [.magnitude()](#magnitude) ⇒ <code>Number</code>
    * [.magSq()](#magSq) ⇒
    * [.midpoint(vector)](#midpoint) ⇒ [<code>Vector2</code>](#Vector2)
    * [.multiply(vector)](#multiply) ⇒ [<code>Vector2</code>](#Vector2)
    * [.multiplyScalar(scalar)](#multiplyScalar) ⇒ [<code>Vector2</code>](#Vector2)
    * [.normalize()](#normalize) ⇒
    * [.set(props)](#set)
    * [.setFromPolar(length, angle)](#setFromPolar) ⇒ [<code>Vector2</code>](#Vector2)
    * [.sub(vector)](#sub) ⇒ [<code>Vector2</code>](#Vector2)
    * [.subScalar(scalar)](#subScalar) ⇒ [<code>Vector2</code>](#Vector2)
    * [.subVectors(vector1, vector2)](#subVectors) ⇒ [<code>Vector2</code>](#Vector2)

<a name="new_Vector2_new"></a>

### new Vector2(x, y)

Constructor

| Param | Type | Default | Description |
| --- | --- | --- | --- |
| x | <code>Number</code> | <code>0</code> | x value for vector |
| y | <code>Number</code> | <code>0</code> | y value for vector |

<a name="add"></a>

### vector2.add(vector) ⇒ [<code>Vector2</code>](#Vector2)

Add another vector2 to this vector2
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | Vector2 to add to this one |

**Example**  
```js
- vector1.add(vector2);
```

<a name="addScalar"></a>

### vector2.addScalar(scalar) ⇒ [<code>Vector2</code>](#Vector2)

Add a scalar value to our vector
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| scalar | <code>Number</code> | number to add to both x and y |

**Example**
```js
- vector.addScalar(5);
```
<a name="addVectors"></a>

### vector2.addVectors(vector1, vector2) ⇒ [<code>Vector2</code>](#Vector2)

Set this x and y vector to be the addition of two Vector2(s)
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector1 | [<code>Vector2</code>](#Vector2) | first vector to add to this |
| vector2 | [<code>Vector2</code>](#Vector2) | second vector to add to this |

**Example**  
```js
- let vector = new Vector2().addVectors(vector1, vector2);
```

<a name="angle"></a>

### vector2.angle() ⇒ <code>Number</code>

Calculate the angle to the coordinates 0, 0
  
**Returns**: <code>Number</code> - - the angle from (0, 0) of this vector 

<a name="angleBetween"></a>

### vector2.angleBetween(vector) ⇒ <code>Number</code>

Calculate the angle between this vector and another vector
  
**Returns**: <code>Number</code> - - the angle between this vector and another vector  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | a vector to get the angle of |

**Example**  
```js
- let angle = vector1.angleBetween(vector2);
```

<a name="angleTo"></a>

### vector2.angleTo(vector) ⇒ <code>Number</code>

Calculate the angle in radians from this vector to another
  
**Returns**: <code>Number</code> - - the angle in radians from this vector to another  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | Vector2 to get the angle too |

**Example**  
```js
- let angle = vector1.angleTo(vector2);
```

<a name="cartesianToPolar"></a>

### vector2.cartesianToPolar(x, y) ⇒ <code>Object</code>

Calculate polar coordinates from our current x and y properties OR from a passed in x and y value
  
**Returns**: <code>Object</code> - - The vector representation in polar coordinates (length and angle)  

| Param | Type | Description |
| --- | --- | --- |
| x | <code>Number</code> | x cartesian value - defaults to this Vector2 |
| y | <code>Number</code> | y cartesian value - defaults to this Vector2 |

**Example**  
```js
- let polar = vector.cartesianToPolar();
```

<a name="clone"></a>

### vector2.clone() ⇒ [<code>Vector2</code>](#Vector2)

Create a new vector of this vector
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the copy of this vector 

<a name="cross"></a>

### vector2.cross() ⇒ <code>Number</code>

Calculate the cross product between this Vector2 and another Vector2
  
**Returns**: <code>Number</code> - - the cross product  

**Example**  
```js
- let crossProduct = vector1.cross(vector2);
```

<a name="distanceTo"></a>

### vector2.distanceTo(vector2) ⇒ <code>Number</code>

Calculate the distance between the 2 Vector2 Objects
  
**Returns**: <code>Number</code> - - the distance between this vector and another  

| Param | Type | Description |
| --- | --- | --- |
| vector2 | [<code>Vector2</code>](#Vector2) | vector 2 to measure distance to this vector |

**Example**  
```js
- let distance = vector1.distanceTo(vector2);
```

<a name="divide"></a>

### vector2.divide(vector) ⇒ [<code>Vector2</code>](#Vector2)

Divide a Vector2 from this
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | Vector2 to divide from this |

**Example**  
```js
- vector1.divide(vector2);
```

<a name="divideScalar"></a>

### vector2.divideScalar(scalar) ⇒ [<code>Vector2</code>](#Vector2)

Divide a scalar value to our vector
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| scalar | <code>Number</code> | scalar number to divide to both x and y |

**Example**  
```js
- vector.divide(5);
```

<a name="dot"></a>

### vector2.dot(vector) ⇒ <code>Number</code>

The dot product gives a number as a "scalar"
  
**Returns**: <code>Number</code> - - A number or scalar value which is the dot product  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | {x: 0, y: 0} |

**Example**  
```js
- let dot = vector1.dot(vector2);
```

<a name="length"></a>

### vector2.length(x, y) ⇒ <code>Number</code>

Return the length of the x and y value
  
**Returns**: <code>Number</code> - - the length or magnitude of this vector  

| Param | Type | Description |
| --- | --- | --- |
| x | <code>Number</code> | the x value - defaults to this.x |
| y | <code>Number</code> | the y value - defaults to this.y |

**Example**  
```js
- let length = vector.length();
```

<a name="limit"></a>

### vector2.limit(value) ⇒ [<code>Vector2</code>](#Vector2)

Set or limit the magnitude to a value
  
**Returns**: [<code>Vector2</code>](#Vector2) - - the modified vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| value | <code>Number</code> | Value to limit the magnitude too |

**Example**  
```js
- vector.limit(5);
```

<a name="mag"></a>

### vector2.mag() ⇒ <code>Number</code>

Calculate the magnitude or length of the vector (shorthand function)
  
**Returns**: <code>Number</code> - - the length or magnitude of this vector  

**Example**  
```js
- let mag = vector.mag();
```

<a name="magnitude"></a>

### vector2.magnitude() ⇒ <code>Number</code>

Calculate the magnitude or length of the vector
  
**Returns**: <code>Number</code> - - the length or magnitude of this vector  

**Example**  
```js
- let mag = vector.magnitude();
```

<a name="magSq"></a>

### vector2.magSq() ⇒

Calculate the magnitude squared
  
**Returns**: - Vector2 magnitude squared  

**Example**  
```js
= let magSq = vector.magSq();
```

<a name="midpoint"></a>

### vector2.midpoint(vector) ⇒ [<code>Vector2</code>](#Vector2)

Get the midpoint between this Vector2 to another Vector2
  
**Returns**: [<code>Vector2</code>](#Vector2) - - {x: x, y: y} midpoint values  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | {x: 0, y: 0} |

**Example**  
```js
- let midpoint = vector1.midpoint(vector2);
```

<a name="multiply"></a>

### vector2.multiply(vector) ⇒ [<code>Vector2</code>](#Vector2)

Multiply a Vector2 from this
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | Vector2 to multiply from this |

**Example**  
```js
- vector1.multiply(vector2);
```

<a name="multiplyScalar"></a>

### vector2.multiplyScalar(scalar) ⇒ [<code>Vector2</code>](#Vector2)

Multiply a scalar value to our vector
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| scalar | <code>Number</code> | scalar number to multiply to both x and y |

**Example**  
```js
- vector.multiplyScalar(5);
```

<a name="normalize"></a>

### vector2.normalize() ⇒

The normalized vector or keep the direction of the Vector2 the same but the length is 1
  
**Returns**: normalized value  

**Example**  
```js
- vector.noramlize();
```

<a name="set"></a>

### vector2.set(props)

Set the properties on this to be the properties of a passed in Object
  
| Param | Type | Description |
| --- | --- | --- |
| props | <code>Object</code> | object with properties to set on this |

**Example**  
```js
- {x: 50, y: 100}
```

<a name="setFromPolar"></a>

### vector2.setFromPolar(length, angle) ⇒ [<code>Vector2</code>](#Vector2)

Set our X and Y Cartesian Coordiantes based off the provided Polar Coordinates
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| length | <code>Number</code> | the length or radius of the Polar Coordinates |
| angle | <code>Number</code> | the angle or theta of the Polar Coordinates |

**Example**  
```js
- vector.setFromPolar(5, Math.PI() / 2);
```

<a name="sub"></a>

### vector2.sub(vector) ⇒ [<code>Vector2</code>](#Vector2)

Subtract a Vector2 from this
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector | [<code>Vector2</code>](#Vector2) | Vector2 to subtract from this |

**Example**  
```js
- vector1.sub(vector2);
```

<a name="subScalar"></a>

### vector2.subScalar(scalar) ⇒ [<code>Vector2</code>](#Vector2)

Subtract a scalar value to our vector
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| scalar | <code>Number</code> | number to subtract to both x and y |

**Example**  
```js
- vector.subScalar(5);
```

<a name="subVectors"></a>

### vector2.subVectors(vector1, vector2) ⇒ [<code>Vector2</code>](#Vector2)

Set this x and y vector to be the subtraction of two Vector2(s)
  
**Returns**: [<code>Vector2</code>](#Vector2) - - The modified Vector (this)  

| Param | Type | Description |
| --- | --- | --- |
| vector1 | [<code>Vector2</code>](#Vector2) | first vector to subtract to this |
| vector2 | [<code>Vector2</code>](#Vector2) | second vector to subtract to this |

**Example**  
```js
- let vector = new Vector2().subVectors(vector1, vector2);
```