@mapbox/point-geometry
Advanced tools
+196
| /** | ||
| * A standalone point geometry with useful accessor, comparison, and | ||
| * modification methods. | ||
| * | ||
| * @example | ||
| * const point = new Point(-77, 38); | ||
| */ | ||
| export default class Point { | ||
| /** | ||
| * Construct a point from an array if necessary, otherwise if the input | ||
| * is already a Point, or an unknown type, return it unchanged | ||
| * @param {[number, number] | Point} a any kind of input value | ||
| * @return {Point} constructed point, or passed-through value. | ||
| * @example | ||
| * // this | ||
| * var point = Point.convert([0, 1]); | ||
| * // is equivalent to | ||
| * var point = new Point(0, 1); | ||
| */ | ||
| static convert(a: [number, number] | Point): Point; | ||
| /** | ||
| * @param {number} x the x-coordinate. This could be longitude or screen pixels, or any other sort of unit. | ||
| * @param {number} y the y-coordinate. This could be latitude or screen pixels, or any other sort of unit. | ||
| */ | ||
| constructor(x: number, y: number); | ||
| x: number; | ||
| y: number; | ||
| /** | ||
| * Clone this point, returning a new point that can be modified | ||
| * without affecting the old one. | ||
| * @return {Point} the clone | ||
| */ | ||
| clone(): Point; | ||
| /** | ||
| * Add this point's x & y coordinates to another point, | ||
| * yielding a new point. | ||
| * @param {Point} p the other point | ||
| * @return {Point} output point | ||
| */ | ||
| add(p: Point): Point; | ||
| /** | ||
| * Subtract this point's x & y coordinates to from point, | ||
| * yielding a new point. | ||
| * @param {Point} p the other point | ||
| * @return {Point} output point | ||
| */ | ||
| sub(p: Point): Point; | ||
| /** | ||
| * Multiply this point's x & y coordinates by point, | ||
| * yielding a new point. | ||
| * @param {Point} p the other point | ||
| * @return {Point} output point | ||
| */ | ||
| multByPoint(p: Point): Point; | ||
| /** | ||
| * Divide this point's x & y coordinates by point, | ||
| * yielding a new point. | ||
| * @param {Point} p the other point | ||
| * @return {Point} output point | ||
| */ | ||
| divByPoint(p: Point): Point; | ||
| /** | ||
| * Multiply this point's x & y coordinates by a factor, | ||
| * yielding a new point. | ||
| * @param {number} k factor | ||
| * @return {Point} output point | ||
| */ | ||
| mult(k: number): Point; | ||
| /** | ||
| * Divide this point's x & y coordinates by a factor, | ||
| * yielding a new point. | ||
| * @param {number} k factor | ||
| * @return {Point} output point | ||
| */ | ||
| div(k: number): Point; | ||
| /** | ||
| * Rotate this point around the 0, 0 origin by an angle a, | ||
| * given in radians | ||
| * @param {number} a angle to rotate around, in radians | ||
| * @return {Point} output point | ||
| */ | ||
| rotate(a: number): Point; | ||
| /** | ||
| * Rotate this point around p point by an angle a, | ||
| * given in radians | ||
| * @param {number} a angle to rotate around, in radians | ||
| * @param {Point} p Point to rotate around | ||
| * @return {Point} output point | ||
| */ | ||
| rotateAround(a: number, p: Point): Point; | ||
| /** | ||
| * Multiply this point by a 4x1 transformation matrix | ||
| * @param {[number, number, number, number]} m transformation matrix | ||
| * @return {Point} output point | ||
| */ | ||
| matMult(m: [number, number, number, number]): Point; | ||
| /** | ||
| * Calculate this point but as a unit vector from 0, 0, meaning | ||
| * that the distance from the resulting point to the 0, 0 | ||
| * coordinate will be equal to 1 and the angle from the resulting | ||
| * point to the 0, 0 coordinate will be the same as before. | ||
| * @return {Point} unit vector point | ||
| */ | ||
| unit(): Point; | ||
| /** | ||
| * Compute a perpendicular point, where the new y coordinate | ||
| * is the old x coordinate and the new x coordinate is the old y | ||
| * coordinate multiplied by -1 | ||
| * @return {Point} perpendicular point | ||
| */ | ||
| perp(): Point; | ||
| /** | ||
| * Return a version of this point with the x & y coordinates | ||
| * rounded to integers. | ||
| * @return {Point} rounded point | ||
| */ | ||
| round(): Point; | ||
| /** | ||
| * Return the magnitude of this point: this is the Euclidean | ||
| * distance from the 0, 0 coordinate to this point's x and y | ||
| * coordinates. | ||
| * @return {number} magnitude | ||
| */ | ||
| mag(): number; | ||
| /** | ||
| * Judge whether this point is equal to another point, returning | ||
| * true or false. | ||
| * @param {Point} other the other point | ||
| * @return {boolean} whether the points are equal | ||
| */ | ||
| equals(other: Point): boolean; | ||
| /** | ||
| * Calculate the distance from this point to another point | ||
| * @param {Point} p the other point | ||
| * @return {number} distance | ||
| */ | ||
| dist(p: Point): number; | ||
| /** | ||
| * Calculate the distance from this point to another point, | ||
| * without the square root step. Useful if you're comparing | ||
| * relative distances. | ||
| * @param {Point} p the other point | ||
| * @return {number} distance | ||
| */ | ||
| distSqr(p: Point): number; | ||
| /** | ||
| * Get the angle from the 0, 0 coordinate to this point, in radians | ||
| * coordinates. | ||
| * @return {number} angle | ||
| */ | ||
| angle(): number; | ||
| /** | ||
| * Get the angle from this point to another point, in radians | ||
| * @param {Point} b the other point | ||
| * @return {number} angle | ||
| */ | ||
| angleTo(b: Point): number; | ||
| /** | ||
| * Get the angle between this point and another point, in radians | ||
| * @param {Point} b the other point | ||
| * @return {number} angle | ||
| */ | ||
| angleWith(b: Point): number; | ||
| /** | ||
| * Find the angle of the two vectors, solving the formula for | ||
| * the cross product a x b = |a||b|sin(θ) for θ. | ||
| * @param {number} x the x-coordinate | ||
| * @param {number} y the y-coordinate | ||
| * @return {number} the angle in radians | ||
| */ | ||
| angleWithSep(x: number, y: number): number; | ||
| /** @param {[number, number, number, number]} m */ | ||
| _matMult(m: [number, number, number, number]): this; | ||
| /** @param {Point} p */ | ||
| _add(p: Point): this; | ||
| /** @param {Point} p */ | ||
| _sub(p: Point): this; | ||
| /** @param {number} k */ | ||
| _mult(k: number): this; | ||
| /** @param {number} k */ | ||
| _div(k: number): this; | ||
| /** @param {Point} p */ | ||
| _multByPoint(p: Point): this; | ||
| /** @param {Point} p */ | ||
| _divByPoint(p: Point): this; | ||
| _unit(): this; | ||
| _perp(): this; | ||
| /** @param {number} angle */ | ||
| _rotate(angle: number): this; | ||
| /** | ||
| * @param {number} angle | ||
| * @param {Point} p | ||
| */ | ||
| _rotateAround(angle: number, p: Point): this; | ||
| _round(): this; | ||
| } |
+114
-108
@@ -1,5 +0,1 @@ | ||
| 'use strict'; | ||
| module.exports = Point; | ||
| /** | ||
@@ -9,17 +5,15 @@ * A standalone point geometry with useful accessor, comparison, and | ||
| * | ||
| * @class Point | ||
| * @param {Number} x the x-coordinate. this could be longitude or screen | ||
| * pixels, or any other sort of unit. | ||
| * @param {Number} y the y-coordinate. this could be latitude or screen | ||
| * pixels, or any other sort of unit. | ||
| * @example | ||
| * var point = new Point(-77, 38); | ||
| * const point = new Point(-77, 38); | ||
| */ | ||
| function Point(x, y) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| export default class Point { | ||
| /** | ||
| * @param {number} x the x-coordinate. This could be longitude or screen pixels, or any other sort of unit. | ||
| * @param {number} y the y-coordinate. This could be latitude or screen pixels, or any other sort of unit. | ||
| */ | ||
| constructor(x, y) { | ||
| this.x = x; | ||
| this.y = y; | ||
| } | ||
| Point.prototype = { | ||
| /** | ||
@@ -30,3 +24,3 @@ * Clone this point, returning a new point that can be modified | ||
| */ | ||
| clone: function() { return new Point(this.x, this.y); }, | ||
| clone() { return new Point(this.x, this.y); } | ||
@@ -39,3 +33,3 @@ /** | ||
| */ | ||
| add: function(p) { return this.clone()._add(p); }, | ||
| add(p) { return this.clone()._add(p); } | ||
@@ -48,3 +42,3 @@ /** | ||
| */ | ||
| sub: function(p) { return this.clone()._sub(p); }, | ||
| sub(p) { return this.clone()._sub(p); } | ||
@@ -57,3 +51,3 @@ /** | ||
| */ | ||
| multByPoint: function(p) { return this.clone()._multByPoint(p); }, | ||
| multByPoint(p) { return this.clone()._multByPoint(p); } | ||
@@ -66,3 +60,3 @@ /** | ||
| */ | ||
| divByPoint: function(p) { return this.clone()._divByPoint(p); }, | ||
| divByPoint(p) { return this.clone()._divByPoint(p); } | ||
@@ -72,6 +66,6 @@ /** | ||
| * yielding a new point. | ||
| * @param {Point} k factor | ||
| * @param {number} k factor | ||
| * @return {Point} output point | ||
| */ | ||
| mult: function(k) { return this.clone()._mult(k); }, | ||
| mult(k) { return this.clone()._mult(k); } | ||
@@ -81,6 +75,6 @@ /** | ||
| * yielding a new point. | ||
| * @param {Point} k factor | ||
| * @param {number} k factor | ||
| * @return {Point} output point | ||
| */ | ||
| div: function(k) { return this.clone()._div(k); }, | ||
| div(k) { return this.clone()._div(k); } | ||
@@ -90,6 +84,6 @@ /** | ||
| * given in radians | ||
| * @param {Number} a angle to rotate around, in radians | ||
| * @param {number} a angle to rotate around, in radians | ||
| * @return {Point} output point | ||
| */ | ||
| rotate: function(a) { return this.clone()._rotate(a); }, | ||
| rotate(a) { return this.clone()._rotate(a); } | ||
@@ -99,14 +93,14 @@ /** | ||
| * given in radians | ||
| * @param {Number} a angle to rotate around, in radians | ||
| * @param {number} a angle to rotate around, in radians | ||
| * @param {Point} p Point to rotate around | ||
| * @return {Point} output point | ||
| */ | ||
| rotateAround: function(a,p) { return this.clone()._rotateAround(a,p); }, | ||
| rotateAround(a, p) { return this.clone()._rotateAround(a, p); } | ||
| /** | ||
| * Multiply this point by a 4x1 transformation matrix | ||
| * @param {Array<Number>} m transformation matrix | ||
| * @param {[number, number, number, number]} m transformation matrix | ||
| * @return {Point} output point | ||
| */ | ||
| matMult: function(m) { return this.clone()._matMult(m); }, | ||
| matMult(m) { return this.clone()._matMult(m); } | ||
@@ -120,3 +114,3 @@ /** | ||
| */ | ||
| unit: function() { return this.clone()._unit(); }, | ||
| unit() { return this.clone()._unit(); } | ||
@@ -129,3 +123,3 @@ /** | ||
| */ | ||
| perp: function() { return this.clone()._perp(); }, | ||
| perp() { return this.clone()._perp(); } | ||
@@ -137,13 +131,13 @@ /** | ||
| */ | ||
| round: function() { return this.clone()._round(); }, | ||
| round() { return this.clone()._round(); } | ||
| /** | ||
| * Return the magitude of this point: this is the Euclidean | ||
| * Return the magnitude of this point: this is the Euclidean | ||
| * distance from the 0, 0 coordinate to this point's x and y | ||
| * coordinates. | ||
| * @return {Number} magnitude | ||
| * @return {number} magnitude | ||
| */ | ||
| mag: function() { | ||
| mag() { | ||
| return Math.sqrt(this.x * this.x + this.y * this.y); | ||
| }, | ||
| } | ||
@@ -156,6 +150,6 @@ /** | ||
| */ | ||
| equals: function(other) { | ||
| equals(other) { | ||
| return this.x === other.x && | ||
| this.y === other.y; | ||
| }, | ||
| } | ||
@@ -165,7 +159,7 @@ /** | ||
| * @param {Point} p the other point | ||
| * @return {Number} distance | ||
| * @return {number} distance | ||
| */ | ||
| dist: function(p) { | ||
| dist(p) { | ||
| return Math.sqrt(this.distSqr(p)); | ||
| }, | ||
| } | ||
@@ -177,9 +171,9 @@ /** | ||
| * @param {Point} p the other point | ||
| * @return {Number} distance | ||
| * @return {number} distance | ||
| */ | ||
| distSqr: function(p) { | ||
| var dx = p.x - this.x, | ||
| distSqr(p) { | ||
| const dx = p.x - this.x, | ||
| dy = p.y - this.y; | ||
| return dx * dx + dy * dy; | ||
| }, | ||
| } | ||
@@ -189,7 +183,7 @@ /** | ||
| * coordinates. | ||
| * @return {Number} angle | ||
| * @return {number} angle | ||
| */ | ||
| angle: function() { | ||
| angle() { | ||
| return Math.atan2(this.y, this.x); | ||
| }, | ||
| } | ||
@@ -199,7 +193,7 @@ /** | ||
| * @param {Point} b the other point | ||
| * @return {Number} angle | ||
| * @return {number} angle | ||
| */ | ||
| angleTo: function(b) { | ||
| angleTo(b) { | ||
| return Math.atan2(this.y - b.y, this.x - b.x); | ||
| }, | ||
| } | ||
@@ -209,23 +203,24 @@ /** | ||
| * @param {Point} b the other point | ||
| * @return {Number} angle | ||
| * @return {number} angle | ||
| */ | ||
| angleWith: function(b) { | ||
| angleWith(b) { | ||
| return this.angleWithSep(b.x, b.y); | ||
| }, | ||
| } | ||
| /* | ||
| /** | ||
| * Find the angle of the two vectors, solving the formula for | ||
| * the cross product a x b = |a||b|sin(θ) for θ. | ||
| * @param {Number} x the x-coordinate | ||
| * @param {Number} y the y-coordinate | ||
| * @return {Number} the angle in radians | ||
| * @param {number} x the x-coordinate | ||
| * @param {number} y the y-coordinate | ||
| * @return {number} the angle in radians | ||
| */ | ||
| angleWithSep: function(x, y) { | ||
| angleWithSep(x, y) { | ||
| return Math.atan2( | ||
| this.x * y - this.y * x, | ||
| this.x * x + this.y * y); | ||
| }, | ||
| } | ||
| _matMult: function(m) { | ||
| var x = m[0] * this.x + m[1] * this.y, | ||
| /** @param {[number, number, number, number]} m */ | ||
| _matMult(m) { | ||
| const x = m[0] * this.x + m[1] * this.y, | ||
| y = m[2] * this.x + m[3] * this.y; | ||
@@ -235,54 +230,61 @@ this.x = x; | ||
| return this; | ||
| }, | ||
| } | ||
| _add: function(p) { | ||
| /** @param {Point} p */ | ||
| _add(p) { | ||
| this.x += p.x; | ||
| this.y += p.y; | ||
| return this; | ||
| }, | ||
| } | ||
| _sub: function(p) { | ||
| /** @param {Point} p */ | ||
| _sub(p) { | ||
| this.x -= p.x; | ||
| this.y -= p.y; | ||
| return this; | ||
| }, | ||
| } | ||
| _mult: function(k) { | ||
| /** @param {number} k */ | ||
| _mult(k) { | ||
| this.x *= k; | ||
| this.y *= k; | ||
| return this; | ||
| }, | ||
| } | ||
| _div: function(k) { | ||
| /** @param {number} k */ | ||
| _div(k) { | ||
| this.x /= k; | ||
| this.y /= k; | ||
| return this; | ||
| }, | ||
| } | ||
| _multByPoint: function(p) { | ||
| /** @param {Point} p */ | ||
| _multByPoint(p) { | ||
| this.x *= p.x; | ||
| this.y *= p.y; | ||
| return this; | ||
| }, | ||
| } | ||
| _divByPoint: function(p) { | ||
| /** @param {Point} p */ | ||
| _divByPoint(p) { | ||
| this.x /= p.x; | ||
| this.y /= p.y; | ||
| return this; | ||
| }, | ||
| } | ||
| _unit: function() { | ||
| _unit() { | ||
| this._div(this.mag()); | ||
| return this; | ||
| }, | ||
| } | ||
| _perp: function() { | ||
| var y = this.y; | ||
| _perp() { | ||
| const y = this.y; | ||
| this.y = this.x; | ||
| this.x = -y; | ||
| return this; | ||
| }, | ||
| } | ||
| _rotate: function(angle) { | ||
| var cos = Math.cos(angle), | ||
| /** @param {number} angle */ | ||
| _rotate(angle) { | ||
| const cos = Math.cos(angle), | ||
| sin = Math.sin(angle), | ||
@@ -294,6 +296,10 @@ x = cos * this.x - sin * this.y, | ||
| return this; | ||
| }, | ||
| } | ||
| _rotateAround: function(angle, p) { | ||
| var cos = Math.cos(angle), | ||
| /** | ||
| * @param {number} angle | ||
| * @param {Point} p | ||
| */ | ||
| _rotateAround(angle, p) { | ||
| const cos = Math.cos(angle), | ||
| sin = Math.sin(angle), | ||
@@ -305,5 +311,5 @@ x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y), | ||
| return this; | ||
| }, | ||
| } | ||
| _round: function() { | ||
| _round() { | ||
| this.x = Math.round(this.x); | ||
@@ -313,23 +319,23 @@ this.y = Math.round(this.y); | ||
| } | ||
| }; | ||
| /** | ||
| * Construct a point from an array if necessary, otherwise if the input | ||
| * is already a Point, or an unknown type, return it unchanged | ||
| * @param {Array<Number>|Point|*} a any kind of input value | ||
| * @return {Point} constructed point, or passed-through value. | ||
| * @example | ||
| * // this | ||
| * var point = Point.convert([0, 1]); | ||
| * // is equivalent to | ||
| * var point = new Point(0, 1); | ||
| */ | ||
| Point.convert = function (a) { | ||
| if (a instanceof Point) { | ||
| /** | ||
| * Construct a point from an array if necessary, otherwise if the input | ||
| * is already a Point, or an unknown type, return it unchanged | ||
| * @param {[number, number] | Point} a any kind of input value | ||
| * @return {Point} constructed point, or passed-through value. | ||
| * @example | ||
| * // this | ||
| * var point = Point.convert([0, 1]); | ||
| * // is equivalent to | ||
| * var point = new Point(0, 1); | ||
| */ | ||
| static convert(a) { | ||
| if (a instanceof Point) { | ||
| return a; | ||
| } | ||
| if (Array.isArray(a)) { | ||
| return new Point(a[0], a[1]); | ||
| } | ||
| return a; | ||
| } | ||
| if (Array.isArray(a)) { | ||
| return new Point(a[0], a[1]); | ||
| } | ||
| return a; | ||
| }; | ||
| } |
+1
-1
@@ -1,2 +0,2 @@ | ||
| Copyright (c) 2015, Mapbox <> | ||
| Copyright (c) 2024, Mapbox | ||
@@ -3,0 +3,0 @@ Permission to use, copy, modify, and/or distribute this software for any |
+17
-10
| { | ||
| "name": "@mapbox/point-geometry", | ||
| "version": "0.1.0", | ||
| "version": "1.0.0", | ||
| "description": "a point geometry with transforms", | ||
| "main": "index.js", | ||
| "type": "module", | ||
| "exports": "./index.js", | ||
| "types": "index.d.ts", | ||
| "scripts": { | ||
| "test": "tape test.js", | ||
| "doc": "dox -r < index.js | doxme --readme > README.md", | ||
| "cov": "istanbul cover test.js && coveralls < ./coverage/lcov.info" | ||
| "lint": "eslint --fix index.js test.js", | ||
| "pretest": "npm run lint", | ||
| "test": "tsc && node test.js", | ||
| "doc": "documentation readme index.js --section=API --markdown-toc=false", | ||
| "cov": "node --test --experimental-test-coverage" | ||
| }, | ||
@@ -27,8 +32,10 @@ "repository": { | ||
| "devDependencies": { | ||
| "coveralls": "~2.10.1", | ||
| "dox": "^0.6.1", | ||
| "doxme": "^1.8.2", | ||
| "istanbul": "~0.2.11", | ||
| "tape": "~2.13.3" | ||
| } | ||
| "documentation": "^14.0.3", | ||
| "eslint": "^9.6.0", | ||
| "eslint-config-mourner": "^4.0.2", | ||
| "typescript": "^5.5.3" | ||
| }, | ||
| "files": [ | ||
| "index.d.ts" | ||
| ] | ||
| } |
+98
-203
@@ -1,184 +0,139 @@ | ||
| # point-geometry | ||
| # @mapbox/point-geometry | ||
| [](http://travis-ci.org/mapbox/point-geometry) [](https://coveralls.io/r/mapbox/point-geometry?branch=master) | ||
| A `Point` class for representing point geometry with useful utility methods. | ||
| a point geometry with transforms | ||
| ## Installation | ||
| ```sh | ||
| $ npm install @mapbox/point-geometry | ||
| ``` | ||
| ### `Point(x, y)` | ||
| ## API | ||
| <!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
| ### Point | ||
| A standalone point geometry with useful accessor, comparison, and | ||
| modification methods. | ||
| #### Parameters | ||
| ### Parameters | ||
| * `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the x-coordinate. This could be longitude or screen pixels, or any other sort of unit. | ||
| * `y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the y-coordinate. This could be latitude or screen pixels, or any other sort of unit. | ||
| | parameter | type | description | | ||
| | --------- | ------ | -------------------------------------------------------------------------------------- | | ||
| | `x` | Number | the x-coordinate. this could be longitude or screen pixels, or any other sort of unit. | | ||
| | `y` | Number | the y-coordinate. this could be latitude or screen pixels, or any other sort of unit. | | ||
| #### Examples | ||
| ### Example | ||
| ```js | ||
| var point = new Point(-77, 38); | ||
| ```javascript | ||
| const point = new Point(-77, 38); | ||
| ``` | ||
| #### clone | ||
| ### `clone` | ||
| Clone this point, returning a new point that can be modified | ||
| without affecting the old one. | ||
| Returns **[Point](#point)** the clone | ||
| **Returns** `Point`, the clone | ||
| #### add | ||
| ### `add(p)` | ||
| Add this point's x & y coordinates to another point, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[Point](#point)** output point | ||
| #### sub | ||
| **Returns** `Point`, output point | ||
| ### `sub(p)` | ||
| Subtract this point's x & y coordinates to from point, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[Point](#point)** output point | ||
| #### multByPoint | ||
| **Returns** `Point`, output point | ||
| ### `multByPoint(p)` | ||
| Multiply this point's x & y coordinates by point, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[Point](#point)** output point | ||
| #### divByPoint | ||
| **Returns** `Point`, output point | ||
| ### `divByPoint(p)` | ||
| Divide this point's x & y coordinates by point, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[Point](#point)** output point | ||
| #### mult | ||
| **Returns** `Point`, output point | ||
| ### `mult(k)` | ||
| Multiply this point's x & y coordinates by a factor, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | ----------- | | ||
| | `k` | Point | factor | | ||
| * `k` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** factor | ||
| Returns **[Point](#point)** output point | ||
| #### div | ||
| **Returns** `Point`, output point | ||
| ### `div(k)` | ||
| Divide this point's x & y coordinates by a factor, | ||
| yielding a new point. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | ----------- | | ||
| | `k` | Point | factor | | ||
| * `k` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** factor | ||
| Returns **[Point](#point)** output point | ||
| #### rotate | ||
| **Returns** `Point`, output point | ||
| ### `rotate(a)` | ||
| Rotate this point around the 0, 0 origin by an angle a, | ||
| given in radians | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ------ | ---------------------------------- | | ||
| | `a` | Number | angle to rotate around, in radians | | ||
| * `a` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle to rotate around, in radians | ||
| Returns **[Point](#point)** output point | ||
| #### rotateAround | ||
| **Returns** `Point`, output point | ||
| ### `rotateAround(a, p)` | ||
| Rotate this point around p point by an angle a, | ||
| given in radians | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ------ | ---------------------------------- | | ||
| | `a` | Number | angle to rotate around, in radians | | ||
| | `p` | Point | Point to rotate around | | ||
| * `a` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle to rotate around, in radians | ||
| * `p` **[Point](#point)** Point to rotate around | ||
| Returns **[Point](#point)** output point | ||
| #### matMult | ||
| **Returns** `Point`, output point | ||
| ### `matMult(m)` | ||
| Multiply this point by a 4x1 transformation matrix | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----------------- | --------------------- | | ||
| | `m` | Array\.\<Number\> | transformation matrix | | ||
| * `m` **\[[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)]** transformation matrix | ||
| Returns **[Point](#point)** output point | ||
| #### unit | ||
| **Returns** `Point`, output point | ||
| ### `unit` | ||
| Calculate this point but as a unit vector from 0, 0, meaning | ||
@@ -189,8 +144,6 @@ that the distance from the resulting point to the 0, 0 | ||
| Returns **[Point](#point)** unit vector point | ||
| **Returns** `Point`, unit vector point | ||
| #### perp | ||
| ### `perp` | ||
| Compute a perpendicular point, where the new y coordinate | ||
@@ -200,58 +153,42 @@ is the old x coordinate and the new x coordinate is the old y | ||
| Returns **[Point](#point)** perpendicular point | ||
| **Returns** `Point`, perpendicular point | ||
| #### round | ||
| ### `round` | ||
| Return a version of this point with the x & y coordinates | ||
| rounded to integers. | ||
| Returns **[Point](#point)** rounded point | ||
| **Returns** `Point`, rounded point | ||
| #### mag | ||
| ### `mag` | ||
| Return the magitude of this point: this is the Euclidean | ||
| Return the magnitude of this point: this is the Euclidean | ||
| distance from the 0, 0 coordinate to this point's x and y | ||
| coordinates. | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** magnitude | ||
| **Returns** `Number`, magnitude | ||
| #### equals | ||
| ### `equals(other)` | ||
| Judge whether this point is equal to another point, returning | ||
| true or false. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `other` | Point | the other point | | ||
| * `other` **[Point](#point)** the other point | ||
| Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** whether the points are equal | ||
| #### dist | ||
| **Returns** `boolean`, whether the points are equal | ||
| ### `dist(p)` | ||
| Calculate the distance from this point to another point | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance | ||
| #### distSqr | ||
| **Returns** `Number`, distance | ||
| ### `distSqr(p)` | ||
| Calculate the distance from this point to another point, | ||
@@ -261,84 +198,59 @@ without the square root step. Useful if you're comparing | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `p` | Point | the other point | | ||
| * `p` **[Point](#point)** the other point | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** distance | ||
| #### angle | ||
| **Returns** `Number`, distance | ||
| ### `angle` | ||
| Get the angle from the 0, 0 coordinate to this point, in radians | ||
| coordinates. | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle | ||
| **Returns** `Number`, angle | ||
| #### angleTo | ||
| ### `angleTo(b)` | ||
| Get the angle from this point to another point, in radians | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `b` | Point | the other point | | ||
| * `b` **[Point](#point)** the other point | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle | ||
| #### angleWith | ||
| **Returns** `Number`, angle | ||
| ### `angleWith(b)` | ||
| Get the angle between this point and another point, in radians | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ----- | --------------- | | ||
| | `b` | Point | the other point | | ||
| * `b` **[Point](#point)** the other point | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** angle | ||
| #### angleWithSep | ||
| **Returns** `Number`, angle | ||
| ### `angleWithSep(x, y)` | ||
| Find the angle of the two vectors, solving the formula for | ||
| the cross product a x b = |a||b|sin(θ) for θ. | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ------ | ---------------- | | ||
| | `x` | Number | the x-coordinate | | ||
| | `y` | Number | the y-coordinate | | ||
| * `x` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the x-coordinate | ||
| * `y` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the y-coordinate | ||
| Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** the angle in radians | ||
| #### convert | ||
| **Returns** `Number`, the angle in radians | ||
| ### `convert(a)` | ||
| Construct a point from an array if necessary, otherwise if the input | ||
| is already a Point, or an unknown type, return it unchanged | ||
| ### Parameters | ||
| ##### Parameters | ||
| | parameter | type | description | | ||
| | --------- | ------------------------ | ----------------------- | | ||
| | `a` | Array\.\<Number\>\,Point | any kind of input value | | ||
| * `a` **(\[[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)] | [Point](#point))** any kind of input value | ||
| ##### Examples | ||
| ### Example | ||
| ```js | ||
| ```javascript | ||
| // this | ||
@@ -350,19 +262,2 @@ var point = Point.convert([0, 1]); | ||
| **Returns** `Point`, constructed point, or passed-through value. | ||
| ## Installation | ||
| Requires [nodejs](http://nodejs.org/). | ||
| ```sh | ||
| $ npm install point-geometry | ||
| ``` | ||
| ## Tests | ||
| ```sh | ||
| $ npm test | ||
| ``` | ||
| Returns **[Point](#point)** constructed point, or passed-through value. |
| language: node_js | ||
| node_js: | ||
| - "0.10" | ||
| before_install: | ||
| - npm install -g npm@~1.4.6 | ||
| script: | ||
| - npm test | ||
| - npm run cov |
| ## 0.1.0 | ||
| * Adds [rotateAround](https://github.com/mapbox/point-geometry/pull/5) and | ||
| [multByPoint](https://github.com/mapbox/point-geometry/pull/7) and divByPoint | ||
| methods. |
-139
| 'use strict'; | ||
| var test = require('tape').test; | ||
| var Point = require('./'); | ||
| test('Point', function(t) { | ||
| t.test('.convert', function(t) { | ||
| t.equal(Point.convert(new Point(20, 30)).equals(new Point(20, 30)), true); | ||
| t.equal(Point.convert([20, 30]).equals(new Point(20, 30)), true); | ||
| t.equal(Point.convert('somestring'), 'somestring'); | ||
| t.end(); | ||
| }); | ||
| t.test('vector operations', function(t) { | ||
| t.test('#mag', function(t) { | ||
| t.test('gets the magnitude of a vector', function() { | ||
| t.equal(new Point(0, 2).mag(), 2); | ||
| t.equal(new Point(0, 0).mag(), 0); | ||
| t.equal(new Point(10, 0).mag(), 10); | ||
| t.end(); | ||
| }); | ||
| }); | ||
| t.test('#unit', function(t) { | ||
| t.test('calculates the unit vector', function() { | ||
| t.deepEqual(new Point(0, 1000).unit(), new Point(0, 1)); | ||
| t.end(); | ||
| }); | ||
| }); | ||
| t.test('#equals', function(t) { | ||
| t.equals((new Point(0, 0).equals(new Point(0, 0))), true, 'equal'); | ||
| t.equals((new Point(0, 0).equals(new Point(0, 10))), false, 'not equal'); | ||
| t.end(); | ||
| }); | ||
| t.test('#dist', function(t) { | ||
| t.equals((new Point(0, 10).dist(new Point(0, 0))), 10); | ||
| t.equals((new Point(Math.sqrt(2), Math.sqrt(2)).dist(new Point(0, 0))), 2); | ||
| t.equals((new Point(0, 0).dist(new Point(0, 0))), 0); | ||
| t.end(); | ||
| }); | ||
| t.test('#mult', function(t) { | ||
| t.equals((new Point(0, 0).mult(5)).equals(new Point(0, 0)), true); | ||
| t.equals((new Point(0, 1).mult(5)).equals(new Point(0, 5)), true); | ||
| t.equals((new Point(1, 1).mult(5)).equals(new Point(5, 5)), true); | ||
| t.end(); | ||
| }); | ||
| t.test('#div', function(t) { | ||
| t.equals((new Point(0, 0).div(5)).equals(new Point(0, 0)), true); | ||
| t.equals((new Point(0, 1).div(5)).equals(new Point(0, 1/5)), true); | ||
| t.equals((new Point(1, 1).div(5)).equals(new Point(1/5, 1/5)), true); | ||
| t.end(); | ||
| }); | ||
| t.test('#multByPoint', function(t) { | ||
| t.equals((new Point(0, 0).multByPoint(new Point(5,5))).equals(new Point(0, 0)), true); | ||
| t.equals((new Point(0, 1).multByPoint(new Point(5,5))).equals(new Point(0, 5)), true); | ||
| t.equals((new Point(1, 1).multByPoint(new Point(4,5))).equals(new Point(4, 5)), true); | ||
| t.end(); | ||
| }); | ||
| t.test('#divByPoint', function(t) { | ||
| t.equals((new Point(0, 0).divByPoint(new Point(5,5))).equals(new Point(0, 0)), true); | ||
| t.equals((new Point(0, 1).divByPoint(new Point(5,5))).equals(new Point(0, 1/5)), true); | ||
| t.equals((new Point(1, 1).divByPoint(new Point(4,5))).equals(new Point(1/4, 1/5)), true); | ||
| t.end(); | ||
| }); | ||
| t.test('#rotate', function(t) { | ||
| t.equals((new Point(0, 0).rotate(0)).equals(new Point(0, 0)), true); | ||
| t.deepEquals((new Point(0, 1).rotate(Math.PI/2)).round(), new Point(-1, 0)); | ||
| t.deepEquals((new Point(0, 1).rotate(Math.PI)).round(), new Point(0, -1)); | ||
| t.end(); | ||
| }); | ||
| t.test('#rotateAround', function(t) { | ||
| t.deepEquals((new Point(2, 3).rotateAround(Math.PI/2, new Point(2,2))).round(), new Point(1, 2)); | ||
| t.deepEquals((new Point(2, 3).rotateAround(Math.PI, new Point(2,2))).round(), new Point(2, 1)); | ||
| t.end(); | ||
| }); | ||
| t.test('#round', function(t) { | ||
| t.equals((new Point(0, 0).round()).equals(new Point(0, 0)), true); | ||
| t.equals((new Point(0, 0.5).round()).equals(new Point(0, 1)), true); | ||
| t.equals((new Point(0.2, 0.2).round()).equals(new Point(0, 0)), true); | ||
| t.end(); | ||
| }); | ||
| t.test('#angle', function(t) { | ||
| t.equals((new Point(0, 0).angle()), 0); | ||
| t.equals((new Point(10, 10).angle()), Math.PI / 4); | ||
| t.equals((new Point(0, 10).angle()), Math.PI / 2); | ||
| t.equals((new Point(10, 0).angle()), 0); | ||
| t.end(); | ||
| }); | ||
| t.test('#angleTo', function(t) { | ||
| var b = new Point(0, 0); | ||
| t.equals((new Point(0, 0).angleTo(b)), 0); | ||
| t.equals((new Point(10, 10).angleTo(b)), Math.PI / 4); | ||
| t.equals((new Point(0, 10).angleTo(b)), Math.PI / 2); | ||
| t.equals((new Point(10, 0).angleTo(b)), 0); | ||
| t.end(); | ||
| }); | ||
| t.test('#angleWith', function(t) { | ||
| var b = new Point(0, 0); | ||
| t.equals((new Point(0, 0).angleWith(b)), 0); | ||
| t.equals((new Point(10, 10).angleWith(b)), 0); | ||
| t.equals((new Point(0, 10).angleWith(b)), 0); | ||
| t.equals((new Point(10, 0).angleWith(b)), 0); | ||
| t.end(); | ||
| }); | ||
| t.test('#angleWithSep', function(t) { | ||
| t.equals((new Point(0, 0).angleWithSep(0, 0)), 0); | ||
| t.equals((new Point(10, 10).angleWithSep(0, 0)), 0); | ||
| t.equals((new Point(0, 10).angleWithSep(0, 0)), 0); | ||
| t.equals((new Point(10, 0).angleWithSep(0, 0)), 0); | ||
| t.end(); | ||
| }); | ||
| t.test('#matMult', function(t) { | ||
| t.equals((new Point(0, 0).matMult([0, 0, 0, 0])).equals(new Point(0, 0)), true); | ||
| t.deepEquals((new Point(1, 1).matMult([0, 0, 0, 0])), new Point(0, 0)); | ||
| t.deepEquals((new Point(1, 1).matMult([1, 0, 1, 0])), new Point(1, 1)); | ||
| t.deepEquals((new Point(1, 1).matMult([1, 0, 0, 0])), new Point(1, 0)); | ||
| t.deepEquals((new Point(1, 1).matMult([0, 0, 1, 0])), new Point(0, 1)); | ||
| t.deepEquals((new Point(1, 1).matMult([0, 0, 1, 2])), new Point(0, 3)); | ||
| t.deepEquals((new Point(1, 1).matMult([1, 1, 1, 1])), new Point(2, 2)); | ||
| t.end(); | ||
| }); | ||
| t.test('#perp', function(t) { | ||
| t.test('calculates a vector perpendicular to the given vector', function() { | ||
| t.deepEqual(new Point(0, 1000).perp(), new Point(-1000, 0)); | ||
| t.end(); | ||
| }); | ||
| }); | ||
| t.test('#add', function(t) { | ||
| t.test('adds two vectors', function() { | ||
| t.deepEqual(new Point(0, 0).add(new Point(10, 10)), new Point(10, 10)); | ||
| t.end(); | ||
| }); | ||
| }); | ||
| t.test('#sub', function(t) { | ||
| t.test('adds subtracts a vector from another', function() { | ||
| t.deepEqual(new Point(0, 0).sub(new Point(10, 10)), new Point(-10, -10)); | ||
| t.end(); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
-20%480
16.5%0
-100%Yes
NaN23542
-1.29%5
-28.57%260
-28.77%2
Infinity%