Skip to content

Latest commit

 

History

History
163 lines (101 loc) · 5.02 KB

Vector.md

File metadata and controls

163 lines (101 loc) · 5.02 KB

Type Enforcer Math

An extension of type-enforcer with Math related data types and enforcer functions

npm build coverage deps size vulnerabilities license


Vector

A Euclidean Vector model.


new Vector([args])

Param Type Description
[args] unknown Accepts:
- A start and end point (or values that can be coerced into points)
- An array of two points (or values that can be coerced into points)
- Another vector instance
- A single start point (or value that can be coerced into a point)

Example

import { Vector } from 'type-enforcer-math';


vector.isSame(vector2) ⇒ boolean

Determine if another vector is the same as this one.

Param Type Description
vector2 Vector Another vector.


vector.invert() ⇒ this     🔗 Chainable

Switch the start and end points.


vector.toString() ⇒ string

Get a string representation of the value of the vector.


vector.valueOf() ⇒ Array

Returns an array with the values of the start and end points.


vector.start([point]) ⇒ Point     🔗 Chainable

The start point

Param Type
[point] Point


vector.end([point]) ⇒ Point     🔗 Chainable

The end point

Param Type
[point] Point


vector.length([length]) ⇒ number     🔗 Chainable

The length (magnitude) of the vector. Resets the end point.

Param Type
[length] number


vector.angle([angle]) ⇒ number     🔗 Chainable

The angle from the start point to the end point. Resets the end point

Param Type
[angle] number


vector.offset([point]) ⇒ Point     🔗 Chainable

The x and y difference represented as a point

Param Type
[point] Point


Vector.isValid(value) ⇒ boolean

Determine if a value is a Vector or can be coerced into a vector.

Param Type Description
value unknown The value to check.