Skip to content

Latest commit

 

History

History
226 lines (147 loc) · 7.16 KB

Point.md

File metadata and controls

226 lines (147 loc) · 7.16 KB

Type Enforcer Math

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

npm build coverage deps size vulnerabilities license


Point

Point model with helper methods


new Point([x], [y])

Param Type Default
[x] number, Array, object 0
[y] number 0

Example

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

const point1 = new Point();
console.log(point1.toString());
// => '0,0'

const point2 = new Point({x:1, y:2});
console.log(point2.toString());
// => '1,2'

const point3 = new Point([3, 4]);
console.log(point3.toString());
// => '3,4'

const point4 = new Point(5, 6);
console.log(point4.toString());
// => '5,6'
console.log(point4.x);
// => 5
console.log(point4.y);
// => 6


point.set(x, [y]) ⇒ this     🔗 Chainable

Set x and y.

Param Type Description
x number, string, Array, object, Point The x coordinate as a number (must also provide y param), or a comma separated string as 'x,y', or an Array as [x, y], or an object as { x: 0, y: 0 }, or another valid Point.
[y] number The y coordinate as a number.


point.toString([suffix]) ⇒ string

Get the point as a string with an optional suffix.

Param Type Description
[suffix] string A suffix to append to each coordinate.


point.valueOf() ⇒ Array

Get the value of the point as an array.


point.isSame(point2) ⇒ boolean

Determine if another point is the same as this one.

Param Type Description
point2 Point Another point.


point.add(point) ⇒ Point

Adds the coordinates of another point to this one and returns a new point.

Param Type Description
point Point Another point.


point.subtract(point) ⇒ Point

Subtracts the coordinates of another point from this one and returns a new point.

Param Type Description
point Point Another point.


point.multiply(point) ⇒ Point

Multiplies the coordinates of another point with this one and returns a new point.

Param Type Description
point Point Another point.


point.round([fractionDigits], [precision]) ⇒ Point

Rounds the coordinates of this point and returns a new point.

Param Type Default Description
[fractionDigits] number 0 Must be a positive integer or null.
[precision] number Significant digits.


point.distance() ⇒ number

Finds the distance from point to origin (0, 0). Always returns a positive number or 0.


point.angle() ⇒ number

Finds the angle to this point from origin.


point.pointAtDistance(angle, distance) ⇒ Point

Returns a new point at a specific angle and distance from this point.

Param Type Description
angle number The angle.
distance number The distance.


point.clone() ⇒ Point

Get a clone of this point.


Point.isValid(value) ⇒ boolean

Determine if something is a valid point.

Param Type Description
value unknown The value to check.


Point.normalizeAngle(angle) ⇒ number

Returns the same angle between 0 and 2 * PI.

Returns: number - - The normalized angle.

Param Type Description
angle number The angle to normalize.