@turf/polygonize 6.5.0 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var util_1 = require("./util");
3
+ const util_1 = require("./util");
4
4
  /**
5
5
  * Node
6
6
  */
7
- var Node = /** @class */ (function () {
8
- function Node(coordinates) {
7
+ class Node {
8
+ constructor(coordinates) {
9
9
  this.id = Node.buildId(coordinates);
10
10
  this.coordinates = coordinates; //< {Number[]}
11
11
  this.innerEdges = []; //< {Edge[]}
@@ -13,64 +13,63 @@ var Node = /** @class */ (function () {
13
13
  this.outerEdges = []; //< {Edge[]}
14
14
  this.outerEdgesSorted = false; //< {Boolean} flag that stores if the outer Edges had been sorted
15
15
  }
16
- Node.buildId = function (coordinates) {
16
+ static buildId(coordinates) {
17
17
  return coordinates.join(",");
18
- };
19
- Node.prototype.removeInnerEdge = function (edge) {
20
- this.innerEdges = this.innerEdges.filter(function (e) { return e.from.id !== edge.from.id; });
21
- };
22
- Node.prototype.removeOuterEdge = function (edge) {
23
- this.outerEdges = this.outerEdges.filter(function (e) { return e.to.id !== edge.to.id; });
24
- };
18
+ }
19
+ removeInnerEdge(edge) {
20
+ this.innerEdges = this.innerEdges.filter((e) => e.from.id !== edge.from.id);
21
+ }
22
+ removeOuterEdge(edge) {
23
+ this.outerEdges = this.outerEdges.filter((e) => e.to.id !== edge.to.id);
24
+ }
25
25
  /**
26
26
  * Outer edges are stored CCW order.
27
27
  *
28
28
  * @memberof Node
29
29
  * @param {Edge} edge - Edge to add as an outerEdge.
30
30
  */
31
- Node.prototype.addOuterEdge = function (edge) {
31
+ addOuterEdge(edge) {
32
32
  this.outerEdges.push(edge);
33
33
  this.outerEdgesSorted = false;
34
- };
34
+ }
35
35
  /**
36
36
  * Sorts outer edges in CCW way.
37
37
  *
38
38
  * @memberof Node
39
39
  * @private
40
40
  */
41
- Node.prototype.sortOuterEdges = function () {
42
- var _this = this;
41
+ sortOuterEdges() {
43
42
  if (!this.outerEdgesSorted) {
44
43
  //this.outerEdges.sort((a, b) => a.compareTo(b));
45
44
  // Using this comparator in order to be deterministic
46
- this.outerEdges.sort(function (a, b) {
47
- var aNode = a.to, bNode = b.to;
48
- if (aNode.coordinates[0] - _this.coordinates[0] >= 0 &&
49
- bNode.coordinates[0] - _this.coordinates[0] < 0)
45
+ this.outerEdges.sort((a, b) => {
46
+ const aNode = a.to, bNode = b.to;
47
+ if (aNode.coordinates[0] - this.coordinates[0] >= 0 &&
48
+ bNode.coordinates[0] - this.coordinates[0] < 0)
50
49
  return 1;
51
- if (aNode.coordinates[0] - _this.coordinates[0] < 0 &&
52
- bNode.coordinates[0] - _this.coordinates[0] >= 0)
50
+ if (aNode.coordinates[0] - this.coordinates[0] < 0 &&
51
+ bNode.coordinates[0] - this.coordinates[0] >= 0)
53
52
  return -1;
54
- if (aNode.coordinates[0] - _this.coordinates[0] === 0 &&
55
- bNode.coordinates[0] - _this.coordinates[0] === 0) {
56
- if (aNode.coordinates[1] - _this.coordinates[1] >= 0 ||
57
- bNode.coordinates[1] - _this.coordinates[1] >= 0)
53
+ if (aNode.coordinates[0] - this.coordinates[0] === 0 &&
54
+ bNode.coordinates[0] - this.coordinates[0] === 0) {
55
+ if (aNode.coordinates[1] - this.coordinates[1] >= 0 ||
56
+ bNode.coordinates[1] - this.coordinates[1] >= 0)
58
57
  return aNode.coordinates[1] - bNode.coordinates[1];
59
58
  return bNode.coordinates[1] - aNode.coordinates[1];
60
59
  }
61
- var det = util_1.orientationIndex(_this.coordinates, aNode.coordinates, bNode.coordinates);
60
+ const det = util_1.orientationIndex(this.coordinates, aNode.coordinates, bNode.coordinates);
62
61
  if (det < 0)
63
62
  return 1;
64
63
  if (det > 0)
65
64
  return -1;
66
- var d1 = Math.pow(aNode.coordinates[0] - _this.coordinates[0], 2) +
67
- Math.pow(aNode.coordinates[1] - _this.coordinates[1], 2), d2 = Math.pow(bNode.coordinates[0] - _this.coordinates[0], 2) +
68
- Math.pow(bNode.coordinates[1] - _this.coordinates[1], 2);
65
+ const d1 = Math.pow(aNode.coordinates[0] - this.coordinates[0], 2) +
66
+ Math.pow(aNode.coordinates[1] - this.coordinates[1], 2), d2 = Math.pow(bNode.coordinates[0] - this.coordinates[0], 2) +
67
+ Math.pow(bNode.coordinates[1] - this.coordinates[1], 2);
69
68
  return d1 - d2;
70
69
  });
71
70
  this.outerEdgesSorted = true;
72
71
  }
73
- };
72
+ }
74
73
  /**
75
74
  * Retrieves outer edges.
76
75
  *
@@ -79,17 +78,16 @@ var Node = /** @class */ (function () {
79
78
  * @memberof Node
80
79
  * @returns {Edge[]} - List of outer edges sorted in a CCW order.
81
80
  */
82
- Node.prototype.getOuterEdges = function () {
81
+ getOuterEdges() {
83
82
  this.sortOuterEdges();
84
83
  return this.outerEdges;
85
- };
86
- Node.prototype.getOuterEdge = function (i) {
84
+ }
85
+ getOuterEdge(i) {
87
86
  this.sortOuterEdges();
88
87
  return this.outerEdges[i];
89
- };
90
- Node.prototype.addInnerEdge = function (edge) {
88
+ }
89
+ addInnerEdge(edge) {
91
90
  this.innerEdges.push(edge);
92
- };
93
- return Node;
94
- }());
91
+ }
92
+ }
95
93
  exports.default = Node;
@@ -1,4 +1,4 @@
1
- import { Feature, Polygon } from "@turf/helpers";
1
+ import { Feature, Polygon } from "geojson";
2
2
  /**
3
3
  * Returns the direction of the point q relative to the vector p1 -> p2.
4
4
  *
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon"));
7
- var helpers_1 = require("@turf/helpers");
3
+ const tslib_1 = require("tslib");
4
+ const boolean_point_in_polygon_1 = tslib_1.__importDefault(require("@turf/boolean-point-in-polygon"));
5
+ const helpers_1 = require("@turf/helpers");
8
6
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign#Polyfill
9
7
  function mathSign(x) {
10
8
  return ((x > 0) - (x < 0) || +x);
@@ -24,7 +22,7 @@ function mathSign(x) {
24
22
  * 0 if q is colinear with p1->p2
25
23
  */
26
24
  function orientationIndex(p1, p2, q) {
27
- var dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1], dx2 = q[0] - p2[0], dy2 = q[1] - p2[1];
25
+ const dx1 = p2[0] - p1[0], dy1 = p2[1] - p1[1], dx2 = q[0] - p2[0], dy2 = q[1] - p2[1];
28
26
  return mathSign(dx1 * dy2 - dx2 * dy1);
29
27
  }
30
28
  exports.orientationIndex = orientationIndex;
@@ -38,7 +36,7 @@ exports.orientationIndex = orientationIndex;
38
36
  * @returns {boolean} - True if the envelopes are equal
39
37
  */
40
38
  function envelopeIsEqual(env1, env2) {
41
- var envX1 = env1.geometry.coordinates[0].map(function (c) { return c[0]; }), envY1 = env1.geometry.coordinates[0].map(function (c) { return c[1]; }), envX2 = env2.geometry.coordinates[0].map(function (c) { return c[0]; }), envY2 = env2.geometry.coordinates[0].map(function (c) { return c[1]; });
39
+ const envX1 = env1.geometry.coordinates[0].map((c) => c[0]), envY1 = env1.geometry.coordinates[0].map((c) => c[1]), envX2 = env2.geometry.coordinates[0].map((c) => c[0]), envY2 = env2.geometry.coordinates[0].map((c) => c[1]);
42
40
  return (Math.max.apply(null, envX1) === Math.max.apply(null, envX2) &&
43
41
  Math.max.apply(null, envY1) === Math.max.apply(null, envY2) &&
44
42
  Math.min.apply(null, envX1) === Math.min.apply(null, envX2) &&
@@ -57,9 +55,7 @@ exports.envelopeIsEqual = envelopeIsEqual;
57
55
  * @returns {boolean} - True if env is contained in self
58
56
  */
59
57
  function envelopeContains(self, env) {
60
- return env.geometry.coordinates[0].every(function (c) {
61
- return boolean_point_in_polygon_1.default(helpers_1.point(c), self);
62
- });
58
+ return env.geometry.coordinates[0].every((c) => boolean_point_in_polygon_1.default(helpers_1.point(c), self));
63
59
  }
64
60
  exports.envelopeContains = envelopeContains;
65
61
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/polygonize",
3
- "version": "6.5.0",
3
+ "version": "7.0.0-alpha.1",
4
4
  "description": "turf polygonize module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -31,6 +31,7 @@
31
31
  "exports": {
32
32
  "./package.json": "./package.json",
33
33
  ".": {
34
+ "types": "./dist/js/index.d.ts",
34
35
  "import": "./dist/es/index.js",
35
36
  "require": "./dist/js/index.js"
36
37
  }
@@ -41,14 +42,14 @@
41
42
  "dist"
42
43
  ],
43
44
  "scripts": {
44
- "bench": "ts-node bench.js",
45
+ "bench": "tsx bench.js",
45
46
  "build": "npm-run-all build:*",
46
47
  "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
47
48
  "build:js": "tsc",
48
- "docs": "node ../../scripts/generate-readmes",
49
+ "docs": "tsx ../../scripts/generate-readmes",
49
50
  "test": "npm-run-all test:*",
50
- "test:tape": "ts-node -r esm test.js",
51
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
51
+ "test:tape": "tsx test.js",
52
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
52
53
  },
53
54
  "devDependencies": {
54
55
  "benchmark": "*",
@@ -56,16 +57,17 @@
56
57
  "npm-run-all": "*",
57
58
  "rollup": "*",
58
59
  "tape": "*",
59
- "ts-node": "*",
60
+ "tsx": "*",
60
61
  "typescript": "*",
61
62
  "write-json-file": "*"
62
63
  },
63
64
  "dependencies": {
64
- "@turf/boolean-point-in-polygon": "^6.5.0",
65
- "@turf/envelope": "^6.5.0",
66
- "@turf/helpers": "^6.5.0",
67
- "@turf/invariant": "^6.5.0",
68
- "@turf/meta": "^6.5.0"
65
+ "@turf/boolean-point-in-polygon": "^7.0.0-alpha.1",
66
+ "@turf/envelope": "^7.0.0-alpha.1",
67
+ "@turf/helpers": "^7.0.0-alpha.1",
68
+ "@turf/invariant": "^7.0.0-alpha.1",
69
+ "@turf/meta": "^7.0.0-alpha.1",
70
+ "tslib": "^2.3.0"
69
71
  },
70
- "gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
72
+ "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
71
73
  }