@math.gl/polygon 3.5.6 → 3.6.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.
- package/dist/cut-by-grid.d.ts +20 -0
- package/dist/cut-by-grid.d.ts.map +1 -0
- package/dist/cut-by-grid.js +216 -0
- package/dist/cut-by-mercator-bounds.d.ts +16 -0
- package/dist/cut-by-mercator-bounds.d.ts.map +1 -0
- package/dist/cut-by-mercator-bounds.js +145 -0
- package/dist/{esm/earcut.d.ts → earcut.d.ts} +4 -2
- package/dist/earcut.d.ts.map +1 -0
- package/dist/earcut.js +611 -0
- package/dist/es5/cut-by-grid.js +70 -79
- package/dist/es5/cut-by-grid.js.map +1 -1
- package/dist/es5/cut-by-mercator-bounds.js +55 -87
- package/dist/es5/cut-by-mercator-bounds.js.map +1 -1
- package/dist/es5/earcut.js +97 -102
- package/dist/es5/earcut.js.map +1 -1
- package/dist/es5/index.js +14 -14
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lineclip.js +38 -41
- package/dist/es5/lineclip.js.map +1 -1
- package/dist/es5/polygon-utils.js +61 -69
- package/dist/es5/polygon-utils.js.map +1 -1
- package/dist/es5/polygon.js +35 -43
- package/dist/es5/polygon.js.map +1 -1
- package/dist/es5/utils.js +11 -12
- package/dist/es5/utils.js.map +1 -1
- package/dist/esm/cut-by-grid.js +4 -4
- package/dist/esm/cut-by-grid.js.map +1 -1
- package/dist/esm/cut-by-mercator-bounds.js +5 -5
- package/dist/esm/cut-by-mercator-bounds.js.map +1 -1
- package/dist/esm/earcut.js +9 -10
- package/dist/esm/earcut.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lineclip.js +5 -5
- package/dist/esm/lineclip.js.map +1 -1
- package/dist/esm/polygon-utils.js +7 -4
- package/dist/esm/polygon-utils.js.map +1 -1
- package/dist/esm/polygon.js +7 -0
- package/dist/esm/polygon.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/lineclip.d.ts +31 -0
- package/dist/lineclip.d.ts.map +1 -0
- package/dist/lineclip.js +178 -0
- package/dist/{es5/polygon-utils.d.ts → polygon-utils.d.ts} +28 -64
- package/dist/polygon-utils.d.ts.map +1 -0
- package/dist/polygon-utils.js +140 -0
- package/dist/polygon.d.ts +40 -0
- package/dist/polygon.d.ts.map +1 -0
- package/dist/polygon.js +67 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +34 -0
- package/package.json +4 -3
- package/src/{cut-by-grid.js → cut-by-grid.ts} +32 -4
- package/src/{cut-by-mercator-bounds.js → cut-by-mercator-bounds.ts} +26 -7
- package/src/{earcut.js → earcut.ts} +25 -13
- package/src/{index.js → index.ts} +0 -0
- package/src/{lineclip.js → lineclip.ts} +48 -20
- package/src/polygon-utils.ts +225 -0
- package/src/{polygon.js → polygon.ts} +40 -9
- package/src/{utils.js → utils.ts} +0 -0
- package/dist/es5/cut-by-grid.d.ts +0 -24
- package/dist/es5/cut-by-mercator-bounds.d.ts +0 -23
- package/dist/es5/earcut.d.ts +0 -9
- package/dist/es5/lineclip.d.ts +0 -25
- package/dist/es5/polygon.d.ts +0 -36
- package/dist/esm/cut-by-grid.d.ts +0 -24
- package/dist/esm/cut-by-mercator-bounds.d.ts +0 -23
- package/dist/esm/lineclip.d.ts +0 -25
- package/dist/esm/polygon-utils.d.ts +0 -117
- package/dist/esm/polygon.d.ts +0 -36
- package/src/cut-by-grid.d.ts +0 -24
- package/src/cut-by-mercator-bounds.d.ts +0 -23
- package/src/earcut.d.ts +0 -9
- package/src/lineclip.d.ts +0 -25
- package/src/polygon-utils.d.ts +0 -117
- package/src/polygon-utils.js +0 -127
- package/src/polygon.d.ts +0 -36
package/dist/es5/index.js
CHANGED
|
@@ -7,85 +7,85 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
Object.defineProperty(exports, "Polygon", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function
|
|
10
|
+
get: function () {
|
|
11
11
|
return _polygon.default;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
Object.defineProperty(exports, "_Polygon", {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function
|
|
16
|
+
get: function () {
|
|
17
17
|
return _polygon.default;
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
Object.defineProperty(exports, "getPolygonSignedArea", {
|
|
21
21
|
enumerable: true,
|
|
22
|
-
get: function
|
|
22
|
+
get: function () {
|
|
23
23
|
return _polygonUtils.getPolygonSignedArea;
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
Object.defineProperty(exports, "getPolygonWindingDirection", {
|
|
27
27
|
enumerable: true,
|
|
28
|
-
get: function
|
|
28
|
+
get: function () {
|
|
29
29
|
return _polygonUtils.getPolygonWindingDirection;
|
|
30
30
|
}
|
|
31
31
|
});
|
|
32
32
|
Object.defineProperty(exports, "forEachSegmentInPolygon", {
|
|
33
33
|
enumerable: true,
|
|
34
|
-
get: function
|
|
34
|
+
get: function () {
|
|
35
35
|
return _polygonUtils.forEachSegmentInPolygon;
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
Object.defineProperty(exports, "modifyPolygonWindingDirection", {
|
|
39
39
|
enumerable: true,
|
|
40
|
-
get: function
|
|
40
|
+
get: function () {
|
|
41
41
|
return _polygonUtils.modifyPolygonWindingDirection;
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
44
|
Object.defineProperty(exports, "WINDING", {
|
|
45
45
|
enumerable: true,
|
|
46
|
-
get: function
|
|
46
|
+
get: function () {
|
|
47
47
|
return _polygonUtils.WINDING;
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
Object.defineProperty(exports, "earcut", {
|
|
51
51
|
enumerable: true,
|
|
52
|
-
get: function
|
|
52
|
+
get: function () {
|
|
53
53
|
return _earcut.earcut;
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
56
|
Object.defineProperty(exports, "clipPolygon", {
|
|
57
57
|
enumerable: true,
|
|
58
|
-
get: function
|
|
58
|
+
get: function () {
|
|
59
59
|
return _lineclip.clipPolygon;
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
Object.defineProperty(exports, "clipPolyline", {
|
|
63
63
|
enumerable: true,
|
|
64
|
-
get: function
|
|
64
|
+
get: function () {
|
|
65
65
|
return _lineclip.clipPolyline;
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
Object.defineProperty(exports, "cutPolygonByGrid", {
|
|
69
69
|
enumerable: true,
|
|
70
|
-
get: function
|
|
70
|
+
get: function () {
|
|
71
71
|
return _cutByGrid.cutPolygonByGrid;
|
|
72
72
|
}
|
|
73
73
|
});
|
|
74
74
|
Object.defineProperty(exports, "cutPolylineByGrid", {
|
|
75
75
|
enumerable: true,
|
|
76
|
-
get: function
|
|
76
|
+
get: function () {
|
|
77
77
|
return _cutByGrid.cutPolylineByGrid;
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
80
|
Object.defineProperty(exports, "cutPolylineByMercatorBounds", {
|
|
81
81
|
enumerable: true,
|
|
82
|
-
get: function
|
|
82
|
+
get: function () {
|
|
83
83
|
return _cutByMercatorBounds.cutPolylineByMercatorBounds;
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
Object.defineProperty(exports, "cutPolygonByMercatorBounds", {
|
|
87
87
|
enumerable: true,
|
|
88
|
-
get: function
|
|
88
|
+
get: function () {
|
|
89
89
|
return _cutByMercatorBounds.cutPolygonByMercatorBounds;
|
|
90
90
|
}
|
|
91
91
|
});
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AAQA;;AAEA;;AAEA;;AAEA","sourcesContent":["export {default as Polygon} from './polygon';\n\nexport {\n getPolygonSignedArea,\n getPolygonWindingDirection,\n forEachSegmentInPolygon,\n modifyPolygonWindingDirection,\n WINDING\n} from './polygon-utils';\n\nexport {earcut} from './earcut';\n\nexport {clipPolygon, clipPolyline} from './lineclip';\n\nexport {cutPolygonByGrid, cutPolylineByGrid} from './cut-by-grid';\n\nexport {cutPolylineByMercatorBounds, cutPolygonByMercatorBounds} from './cut-by-mercator-bounds';\n\n// DEPRECATED\nexport {default as _Polygon} from './polygon';\n"],"file":"index.js"}
|
package/dist/es5/lineclip.js
CHANGED
|
@@ -10,24 +10,22 @@ exports.bitCode = bitCode;
|
|
|
10
10
|
|
|
11
11
|
var _utils = require("./utils");
|
|
12
12
|
|
|
13
|
-
function clipPolyline(positions, bbox) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
for (var i = 1; i < numPoints; i++) {
|
|
13
|
+
function clipPolyline(positions, bbox, options) {
|
|
14
|
+
const {
|
|
15
|
+
size = 2,
|
|
16
|
+
startIndex = 0,
|
|
17
|
+
endIndex = positions.length
|
|
18
|
+
} = options || {};
|
|
19
|
+
const numPoints = (endIndex - startIndex) / size;
|
|
20
|
+
const result = [];
|
|
21
|
+
let part = [];
|
|
22
|
+
let a;
|
|
23
|
+
let b;
|
|
24
|
+
let codeA = -1;
|
|
25
|
+
let codeB;
|
|
26
|
+
let lastCode;
|
|
27
|
+
|
|
28
|
+
for (let i = 1; i < numPoints; i++) {
|
|
31
29
|
a = (0, _utils.getPointAtIndex)(positions, i - 1, size, startIndex, a);
|
|
32
30
|
b = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, b);
|
|
33
31
|
|
|
@@ -71,27 +69,27 @@ function clipPolyline(positions, bbox) {
|
|
|
71
69
|
return result;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
function clipPolygon(positions, bbox) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (
|
|
72
|
+
function clipPolygon(positions, bbox, options) {
|
|
73
|
+
const {
|
|
74
|
+
size = 2,
|
|
75
|
+
endIndex = positions.length
|
|
76
|
+
} = options || {};
|
|
77
|
+
let {
|
|
78
|
+
startIndex = 0
|
|
79
|
+
} = options || {};
|
|
80
|
+
let numPoints = (endIndex - startIndex) / size;
|
|
81
|
+
let result;
|
|
82
|
+
let p;
|
|
83
|
+
let prev;
|
|
84
|
+
let inside;
|
|
85
|
+
let prevInside;
|
|
86
|
+
|
|
87
|
+
for (let edge = 1; edge <= 8; edge *= 2) {
|
|
90
88
|
result = [];
|
|
91
89
|
prev = (0, _utils.getPointAtIndex)(positions, numPoints - 1, size, startIndex, prev);
|
|
92
90
|
prevInside = !(bitCode(prev, bbox) & edge);
|
|
93
91
|
|
|
94
|
-
for (
|
|
92
|
+
for (let i = 0; i < numPoints; i++) {
|
|
95
93
|
p = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, p);
|
|
96
94
|
inside = !(bitCode(p, bbox) & edge);
|
|
97
95
|
if (inside !== prevInside) (0, _utils.push)(result, intersect(prev, p, edge, bbox));
|
|
@@ -109,10 +107,9 @@ function clipPolygon(positions, bbox) {
|
|
|
109
107
|
return result;
|
|
110
108
|
}
|
|
111
109
|
|
|
112
|
-
function intersect(a, b, edge, bbox) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var snap;
|
|
110
|
+
function intersect(a, b, edge, bbox, out = []) {
|
|
111
|
+
let t;
|
|
112
|
+
let snap;
|
|
116
113
|
|
|
117
114
|
if (edge & 8) {
|
|
118
115
|
t = (bbox[3] - a[1]) / (b[1] - a[1]);
|
|
@@ -130,7 +127,7 @@ function intersect(a, b, edge, bbox) {
|
|
|
130
127
|
return null;
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
for (
|
|
130
|
+
for (let i = 0; i < a.length; i++) {
|
|
134
131
|
out[i] = (snap & 1) === i ? bbox[snap] : t * (b[i] - a[i]) + a[i];
|
|
135
132
|
}
|
|
136
133
|
|
|
@@ -138,7 +135,7 @@ function intersect(a, b, edge, bbox) {
|
|
|
138
135
|
}
|
|
139
136
|
|
|
140
137
|
function bitCode(p, bbox) {
|
|
141
|
-
|
|
138
|
+
let code = 0;
|
|
142
139
|
if (p[0] < bbox[0]) code |= 1;else if (p[0] > bbox[2]) code |= 2;
|
|
143
140
|
if (p[1] < bbox[1]) code |= 4;else if (p[1] > bbox[3]) code |= 8;
|
|
144
141
|
return code;
|
package/dist/es5/lineclip.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lineclip.js"],"names":["clipPolyline","positions","bbox","options","size","startIndex","endIndex","length","numPoints","result","part","a","b","codeA","codeB","lastCode","i","bitCode","push","intersect","clipPolygon","p","prev","inside","prevInside","edge","out","t","snap","code"],"mappings":";;;;;;;;;;AAwBA;;AAIO,SAASA,YAAT,CAAsBC,SAAtB,EAAiCC,IAAjC,EAAqD;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AAC1D,sBAAgEA,OAAhE,CAAOC,IAAP;AAAA,MAAOA,IAAP,8BAAc,CAAd;AAAA,4BAAgED,OAAhE,CAAiBE,UAAjB;AAAA,MAAiBA,UAAjB,oCAA8B,CAA9B;AAAA,0BAAgEF,OAAhE,CAAiCG,QAAjC;AAAA,MAAiCA,QAAjC,kCAA4CL,SAAS,CAACM,MAAtD;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ST,OAAT,CAAiBI,CAAjB,EAAoBnB,IAApB,EAA0B;AAC/B,MAAI2B,IAAI,GAAG,CAAX;AAEA,MAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR,CAApB,KAEK,IAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR;AAEzB,MAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR,CAApB,KAEK,IAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR;AAEzB,SAAOA,IAAP;AACD","sourcesContent":["/*\n Adapted from https://github.com/mapbox/lineclip to work with flat arrays\n and 3d positions\n\n ISC License\n\n Copyright (c) 2015, Mapbox\n\n Permission to use, copy, modify, and/or distribute this software for any purpose\n with or without fee is hereby granted, provided that the above copyright notice\n and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n THIS SOFTWARE.\n\n */\n\n/* eslint-disable max-statements, max-depth */\n\nimport {push, copy, getPointAtIndex} from './utils';\n\n// Cohen-Sutherland line clipping algorithm, adapted to efficiently\n// handle polylines rather than just segments\nexport function clipPolyline(positions, bbox, options = {}) {\n const {size = 2, startIndex = 0, endIndex = positions.length} = options;\n const numPoints = (endIndex - startIndex) / size;\n const result = [];\n let part = [];\n let a;\n let b;\n let codeA = -1;\n let codeB;\n let lastCode;\n\n for (let i = 1; i < numPoints; i++) {\n a = getPointAtIndex(positions, i - 1, size, startIndex, a);\n b = getPointAtIndex(positions, i, size, startIndex, b);\n if (codeA < 0) {\n codeA = bitCode(a, bbox);\n }\n codeB = lastCode = bitCode(b, bbox);\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (!(codeA | codeB)) {\n // accept\n push(part, a);\n\n if (codeB !== lastCode) {\n // segment went outside\n push(part, b);\n\n if (i < numPoints - 1) {\n // start a new line\n result.push(part);\n part = [];\n }\n } else if (i === numPoints - 1) {\n push(part, b);\n }\n break;\n } else if (codeA & codeB) {\n // trivial reject\n break;\n } else if (codeA) {\n // a outside, intersect with clip edge\n intersect(a, b, codeA, bbox, a);\n codeA = bitCode(a, bbox);\n } else {\n // b outside\n intersect(a, b, codeB, bbox, b);\n codeB = bitCode(b, bbox);\n }\n }\n\n codeA = lastCode;\n }\n\n if (part.length) result.push(part);\n\n return result;\n}\n\n// Sutherland-Hodgeman polygon clipping algorithm\n// polygon must be closed (first vertex == last vertex)\nexport function clipPolygon(positions, bbox, options = {}) {\n const {size = 2, endIndex = positions.length} = options;\n let {startIndex = 0} = options;\n let numPoints = (endIndex - startIndex) / size;\n let result;\n let p;\n let prev;\n let inside;\n let prevInside;\n\n // clip against each side of the clip rectangle\n for (let edge = 1; edge <= 8; edge *= 2) {\n result = [];\n prev = getPointAtIndex(positions, numPoints - 1, size, startIndex, prev);\n prevInside = !(bitCode(prev, bbox) & edge);\n\n for (let i = 0; i < numPoints; i++) {\n p = getPointAtIndex(positions, i, size, startIndex, p);\n inside = !(bitCode(p, bbox) & edge);\n\n // if segment goes through the clip window, add an intersection\n if (inside !== prevInside) push(result, intersect(prev, p, edge, bbox));\n\n if (inside) push(result, p); // add a point if it's inside\n\n copy(prev, p);\n prevInside = inside;\n }\n\n // close loop\n positions = result;\n startIndex = 0;\n numPoints = result.length / size;\n\n if (!numPoints) break;\n }\n\n return result;\n}\n\n// intersect a segment against one of the 4 lines that make up the bbox\n\nexport function intersect(a, b, edge, bbox, out = []) {\n let t;\n // Forces out[snapI] to be on the bbox edge\n // Interpolation introduces precision issue which may cause lineclip to be\n // stuck in an infinite loop\n let snap;\n if (edge & 8) {\n // top\n t = (bbox[3] - a[1]) / (b[1] - a[1]);\n snap = 3;\n } else if (edge & 4) {\n // bottom\n t = (bbox[1] - a[1]) / (b[1] - a[1]);\n snap = 1;\n } else if (edge & 2) {\n // right\n t = (bbox[2] - a[0]) / (b[0] - a[0]);\n snap = 2;\n } else if (edge & 1) {\n // left\n t = (bbox[0] - a[0]) / (b[0] - a[0]);\n snap = 0;\n } else {\n return null;\n }\n for (let i = 0; i < a.length; i++) {\n out[i] = (snap & 1) === i ? bbox[snap] : t * (b[i] - a[i]) + a[i];\n }\n return out;\n}\n\n// bit code reflects the point position relative to the bbox:\n\n// left mid right\n// top 1001 1000 1010\n// mid 0001 0000 0010\n// bottom 0101 0100 0110\n\nexport function bitCode(p, bbox) {\n let code = 0;\n\n if (p[0] < bbox[0]) code |= 1;\n // left\n else if (p[0] > bbox[2]) code |= 2; // right\n\n if (p[1] < bbox[1]) code |= 4;\n // bottom\n else if (p[1] > bbox[3]) code |= 8; // top\n\n return code;\n}\n"],"file":"lineclip.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/lineclip.ts"],"names":["clipPolyline","positions","bbox","options","size","startIndex","endIndex","length","numPoints","result","part","a","b","codeA","codeB","lastCode","i","bitCode","push","intersect","clipPolygon","p","prev","inside","prevInside","edge","out","t","snap","code"],"mappings":";;;;;;;;;;AAwBA;;AAQO,SAASA,YAAT,CACLC,SADK,EAELC,IAFK,EAGLC,OAHK,EAQO;AACZ,QAAM;AAACC,IAAAA,IAAI,GAAG,CAAR;AAAWC,IAAAA,UAAU,GAAG,CAAx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I,CAAjB,EAA8BnB,IAA9B,EAAyD;AAC9D,MAAI2B,IAAI,GAAG,CAAX;AAEA,MAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR,CAApB,KAEK,IAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR;AAEzB,MAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR,CAApB,KAEK,IAAIR,CAAC,CAAC,CAAD,CAAD,GAAOnB,IAAI,CAAC,CAAD,CAAf,EAAoB2B,IAAI,IAAI,CAAR;AAEzB,SAAOA,IAAP;AACD","sourcesContent":["/*\n Adapted from https://github.com/mapbox/lineclip to work with flat arrays\n and 3d positions\n\n ISC License\n\n Copyright (c) 2015, Mapbox\n\n Permission to use, copy, modify, and/or distribute this software for any purpose\n with or without fee is hereby granted, provided that the above copyright notice\n and this permission notice appear in all copies.\n\n THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND\n FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS\n OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER\n TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF\n THIS SOFTWARE.\n\n */\n\n/* eslint-disable max-statements, max-depth, complexity */\n\nimport {push, copy, getPointAtIndex} from './utils';\n\ntype BoundingBox = [number, number, number, number];\n\n/**\n * Cohen-Sutherland line clipping algorithm, adapted to efficiently\n * handle polylines rather than just segments\n */\nexport function clipPolyline(\n positions: number[],\n bbox: BoundingBox,\n options?: {\n size?: number;\n startIndex?: number;\n endIndex?: number;\n }\n): number[][] {\n const {size = 2, startIndex = 0, endIndex = positions.length} = options || {};\n const numPoints = (endIndex - startIndex) / size;\n const result = [];\n let part = [];\n let a;\n let b;\n let codeA = -1;\n let codeB;\n let lastCode;\n\n for (let i = 1; i < numPoints; i++) {\n a = getPointAtIndex(positions, i - 1, size, startIndex, a);\n b = getPointAtIndex(positions, i, size, startIndex, b);\n if (codeA < 0) {\n codeA = bitCode(a, bbox);\n }\n codeB = lastCode = bitCode(b, bbox);\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n if (!(codeA | codeB)) {\n // accept\n push(part, a);\n\n if (codeB !== lastCode) {\n // segment went outside\n push(part, b);\n\n if (i < numPoints - 1) {\n // start a new line\n result.push(part);\n part = [];\n }\n } else if (i === numPoints - 1) {\n push(part, b);\n }\n break;\n } else if (codeA & codeB) {\n // trivial reject\n break;\n } else if (codeA) {\n // a outside, intersect with clip edge\n intersect(a, b, codeA, bbox, a);\n codeA = bitCode(a, bbox);\n } else {\n // b outside\n intersect(a, b, codeB, bbox, b);\n codeB = bitCode(b, bbox);\n }\n }\n\n codeA = lastCode;\n }\n\n if (part.length) result.push(part);\n\n return result;\n}\n\n/**\n * Sutherland-Hodgeman polygon clipping algorithm\n * polygon must be closed (first vertex == last vertex)\n */\nexport function clipPolygon(\n positions: number[],\n bbox: BoundingBox,\n options?: {\n size?: number;\n startIndex?: number;\n endIndex?: number;\n }\n): number[] {\n const {size = 2, endIndex = positions.length} = options || {};\n let {startIndex = 0} = options || {};\n let numPoints = (endIndex - startIndex) / size;\n let result;\n let p;\n let prev;\n let inside;\n let prevInside;\n\n // clip against each side of the clip rectangle\n for (let edge = 1; edge <= 8; edge *= 2) {\n result = [];\n prev = getPointAtIndex(positions, numPoints - 1, size, startIndex, prev);\n prevInside = !(bitCode(prev, bbox) & edge);\n\n for (let i = 0; i < numPoints; i++) {\n p = getPointAtIndex(positions, i, size, startIndex, p);\n inside = !(bitCode(p, bbox) & edge);\n\n // if segment goes through the clip window, add an intersection\n if (inside !== prevInside) push(result, intersect(prev, p, edge, bbox));\n\n if (inside) push(result, p); // add a point if it's inside\n\n copy(prev, p);\n prevInside = inside;\n }\n\n // close loop\n positions = result;\n startIndex = 0;\n numPoints = result.length / size;\n\n if (!numPoints) break;\n }\n\n return result;\n}\n\n/** intersect a segment against one of the 4 lines that make up the bbox */\n\nexport function intersect(\n a: number[],\n b: number[],\n edge: number,\n bbox: BoundingBox,\n out: number[] = []\n): number[] {\n let t;\n // Forces out[snapI] to be on the bbox edge\n // Interpolation introduces precision issue which may cause lineclip to be\n // stuck in an infinite loop\n let snap;\n if (edge & 8) {\n // top\n t = (bbox[3] - a[1]) / (b[1] - a[1]);\n snap = 3;\n } else if (edge & 4) {\n // bottom\n t = (bbox[1] - a[1]) / (b[1] - a[1]);\n snap = 1;\n } else if (edge & 2) {\n // right\n t = (bbox[2] - a[0]) / (b[0] - a[0]);\n snap = 2;\n } else if (edge & 1) {\n // left\n t = (bbox[0] - a[0]) / (b[0] - a[0]);\n snap = 0;\n } else {\n return null;\n }\n for (let i = 0; i < a.length; i++) {\n out[i] = (snap & 1) === i ? bbox[snap] : t * (b[i] - a[i]) + a[i];\n }\n return out;\n}\n\n/**\n * bit code reflects the point position relative to the bbox:\n * left mid right\n * top 1001 1000 1010\n * mid 0001 0000 0010\n * bottom 0101 0100 0110\n */\nexport function bitCode(p: number[], bbox: BoundingBox): number {\n let code = 0;\n\n if (p[0] < bbox[0]) code |= 1;\n // left\n else if (p[0] > bbox[2]) code |= 2; // right\n\n if (p[1] < bbox[1]) code |= 4;\n // bottom\n else if (p[1] > bbox[3]) code |= 8; // top\n\n return code;\n}\n"],"file":"lineclip.js"}
|
|
@@ -15,15 +15,16 @@ exports.WINDING = void 0;
|
|
|
15
15
|
|
|
16
16
|
var _core = require("@math.gl/core");
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
CLOCKWISE: 1,
|
|
20
|
-
COUNTER_CLOCKWISE: -1
|
|
21
|
-
};
|
|
18
|
+
let WINDING;
|
|
22
19
|
exports.WINDING = WINDING;
|
|
23
20
|
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
(function (WINDING) {
|
|
22
|
+
WINDING[WINDING["CLOCKWISE"] = 1] = "CLOCKWISE";
|
|
23
|
+
WINDING[WINDING["COUNTER_CLOCKWISE"] = -1] = "COUNTER_CLOCKWISE";
|
|
24
|
+
})(WINDING || (exports.WINDING = WINDING = {}));
|
|
25
|
+
|
|
26
|
+
function modifyPolygonWindingDirection(points, direction, options = {}) {
|
|
27
|
+
const windingDirection = getPolygonWindingDirection(points, options);
|
|
27
28
|
|
|
28
29
|
if (windingDirection !== direction) {
|
|
29
30
|
reversePolygon(points, options);
|
|
@@ -33,21 +34,19 @@ function modifyPolygonWindingDirection(points, direction) {
|
|
|
33
34
|
return false;
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
function getPolygonWindingDirection(points) {
|
|
37
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
37
|
+
function getPolygonWindingDirection(points, options = {}) {
|
|
38
38
|
return Math.sign(getPolygonSignedArea(points, options));
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function getPolygonSignedArea(points) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var area = 0;
|
|
41
|
+
function getPolygonSignedArea(points, options = {}) {
|
|
42
|
+
const {
|
|
43
|
+
start = 0,
|
|
44
|
+
end = points.length
|
|
45
|
+
} = options;
|
|
46
|
+
const dim = options.size || 2;
|
|
47
|
+
let area = 0;
|
|
49
48
|
|
|
50
|
-
for (
|
|
49
|
+
for (let i = start, j = end - dim; i < end; i += dim) {
|
|
51
50
|
area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);
|
|
52
51
|
j = i;
|
|
53
52
|
}
|
|
@@ -55,23 +54,21 @@ function getPolygonSignedArea(points) {
|
|
|
55
54
|
return area / 2;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
|
-
function forEachSegmentInPolygon(points, visitor) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
for (var i = 0; i < numPoints - 1; ++i) {
|
|
57
|
+
function forEachSegmentInPolygon(points, visitor, options = {}) {
|
|
58
|
+
const {
|
|
59
|
+
start = 0,
|
|
60
|
+
end = points.length,
|
|
61
|
+
size = 2,
|
|
62
|
+
isClosed
|
|
63
|
+
} = options;
|
|
64
|
+
const numPoints = (end - start) / size;
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < numPoints - 1; ++i) {
|
|
70
67
|
visitor(points[start + i * size], points[start + i * size + 1], points[start + (i + 1) * size], points[start + (i + 1) * size + 1], i, i + 1);
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const endPointIndex = start + (numPoints - 1) * size;
|
|
71
|
+
const isClosedEx = isClosed || (0, _core.equals)(points[start], points[endPointIndex]) && (0, _core.equals)(points[start + 1], points[endPointIndex + 1]);
|
|
75
72
|
|
|
76
73
|
if (!isClosedEx) {
|
|
77
74
|
visitor(points[endPointIndex], points[endPointIndex + 1], points[start], points[start + 1], numPoints - 1, 0);
|
|
@@ -79,30 +76,28 @@ function forEachSegmentInPolygon(points, visitor) {
|
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
function reversePolygon(points, options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var tmp = points[b1 + j];
|
|
79
|
+
const {
|
|
80
|
+
start = 0,
|
|
81
|
+
end = points.length,
|
|
82
|
+
size = 2
|
|
83
|
+
} = options;
|
|
84
|
+
const numPoints = (end - start) / size;
|
|
85
|
+
const numSwaps = Math.floor(numPoints / 2);
|
|
86
|
+
|
|
87
|
+
for (let i = 0; i < numSwaps; ++i) {
|
|
88
|
+
const b1 = start + i * size;
|
|
89
|
+
const b2 = start + (numPoints - 1 - i) * size;
|
|
90
|
+
|
|
91
|
+
for (let j = 0; j < size; ++j) {
|
|
92
|
+
const tmp = points[b1 + j];
|
|
97
93
|
points[b1 + j] = points[b2 + j];
|
|
98
94
|
points[b2 + j] = tmp;
|
|
99
95
|
}
|
|
100
96
|
}
|
|
101
97
|
}
|
|
102
98
|
|
|
103
|
-
function modifyPolygonWindingDirectionPoints(points, direction) {
|
|
104
|
-
|
|
105
|
-
var currentDirection = getPolygonWindingDirectionPoints(points, options);
|
|
99
|
+
function modifyPolygonWindingDirectionPoints(points, direction, options = {}) {
|
|
100
|
+
const currentDirection = getPolygonWindingDirectionPoints(points, options);
|
|
106
101
|
|
|
107
102
|
if (currentDirection !== direction) {
|
|
108
103
|
points.reverse();
|
|
@@ -112,20 +107,18 @@ function modifyPolygonWindingDirectionPoints(points, direction) {
|
|
|
112
107
|
return false;
|
|
113
108
|
}
|
|
114
109
|
|
|
115
|
-
function getPolygonWindingDirectionPoints(points) {
|
|
116
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
110
|
+
function getPolygonWindingDirectionPoints(points, options = {}) {
|
|
117
111
|
return Math.sign(getPolygonSignedAreaPoints(points, options));
|
|
118
112
|
}
|
|
119
113
|
|
|
120
|
-
function getPolygonSignedAreaPoints(points) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
var area = 0;
|
|
114
|
+
function getPolygonSignedAreaPoints(points, options = {}) {
|
|
115
|
+
const {
|
|
116
|
+
start = 0,
|
|
117
|
+
end = points.length
|
|
118
|
+
} = options;
|
|
119
|
+
let area = 0;
|
|
127
120
|
|
|
128
|
-
for (
|
|
121
|
+
for (let i = start, j = end - 1; i < end; ++i) {
|
|
129
122
|
area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);
|
|
130
123
|
j = i;
|
|
131
124
|
}
|
|
@@ -133,19 +126,18 @@ function getPolygonSignedAreaPoints(points) {
|
|
|
133
126
|
return area / 2;
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
function forEachSegmentInPolygonPoints(points, visitor) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
isClosed = options.isClosed;
|
|
129
|
+
function forEachSegmentInPolygonPoints(points, visitor, options = {}) {
|
|
130
|
+
const {
|
|
131
|
+
start = 0,
|
|
132
|
+
end = points.length,
|
|
133
|
+
isClosed
|
|
134
|
+
} = options;
|
|
143
135
|
|
|
144
|
-
for (
|
|
136
|
+
for (let i = start; i < end - 1; ++i) {
|
|
145
137
|
visitor(points[i], points[i + 1], i, i + 1);
|
|
146
138
|
}
|
|
147
139
|
|
|
148
|
-
|
|
140
|
+
const isClosedEx = isClosed || (0, _core.equals)(points[end - 1], points[0]);
|
|
149
141
|
|
|
150
142
|
if (!isClosedEx) {
|
|
151
143
|
visitor(points[end - 1], points[0], end - 1, 0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/polygon-utils.js"],"names":["WINDING","CLOCKWISE","COUNTER_CLOCKWISE","modifyPolygonWindingDirection","points","direction","options","windingDirection","getPolygonWindingDirection","reversePolygon","Math","sign","getPolygonSignedArea","start","end","length","dim","size","area","i","j","forEachSegmentInPolygon","visitor","isClosed","numPoints","endPointIndex","isClosedEx","numSwaps","floor","b1","b2","tmp","modifyPolygonWindingDirectionPoints","currentDirection","getPolygonWindingDirectionPoints","reverse","getPolygonSignedAreaPoints","forEachSegmentInPolygonPoints"],"mappings":";;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A,CAAC,GAAGD,CAAJ;AACD;;AACD,SAAOD,IAAI,GAAG,CAAd;AACD;;AAGM,SAASmB,6BAAT,CAAuCjC,MAAvC,EAA+CkB,OAA/C,EAAsE;AAAA,MAAdhB,OAAc,uEAAJ,EAAI;AAC3E,wBAAmDA,OAAnD,CAAOO,KAAP;AAAA,MAAOA,KAAP,gCAAe,CAAf;AAAA,sBAAmDP,OAAnD,CAAkBQ,GAAlB;AAAA,MAAkBA,GAAlB,8BAAwBV,MAAM,CAACW,MAA/B;AAAA,MAAuCQ,QAAvC,GAAmDjB,OAAnD,CAAuCiB,QAAvC;;AACA,OAAK,IAAIJ,CAAC,GAAGN,KAAb,EAAoBM,CAAC,GAAGL,GAAG,GAAG,CAA9B,EAAiC,EAAEK,CAAnC,EAAsC;AACpCG,IAAAA,OAAO,CAAClB,MAAM,CAACe,CAAD,CAAP,EAAYf,MAAM,CAACe,CAAC,GAAG,CAAL,CAAlB,EAA2BA,CAA3B,EAA8BA,CAAC,GAAG,CAAlC,CAAP;AACD;;AAED,MAAMO,UAAU,GAAGH,QAAQ,IAAI,kBAAOnB,MAAM,CAACU,GAAG,GAAG,CAAP,CAAb,EAAwBV,MAAM,CAAC,CAAD,CAA9B,CAA/B;;AACA,MAAI,CAACsB,UAAL,EAAiB;AACfJ,IAAAA,OAAO,CAAClB,MAAM,CAACU,GAAG,GAAG,CAAP,CAAP,EAAkBV,MAAM,CAAC,CAAD,CAAxB,EAA6BU,GAAG,GAAG,CAAnC,EAAsC,CAAtC,CAAP;AACD;AACF","sourcesContent":["/* eslint-disable max-statements, max-depth, complexity, no-unused-expressions */\n\nimport {equals} from '@math.gl/core';\n\n/** @type {typeof import('./polygon-utils').WINDING} */\nexport const WINDING = {\n CLOCKWISE: 1,\n COUNTER_CLOCKWISE: -1\n};\n\n/** @type {typeof import('./polygon-utils').modifyPolygonWindingDirection} */\nexport function modifyPolygonWindingDirection(points, direction, options = {}) {\n const windingDirection = getPolygonWindingDirection(points, options);\n if (windingDirection !== direction) {\n reversePolygon(points, options);\n return true;\n }\n return false;\n}\n\n/** @type {typeof import('./polygon-utils').getPolygonWindingDirection} */\nexport function getPolygonWindingDirection(points, options = {}) {\n return Math.sign(getPolygonSignedArea(points, options));\n}\n\n/** @type {typeof import('./polygon-utils').getPolygonSignedArea} */\nexport function getPolygonSignedArea(points, options = {}) {\n // https://en.wikipedia.org/wiki/Shoelace_formula\n const {start = 0, end = points.length} = options;\n const dim = options.size || 2;\n let area = 0;\n for (let i = start, j = end - dim; i < end; i += dim) {\n area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);\n j = i;\n }\n return area / 2;\n}\n\n/** @type {typeof import('./polygon-utils').forEachSegmentInPolygon} */\nexport function forEachSegmentInPolygon(points, visitor, options = {}) {\n const {start = 0, end = points.length, size = 2, isClosed} = options;\n\n const numPoints = (end - start) / size;\n for (let i = 0; i < numPoints - 1; ++i) {\n visitor(\n points[start + i * size],\n points[start + i * size + 1],\n points[start + (i + 1) * size],\n points[start + (i + 1) * size + 1],\n i,\n i + 1\n );\n }\n\n const endPointIndex = start + (numPoints - 1) * size;\n const isClosedEx =\n isClosed ||\n (equals(points[start], points[endPointIndex]) &&\n equals(points[start + 1], points[endPointIndex + 1]));\n\n if (!isClosedEx) {\n visitor(\n points[endPointIndex],\n points[endPointIndex + 1],\n points[start],\n points[start + 1],\n numPoints - 1,\n 0\n );\n }\n}\n\nfunction reversePolygon(points, options) {\n const {start = 0, end = points.length, size = 2} = options;\n\n const numPoints = (end - start) / size;\n const numSwaps = Math.floor(numPoints / 2);\n for (let i = 0; i < numSwaps; ++i) {\n const b1 = start + i * size;\n const b2 = start + (numPoints - 1 - i) * size;\n for (let j = 0; j < size; ++j) {\n const tmp = points[b1 + j];\n points[b1 + j] = points[b2 + j];\n points[b2 + j] = tmp;\n }\n }\n}\n\n/** @type {typeof import('./polygon-utils').modifyPolygonWindingDirectionPoints} */\nexport function modifyPolygonWindingDirectionPoints(points, direction, options = {}) {\n const currentDirection = getPolygonWindingDirectionPoints(points, options);\n if (currentDirection !== direction) {\n points.reverse();\n return true;\n }\n return false;\n}\n\n/** @type {typeof import('./polygon-utils').getPolygonWindingDirectionPoints} */\nexport function getPolygonWindingDirectionPoints(points, options = {}) {\n return Math.sign(getPolygonSignedAreaPoints(points, options));\n}\n\n/** @type {typeof import('./polygon-utils').getPolygonSignedAreaPoints} */\nexport function getPolygonSignedAreaPoints(points, options = {}) {\n // https://en.wikipedia.org/wiki/Shoelace_formula\n const {start = 0, end = points.length} = options;\n let area = 0;\n for (let i = start, j = end - 1; i < end; ++i) {\n area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);\n j = i;\n }\n return area / 2;\n}\n\n/** @type {typeof import('./polygon-utils').forEachSegmentInPolygonPoints} */\nexport function forEachSegmentInPolygonPoints(points, visitor, options = {}) {\n const {start = 0, end = points.length, isClosed} = options;\n for (let i = start; i < end - 1; ++i) {\n visitor(points[i], points[i + 1], i, i + 1);\n }\n\n const isClosedEx = isClosed || equals(points[end - 1], points[0]);\n if (!isClosedEx) {\n visitor(points[end - 1], points[0], end - 1, 0);\n }\n}\n"],"file":"polygon-utils.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/polygon-utils.ts"],"names":["WINDING","modifyPolygonWindingDirection","points","direction","options","windingDirection","getPolygonWindingDirection","reversePolygon","Math","sign","getPolygonSignedArea","start","end","length","dim","size","area","i","j","forEachSegmentInPolygon","visitor","isClosed","numPoints","endPointIndex","isClosedEx","numSwaps","floor","b1","b2","tmp","modifyPolygonWindingDirectionPoints","currentDirection","getPolygonWindingDirectionPoints","reverse","getPolygonSignedAreaPoints","forEachSegmentInPolygonPoints"],"mappings":";;;;;;;;;;;;;;;AAEA;;IAGYA,O;;;WAAAA,O;AAAAA,EAAAA,O,CAAAA,O;AAAAA,EAAAA,O,CAAAA,O;GAAAA,O,uBAAAA,O;;AA0CL,SAASC,6BAAT,CACLC,MADK,EAELC,SAFK,EAGLC,OAAsB,GAAG,EAHpB,EAII;AAC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AM,CAAC,CAAD,CAA9B,CAA/B;;AACA,MAAI,CAACsB,UAAL,EAAiB;AACfJ,IAAAA,OAAO,CAAClB,MAAM,CAACU,GAAG,GAAG,CAAP,CAAP,EAAkBV,MAAM,CAAC,CAAD,CAAxB,EAA6BU,GAAG,GAAG,CAAnC,EAAsC,CAAtC,CAAP;AACD;AACF","sourcesContent":["/* eslint-disable max-statements, max-depth, complexity, no-unused-expressions */\n\nimport {equals} from '@math.gl/core';\nimport type {NumericArray} from '@math.gl/core';\n\nexport enum WINDING {\n CLOCKWISE = 1,\n COUNTER_CLOCKWISE = -1\n}\n\n/** Polygon representation where each point is represented as a separate array of positions. */\ntype PointsArray = NumericArray[];\n\n/** Segment visitor callback type for polygons defined with flat arrays, */\ntype SegmentVisitorFlat = (\n p1x: number,\n p1y: number,\n p2x: number,\n p2y: number,\n i1: number,\n i2: number\n) => void;\n\n/** Segment visitor callback type for polygons defined with array of points. */\nexport type SegmentVisitorPoints = (\n p1: NumericArray,\n p2: NumericArray,\n i1: number,\n i2: number\n) => void;\n\n/** Parameters of a polygon. */\ntype PolygonParams = {\n start?: number; // Start index of the polygon in the array of positions. Defaults to 0.\n end?: number; // End index of the polygon in the array of positions. Defaults to number of positions.\n size?: number; // Size of a point, 2 (XZ) or 3 (XYZ). Defaults to 2. Affects only polygons stored in flat arrays.\n isClosed?: boolean; // Indicates that the first point of the polygon is equal to the last point, and additional checks should be ommited.\n};\n\n/**\n * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.\n * Note: points are modified in-place.\n * @param points An array that represents points of the polygon.\n * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.\n * @param options Parameters of the polygon.\n * @return Returns true if the winding direction was changed.\n */\nexport function modifyPolygonWindingDirection(\n points: NumericArray,\n direction: number,\n options: PolygonParams = {}\n): boolean {\n const windingDirection = getPolygonWindingDirection(points, options);\n if (windingDirection !== direction) {\n reversePolygon(points, options);\n return true;\n }\n return false;\n}\n\n/**\n * Returns winding direction of the polygon.\n * @param points An array that represents points of the polygon.\n * @param options Parameters of the polygon.\n * @returns Winding direction of the polygon.\n */\nexport function getPolygonWindingDirection(\n points: NumericArray,\n options: PolygonParams = {}\n): number {\n return Math.sign(getPolygonSignedArea(points, options));\n}\n\n/**\n * Returns signed area of the polygon.\n * @param points An array that represents points of the polygon.\n * @param options Parameters of the polygon.\n * @returns Signed area of the polygon.\n * https://en.wikipedia.org/wiki/Shoelace_formula\n */\nexport function getPolygonSignedArea(points: NumericArray, options: PolygonParams = {}): number {\n const {start = 0, end = points.length} = options;\n const dim = options.size || 2;\n let area = 0;\n for (let i = start, j = end - dim; i < end; i += dim) {\n area += (points[i] - points[j]) * (points[i + 1] + points[j + 1]);\n j = i;\n }\n return area / 2;\n}\n\n/**\n * Calls the visitor callback for each segment in the polygon.\n * @param points An array that represents points of the polygon\n * @param visitor A callback to call for each segment.\n * @param options Parameters of the polygon.\n */\nexport function forEachSegmentInPolygon(\n points: NumericArray,\n visitor: SegmentVisitorFlat,\n options: PolygonParams = {}\n): void {\n const {start = 0, end = points.length, size = 2, isClosed} = options;\n\n const numPoints = (end - start) / size;\n for (let i = 0; i < numPoints - 1; ++i) {\n visitor(\n points[start + i * size],\n points[start + i * size + 1],\n points[start + (i + 1) * size],\n points[start + (i + 1) * size + 1],\n i,\n i + 1\n );\n }\n\n const endPointIndex = start + (numPoints - 1) * size;\n const isClosedEx =\n isClosed ||\n (equals(points[start], points[endPointIndex]) &&\n equals(points[start + 1], points[endPointIndex + 1]));\n\n if (!isClosedEx) {\n visitor(\n points[endPointIndex],\n points[endPointIndex + 1],\n points[start],\n points[start + 1],\n numPoints - 1,\n 0\n );\n }\n}\n\nfunction reversePolygon(points, options) {\n const {start = 0, end = points.length, size = 2} = options;\n\n const numPoints = (end - start) / size;\n const numSwaps = Math.floor(numPoints / 2);\n for (let i = 0; i < numSwaps; ++i) {\n const b1 = start + i * size;\n const b2 = start + (numPoints - 1 - i) * size;\n for (let j = 0; j < size; ++j) {\n const tmp = points[b1 + j];\n points[b1 + j] = points[b2 + j];\n points[b2 + j] = tmp;\n }\n }\n}\n\n/**\n * Checks winding direction of the polygon and reverses the polygon in case of opposite winding direction.\n * Note: points are modified in-place.\n * @param points Array of points that represent the polygon.\n * @param direction Requested winding direction. 1 is for clockwise, -1 for counterclockwise winding direction.\n * @param options Parameters of the polygon.\n * @return Returns true if the winding direction was changed.\n */\nexport function modifyPolygonWindingDirectionPoints(\n points: PointsArray,\n direction: number,\n options: PolygonParams = {}\n): boolean {\n const currentDirection = getPolygonWindingDirectionPoints(points, options);\n if (currentDirection !== direction) {\n points.reverse();\n return true;\n }\n return false;\n}\n\n/**\n * Returns winding direction of the polygon.\n * @param points Array of points that represent the polygon.\n * @param options Parameters of the polygon.\n * @returns Winding direction of the polygon.\n */\nexport function getPolygonWindingDirectionPoints(\n points: PointsArray,\n options: PolygonParams = {}\n): number {\n return Math.sign(getPolygonSignedAreaPoints(points, options));\n}\n\n/**\n * Returns signed area of the polygon.\n * @param points Array of points that represent the polygon.\n * @param options Parameters of the polygon.\n * @returns Signed area of the polygon.\n */\nexport function getPolygonSignedAreaPoints(\n points: PointsArray,\n options: PolygonParams = {}\n): number {\n // https://en.wikipedia.org/wiki/Shoelace_formula\n const {start = 0, end = points.length} = options;\n let area = 0;\n for (let i = start, j = end - 1; i < end; ++i) {\n area += (points[i][0] - points[j][0]) * (points[i][1] + points[j][1]);\n j = i;\n }\n return area / 2;\n}\n\n/**\n * Calls visitor callback for each segment in the polygon.\n * @param points Array of points that represent the polygon.\n * @param visitor A callback to call for each segment.\n * @param options Parameters of the polygon.\n */\nexport function forEachSegmentInPolygonPoints(\n points: PointsArray,\n visitor: SegmentVisitorPoints,\n options: PolygonParams = {}\n): void {\n const {start = 0, end = points.length, isClosed} = options;\n for (let i = start; i < end - 1; ++i) {\n visitor(points[i], points[i + 1], i, i + 1);\n }\n\n const isClosedEx = isClosed || equals(points[end - 1], points[0]);\n if (!isClosedEx) {\n visitor(points[end - 1], points[0], end - 1, 0);\n }\n}\n"],"file":"polygon-utils.js"}
|
package/dist/es5/polygon.js
CHANGED
|
@@ -7,18 +7,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
11
|
|
|
14
12
|
var _core = require("@math.gl/core");
|
|
15
13
|
|
|
16
14
|
var _polygonUtils = require("./polygon-utils");
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(0,
|
|
16
|
+
class Polygon {
|
|
17
|
+
constructor(points, options = {}) {
|
|
18
|
+
(0, _defineProperty2.default)(this, "points", void 0);
|
|
19
|
+
(0, _defineProperty2.default)(this, "isFlatArray", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "options", void 0);
|
|
22
21
|
this.points = points;
|
|
23
22
|
this.isFlatArray = !(0, _core.isArray)(points[0]);
|
|
24
23
|
this.options = {
|
|
@@ -30,45 +29,38 @@ var Polygon = function () {
|
|
|
30
29
|
Object.freeze(this);
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(0, _polygonUtils.forEachSegmentInPolygon)(this.points, function (x1, y1, x2, y2, i1, i2) {
|
|
54
|
-
visitor([x1, y1], [x2, y2], i1, i2);
|
|
55
|
-
}, this.options);
|
|
56
|
-
} else {
|
|
57
|
-
(0, _polygonUtils.forEachSegmentInPolygonPoints)(this.points, visitor, this.options);
|
|
58
|
-
}
|
|
32
|
+
getSignedArea() {
|
|
33
|
+
if (this.isFlatArray) return (0, _polygonUtils.getPolygonSignedArea)(this.points, this.options);
|
|
34
|
+
return (0, _polygonUtils.getPolygonSignedAreaPoints)(this.points, this.options);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getArea() {
|
|
38
|
+
return Math.abs(this.getSignedArea());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getWindingDirection() {
|
|
42
|
+
return Math.sign(this.getSignedArea());
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
forEachSegment(visitor) {
|
|
46
|
+
if (this.isFlatArray) {
|
|
47
|
+
(0, _polygonUtils.forEachSegmentInPolygon)(this.points, (x1, y1, x2, y2, i1, i2) => {
|
|
48
|
+
visitor([x1, y1], [x2, y2], i1, i2);
|
|
49
|
+
}, this.options);
|
|
50
|
+
} else {
|
|
51
|
+
(0, _polygonUtils.forEachSegmentInPolygonPoints)(this.points, visitor, this.options);
|
|
59
52
|
}
|
|
60
|
-
}
|
|
61
|
-
key: "modifyWindingDirection",
|
|
62
|
-
value: function modifyWindingDirection(direction) {
|
|
63
|
-
if (this.isFlatArray) {
|
|
64
|
-
return (0, _polygonUtils.modifyPolygonWindingDirection)(this.points, direction, this.options);
|
|
65
|
-
}
|
|
53
|
+
}
|
|
66
54
|
|
|
67
|
-
|
|
55
|
+
modifyWindingDirection(direction) {
|
|
56
|
+
if (this.isFlatArray) {
|
|
57
|
+
return (0, _polygonUtils.modifyPolygonWindingDirection)(this.points, direction, this.options);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
59
|
+
|
|
60
|
+
return (0, _polygonUtils.modifyPolygonWindingDirectionPoints)(this.points, direction, this.options);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
72
64
|
|
|
73
65
|
exports.default = Polygon;
|
|
74
66
|
//# sourceMappingURL=polygon.js.map
|