2D Point
Create and manipulate 2d point object.
Installation
Available as a node package. To install use
$ npm install 2d-point
Methods
The following methods are available.
Use
Point.create(x, y)
create Creates a frozen 2D point. Defaults to origin coordinate if no arguments given.
var Point = ; var pt = Point;// => {x: 2, y: 4} var origin = Point;// => {x: 0, y: 0}
Point.add(p, q)
add Vector add two points returning a new point.
var p = Point;var q = Point; Point;// => {x: 6, y: 8}
Point.subtract(p, q)
subtract Vector subtract two points returning a new point.
var p = Point;var q = Point; Point;// => {x: -2, y: -2}
Point.multiply(a, p)
multiply Vector scalar multiply a point returning a new point.
var a = 3;var p = Point; Point;// => {x: 6, y: 9}
Point.fitWithin(container, vector)
fitWithin Scales vector to fit just within the bounding box of the container point.
var container = Point;var landscape = Point;var portrait = Point; Point;// => {x: 2, y: 1} Point;// => {x: 1, y: 2}
Point.fitWithin(container, vector)
fitOnce Scales vector to fit just within on dimension of the bounding box of the container point.
var container = Point;var landscape = Point;var portrait = Point; Point;// => {x: 4, y: 2} Point;// => {x: 2, y: 4}
Considered extensions
- fit within to deal with zeros ?
- negate ?
- Curry methods ?
- comparison methods ?
- conditionally make svg point if available ? No
- tests in browser ? No
- dot product ?
- convert to radial ? No
- furthest ?
- nearest ?