@turf/polygonize 6.5.0 → 7.0.0-alpha.0
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.
- package/README.md +7 -6
- package/dist/es/index.js +6 -6
- package/dist/es/lib/Edge.js +16 -18
- package/dist/es/lib/EdgeRing.js +49 -60
- package/dist/es/lib/Graph.js +73 -86
- package/dist/es/lib/Node.js +35 -38
- package/dist/es/lib/util.js +3 -5
- package/dist/js/index.d.ts +1 -1
- package/dist/js/index.js +10 -12
- package/dist/js/lib/Edge.d.ts +1 -1
- package/dist/js/lib/Edge.js +18 -19
- package/dist/js/lib/EdgeRing.d.ts +2 -2
- package/dist/js/lib/EdgeRing.js +53 -65
- package/dist/js/lib/Graph.d.ts +1 -1
- package/dist/js/lib/Graph.js +79 -93
- package/dist/js/lib/Node.js +36 -38
- package/dist/js/lib/util.d.ts +1 -1
- package/dist/js/lib/util.js +6 -10
- package/package.json +9 -8
package/dist/js/lib/Node.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
const util_1 = require("./util");
|
|
4
4
|
/**
|
|
5
5
|
* Node
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
16
|
+
static buildId(coordinates) {
|
|
17
17
|
return coordinates.join(",");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
this.innerEdges = this.innerEdges.filter(
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
this.outerEdges = this.outerEdges.filter(
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
47
|
-
|
|
48
|
-
if (aNode.coordinates[0] -
|
|
49
|
-
bNode.coordinates[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] -
|
|
52
|
-
bNode.coordinates[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] -
|
|
55
|
-
bNode.coordinates[0] -
|
|
56
|
-
if (aNode.coordinates[1] -
|
|
57
|
-
bNode.coordinates[1] -
|
|
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
|
-
|
|
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
|
-
|
|
67
|
-
Math.pow(aNode.coordinates[1] -
|
|
68
|
-
Math.pow(bNode.coordinates[1] -
|
|
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
|
-
|
|
81
|
+
getOuterEdges() {
|
|
83
82
|
this.sortOuterEdges();
|
|
84
83
|
return this.outerEdges;
|
|
85
|
-
}
|
|
86
|
-
|
|
84
|
+
}
|
|
85
|
+
getOuterEdge(i) {
|
|
87
86
|
this.sortOuterEdges();
|
|
88
87
|
return this.outerEdges[i];
|
|
89
|
-
}
|
|
90
|
-
|
|
88
|
+
}
|
|
89
|
+
addInnerEdge(edge) {
|
|
91
90
|
this.innerEdges.push(edge);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
}());
|
|
91
|
+
}
|
|
92
|
+
}
|
|
95
93
|
exports.default = Node;
|
package/dist/js/lib/util.d.ts
CHANGED
package/dist/js/lib/util.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
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": "
|
|
3
|
+
"version": "7.0.0-alpha.0",
|
|
4
4
|
"description": "turf polygonize module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"docs": "node ../../scripts/generate-readmes",
|
|
49
49
|
"test": "npm-run-all test:*",
|
|
50
50
|
"test:tape": "ts-node -r esm test.js",
|
|
51
|
-
"test:types": "tsc --esModuleInterop --noEmit types.ts"
|
|
51
|
+
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"benchmark": "*",
|
|
@@ -61,11 +61,12 @@
|
|
|
61
61
|
"write-json-file": "*"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@turf/boolean-point-in-polygon": "^
|
|
65
|
-
"@turf/envelope": "^
|
|
66
|
-
"@turf/helpers": "^
|
|
67
|
-
"@turf/invariant": "^
|
|
68
|
-
"@turf/meta": "^
|
|
64
|
+
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.0",
|
|
65
|
+
"@turf/envelope": "^7.0.0-alpha.0",
|
|
66
|
+
"@turf/helpers": "^7.0.0-alpha.0",
|
|
67
|
+
"@turf/invariant": "^7.0.0-alpha.0",
|
|
68
|
+
"@turf/meta": "^7.0.0-alpha.0",
|
|
69
|
+
"tslib": "^2.3.0"
|
|
69
70
|
},
|
|
70
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
|
|
71
72
|
}
|