An extension of type-enforcer with Math related data types and enforcer functions
A Euclidean Vector model.
- Vector
- new Vector([args])
- instance
- .isSame(vector2) ⇒
boolean
- .invert() ⇒
this
- .toString() ⇒
string
- .valueOf() ⇒
Array
- .start([point]) ⇒
Point
- .end([point]) ⇒
Point
- .length([length]) ⇒
number
- .angle([angle]) ⇒
number
- .offset([point]) ⇒
Point
- .isSame(vector2) ⇒
- static
- .isValid(value) ⇒
boolean
- .isValid(value) ⇒
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';
Determine if another vector is the same as this one.
Param | Type | Description |
---|---|---|
vector2 | Vector |
Another vector. |
Switch the start and end points.
Get a string representation of the value of the vector.
Returns an array with the values of the start and end points.
The start point
Param | Type |
---|---|
[point] | Point |
The end point
Param | Type |
---|---|
[point] | Point |
The length (magnitude) of the vector. Resets the end point.
Param | Type |
---|---|
[length] | number |
The angle from the start point to the end point. Resets the end point
Param | Type |
---|---|
[angle] | number |
The x and y difference represented as a point
Param | Type |
---|---|
[point] | Point |
Determine if a value is a Vector or can be coerced into a vector.
Param | Type | Description |
---|---|---|
value | unknown |
The value to check. |