rm-graphical-computing-node 1.0.151 → 1.0.153
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/index.mjs +1765 -10
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,1726 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
mod
|
|
29
29
|
));
|
|
30
30
|
|
|
31
|
+
// node_modules/splaytree/dist/splaytree.umd.cjs
|
|
32
|
+
var require_splaytree_umd = __commonJS({
|
|
33
|
+
"node_modules/splaytree/dist/splaytree.umd.cjs"(exports, module) {
|
|
34
|
+
(function(h, c) {
|
|
35
|
+
typeof exports == "object" && typeof module < "u" ? module.exports = c() : typeof define == "function" && define.amd ? define(c) : (h = typeof globalThis < "u" ? globalThis : h || self, h.SplayTree = c());
|
|
36
|
+
})(exports, (function() {
|
|
37
|
+
"use strict";
|
|
38
|
+
class h {
|
|
39
|
+
constructor(t, e) {
|
|
40
|
+
this.next = null, this.key = t, this.data = e, this.left = null, this.right = null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function c(n, t) {
|
|
44
|
+
return n > t ? 1 : n < t ? -1 : 0;
|
|
45
|
+
}
|
|
46
|
+
function u4(n, t, e) {
|
|
47
|
+
const r = new h(null, null);
|
|
48
|
+
let i = r, l = r;
|
|
49
|
+
for (; ; ) {
|
|
50
|
+
const o = e(n, t.key);
|
|
51
|
+
if (o < 0) {
|
|
52
|
+
if (t.left === null) break;
|
|
53
|
+
if (e(n, t.left.key) < 0) {
|
|
54
|
+
const s = t.left;
|
|
55
|
+
if (t.left = s.right, s.right = t, t = s, t.left === null) break;
|
|
56
|
+
}
|
|
57
|
+
l.left = t, l = t, t = t.left;
|
|
58
|
+
} else if (o > 0) {
|
|
59
|
+
if (t.right === null) break;
|
|
60
|
+
if (e(n, t.right.key) > 0) {
|
|
61
|
+
const s = t.right;
|
|
62
|
+
if (t.right = s.left, s.left = t, t = s, t.right === null) break;
|
|
63
|
+
}
|
|
64
|
+
i.right = t, i = t, t = t.right;
|
|
65
|
+
} else break;
|
|
66
|
+
}
|
|
67
|
+
return i.right = t.left, l.left = t.right, t.left = r.right, t.right = r.left, t;
|
|
68
|
+
}
|
|
69
|
+
function _(n, t, e, r) {
|
|
70
|
+
const i = new h(n, t);
|
|
71
|
+
if (e === null) return i.left = i.right = null, i;
|
|
72
|
+
e = u4(n, e, r);
|
|
73
|
+
const l = r(n, e.key);
|
|
74
|
+
return l < 0 ? (i.left = e.left, i.right = e, e.left = null) : l >= 0 && (i.right = e.right, i.left = e, e.right = null), i;
|
|
75
|
+
}
|
|
76
|
+
function d(n, t, e) {
|
|
77
|
+
let r = null, i = null;
|
|
78
|
+
if (t) {
|
|
79
|
+
t = u4(n, t, e);
|
|
80
|
+
const l = e(t.key, n);
|
|
81
|
+
l === 0 ? (r = t.left, i = t.right) : l < 0 ? (i = t.right, t.right = null, r = t) : (r = t.left, t.left = null, i = t);
|
|
82
|
+
}
|
|
83
|
+
return { left: r, right: i };
|
|
84
|
+
}
|
|
85
|
+
function w(n, t, e) {
|
|
86
|
+
return t === null ? n : (n === null || (t = u4(n.key, t, e), t.left = n), t);
|
|
87
|
+
}
|
|
88
|
+
function a(n, t, e, r, i) {
|
|
89
|
+
if (n) {
|
|
90
|
+
r(`${t}${e ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 "}${i(n)}
|
|
91
|
+
`);
|
|
92
|
+
const l = t + (e ? " " : "\u2502 ");
|
|
93
|
+
n.left && a(n.left, l, false, r, i), n.right && a(n.right, l, true, r, i);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class x {
|
|
97
|
+
constructor(t = c) {
|
|
98
|
+
this._root = null, this._size = 0, this._comparator = t;
|
|
99
|
+
}
|
|
100
|
+
insert(t, e) {
|
|
101
|
+
return this._size++, this._root = _(t, e, this._root, this._comparator);
|
|
102
|
+
}
|
|
103
|
+
add(t, e) {
|
|
104
|
+
const r = new h(t, e);
|
|
105
|
+
this._root === null && (r.left = r.right = null, this._size++, this._root = r);
|
|
106
|
+
const i = this._comparator, l = u4(t, this._root, i), o = i(t, l.key);
|
|
107
|
+
return o === 0 ? this._root = l : (o < 0 ? (r.left = l.left, r.right = l, l.left = null) : o > 0 && (r.right = l.right, r.left = l, l.right = null), this._size++, this._root = r), this._root;
|
|
108
|
+
}
|
|
109
|
+
remove(t) {
|
|
110
|
+
this._root = this._remove(t, this._root, this._comparator);
|
|
111
|
+
}
|
|
112
|
+
_remove(t, e, r) {
|
|
113
|
+
let i;
|
|
114
|
+
return e === null ? null : (e = u4(t, e, r), r(t, e.key) === 0 ? (e.left === null ? i = e.right : (i = u4(t, e.left, r), i.right = e.right), this._size--, i) : e);
|
|
115
|
+
}
|
|
116
|
+
pop() {
|
|
117
|
+
let t = this._root;
|
|
118
|
+
if (t) {
|
|
119
|
+
for (; t.left; ) t = t.left;
|
|
120
|
+
return this._root = u4(t.key, this._root, this._comparator), this._root = this._remove(t.key, this._root, this._comparator), { key: t.key, data: t.data };
|
|
121
|
+
}
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
findStatic(t) {
|
|
125
|
+
let e = this._root;
|
|
126
|
+
const r = this._comparator;
|
|
127
|
+
for (; e; ) {
|
|
128
|
+
const i = r(t, e.key);
|
|
129
|
+
if (i === 0) return e;
|
|
130
|
+
i < 0 ? e = e.left : e = e.right;
|
|
131
|
+
}
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
find(t) {
|
|
135
|
+
return this._root && (this._root = u4(t, this._root, this._comparator), this._comparator(t, this._root.key) !== 0) ? null : this._root;
|
|
136
|
+
}
|
|
137
|
+
contains(t) {
|
|
138
|
+
let e = this._root;
|
|
139
|
+
const r = this._comparator;
|
|
140
|
+
for (; e; ) {
|
|
141
|
+
const i = r(t, e.key);
|
|
142
|
+
if (i === 0) return true;
|
|
143
|
+
i < 0 ? e = e.left : e = e.right;
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
forEach(t, e) {
|
|
148
|
+
let r = this._root;
|
|
149
|
+
const i = [];
|
|
150
|
+
let l = false;
|
|
151
|
+
for (; !l; ) r !== null ? (i.push(r), r = r.left) : i.length !== 0 ? (r = i.pop(), t.call(e, r), r = r.right) : l = true;
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
range(t, e, r, i) {
|
|
155
|
+
const l = [], o = this._comparator;
|
|
156
|
+
let s = this._root, f;
|
|
157
|
+
for (; l.length !== 0 || s; ) if (s) l.push(s), s = s.left;
|
|
158
|
+
else {
|
|
159
|
+
if (s = l.pop(), f = o(s.key, e), f > 0) break;
|
|
160
|
+
if (o(s.key, t) >= 0 && r.call(i, s)) return this;
|
|
161
|
+
s = s.right;
|
|
162
|
+
}
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
keys() {
|
|
166
|
+
const t = [];
|
|
167
|
+
return this.forEach(({ key: e }) => {
|
|
168
|
+
t.push(e);
|
|
169
|
+
}), t;
|
|
170
|
+
}
|
|
171
|
+
values() {
|
|
172
|
+
const t = [];
|
|
173
|
+
return this.forEach(({ data: e }) => {
|
|
174
|
+
t.push(e);
|
|
175
|
+
}), t;
|
|
176
|
+
}
|
|
177
|
+
min() {
|
|
178
|
+
return this._root ? this.minNode(this._root).key : null;
|
|
179
|
+
}
|
|
180
|
+
max() {
|
|
181
|
+
return this._root ? this.maxNode(this._root).key : null;
|
|
182
|
+
}
|
|
183
|
+
minNode(t = this._root) {
|
|
184
|
+
if (t) for (; t.left; ) t = t.left;
|
|
185
|
+
return t;
|
|
186
|
+
}
|
|
187
|
+
maxNode(t = this._root) {
|
|
188
|
+
if (t) for (; t.right; ) t = t.right;
|
|
189
|
+
return t;
|
|
190
|
+
}
|
|
191
|
+
at(t) {
|
|
192
|
+
let e = this._root, r = false, i = 0;
|
|
193
|
+
const l = [];
|
|
194
|
+
for (; !r; ) if (e) l.push(e), e = e.left;
|
|
195
|
+
else if (l.length > 0) {
|
|
196
|
+
if (e = l.pop(), i === t) return e;
|
|
197
|
+
i++, e = e.right;
|
|
198
|
+
} else r = true;
|
|
199
|
+
return null;
|
|
200
|
+
}
|
|
201
|
+
next(t) {
|
|
202
|
+
let e = this._root, r = null;
|
|
203
|
+
if (t.right) {
|
|
204
|
+
for (r = t.right; r.left; ) r = r.left;
|
|
205
|
+
return r;
|
|
206
|
+
}
|
|
207
|
+
const i = this._comparator;
|
|
208
|
+
for (; e; ) {
|
|
209
|
+
const l = i(t.key, e.key);
|
|
210
|
+
if (l === 0) break;
|
|
211
|
+
l < 0 ? (r = e, e = e.left) : e = e.right;
|
|
212
|
+
}
|
|
213
|
+
return r;
|
|
214
|
+
}
|
|
215
|
+
prev(t) {
|
|
216
|
+
let e = this._root, r = null;
|
|
217
|
+
if (t.left !== null) {
|
|
218
|
+
for (r = t.left; r.right; ) r = r.right;
|
|
219
|
+
return r;
|
|
220
|
+
}
|
|
221
|
+
const i = this._comparator;
|
|
222
|
+
for (; e; ) {
|
|
223
|
+
const l = i(t.key, e.key);
|
|
224
|
+
if (l === 0) break;
|
|
225
|
+
l < 0 ? e = e.left : (r = e, e = e.right);
|
|
226
|
+
}
|
|
227
|
+
return r;
|
|
228
|
+
}
|
|
229
|
+
clear() {
|
|
230
|
+
return this._root = null, this._size = 0, this;
|
|
231
|
+
}
|
|
232
|
+
toList() {
|
|
233
|
+
return y(this._root);
|
|
234
|
+
}
|
|
235
|
+
load(t, e = [], r = false) {
|
|
236
|
+
let i = t.length;
|
|
237
|
+
const l = this._comparator;
|
|
238
|
+
if (r && m(t, e, 0, i - 1, l), this._root === null) this._root = p(t, e, 0, i), this._size = i;
|
|
239
|
+
else {
|
|
240
|
+
const o = z(this.toList(), k(t, e), l);
|
|
241
|
+
i = this._size + i, this._root = g({ head: o }, 0, i);
|
|
242
|
+
}
|
|
243
|
+
return this;
|
|
244
|
+
}
|
|
245
|
+
isEmpty() {
|
|
246
|
+
return this._root === null;
|
|
247
|
+
}
|
|
248
|
+
get size() {
|
|
249
|
+
return this._size;
|
|
250
|
+
}
|
|
251
|
+
get root() {
|
|
252
|
+
return this._root;
|
|
253
|
+
}
|
|
254
|
+
toString(t = (e) => String(e.key)) {
|
|
255
|
+
const e = [];
|
|
256
|
+
return a(this._root, "", true, (r) => e.push(r), t), e.join("");
|
|
257
|
+
}
|
|
258
|
+
update(t, e, r) {
|
|
259
|
+
const i = this._comparator;
|
|
260
|
+
let { left: l, right: o } = d(t, this._root, i);
|
|
261
|
+
i(t, e) < 0 ? o = _(e, r, o, i) : l = _(e, r, l, i), this._root = w(l, o, i);
|
|
262
|
+
}
|
|
263
|
+
split(t) {
|
|
264
|
+
return d(t, this._root, this._comparator);
|
|
265
|
+
}
|
|
266
|
+
*[Symbol.iterator]() {
|
|
267
|
+
let t = this._root;
|
|
268
|
+
const e = [];
|
|
269
|
+
let r = false;
|
|
270
|
+
for (; !r; ) t !== null ? (e.push(t), t = t.left) : e.length !== 0 ? (t = e.pop(), yield t, t = t.right) : r = true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function p(n, t, e, r) {
|
|
274
|
+
const i = r - e;
|
|
275
|
+
if (i > 0) {
|
|
276
|
+
const l = e + Math.floor(i / 2), o = n[l], s = t[l], f = new h(o, s);
|
|
277
|
+
return f.left = p(n, t, e, l), f.right = p(n, t, l + 1, r), f;
|
|
278
|
+
}
|
|
279
|
+
return null;
|
|
280
|
+
}
|
|
281
|
+
function k(n, t) {
|
|
282
|
+
const e = new h(null, null);
|
|
283
|
+
let r = e;
|
|
284
|
+
for (let i = 0; i < n.length; i++) r = r.next = new h(n[i], t[i]);
|
|
285
|
+
return r.next = null, e.next;
|
|
286
|
+
}
|
|
287
|
+
function y(n) {
|
|
288
|
+
let t = n;
|
|
289
|
+
const e = [];
|
|
290
|
+
let r = false;
|
|
291
|
+
const i = new h(null, null);
|
|
292
|
+
let l = i;
|
|
293
|
+
for (; !r; ) t ? (e.push(t), t = t.left) : e.length > 0 ? (t = l = l.next = e.pop(), t = t.right) : r = true;
|
|
294
|
+
return l.next = null, i.next;
|
|
295
|
+
}
|
|
296
|
+
function g(n, t, e) {
|
|
297
|
+
const r = e - t;
|
|
298
|
+
if (r > 0) {
|
|
299
|
+
const i = t + Math.floor(r / 2), l = g(n, t, i), o = n.head;
|
|
300
|
+
return o.left = l, n.head = n.head.next, o.right = g(n, i + 1, e), o;
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
function z(n, t, e) {
|
|
305
|
+
const r = new h(null, null);
|
|
306
|
+
let i = r, l = n, o = t;
|
|
307
|
+
for (; l !== null && o !== null; ) e(l.key, o.key) < 0 ? (i.next = l, l = l.next) : (i.next = o, o = o.next), i = i.next;
|
|
308
|
+
return l !== null ? i.next = l : o !== null && (i.next = o), r.next;
|
|
309
|
+
}
|
|
310
|
+
function m(n, t, e, r, i) {
|
|
311
|
+
if (e >= r) return;
|
|
312
|
+
const l = n[e + r >> 1];
|
|
313
|
+
let o = e - 1, s = r + 1;
|
|
314
|
+
for (; ; ) {
|
|
315
|
+
do
|
|
316
|
+
o++;
|
|
317
|
+
while (i(n[o], l) < 0);
|
|
318
|
+
do
|
|
319
|
+
s--;
|
|
320
|
+
while (i(n[s], l) > 0);
|
|
321
|
+
if (o >= s) break;
|
|
322
|
+
let f = n[o];
|
|
323
|
+
n[o] = n[s], n[s] = f, f = t[o], t[o] = t[s], t[s] = f;
|
|
324
|
+
}
|
|
325
|
+
m(n, t, e, s, i), m(n, t, s + 1, r, i);
|
|
326
|
+
}
|
|
327
|
+
return x;
|
|
328
|
+
}));
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// node_modules/polygon-clipping/dist/polygon-clipping.cjs.js
|
|
333
|
+
var require_polygon_clipping_cjs = __commonJS({
|
|
334
|
+
"node_modules/polygon-clipping/dist/polygon-clipping.cjs.js"(exports, module) {
|
|
335
|
+
"use strict";
|
|
336
|
+
var SplayTree = require_splaytree_umd();
|
|
337
|
+
function _interopDefaultLegacy(e) {
|
|
338
|
+
return e && typeof e === "object" && "default" in e ? e : { "default": e };
|
|
339
|
+
}
|
|
340
|
+
var SplayTree__default = /* @__PURE__ */ _interopDefaultLegacy(SplayTree);
|
|
341
|
+
var isInBbox = (bbox2, point2) => {
|
|
342
|
+
return bbox2.ll.x <= point2.x && point2.x <= bbox2.ur.x && bbox2.ll.y <= point2.y && point2.y <= bbox2.ur.y;
|
|
343
|
+
};
|
|
344
|
+
var getBboxOverlap = (b1, b2) => {
|
|
345
|
+
if (b2.ur.x < b1.ll.x || b1.ur.x < b2.ll.x || b2.ur.y < b1.ll.y || b1.ur.y < b2.ll.y) return null;
|
|
346
|
+
const lowerX = b1.ll.x < b2.ll.x ? b2.ll.x : b1.ll.x;
|
|
347
|
+
const upperX = b1.ur.x < b2.ur.x ? b1.ur.x : b2.ur.x;
|
|
348
|
+
const lowerY = b1.ll.y < b2.ll.y ? b2.ll.y : b1.ll.y;
|
|
349
|
+
const upperY = b1.ur.y < b2.ur.y ? b1.ur.y : b2.ur.y;
|
|
350
|
+
return {
|
|
351
|
+
ll: {
|
|
352
|
+
x: lowerX,
|
|
353
|
+
y: lowerY
|
|
354
|
+
},
|
|
355
|
+
ur: {
|
|
356
|
+
x: upperX,
|
|
357
|
+
y: upperY
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
};
|
|
361
|
+
var epsilon$1 = Number.EPSILON;
|
|
362
|
+
if (epsilon$1 === void 0) epsilon$1 = Math.pow(2, -52);
|
|
363
|
+
var EPSILON_SQ = epsilon$1 * epsilon$1;
|
|
364
|
+
var cmp = (a, b) => {
|
|
365
|
+
if (-epsilon$1 < a && a < epsilon$1) {
|
|
366
|
+
if (-epsilon$1 < b && b < epsilon$1) {
|
|
367
|
+
return 0;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
const ab4 = a - b;
|
|
371
|
+
if (ab4 * ab4 < EPSILON_SQ * a * b) {
|
|
372
|
+
return 0;
|
|
373
|
+
}
|
|
374
|
+
return a < b ? -1 : 1;
|
|
375
|
+
};
|
|
376
|
+
var PtRounder = class {
|
|
377
|
+
constructor() {
|
|
378
|
+
this.reset();
|
|
379
|
+
}
|
|
380
|
+
reset() {
|
|
381
|
+
this.xRounder = new CoordRounder();
|
|
382
|
+
this.yRounder = new CoordRounder();
|
|
383
|
+
}
|
|
384
|
+
round(x, y) {
|
|
385
|
+
return {
|
|
386
|
+
x: this.xRounder.round(x),
|
|
387
|
+
y: this.yRounder.round(y)
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
var CoordRounder = class {
|
|
392
|
+
constructor() {
|
|
393
|
+
this.tree = new SplayTree__default["default"]();
|
|
394
|
+
this.round(0);
|
|
395
|
+
}
|
|
396
|
+
// Note: this can rounds input values backwards or forwards.
|
|
397
|
+
// You might ask, why not restrict this to just rounding
|
|
398
|
+
// forwards? Wouldn't that allow left endpoints to always
|
|
399
|
+
// remain left endpoints during splitting (never change to
|
|
400
|
+
// right). No - it wouldn't, because we snap intersections
|
|
401
|
+
// to endpoints (to establish independence from the segment
|
|
402
|
+
// angle for t-intersections).
|
|
403
|
+
round(coord) {
|
|
404
|
+
const node = this.tree.add(coord);
|
|
405
|
+
const prevNode = this.tree.prev(node);
|
|
406
|
+
if (prevNode !== null && cmp(node.key, prevNode.key) === 0) {
|
|
407
|
+
this.tree.remove(coord);
|
|
408
|
+
return prevNode.key;
|
|
409
|
+
}
|
|
410
|
+
const nextNode = this.tree.next(node);
|
|
411
|
+
if (nextNode !== null && cmp(node.key, nextNode.key) === 0) {
|
|
412
|
+
this.tree.remove(coord);
|
|
413
|
+
return nextNode.key;
|
|
414
|
+
}
|
|
415
|
+
return coord;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
var rounder = new PtRounder();
|
|
419
|
+
var epsilon3 = 11102230246251565e-32;
|
|
420
|
+
var splitter2 = 134217729;
|
|
421
|
+
var resulterrbound2 = (3 + 8 * epsilon3) * epsilon3;
|
|
422
|
+
function sum2(elen, e, flen, f, h) {
|
|
423
|
+
let Q, Qnew, hh, bvirt;
|
|
424
|
+
let enow = e[0];
|
|
425
|
+
let fnow = f[0];
|
|
426
|
+
let eindex = 0;
|
|
427
|
+
let findex = 0;
|
|
428
|
+
if (fnow > enow === fnow > -enow) {
|
|
429
|
+
Q = enow;
|
|
430
|
+
enow = e[++eindex];
|
|
431
|
+
} else {
|
|
432
|
+
Q = fnow;
|
|
433
|
+
fnow = f[++findex];
|
|
434
|
+
}
|
|
435
|
+
let hindex = 0;
|
|
436
|
+
if (eindex < elen && findex < flen) {
|
|
437
|
+
if (fnow > enow === fnow > -enow) {
|
|
438
|
+
Qnew = enow + Q;
|
|
439
|
+
hh = Q - (Qnew - enow);
|
|
440
|
+
enow = e[++eindex];
|
|
441
|
+
} else {
|
|
442
|
+
Qnew = fnow + Q;
|
|
443
|
+
hh = Q - (Qnew - fnow);
|
|
444
|
+
fnow = f[++findex];
|
|
445
|
+
}
|
|
446
|
+
Q = Qnew;
|
|
447
|
+
if (hh !== 0) {
|
|
448
|
+
h[hindex++] = hh;
|
|
449
|
+
}
|
|
450
|
+
while (eindex < elen && findex < flen) {
|
|
451
|
+
if (fnow > enow === fnow > -enow) {
|
|
452
|
+
Qnew = Q + enow;
|
|
453
|
+
bvirt = Qnew - Q;
|
|
454
|
+
hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
|
455
|
+
enow = e[++eindex];
|
|
456
|
+
} else {
|
|
457
|
+
Qnew = Q + fnow;
|
|
458
|
+
bvirt = Qnew - Q;
|
|
459
|
+
hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
|
460
|
+
fnow = f[++findex];
|
|
461
|
+
}
|
|
462
|
+
Q = Qnew;
|
|
463
|
+
if (hh !== 0) {
|
|
464
|
+
h[hindex++] = hh;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
while (eindex < elen) {
|
|
469
|
+
Qnew = Q + enow;
|
|
470
|
+
bvirt = Qnew - Q;
|
|
471
|
+
hh = Q - (Qnew - bvirt) + (enow - bvirt);
|
|
472
|
+
enow = e[++eindex];
|
|
473
|
+
Q = Qnew;
|
|
474
|
+
if (hh !== 0) {
|
|
475
|
+
h[hindex++] = hh;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
while (findex < flen) {
|
|
479
|
+
Qnew = Q + fnow;
|
|
480
|
+
bvirt = Qnew - Q;
|
|
481
|
+
hh = Q - (Qnew - bvirt) + (fnow - bvirt);
|
|
482
|
+
fnow = f[++findex];
|
|
483
|
+
Q = Qnew;
|
|
484
|
+
if (hh !== 0) {
|
|
485
|
+
h[hindex++] = hh;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (Q !== 0 || hindex === 0) {
|
|
489
|
+
h[hindex++] = Q;
|
|
490
|
+
}
|
|
491
|
+
return hindex;
|
|
492
|
+
}
|
|
493
|
+
function estimate2(elen, e) {
|
|
494
|
+
let Q = e[0];
|
|
495
|
+
for (let i = 1; i < elen; i++) Q += e[i];
|
|
496
|
+
return Q;
|
|
497
|
+
}
|
|
498
|
+
function vec2(n) {
|
|
499
|
+
return new Float64Array(n);
|
|
500
|
+
}
|
|
501
|
+
var ccwerrboundA2 = (3 + 16 * epsilon3) * epsilon3;
|
|
502
|
+
var ccwerrboundB2 = (2 + 12 * epsilon3) * epsilon3;
|
|
503
|
+
var ccwerrboundC2 = (9 + 64 * epsilon3) * epsilon3 * epsilon3;
|
|
504
|
+
var B2 = vec2(4);
|
|
505
|
+
var C12 = vec2(8);
|
|
506
|
+
var C22 = vec2(12);
|
|
507
|
+
var D2 = vec2(16);
|
|
508
|
+
var u4 = vec2(4);
|
|
509
|
+
function orient2dadapt2(ax, ay, bx, by, cx, cy, detsum) {
|
|
510
|
+
let acxtail, acytail, bcxtail, bcytail;
|
|
511
|
+
let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u32;
|
|
512
|
+
const acx = ax - cx;
|
|
513
|
+
const bcx = bx - cx;
|
|
514
|
+
const acy = ay - cy;
|
|
515
|
+
const bcy = by - cy;
|
|
516
|
+
s1 = acx * bcy;
|
|
517
|
+
c = splitter2 * acx;
|
|
518
|
+
ahi = c - (c - acx);
|
|
519
|
+
alo = acx - ahi;
|
|
520
|
+
c = splitter2 * bcy;
|
|
521
|
+
bhi = c - (c - bcy);
|
|
522
|
+
blo = bcy - bhi;
|
|
523
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
524
|
+
t1 = acy * bcx;
|
|
525
|
+
c = splitter2 * acy;
|
|
526
|
+
ahi = c - (c - acy);
|
|
527
|
+
alo = acy - ahi;
|
|
528
|
+
c = splitter2 * bcx;
|
|
529
|
+
bhi = c - (c - bcx);
|
|
530
|
+
blo = bcx - bhi;
|
|
531
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
532
|
+
_i = s0 - t0;
|
|
533
|
+
bvirt = s0 - _i;
|
|
534
|
+
B2[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
535
|
+
_j = s1 + _i;
|
|
536
|
+
bvirt = _j - s1;
|
|
537
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
538
|
+
_i = _0 - t1;
|
|
539
|
+
bvirt = _0 - _i;
|
|
540
|
+
B2[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
541
|
+
u32 = _j + _i;
|
|
542
|
+
bvirt = u32 - _j;
|
|
543
|
+
B2[2] = _j - (u32 - bvirt) + (_i - bvirt);
|
|
544
|
+
B2[3] = u32;
|
|
545
|
+
let det = estimate2(4, B2);
|
|
546
|
+
let errbound = ccwerrboundB2 * detsum;
|
|
547
|
+
if (det >= errbound || -det >= errbound) {
|
|
548
|
+
return det;
|
|
549
|
+
}
|
|
550
|
+
bvirt = ax - acx;
|
|
551
|
+
acxtail = ax - (acx + bvirt) + (bvirt - cx);
|
|
552
|
+
bvirt = bx - bcx;
|
|
553
|
+
bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
|
|
554
|
+
bvirt = ay - acy;
|
|
555
|
+
acytail = ay - (acy + bvirt) + (bvirt - cy);
|
|
556
|
+
bvirt = by - bcy;
|
|
557
|
+
bcytail = by - (bcy + bvirt) + (bvirt - cy);
|
|
558
|
+
if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
|
|
559
|
+
return det;
|
|
560
|
+
}
|
|
561
|
+
errbound = ccwerrboundC2 * detsum + resulterrbound2 * Math.abs(det);
|
|
562
|
+
det += acx * bcytail + bcy * acxtail - (acy * bcxtail + bcx * acytail);
|
|
563
|
+
if (det >= errbound || -det >= errbound) return det;
|
|
564
|
+
s1 = acxtail * bcy;
|
|
565
|
+
c = splitter2 * acxtail;
|
|
566
|
+
ahi = c - (c - acxtail);
|
|
567
|
+
alo = acxtail - ahi;
|
|
568
|
+
c = splitter2 * bcy;
|
|
569
|
+
bhi = c - (c - bcy);
|
|
570
|
+
blo = bcy - bhi;
|
|
571
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
572
|
+
t1 = acytail * bcx;
|
|
573
|
+
c = splitter2 * acytail;
|
|
574
|
+
ahi = c - (c - acytail);
|
|
575
|
+
alo = acytail - ahi;
|
|
576
|
+
c = splitter2 * bcx;
|
|
577
|
+
bhi = c - (c - bcx);
|
|
578
|
+
blo = bcx - bhi;
|
|
579
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
580
|
+
_i = s0 - t0;
|
|
581
|
+
bvirt = s0 - _i;
|
|
582
|
+
u4[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
583
|
+
_j = s1 + _i;
|
|
584
|
+
bvirt = _j - s1;
|
|
585
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
586
|
+
_i = _0 - t1;
|
|
587
|
+
bvirt = _0 - _i;
|
|
588
|
+
u4[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
589
|
+
u32 = _j + _i;
|
|
590
|
+
bvirt = u32 - _j;
|
|
591
|
+
u4[2] = _j - (u32 - bvirt) + (_i - bvirt);
|
|
592
|
+
u4[3] = u32;
|
|
593
|
+
const C1len = sum2(4, B2, 4, u4, C12);
|
|
594
|
+
s1 = acx * bcytail;
|
|
595
|
+
c = splitter2 * acx;
|
|
596
|
+
ahi = c - (c - acx);
|
|
597
|
+
alo = acx - ahi;
|
|
598
|
+
c = splitter2 * bcytail;
|
|
599
|
+
bhi = c - (c - bcytail);
|
|
600
|
+
blo = bcytail - bhi;
|
|
601
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
602
|
+
t1 = acy * bcxtail;
|
|
603
|
+
c = splitter2 * acy;
|
|
604
|
+
ahi = c - (c - acy);
|
|
605
|
+
alo = acy - ahi;
|
|
606
|
+
c = splitter2 * bcxtail;
|
|
607
|
+
bhi = c - (c - bcxtail);
|
|
608
|
+
blo = bcxtail - bhi;
|
|
609
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
610
|
+
_i = s0 - t0;
|
|
611
|
+
bvirt = s0 - _i;
|
|
612
|
+
u4[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
613
|
+
_j = s1 + _i;
|
|
614
|
+
bvirt = _j - s1;
|
|
615
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
616
|
+
_i = _0 - t1;
|
|
617
|
+
bvirt = _0 - _i;
|
|
618
|
+
u4[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
619
|
+
u32 = _j + _i;
|
|
620
|
+
bvirt = u32 - _j;
|
|
621
|
+
u4[2] = _j - (u32 - bvirt) + (_i - bvirt);
|
|
622
|
+
u4[3] = u32;
|
|
623
|
+
const C2len = sum2(C1len, C12, 4, u4, C22);
|
|
624
|
+
s1 = acxtail * bcytail;
|
|
625
|
+
c = splitter2 * acxtail;
|
|
626
|
+
ahi = c - (c - acxtail);
|
|
627
|
+
alo = acxtail - ahi;
|
|
628
|
+
c = splitter2 * bcytail;
|
|
629
|
+
bhi = c - (c - bcytail);
|
|
630
|
+
blo = bcytail - bhi;
|
|
631
|
+
s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
632
|
+
t1 = acytail * bcxtail;
|
|
633
|
+
c = splitter2 * acytail;
|
|
634
|
+
ahi = c - (c - acytail);
|
|
635
|
+
alo = acytail - ahi;
|
|
636
|
+
c = splitter2 * bcxtail;
|
|
637
|
+
bhi = c - (c - bcxtail);
|
|
638
|
+
blo = bcxtail - bhi;
|
|
639
|
+
t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
|
|
640
|
+
_i = s0 - t0;
|
|
641
|
+
bvirt = s0 - _i;
|
|
642
|
+
u4[0] = s0 - (_i + bvirt) + (bvirt - t0);
|
|
643
|
+
_j = s1 + _i;
|
|
644
|
+
bvirt = _j - s1;
|
|
645
|
+
_0 = s1 - (_j - bvirt) + (_i - bvirt);
|
|
646
|
+
_i = _0 - t1;
|
|
647
|
+
bvirt = _0 - _i;
|
|
648
|
+
u4[1] = _0 - (_i + bvirt) + (bvirt - t1);
|
|
649
|
+
u32 = _j + _i;
|
|
650
|
+
bvirt = u32 - _j;
|
|
651
|
+
u4[2] = _j - (u32 - bvirt) + (_i - bvirt);
|
|
652
|
+
u4[3] = u32;
|
|
653
|
+
const Dlen = sum2(C2len, C22, 4, u4, D2);
|
|
654
|
+
return D2[Dlen - 1];
|
|
655
|
+
}
|
|
656
|
+
function orient2d2(ax, ay, bx, by, cx, cy) {
|
|
657
|
+
const detleft = (ay - cy) * (bx - cx);
|
|
658
|
+
const detright = (ax - cx) * (by - cy);
|
|
659
|
+
const det = detleft - detright;
|
|
660
|
+
const detsum = Math.abs(detleft + detright);
|
|
661
|
+
if (Math.abs(det) >= ccwerrboundA2 * detsum) return det;
|
|
662
|
+
return -orient2dadapt2(ax, ay, bx, by, cx, cy, detsum);
|
|
663
|
+
}
|
|
664
|
+
var crossProduct = (a, b) => a.x * b.y - a.y * b.x;
|
|
665
|
+
var dotProduct = (a, b) => a.x * b.x + a.y * b.y;
|
|
666
|
+
var compareVectorAngles = (basePt, endPt1, endPt2) => {
|
|
667
|
+
const res = orient2d2(basePt.x, basePt.y, endPt1.x, endPt1.y, endPt2.x, endPt2.y);
|
|
668
|
+
if (res > 0) return -1;
|
|
669
|
+
if (res < 0) return 1;
|
|
670
|
+
return 0;
|
|
671
|
+
};
|
|
672
|
+
var length2 = (v2) => Math.sqrt(dotProduct(v2, v2));
|
|
673
|
+
var sineOfAngle = (pShared, pBase, pAngle) => {
|
|
674
|
+
const vBase = {
|
|
675
|
+
x: pBase.x - pShared.x,
|
|
676
|
+
y: pBase.y - pShared.y
|
|
677
|
+
};
|
|
678
|
+
const vAngle = {
|
|
679
|
+
x: pAngle.x - pShared.x,
|
|
680
|
+
y: pAngle.y - pShared.y
|
|
681
|
+
};
|
|
682
|
+
return crossProduct(vAngle, vBase) / length2(vAngle) / length2(vBase);
|
|
683
|
+
};
|
|
684
|
+
var cosineOfAngle = (pShared, pBase, pAngle) => {
|
|
685
|
+
const vBase = {
|
|
686
|
+
x: pBase.x - pShared.x,
|
|
687
|
+
y: pBase.y - pShared.y
|
|
688
|
+
};
|
|
689
|
+
const vAngle = {
|
|
690
|
+
x: pAngle.x - pShared.x,
|
|
691
|
+
y: pAngle.y - pShared.y
|
|
692
|
+
};
|
|
693
|
+
return dotProduct(vAngle, vBase) / length2(vAngle) / length2(vBase);
|
|
694
|
+
};
|
|
695
|
+
var horizontalIntersection = (pt, v2, y) => {
|
|
696
|
+
if (v2.y === 0) return null;
|
|
697
|
+
return {
|
|
698
|
+
x: pt.x + v2.x / v2.y * (y - pt.y),
|
|
699
|
+
y
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
var verticalIntersection = (pt, v2, x) => {
|
|
703
|
+
if (v2.x === 0) return null;
|
|
704
|
+
return {
|
|
705
|
+
x,
|
|
706
|
+
y: pt.y + v2.y / v2.x * (x - pt.x)
|
|
707
|
+
};
|
|
708
|
+
};
|
|
709
|
+
var intersection$1 = (pt1, v1, pt2, v2) => {
|
|
710
|
+
if (v1.x === 0) return verticalIntersection(pt2, v2, pt1.x);
|
|
711
|
+
if (v2.x === 0) return verticalIntersection(pt1, v1, pt2.x);
|
|
712
|
+
if (v1.y === 0) return horizontalIntersection(pt2, v2, pt1.y);
|
|
713
|
+
if (v2.y === 0) return horizontalIntersection(pt1, v1, pt2.y);
|
|
714
|
+
const kross = crossProduct(v1, v2);
|
|
715
|
+
if (kross == 0) return null;
|
|
716
|
+
const ve = {
|
|
717
|
+
x: pt2.x - pt1.x,
|
|
718
|
+
y: pt2.y - pt1.y
|
|
719
|
+
};
|
|
720
|
+
const d1 = crossProduct(ve, v1) / kross;
|
|
721
|
+
const d2 = crossProduct(ve, v2) / kross;
|
|
722
|
+
const x1 = pt1.x + d2 * v1.x, x2 = pt2.x + d1 * v2.x;
|
|
723
|
+
const y1 = pt1.y + d2 * v1.y, y2 = pt2.y + d1 * v2.y;
|
|
724
|
+
const x = (x1 + x2) / 2;
|
|
725
|
+
const y = (y1 + y2) / 2;
|
|
726
|
+
return {
|
|
727
|
+
x,
|
|
728
|
+
y
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
var SweepEvent = class _SweepEvent {
|
|
732
|
+
// for ordering sweep events in the sweep event queue
|
|
733
|
+
static compare(a, b) {
|
|
734
|
+
const ptCmp = _SweepEvent.comparePoints(a.point, b.point);
|
|
735
|
+
if (ptCmp !== 0) return ptCmp;
|
|
736
|
+
if (a.point !== b.point) a.link(b);
|
|
737
|
+
if (a.isLeft !== b.isLeft) return a.isLeft ? 1 : -1;
|
|
738
|
+
return Segment.compare(a.segment, b.segment);
|
|
739
|
+
}
|
|
740
|
+
// for ordering points in sweep line order
|
|
741
|
+
static comparePoints(aPt, bPt) {
|
|
742
|
+
if (aPt.x < bPt.x) return -1;
|
|
743
|
+
if (aPt.x > bPt.x) return 1;
|
|
744
|
+
if (aPt.y < bPt.y) return -1;
|
|
745
|
+
if (aPt.y > bPt.y) return 1;
|
|
746
|
+
return 0;
|
|
747
|
+
}
|
|
748
|
+
// Warning: 'point' input will be modified and re-used (for performance)
|
|
749
|
+
constructor(point2, isLeft) {
|
|
750
|
+
if (point2.events === void 0) point2.events = [this];
|
|
751
|
+
else point2.events.push(this);
|
|
752
|
+
this.point = point2;
|
|
753
|
+
this.isLeft = isLeft;
|
|
754
|
+
}
|
|
755
|
+
link(other) {
|
|
756
|
+
if (other.point === this.point) {
|
|
757
|
+
throw new Error("Tried to link already linked events");
|
|
758
|
+
}
|
|
759
|
+
const otherEvents = other.point.events;
|
|
760
|
+
for (let i = 0, iMax = otherEvents.length; i < iMax; i++) {
|
|
761
|
+
const evt = otherEvents[i];
|
|
762
|
+
this.point.events.push(evt);
|
|
763
|
+
evt.point = this.point;
|
|
764
|
+
}
|
|
765
|
+
this.checkForConsuming();
|
|
766
|
+
}
|
|
767
|
+
/* Do a pass over our linked events and check to see if any pair
|
|
768
|
+
* of segments match, and should be consumed. */
|
|
769
|
+
checkForConsuming() {
|
|
770
|
+
const numEvents = this.point.events.length;
|
|
771
|
+
for (let i = 0; i < numEvents; i++) {
|
|
772
|
+
const evt1 = this.point.events[i];
|
|
773
|
+
if (evt1.segment.consumedBy !== void 0) continue;
|
|
774
|
+
for (let j = i + 1; j < numEvents; j++) {
|
|
775
|
+
const evt2 = this.point.events[j];
|
|
776
|
+
if (evt2.consumedBy !== void 0) continue;
|
|
777
|
+
if (evt1.otherSE.point.events !== evt2.otherSE.point.events) continue;
|
|
778
|
+
evt1.segment.consume(evt2.segment);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
getAvailableLinkedEvents() {
|
|
783
|
+
const events = [];
|
|
784
|
+
for (let i = 0, iMax = this.point.events.length; i < iMax; i++) {
|
|
785
|
+
const evt = this.point.events[i];
|
|
786
|
+
if (evt !== this && !evt.segment.ringOut && evt.segment.isInResult()) {
|
|
787
|
+
events.push(evt);
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return events;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* Returns a comparator function for sorting linked events that will
|
|
794
|
+
* favor the event that will give us the smallest left-side angle.
|
|
795
|
+
* All ring construction starts as low as possible heading to the right,
|
|
796
|
+
* so by always turning left as sharp as possible we'll get polygons
|
|
797
|
+
* without uncessary loops & holes.
|
|
798
|
+
*
|
|
799
|
+
* The comparator function has a compute cache such that it avoids
|
|
800
|
+
* re-computing already-computed values.
|
|
801
|
+
*/
|
|
802
|
+
getLeftmostComparator(baseEvent) {
|
|
803
|
+
const cache = /* @__PURE__ */ new Map();
|
|
804
|
+
const fillCache = (linkedEvent) => {
|
|
805
|
+
const nextEvent = linkedEvent.otherSE;
|
|
806
|
+
cache.set(linkedEvent, {
|
|
807
|
+
sine: sineOfAngle(this.point, baseEvent.point, nextEvent.point),
|
|
808
|
+
cosine: cosineOfAngle(this.point, baseEvent.point, nextEvent.point)
|
|
809
|
+
});
|
|
810
|
+
};
|
|
811
|
+
return (a, b) => {
|
|
812
|
+
if (!cache.has(a)) fillCache(a);
|
|
813
|
+
if (!cache.has(b)) fillCache(b);
|
|
814
|
+
const {
|
|
815
|
+
sine: asine,
|
|
816
|
+
cosine: acosine
|
|
817
|
+
} = cache.get(a);
|
|
818
|
+
const {
|
|
819
|
+
sine: bsine,
|
|
820
|
+
cosine: bcosine
|
|
821
|
+
} = cache.get(b);
|
|
822
|
+
if (asine >= 0 && bsine >= 0) {
|
|
823
|
+
if (acosine < bcosine) return 1;
|
|
824
|
+
if (acosine > bcosine) return -1;
|
|
825
|
+
return 0;
|
|
826
|
+
}
|
|
827
|
+
if (asine < 0 && bsine < 0) {
|
|
828
|
+
if (acosine < bcosine) return -1;
|
|
829
|
+
if (acosine > bcosine) return 1;
|
|
830
|
+
return 0;
|
|
831
|
+
}
|
|
832
|
+
if (bsine < asine) return -1;
|
|
833
|
+
if (bsine > asine) return 1;
|
|
834
|
+
return 0;
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
var segmentId = 0;
|
|
839
|
+
var Segment = class _Segment {
|
|
840
|
+
/* This compare() function is for ordering segments in the sweep
|
|
841
|
+
* line tree, and does so according to the following criteria:
|
|
842
|
+
*
|
|
843
|
+
* Consider the vertical line that lies an infinestimal step to the
|
|
844
|
+
* right of the right-more of the two left endpoints of the input
|
|
845
|
+
* segments. Imagine slowly moving a point up from negative infinity
|
|
846
|
+
* in the increasing y direction. Which of the two segments will that
|
|
847
|
+
* point intersect first? That segment comes 'before' the other one.
|
|
848
|
+
*
|
|
849
|
+
* If neither segment would be intersected by such a line, (if one
|
|
850
|
+
* or more of the segments are vertical) then the line to be considered
|
|
851
|
+
* is directly on the right-more of the two left inputs.
|
|
852
|
+
*/
|
|
853
|
+
static compare(a, b) {
|
|
854
|
+
const alx = a.leftSE.point.x;
|
|
855
|
+
const blx = b.leftSE.point.x;
|
|
856
|
+
const arx = a.rightSE.point.x;
|
|
857
|
+
const brx = b.rightSE.point.x;
|
|
858
|
+
if (brx < alx) return 1;
|
|
859
|
+
if (arx < blx) return -1;
|
|
860
|
+
const aly = a.leftSE.point.y;
|
|
861
|
+
const bly = b.leftSE.point.y;
|
|
862
|
+
const ary = a.rightSE.point.y;
|
|
863
|
+
const bry = b.rightSE.point.y;
|
|
864
|
+
if (alx < blx) {
|
|
865
|
+
if (bly < aly && bly < ary) return 1;
|
|
866
|
+
if (bly > aly && bly > ary) return -1;
|
|
867
|
+
const aCmpBLeft = a.comparePoint(b.leftSE.point);
|
|
868
|
+
if (aCmpBLeft < 0) return 1;
|
|
869
|
+
if (aCmpBLeft > 0) return -1;
|
|
870
|
+
const bCmpARight = b.comparePoint(a.rightSE.point);
|
|
871
|
+
if (bCmpARight !== 0) return bCmpARight;
|
|
872
|
+
return -1;
|
|
873
|
+
}
|
|
874
|
+
if (alx > blx) {
|
|
875
|
+
if (aly < bly && aly < bry) return -1;
|
|
876
|
+
if (aly > bly && aly > bry) return 1;
|
|
877
|
+
const bCmpALeft = b.comparePoint(a.leftSE.point);
|
|
878
|
+
if (bCmpALeft !== 0) return bCmpALeft;
|
|
879
|
+
const aCmpBRight = a.comparePoint(b.rightSE.point);
|
|
880
|
+
if (aCmpBRight < 0) return 1;
|
|
881
|
+
if (aCmpBRight > 0) return -1;
|
|
882
|
+
return 1;
|
|
883
|
+
}
|
|
884
|
+
if (aly < bly) return -1;
|
|
885
|
+
if (aly > bly) return 1;
|
|
886
|
+
if (arx < brx) {
|
|
887
|
+
const bCmpARight = b.comparePoint(a.rightSE.point);
|
|
888
|
+
if (bCmpARight !== 0) return bCmpARight;
|
|
889
|
+
}
|
|
890
|
+
if (arx > brx) {
|
|
891
|
+
const aCmpBRight = a.comparePoint(b.rightSE.point);
|
|
892
|
+
if (aCmpBRight < 0) return 1;
|
|
893
|
+
if (aCmpBRight > 0) return -1;
|
|
894
|
+
}
|
|
895
|
+
if (arx !== brx) {
|
|
896
|
+
const ay = ary - aly;
|
|
897
|
+
const ax = arx - alx;
|
|
898
|
+
const by = bry - bly;
|
|
899
|
+
const bx = brx - blx;
|
|
900
|
+
if (ay > ax && by < bx) return 1;
|
|
901
|
+
if (ay < ax && by > bx) return -1;
|
|
902
|
+
}
|
|
903
|
+
if (arx > brx) return 1;
|
|
904
|
+
if (arx < brx) return -1;
|
|
905
|
+
if (ary < bry) return -1;
|
|
906
|
+
if (ary > bry) return 1;
|
|
907
|
+
if (a.id < b.id) return -1;
|
|
908
|
+
if (a.id > b.id) return 1;
|
|
909
|
+
return 0;
|
|
910
|
+
}
|
|
911
|
+
/* Warning: a reference to ringWindings input will be stored,
|
|
912
|
+
* and possibly will be later modified */
|
|
913
|
+
constructor(leftSE, rightSE, rings, windings) {
|
|
914
|
+
this.id = ++segmentId;
|
|
915
|
+
this.leftSE = leftSE;
|
|
916
|
+
leftSE.segment = this;
|
|
917
|
+
leftSE.otherSE = rightSE;
|
|
918
|
+
this.rightSE = rightSE;
|
|
919
|
+
rightSE.segment = this;
|
|
920
|
+
rightSE.otherSE = leftSE;
|
|
921
|
+
this.rings = rings;
|
|
922
|
+
this.windings = windings;
|
|
923
|
+
}
|
|
924
|
+
static fromRing(pt1, pt2, ring) {
|
|
925
|
+
let leftPt, rightPt, winding;
|
|
926
|
+
const cmpPts = SweepEvent.comparePoints(pt1, pt2);
|
|
927
|
+
if (cmpPts < 0) {
|
|
928
|
+
leftPt = pt1;
|
|
929
|
+
rightPt = pt2;
|
|
930
|
+
winding = 1;
|
|
931
|
+
} else if (cmpPts > 0) {
|
|
932
|
+
leftPt = pt2;
|
|
933
|
+
rightPt = pt1;
|
|
934
|
+
winding = -1;
|
|
935
|
+
} else throw new Error(`Tried to create degenerate segment at [${pt1.x}, ${pt1.y}]`);
|
|
936
|
+
const leftSE = new SweepEvent(leftPt, true);
|
|
937
|
+
const rightSE = new SweepEvent(rightPt, false);
|
|
938
|
+
return new _Segment(leftSE, rightSE, [ring], [winding]);
|
|
939
|
+
}
|
|
940
|
+
/* When a segment is split, the rightSE is replaced with a new sweep event */
|
|
941
|
+
replaceRightSE(newRightSE) {
|
|
942
|
+
this.rightSE = newRightSE;
|
|
943
|
+
this.rightSE.segment = this;
|
|
944
|
+
this.rightSE.otherSE = this.leftSE;
|
|
945
|
+
this.leftSE.otherSE = this.rightSE;
|
|
946
|
+
}
|
|
947
|
+
bbox() {
|
|
948
|
+
const y1 = this.leftSE.point.y;
|
|
949
|
+
const y2 = this.rightSE.point.y;
|
|
950
|
+
return {
|
|
951
|
+
ll: {
|
|
952
|
+
x: this.leftSE.point.x,
|
|
953
|
+
y: y1 < y2 ? y1 : y2
|
|
954
|
+
},
|
|
955
|
+
ur: {
|
|
956
|
+
x: this.rightSE.point.x,
|
|
957
|
+
y: y1 > y2 ? y1 : y2
|
|
958
|
+
}
|
|
959
|
+
};
|
|
960
|
+
}
|
|
961
|
+
/* A vector from the left point to the right */
|
|
962
|
+
vector() {
|
|
963
|
+
return {
|
|
964
|
+
x: this.rightSE.point.x - this.leftSE.point.x,
|
|
965
|
+
y: this.rightSE.point.y - this.leftSE.point.y
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
isAnEndpoint(pt) {
|
|
969
|
+
return pt.x === this.leftSE.point.x && pt.y === this.leftSE.point.y || pt.x === this.rightSE.point.x && pt.y === this.rightSE.point.y;
|
|
970
|
+
}
|
|
971
|
+
/* Compare this segment with a point.
|
|
972
|
+
*
|
|
973
|
+
* A point P is considered to be colinear to a segment if there
|
|
974
|
+
* exists a distance D such that if we travel along the segment
|
|
975
|
+
* from one * endpoint towards the other a distance D, we find
|
|
976
|
+
* ourselves at point P.
|
|
977
|
+
*
|
|
978
|
+
* Return value indicates:
|
|
979
|
+
*
|
|
980
|
+
* 1: point lies above the segment (to the left of vertical)
|
|
981
|
+
* 0: point is colinear to segment
|
|
982
|
+
* -1: point lies below the segment (to the right of vertical)
|
|
983
|
+
*/
|
|
984
|
+
comparePoint(point2) {
|
|
985
|
+
if (this.isAnEndpoint(point2)) return 0;
|
|
986
|
+
const lPt = this.leftSE.point;
|
|
987
|
+
const rPt = this.rightSE.point;
|
|
988
|
+
const v2 = this.vector();
|
|
989
|
+
if (lPt.x === rPt.x) {
|
|
990
|
+
if (point2.x === lPt.x) return 0;
|
|
991
|
+
return point2.x < lPt.x ? 1 : -1;
|
|
992
|
+
}
|
|
993
|
+
const yDist = (point2.y - lPt.y) / v2.y;
|
|
994
|
+
const xFromYDist = lPt.x + yDist * v2.x;
|
|
995
|
+
if (point2.x === xFromYDist) return 0;
|
|
996
|
+
const xDist = (point2.x - lPt.x) / v2.x;
|
|
997
|
+
const yFromXDist = lPt.y + xDist * v2.y;
|
|
998
|
+
if (point2.y === yFromXDist) return 0;
|
|
999
|
+
return point2.y < yFromXDist ? -1 : 1;
|
|
1000
|
+
}
|
|
1001
|
+
/**
|
|
1002
|
+
* Given another segment, returns the first non-trivial intersection
|
|
1003
|
+
* between the two segments (in terms of sweep line ordering), if it exists.
|
|
1004
|
+
*
|
|
1005
|
+
* A 'non-trivial' intersection is one that will cause one or both of the
|
|
1006
|
+
* segments to be split(). As such, 'trivial' vs. 'non-trivial' intersection:
|
|
1007
|
+
*
|
|
1008
|
+
* * endpoint of segA with endpoint of segB --> trivial
|
|
1009
|
+
* * endpoint of segA with point along segB --> non-trivial
|
|
1010
|
+
* * endpoint of segB with point along segA --> non-trivial
|
|
1011
|
+
* * point along segA with point along segB --> non-trivial
|
|
1012
|
+
*
|
|
1013
|
+
* If no non-trivial intersection exists, return null
|
|
1014
|
+
* Else, return null.
|
|
1015
|
+
*/
|
|
1016
|
+
getIntersection(other) {
|
|
1017
|
+
const tBbox = this.bbox();
|
|
1018
|
+
const oBbox = other.bbox();
|
|
1019
|
+
const bboxOverlap = getBboxOverlap(tBbox, oBbox);
|
|
1020
|
+
if (bboxOverlap === null) return null;
|
|
1021
|
+
const tlp = this.leftSE.point;
|
|
1022
|
+
const trp = this.rightSE.point;
|
|
1023
|
+
const olp = other.leftSE.point;
|
|
1024
|
+
const orp = other.rightSE.point;
|
|
1025
|
+
const touchesOtherLSE = isInBbox(tBbox, olp) && this.comparePoint(olp) === 0;
|
|
1026
|
+
const touchesThisLSE = isInBbox(oBbox, tlp) && other.comparePoint(tlp) === 0;
|
|
1027
|
+
const touchesOtherRSE = isInBbox(tBbox, orp) && this.comparePoint(orp) === 0;
|
|
1028
|
+
const touchesThisRSE = isInBbox(oBbox, trp) && other.comparePoint(trp) === 0;
|
|
1029
|
+
if (touchesThisLSE && touchesOtherLSE) {
|
|
1030
|
+
if (touchesThisRSE && !touchesOtherRSE) return trp;
|
|
1031
|
+
if (!touchesThisRSE && touchesOtherRSE) return orp;
|
|
1032
|
+
return null;
|
|
1033
|
+
}
|
|
1034
|
+
if (touchesThisLSE) {
|
|
1035
|
+
if (touchesOtherRSE) {
|
|
1036
|
+
if (tlp.x === orp.x && tlp.y === orp.y) return null;
|
|
1037
|
+
}
|
|
1038
|
+
return tlp;
|
|
1039
|
+
}
|
|
1040
|
+
if (touchesOtherLSE) {
|
|
1041
|
+
if (touchesThisRSE) {
|
|
1042
|
+
if (trp.x === olp.x && trp.y === olp.y) return null;
|
|
1043
|
+
}
|
|
1044
|
+
return olp;
|
|
1045
|
+
}
|
|
1046
|
+
if (touchesThisRSE && touchesOtherRSE) return null;
|
|
1047
|
+
if (touchesThisRSE) return trp;
|
|
1048
|
+
if (touchesOtherRSE) return orp;
|
|
1049
|
+
const pt = intersection$1(tlp, this.vector(), olp, other.vector());
|
|
1050
|
+
if (pt === null) return null;
|
|
1051
|
+
if (!isInBbox(bboxOverlap, pt)) return null;
|
|
1052
|
+
return rounder.round(pt.x, pt.y);
|
|
1053
|
+
}
|
|
1054
|
+
/**
|
|
1055
|
+
* Split the given segment into multiple segments on the given points.
|
|
1056
|
+
* * Each existing segment will retain its leftSE and a new rightSE will be
|
|
1057
|
+
* generated for it.
|
|
1058
|
+
* * A new segment will be generated which will adopt the original segment's
|
|
1059
|
+
* rightSE, and a new leftSE will be generated for it.
|
|
1060
|
+
* * If there are more than two points given to split on, new segments
|
|
1061
|
+
* in the middle will be generated with new leftSE and rightSE's.
|
|
1062
|
+
* * An array of the newly generated SweepEvents will be returned.
|
|
1063
|
+
*
|
|
1064
|
+
* Warning: input array of points is modified
|
|
1065
|
+
*/
|
|
1066
|
+
split(point2) {
|
|
1067
|
+
const newEvents = [];
|
|
1068
|
+
const alreadyLinked = point2.events !== void 0;
|
|
1069
|
+
const newLeftSE = new SweepEvent(point2, true);
|
|
1070
|
+
const newRightSE = new SweepEvent(point2, false);
|
|
1071
|
+
const oldRightSE = this.rightSE;
|
|
1072
|
+
this.replaceRightSE(newRightSE);
|
|
1073
|
+
newEvents.push(newRightSE);
|
|
1074
|
+
newEvents.push(newLeftSE);
|
|
1075
|
+
const newSeg = new _Segment(newLeftSE, oldRightSE, this.rings.slice(), this.windings.slice());
|
|
1076
|
+
if (SweepEvent.comparePoints(newSeg.leftSE.point, newSeg.rightSE.point) > 0) {
|
|
1077
|
+
newSeg.swapEvents();
|
|
1078
|
+
}
|
|
1079
|
+
if (SweepEvent.comparePoints(this.leftSE.point, this.rightSE.point) > 0) {
|
|
1080
|
+
this.swapEvents();
|
|
1081
|
+
}
|
|
1082
|
+
if (alreadyLinked) {
|
|
1083
|
+
newLeftSE.checkForConsuming();
|
|
1084
|
+
newRightSE.checkForConsuming();
|
|
1085
|
+
}
|
|
1086
|
+
return newEvents;
|
|
1087
|
+
}
|
|
1088
|
+
/* Swap which event is left and right */
|
|
1089
|
+
swapEvents() {
|
|
1090
|
+
const tmpEvt = this.rightSE;
|
|
1091
|
+
this.rightSE = this.leftSE;
|
|
1092
|
+
this.leftSE = tmpEvt;
|
|
1093
|
+
this.leftSE.isLeft = true;
|
|
1094
|
+
this.rightSE.isLeft = false;
|
|
1095
|
+
for (let i = 0, iMax = this.windings.length; i < iMax; i++) {
|
|
1096
|
+
this.windings[i] *= -1;
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/* Consume another segment. We take their rings under our wing
|
|
1100
|
+
* and mark them as consumed. Use for perfectly overlapping segments */
|
|
1101
|
+
consume(other) {
|
|
1102
|
+
let consumer = this;
|
|
1103
|
+
let consumee = other;
|
|
1104
|
+
while (consumer.consumedBy) consumer = consumer.consumedBy;
|
|
1105
|
+
while (consumee.consumedBy) consumee = consumee.consumedBy;
|
|
1106
|
+
const cmp2 = _Segment.compare(consumer, consumee);
|
|
1107
|
+
if (cmp2 === 0) return;
|
|
1108
|
+
if (cmp2 > 0) {
|
|
1109
|
+
const tmp = consumer;
|
|
1110
|
+
consumer = consumee;
|
|
1111
|
+
consumee = tmp;
|
|
1112
|
+
}
|
|
1113
|
+
if (consumer.prev === consumee) {
|
|
1114
|
+
const tmp = consumer;
|
|
1115
|
+
consumer = consumee;
|
|
1116
|
+
consumee = tmp;
|
|
1117
|
+
}
|
|
1118
|
+
for (let i = 0, iMax = consumee.rings.length; i < iMax; i++) {
|
|
1119
|
+
const ring = consumee.rings[i];
|
|
1120
|
+
const winding = consumee.windings[i];
|
|
1121
|
+
const index2 = consumer.rings.indexOf(ring);
|
|
1122
|
+
if (index2 === -1) {
|
|
1123
|
+
consumer.rings.push(ring);
|
|
1124
|
+
consumer.windings.push(winding);
|
|
1125
|
+
} else consumer.windings[index2] += winding;
|
|
1126
|
+
}
|
|
1127
|
+
consumee.rings = null;
|
|
1128
|
+
consumee.windings = null;
|
|
1129
|
+
consumee.consumedBy = consumer;
|
|
1130
|
+
consumee.leftSE.consumedBy = consumer.leftSE;
|
|
1131
|
+
consumee.rightSE.consumedBy = consumer.rightSE;
|
|
1132
|
+
}
|
|
1133
|
+
/* The first segment previous segment chain that is in the result */
|
|
1134
|
+
prevInResult() {
|
|
1135
|
+
if (this._prevInResult !== void 0) return this._prevInResult;
|
|
1136
|
+
if (!this.prev) this._prevInResult = null;
|
|
1137
|
+
else if (this.prev.isInResult()) this._prevInResult = this.prev;
|
|
1138
|
+
else this._prevInResult = this.prev.prevInResult();
|
|
1139
|
+
return this._prevInResult;
|
|
1140
|
+
}
|
|
1141
|
+
beforeState() {
|
|
1142
|
+
if (this._beforeState !== void 0) return this._beforeState;
|
|
1143
|
+
if (!this.prev) this._beforeState = {
|
|
1144
|
+
rings: [],
|
|
1145
|
+
windings: [],
|
|
1146
|
+
multiPolys: []
|
|
1147
|
+
};
|
|
1148
|
+
else {
|
|
1149
|
+
const seg = this.prev.consumedBy || this.prev;
|
|
1150
|
+
this._beforeState = seg.afterState();
|
|
1151
|
+
}
|
|
1152
|
+
return this._beforeState;
|
|
1153
|
+
}
|
|
1154
|
+
afterState() {
|
|
1155
|
+
if (this._afterState !== void 0) return this._afterState;
|
|
1156
|
+
const beforeState = this.beforeState();
|
|
1157
|
+
this._afterState = {
|
|
1158
|
+
rings: beforeState.rings.slice(0),
|
|
1159
|
+
windings: beforeState.windings.slice(0),
|
|
1160
|
+
multiPolys: []
|
|
1161
|
+
};
|
|
1162
|
+
const ringsAfter = this._afterState.rings;
|
|
1163
|
+
const windingsAfter = this._afterState.windings;
|
|
1164
|
+
const mpsAfter = this._afterState.multiPolys;
|
|
1165
|
+
for (let i = 0, iMax = this.rings.length; i < iMax; i++) {
|
|
1166
|
+
const ring = this.rings[i];
|
|
1167
|
+
const winding = this.windings[i];
|
|
1168
|
+
const index2 = ringsAfter.indexOf(ring);
|
|
1169
|
+
if (index2 === -1) {
|
|
1170
|
+
ringsAfter.push(ring);
|
|
1171
|
+
windingsAfter.push(winding);
|
|
1172
|
+
} else windingsAfter[index2] += winding;
|
|
1173
|
+
}
|
|
1174
|
+
const polysAfter = [];
|
|
1175
|
+
const polysExclude = [];
|
|
1176
|
+
for (let i = 0, iMax = ringsAfter.length; i < iMax; i++) {
|
|
1177
|
+
if (windingsAfter[i] === 0) continue;
|
|
1178
|
+
const ring = ringsAfter[i];
|
|
1179
|
+
const poly = ring.poly;
|
|
1180
|
+
if (polysExclude.indexOf(poly) !== -1) continue;
|
|
1181
|
+
if (ring.isExterior) polysAfter.push(poly);
|
|
1182
|
+
else {
|
|
1183
|
+
if (polysExclude.indexOf(poly) === -1) polysExclude.push(poly);
|
|
1184
|
+
const index2 = polysAfter.indexOf(ring.poly);
|
|
1185
|
+
if (index2 !== -1) polysAfter.splice(index2, 1);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
for (let i = 0, iMax = polysAfter.length; i < iMax; i++) {
|
|
1189
|
+
const mp = polysAfter[i].multiPoly;
|
|
1190
|
+
if (mpsAfter.indexOf(mp) === -1) mpsAfter.push(mp);
|
|
1191
|
+
}
|
|
1192
|
+
return this._afterState;
|
|
1193
|
+
}
|
|
1194
|
+
/* Is this segment part of the final result? */
|
|
1195
|
+
isInResult() {
|
|
1196
|
+
if (this.consumedBy) return false;
|
|
1197
|
+
if (this._isInResult !== void 0) return this._isInResult;
|
|
1198
|
+
const mpsBefore = this.beforeState().multiPolys;
|
|
1199
|
+
const mpsAfter = this.afterState().multiPolys;
|
|
1200
|
+
switch (operation.type) {
|
|
1201
|
+
case "union": {
|
|
1202
|
+
const noBefores = mpsBefore.length === 0;
|
|
1203
|
+
const noAfters = mpsAfter.length === 0;
|
|
1204
|
+
this._isInResult = noBefores !== noAfters;
|
|
1205
|
+
break;
|
|
1206
|
+
}
|
|
1207
|
+
case "intersection": {
|
|
1208
|
+
let least;
|
|
1209
|
+
let most;
|
|
1210
|
+
if (mpsBefore.length < mpsAfter.length) {
|
|
1211
|
+
least = mpsBefore.length;
|
|
1212
|
+
most = mpsAfter.length;
|
|
1213
|
+
} else {
|
|
1214
|
+
least = mpsAfter.length;
|
|
1215
|
+
most = mpsBefore.length;
|
|
1216
|
+
}
|
|
1217
|
+
this._isInResult = most === operation.numMultiPolys && least < most;
|
|
1218
|
+
break;
|
|
1219
|
+
}
|
|
1220
|
+
case "xor": {
|
|
1221
|
+
const diff = Math.abs(mpsBefore.length - mpsAfter.length);
|
|
1222
|
+
this._isInResult = diff % 2 === 1;
|
|
1223
|
+
break;
|
|
1224
|
+
}
|
|
1225
|
+
case "difference": {
|
|
1226
|
+
const isJustSubject = (mps) => mps.length === 1 && mps[0].isSubject;
|
|
1227
|
+
this._isInResult = isJustSubject(mpsBefore) !== isJustSubject(mpsAfter);
|
|
1228
|
+
break;
|
|
1229
|
+
}
|
|
1230
|
+
default:
|
|
1231
|
+
throw new Error(`Unrecognized operation type found ${operation.type}`);
|
|
1232
|
+
}
|
|
1233
|
+
return this._isInResult;
|
|
1234
|
+
}
|
|
1235
|
+
};
|
|
1236
|
+
var RingIn = class {
|
|
1237
|
+
constructor(geomRing, poly, isExterior) {
|
|
1238
|
+
if (!Array.isArray(geomRing) || geomRing.length === 0) {
|
|
1239
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
1240
|
+
}
|
|
1241
|
+
this.poly = poly;
|
|
1242
|
+
this.isExterior = isExterior;
|
|
1243
|
+
this.segments = [];
|
|
1244
|
+
if (typeof geomRing[0][0] !== "number" || typeof geomRing[0][1] !== "number") {
|
|
1245
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
1246
|
+
}
|
|
1247
|
+
const firstPoint = rounder.round(geomRing[0][0], geomRing[0][1]);
|
|
1248
|
+
this.bbox = {
|
|
1249
|
+
ll: {
|
|
1250
|
+
x: firstPoint.x,
|
|
1251
|
+
y: firstPoint.y
|
|
1252
|
+
},
|
|
1253
|
+
ur: {
|
|
1254
|
+
x: firstPoint.x,
|
|
1255
|
+
y: firstPoint.y
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
let prevPoint = firstPoint;
|
|
1259
|
+
for (let i = 1, iMax = geomRing.length; i < iMax; i++) {
|
|
1260
|
+
if (typeof geomRing[i][0] !== "number" || typeof geomRing[i][1] !== "number") {
|
|
1261
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
1262
|
+
}
|
|
1263
|
+
let point2 = rounder.round(geomRing[i][0], geomRing[i][1]);
|
|
1264
|
+
if (point2.x === prevPoint.x && point2.y === prevPoint.y) continue;
|
|
1265
|
+
this.segments.push(Segment.fromRing(prevPoint, point2, this));
|
|
1266
|
+
if (point2.x < this.bbox.ll.x) this.bbox.ll.x = point2.x;
|
|
1267
|
+
if (point2.y < this.bbox.ll.y) this.bbox.ll.y = point2.y;
|
|
1268
|
+
if (point2.x > this.bbox.ur.x) this.bbox.ur.x = point2.x;
|
|
1269
|
+
if (point2.y > this.bbox.ur.y) this.bbox.ur.y = point2.y;
|
|
1270
|
+
prevPoint = point2;
|
|
1271
|
+
}
|
|
1272
|
+
if (firstPoint.x !== prevPoint.x || firstPoint.y !== prevPoint.y) {
|
|
1273
|
+
this.segments.push(Segment.fromRing(prevPoint, firstPoint, this));
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
getSweepEvents() {
|
|
1277
|
+
const sweepEvents = [];
|
|
1278
|
+
for (let i = 0, iMax = this.segments.length; i < iMax; i++) {
|
|
1279
|
+
const segment = this.segments[i];
|
|
1280
|
+
sweepEvents.push(segment.leftSE);
|
|
1281
|
+
sweepEvents.push(segment.rightSE);
|
|
1282
|
+
}
|
|
1283
|
+
return sweepEvents;
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
var PolyIn = class {
|
|
1287
|
+
constructor(geomPoly, multiPoly) {
|
|
1288
|
+
if (!Array.isArray(geomPoly)) {
|
|
1289
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
1290
|
+
}
|
|
1291
|
+
this.exteriorRing = new RingIn(geomPoly[0], this, true);
|
|
1292
|
+
this.bbox = {
|
|
1293
|
+
ll: {
|
|
1294
|
+
x: this.exteriorRing.bbox.ll.x,
|
|
1295
|
+
y: this.exteriorRing.bbox.ll.y
|
|
1296
|
+
},
|
|
1297
|
+
ur: {
|
|
1298
|
+
x: this.exteriorRing.bbox.ur.x,
|
|
1299
|
+
y: this.exteriorRing.bbox.ur.y
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
this.interiorRings = [];
|
|
1303
|
+
for (let i = 1, iMax = geomPoly.length; i < iMax; i++) {
|
|
1304
|
+
const ring = new RingIn(geomPoly[i], this, false);
|
|
1305
|
+
if (ring.bbox.ll.x < this.bbox.ll.x) this.bbox.ll.x = ring.bbox.ll.x;
|
|
1306
|
+
if (ring.bbox.ll.y < this.bbox.ll.y) this.bbox.ll.y = ring.bbox.ll.y;
|
|
1307
|
+
if (ring.bbox.ur.x > this.bbox.ur.x) this.bbox.ur.x = ring.bbox.ur.x;
|
|
1308
|
+
if (ring.bbox.ur.y > this.bbox.ur.y) this.bbox.ur.y = ring.bbox.ur.y;
|
|
1309
|
+
this.interiorRings.push(ring);
|
|
1310
|
+
}
|
|
1311
|
+
this.multiPoly = multiPoly;
|
|
1312
|
+
}
|
|
1313
|
+
getSweepEvents() {
|
|
1314
|
+
const sweepEvents = this.exteriorRing.getSweepEvents();
|
|
1315
|
+
for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
|
|
1316
|
+
const ringSweepEvents = this.interiorRings[i].getSweepEvents();
|
|
1317
|
+
for (let j = 0, jMax = ringSweepEvents.length; j < jMax; j++) {
|
|
1318
|
+
sweepEvents.push(ringSweepEvents[j]);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
return sweepEvents;
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
var MultiPolyIn = class {
|
|
1325
|
+
constructor(geom, isSubject) {
|
|
1326
|
+
if (!Array.isArray(geom)) {
|
|
1327
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
1328
|
+
}
|
|
1329
|
+
try {
|
|
1330
|
+
if (typeof geom[0][0][0] === "number") geom = [geom];
|
|
1331
|
+
} catch (ex) {
|
|
1332
|
+
}
|
|
1333
|
+
this.polys = [];
|
|
1334
|
+
this.bbox = {
|
|
1335
|
+
ll: {
|
|
1336
|
+
x: Number.POSITIVE_INFINITY,
|
|
1337
|
+
y: Number.POSITIVE_INFINITY
|
|
1338
|
+
},
|
|
1339
|
+
ur: {
|
|
1340
|
+
x: Number.NEGATIVE_INFINITY,
|
|
1341
|
+
y: Number.NEGATIVE_INFINITY
|
|
1342
|
+
}
|
|
1343
|
+
};
|
|
1344
|
+
for (let i = 0, iMax = geom.length; i < iMax; i++) {
|
|
1345
|
+
const poly = new PolyIn(geom[i], this);
|
|
1346
|
+
if (poly.bbox.ll.x < this.bbox.ll.x) this.bbox.ll.x = poly.bbox.ll.x;
|
|
1347
|
+
if (poly.bbox.ll.y < this.bbox.ll.y) this.bbox.ll.y = poly.bbox.ll.y;
|
|
1348
|
+
if (poly.bbox.ur.x > this.bbox.ur.x) this.bbox.ur.x = poly.bbox.ur.x;
|
|
1349
|
+
if (poly.bbox.ur.y > this.bbox.ur.y) this.bbox.ur.y = poly.bbox.ur.y;
|
|
1350
|
+
this.polys.push(poly);
|
|
1351
|
+
}
|
|
1352
|
+
this.isSubject = isSubject;
|
|
1353
|
+
}
|
|
1354
|
+
getSweepEvents() {
|
|
1355
|
+
const sweepEvents = [];
|
|
1356
|
+
for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
|
|
1357
|
+
const polySweepEvents = this.polys[i].getSweepEvents();
|
|
1358
|
+
for (let j = 0, jMax = polySweepEvents.length; j < jMax; j++) {
|
|
1359
|
+
sweepEvents.push(polySweepEvents[j]);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
return sweepEvents;
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
var RingOut = class _RingOut {
|
|
1366
|
+
/* Given the segments from the sweep line pass, compute & return a series
|
|
1367
|
+
* of closed rings from all the segments marked to be part of the result */
|
|
1368
|
+
static factory(allSegments) {
|
|
1369
|
+
const ringsOut = [];
|
|
1370
|
+
for (let i = 0, iMax = allSegments.length; i < iMax; i++) {
|
|
1371
|
+
const segment = allSegments[i];
|
|
1372
|
+
if (!segment.isInResult() || segment.ringOut) continue;
|
|
1373
|
+
let prevEvent = null;
|
|
1374
|
+
let event = segment.leftSE;
|
|
1375
|
+
let nextEvent = segment.rightSE;
|
|
1376
|
+
const events = [event];
|
|
1377
|
+
const startingPoint = event.point;
|
|
1378
|
+
const intersectionLEs = [];
|
|
1379
|
+
while (true) {
|
|
1380
|
+
prevEvent = event;
|
|
1381
|
+
event = nextEvent;
|
|
1382
|
+
events.push(event);
|
|
1383
|
+
if (event.point === startingPoint) break;
|
|
1384
|
+
while (true) {
|
|
1385
|
+
const availableLEs = event.getAvailableLinkedEvents();
|
|
1386
|
+
if (availableLEs.length === 0) {
|
|
1387
|
+
const firstPt = events[0].point;
|
|
1388
|
+
const lastPt = events[events.length - 1].point;
|
|
1389
|
+
throw new Error(`Unable to complete output ring starting at [${firstPt.x}, ${firstPt.y}]. Last matching segment found ends at [${lastPt.x}, ${lastPt.y}].`);
|
|
1390
|
+
}
|
|
1391
|
+
if (availableLEs.length === 1) {
|
|
1392
|
+
nextEvent = availableLEs[0].otherSE;
|
|
1393
|
+
break;
|
|
1394
|
+
}
|
|
1395
|
+
let indexLE = null;
|
|
1396
|
+
for (let j = 0, jMax = intersectionLEs.length; j < jMax; j++) {
|
|
1397
|
+
if (intersectionLEs[j].point === event.point) {
|
|
1398
|
+
indexLE = j;
|
|
1399
|
+
break;
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
if (indexLE !== null) {
|
|
1403
|
+
const intersectionLE = intersectionLEs.splice(indexLE)[0];
|
|
1404
|
+
const ringEvents = events.splice(intersectionLE.index);
|
|
1405
|
+
ringEvents.unshift(ringEvents[0].otherSE);
|
|
1406
|
+
ringsOut.push(new _RingOut(ringEvents.reverse()));
|
|
1407
|
+
continue;
|
|
1408
|
+
}
|
|
1409
|
+
intersectionLEs.push({
|
|
1410
|
+
index: events.length,
|
|
1411
|
+
point: event.point
|
|
1412
|
+
});
|
|
1413
|
+
const comparator = event.getLeftmostComparator(prevEvent);
|
|
1414
|
+
nextEvent = availableLEs.sort(comparator)[0].otherSE;
|
|
1415
|
+
break;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
ringsOut.push(new _RingOut(events));
|
|
1419
|
+
}
|
|
1420
|
+
return ringsOut;
|
|
1421
|
+
}
|
|
1422
|
+
constructor(events) {
|
|
1423
|
+
this.events = events;
|
|
1424
|
+
for (let i = 0, iMax = events.length; i < iMax; i++) {
|
|
1425
|
+
events[i].segment.ringOut = this;
|
|
1426
|
+
}
|
|
1427
|
+
this.poly = null;
|
|
1428
|
+
}
|
|
1429
|
+
getGeom() {
|
|
1430
|
+
let prevPt = this.events[0].point;
|
|
1431
|
+
const points = [prevPt];
|
|
1432
|
+
for (let i = 1, iMax = this.events.length - 1; i < iMax; i++) {
|
|
1433
|
+
const pt2 = this.events[i].point;
|
|
1434
|
+
const nextPt2 = this.events[i + 1].point;
|
|
1435
|
+
if (compareVectorAngles(pt2, prevPt, nextPt2) === 0) continue;
|
|
1436
|
+
points.push(pt2);
|
|
1437
|
+
prevPt = pt2;
|
|
1438
|
+
}
|
|
1439
|
+
if (points.length === 1) return null;
|
|
1440
|
+
const pt = points[0];
|
|
1441
|
+
const nextPt = points[1];
|
|
1442
|
+
if (compareVectorAngles(pt, prevPt, nextPt) === 0) points.shift();
|
|
1443
|
+
points.push(points[0]);
|
|
1444
|
+
const step = this.isExteriorRing() ? 1 : -1;
|
|
1445
|
+
const iStart = this.isExteriorRing() ? 0 : points.length - 1;
|
|
1446
|
+
const iEnd = this.isExteriorRing() ? points.length : -1;
|
|
1447
|
+
const orderedPoints = [];
|
|
1448
|
+
for (let i = iStart; i != iEnd; i += step) orderedPoints.push([points[i].x, points[i].y]);
|
|
1449
|
+
return orderedPoints;
|
|
1450
|
+
}
|
|
1451
|
+
isExteriorRing() {
|
|
1452
|
+
if (this._isExteriorRing === void 0) {
|
|
1453
|
+
const enclosing = this.enclosingRing();
|
|
1454
|
+
this._isExteriorRing = enclosing ? !enclosing.isExteriorRing() : true;
|
|
1455
|
+
}
|
|
1456
|
+
return this._isExteriorRing;
|
|
1457
|
+
}
|
|
1458
|
+
enclosingRing() {
|
|
1459
|
+
if (this._enclosingRing === void 0) {
|
|
1460
|
+
this._enclosingRing = this._calcEnclosingRing();
|
|
1461
|
+
}
|
|
1462
|
+
return this._enclosingRing;
|
|
1463
|
+
}
|
|
1464
|
+
/* Returns the ring that encloses this one, if any */
|
|
1465
|
+
_calcEnclosingRing() {
|
|
1466
|
+
let leftMostEvt = this.events[0];
|
|
1467
|
+
for (let i = 1, iMax = this.events.length; i < iMax; i++) {
|
|
1468
|
+
const evt = this.events[i];
|
|
1469
|
+
if (SweepEvent.compare(leftMostEvt, evt) > 0) leftMostEvt = evt;
|
|
1470
|
+
}
|
|
1471
|
+
let prevSeg = leftMostEvt.segment.prevInResult();
|
|
1472
|
+
let prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
|
|
1473
|
+
while (true) {
|
|
1474
|
+
if (!prevSeg) return null;
|
|
1475
|
+
if (!prevPrevSeg) return prevSeg.ringOut;
|
|
1476
|
+
if (prevPrevSeg.ringOut !== prevSeg.ringOut) {
|
|
1477
|
+
if (prevPrevSeg.ringOut.enclosingRing() !== prevSeg.ringOut) {
|
|
1478
|
+
return prevSeg.ringOut;
|
|
1479
|
+
} else return prevSeg.ringOut.enclosingRing();
|
|
1480
|
+
}
|
|
1481
|
+
prevSeg = prevPrevSeg.prevInResult();
|
|
1482
|
+
prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
var PolyOut = class {
|
|
1487
|
+
constructor(exteriorRing) {
|
|
1488
|
+
this.exteriorRing = exteriorRing;
|
|
1489
|
+
exteriorRing.poly = this;
|
|
1490
|
+
this.interiorRings = [];
|
|
1491
|
+
}
|
|
1492
|
+
addInterior(ring) {
|
|
1493
|
+
this.interiorRings.push(ring);
|
|
1494
|
+
ring.poly = this;
|
|
1495
|
+
}
|
|
1496
|
+
getGeom() {
|
|
1497
|
+
const geom = [this.exteriorRing.getGeom()];
|
|
1498
|
+
if (geom[0] === null) return null;
|
|
1499
|
+
for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
|
|
1500
|
+
const ringGeom = this.interiorRings[i].getGeom();
|
|
1501
|
+
if (ringGeom === null) continue;
|
|
1502
|
+
geom.push(ringGeom);
|
|
1503
|
+
}
|
|
1504
|
+
return geom;
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
var MultiPolyOut = class {
|
|
1508
|
+
constructor(rings) {
|
|
1509
|
+
this.rings = rings;
|
|
1510
|
+
this.polys = this._composePolys(rings);
|
|
1511
|
+
}
|
|
1512
|
+
getGeom() {
|
|
1513
|
+
const geom = [];
|
|
1514
|
+
for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
|
|
1515
|
+
const polyGeom = this.polys[i].getGeom();
|
|
1516
|
+
if (polyGeom === null) continue;
|
|
1517
|
+
geom.push(polyGeom);
|
|
1518
|
+
}
|
|
1519
|
+
return geom;
|
|
1520
|
+
}
|
|
1521
|
+
_composePolys(rings) {
|
|
1522
|
+
const polys = [];
|
|
1523
|
+
for (let i = 0, iMax = rings.length; i < iMax; i++) {
|
|
1524
|
+
const ring = rings[i];
|
|
1525
|
+
if (ring.poly) continue;
|
|
1526
|
+
if (ring.isExteriorRing()) polys.push(new PolyOut(ring));
|
|
1527
|
+
else {
|
|
1528
|
+
const enclosingRing = ring.enclosingRing();
|
|
1529
|
+
if (!enclosingRing.poly) polys.push(new PolyOut(enclosingRing));
|
|
1530
|
+
enclosingRing.poly.addInterior(ring);
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
return polys;
|
|
1534
|
+
}
|
|
1535
|
+
};
|
|
1536
|
+
var SweepLine = class {
|
|
1537
|
+
constructor(queue) {
|
|
1538
|
+
let comparator = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Segment.compare;
|
|
1539
|
+
this.queue = queue;
|
|
1540
|
+
this.tree = new SplayTree__default["default"](comparator);
|
|
1541
|
+
this.segments = [];
|
|
1542
|
+
}
|
|
1543
|
+
process(event) {
|
|
1544
|
+
const segment = event.segment;
|
|
1545
|
+
const newEvents = [];
|
|
1546
|
+
if (event.consumedBy) {
|
|
1547
|
+
if (event.isLeft) this.queue.remove(event.otherSE);
|
|
1548
|
+
else this.tree.remove(segment);
|
|
1549
|
+
return newEvents;
|
|
1550
|
+
}
|
|
1551
|
+
const node = event.isLeft ? this.tree.add(segment) : this.tree.find(segment);
|
|
1552
|
+
if (!node) throw new Error(`Unable to find segment #${segment.id} [${segment.leftSE.point.x}, ${segment.leftSE.point.y}] -> [${segment.rightSE.point.x}, ${segment.rightSE.point.y}] in SweepLine tree.`);
|
|
1553
|
+
let prevNode = node;
|
|
1554
|
+
let nextNode = node;
|
|
1555
|
+
let prevSeg = void 0;
|
|
1556
|
+
let nextSeg = void 0;
|
|
1557
|
+
while (prevSeg === void 0) {
|
|
1558
|
+
prevNode = this.tree.prev(prevNode);
|
|
1559
|
+
if (prevNode === null) prevSeg = null;
|
|
1560
|
+
else if (prevNode.key.consumedBy === void 0) prevSeg = prevNode.key;
|
|
1561
|
+
}
|
|
1562
|
+
while (nextSeg === void 0) {
|
|
1563
|
+
nextNode = this.tree.next(nextNode);
|
|
1564
|
+
if (nextNode === null) nextSeg = null;
|
|
1565
|
+
else if (nextNode.key.consumedBy === void 0) nextSeg = nextNode.key;
|
|
1566
|
+
}
|
|
1567
|
+
if (event.isLeft) {
|
|
1568
|
+
let prevMySplitter = null;
|
|
1569
|
+
if (prevSeg) {
|
|
1570
|
+
const prevInter = prevSeg.getIntersection(segment);
|
|
1571
|
+
if (prevInter !== null) {
|
|
1572
|
+
if (!segment.isAnEndpoint(prevInter)) prevMySplitter = prevInter;
|
|
1573
|
+
if (!prevSeg.isAnEndpoint(prevInter)) {
|
|
1574
|
+
const newEventsFromSplit = this._splitSafely(prevSeg, prevInter);
|
|
1575
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
1576
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
let nextMySplitter = null;
|
|
1582
|
+
if (nextSeg) {
|
|
1583
|
+
const nextInter = nextSeg.getIntersection(segment);
|
|
1584
|
+
if (nextInter !== null) {
|
|
1585
|
+
if (!segment.isAnEndpoint(nextInter)) nextMySplitter = nextInter;
|
|
1586
|
+
if (!nextSeg.isAnEndpoint(nextInter)) {
|
|
1587
|
+
const newEventsFromSplit = this._splitSafely(nextSeg, nextInter);
|
|
1588
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
1589
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
if (prevMySplitter !== null || nextMySplitter !== null) {
|
|
1595
|
+
let mySplitter = null;
|
|
1596
|
+
if (prevMySplitter === null) mySplitter = nextMySplitter;
|
|
1597
|
+
else if (nextMySplitter === null) mySplitter = prevMySplitter;
|
|
1598
|
+
else {
|
|
1599
|
+
const cmpSplitters = SweepEvent.comparePoints(prevMySplitter, nextMySplitter);
|
|
1600
|
+
mySplitter = cmpSplitters <= 0 ? prevMySplitter : nextMySplitter;
|
|
1601
|
+
}
|
|
1602
|
+
this.queue.remove(segment.rightSE);
|
|
1603
|
+
newEvents.push(segment.rightSE);
|
|
1604
|
+
const newEventsFromSplit = segment.split(mySplitter);
|
|
1605
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
1606
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
if (newEvents.length > 0) {
|
|
1610
|
+
this.tree.remove(segment);
|
|
1611
|
+
newEvents.push(event);
|
|
1612
|
+
} else {
|
|
1613
|
+
this.segments.push(segment);
|
|
1614
|
+
segment.prev = prevSeg;
|
|
1615
|
+
}
|
|
1616
|
+
} else {
|
|
1617
|
+
if (prevSeg && nextSeg) {
|
|
1618
|
+
const inter = prevSeg.getIntersection(nextSeg);
|
|
1619
|
+
if (inter !== null) {
|
|
1620
|
+
if (!prevSeg.isAnEndpoint(inter)) {
|
|
1621
|
+
const newEventsFromSplit = this._splitSafely(prevSeg, inter);
|
|
1622
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
1623
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
if (!nextSeg.isAnEndpoint(inter)) {
|
|
1627
|
+
const newEventsFromSplit = this._splitSafely(nextSeg, inter);
|
|
1628
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
1629
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
this.tree.remove(segment);
|
|
1635
|
+
}
|
|
1636
|
+
return newEvents;
|
|
1637
|
+
}
|
|
1638
|
+
/* Safely split a segment that is currently in the datastructures
|
|
1639
|
+
* IE - a segment other than the one that is currently being processed. */
|
|
1640
|
+
_splitSafely(seg, pt) {
|
|
1641
|
+
this.tree.remove(seg);
|
|
1642
|
+
const rightSE = seg.rightSE;
|
|
1643
|
+
this.queue.remove(rightSE);
|
|
1644
|
+
const newEvents = seg.split(pt);
|
|
1645
|
+
newEvents.push(rightSE);
|
|
1646
|
+
if (seg.consumedBy === void 0) this.tree.add(seg);
|
|
1647
|
+
return newEvents;
|
|
1648
|
+
}
|
|
1649
|
+
};
|
|
1650
|
+
var POLYGON_CLIPPING_MAX_QUEUE_SIZE = typeof process !== "undefined" && process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE || 1e6;
|
|
1651
|
+
var POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS = typeof process !== "undefined" && process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS || 1e6;
|
|
1652
|
+
var Operation = class {
|
|
1653
|
+
run(type, geom, moreGeoms) {
|
|
1654
|
+
operation.type = type;
|
|
1655
|
+
rounder.reset();
|
|
1656
|
+
const multipolys = [new MultiPolyIn(geom, true)];
|
|
1657
|
+
for (let i = 0, iMax = moreGeoms.length; i < iMax; i++) {
|
|
1658
|
+
multipolys.push(new MultiPolyIn(moreGeoms[i], false));
|
|
1659
|
+
}
|
|
1660
|
+
operation.numMultiPolys = multipolys.length;
|
|
1661
|
+
if (operation.type === "difference") {
|
|
1662
|
+
const subject = multipolys[0];
|
|
1663
|
+
let i = 1;
|
|
1664
|
+
while (i < multipolys.length) {
|
|
1665
|
+
if (getBboxOverlap(multipolys[i].bbox, subject.bbox) !== null) i++;
|
|
1666
|
+
else multipolys.splice(i, 1);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
if (operation.type === "intersection") {
|
|
1670
|
+
for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
|
|
1671
|
+
const mpA = multipolys[i];
|
|
1672
|
+
for (let j = i + 1, jMax = multipolys.length; j < jMax; j++) {
|
|
1673
|
+
if (getBboxOverlap(mpA.bbox, multipolys[j].bbox) === null) return [];
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
const queue = new SplayTree__default["default"](SweepEvent.compare);
|
|
1678
|
+
for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
|
|
1679
|
+
const sweepEvents = multipolys[i].getSweepEvents();
|
|
1680
|
+
for (let j = 0, jMax = sweepEvents.length; j < jMax; j++) {
|
|
1681
|
+
queue.insert(sweepEvents[j]);
|
|
1682
|
+
if (queue.size > POLYGON_CLIPPING_MAX_QUEUE_SIZE) {
|
|
1683
|
+
throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).");
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
const sweepLine = new SweepLine(queue);
|
|
1688
|
+
let prevQueueSize = queue.size;
|
|
1689
|
+
let node = queue.pop();
|
|
1690
|
+
while (node) {
|
|
1691
|
+
const evt = node.key;
|
|
1692
|
+
if (queue.size === prevQueueSize) {
|
|
1693
|
+
const seg = evt.segment;
|
|
1694
|
+
throw new Error(`Unable to pop() ${evt.isLeft ? "left" : "right"} SweepEvent [${evt.point.x}, ${evt.point.y}] from segment #${seg.id} [${seg.leftSE.point.x}, ${seg.leftSE.point.y}] -> [${seg.rightSE.point.x}, ${seg.rightSE.point.y}] from queue.`);
|
|
1695
|
+
}
|
|
1696
|
+
if (queue.size > POLYGON_CLIPPING_MAX_QUEUE_SIZE) {
|
|
1697
|
+
throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");
|
|
1698
|
+
}
|
|
1699
|
+
if (sweepLine.segments.length > POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS) {
|
|
1700
|
+
throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");
|
|
1701
|
+
}
|
|
1702
|
+
const newEvents = sweepLine.process(evt);
|
|
1703
|
+
for (let i = 0, iMax = newEvents.length; i < iMax; i++) {
|
|
1704
|
+
const evt2 = newEvents[i];
|
|
1705
|
+
if (evt2.consumedBy === void 0) queue.insert(evt2);
|
|
1706
|
+
}
|
|
1707
|
+
prevQueueSize = queue.size;
|
|
1708
|
+
node = queue.pop();
|
|
1709
|
+
}
|
|
1710
|
+
rounder.reset();
|
|
1711
|
+
const ringsOut = RingOut.factory(sweepLine.segments);
|
|
1712
|
+
const result = new MultiPolyOut(ringsOut);
|
|
1713
|
+
return result.getGeom();
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
var operation = new Operation();
|
|
1717
|
+
var union = function(geom) {
|
|
1718
|
+
for (var _len = arguments.length, moreGeoms = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
1719
|
+
moreGeoms[_key - 1] = arguments[_key];
|
|
1720
|
+
}
|
|
1721
|
+
return operation.run("union", geom, moreGeoms);
|
|
1722
|
+
};
|
|
1723
|
+
var intersection = function(geom) {
|
|
1724
|
+
for (var _len2 = arguments.length, moreGeoms = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
1725
|
+
moreGeoms[_key2 - 1] = arguments[_key2];
|
|
1726
|
+
}
|
|
1727
|
+
return operation.run("intersection", geom, moreGeoms);
|
|
1728
|
+
};
|
|
1729
|
+
var xor = function(geom) {
|
|
1730
|
+
for (var _len3 = arguments.length, moreGeoms = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
1731
|
+
moreGeoms[_key3 - 1] = arguments[_key3];
|
|
1732
|
+
}
|
|
1733
|
+
return operation.run("xor", geom, moreGeoms);
|
|
1734
|
+
};
|
|
1735
|
+
var difference = function(subjectGeom) {
|
|
1736
|
+
for (var _len4 = arguments.length, clippingGeoms = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
1737
|
+
clippingGeoms[_key4 - 1] = arguments[_key4];
|
|
1738
|
+
}
|
|
1739
|
+
return operation.run("difference", subjectGeom, clippingGeoms);
|
|
1740
|
+
};
|
|
1741
|
+
var index = {
|
|
1742
|
+
union,
|
|
1743
|
+
intersection,
|
|
1744
|
+
xor,
|
|
1745
|
+
difference
|
|
1746
|
+
};
|
|
1747
|
+
module.exports = index;
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
|
|
31
1751
|
// node_modules/rbush/rbush.js
|
|
32
1752
|
var require_rbush = __commonJS({
|
|
33
1753
|
"node_modules/rbush/rbush.js"(exports, module) {
|
|
@@ -4874,6 +6594,7 @@ stream_array_default.withParserAsWebStream = (options) => (
|
|
|
4874
6594
|
);
|
|
4875
6595
|
|
|
4876
6596
|
// src/utils/utils.mjs
|
|
6597
|
+
var import_polygon_clipping = __toESM(require_polygon_clipping_cjs(), 1);
|
|
4877
6598
|
var addLine = (pt1, pt2, scene) => {
|
|
4878
6599
|
let lineMaterial = new THREE3.LineBasicMaterial({ color: "#0011ff" });
|
|
4879
6600
|
let pts = [];
|
|
@@ -6006,6 +7727,45 @@ function getRectIntersectionRatio(rect1, rect2) {
|
|
|
6006
7727
|
const intersectionArea = polygonArea4(output);
|
|
6007
7728
|
return Math.max(0, Math.min(100, intersectionArea / area1 * 100));
|
|
6008
7729
|
}
|
|
7730
|
+
function getPolygonIntersectionRatio(polygon1, polygon2) {
|
|
7731
|
+
if (!polygon1 || !polygon2 || polygon1.length < 3 || polygon2.length < 3) {
|
|
7732
|
+
return 0;
|
|
7733
|
+
}
|
|
7734
|
+
const toRing = (points) => {
|
|
7735
|
+
const ring = points.map((p) => [p.x, p.y]);
|
|
7736
|
+
const first = ring[0];
|
|
7737
|
+
const last = ring[ring.length - 1];
|
|
7738
|
+
if (first[0] !== last[0] || first[1] !== last[1]) {
|
|
7739
|
+
ring.push([...first]);
|
|
7740
|
+
}
|
|
7741
|
+
return ring;
|
|
7742
|
+
};
|
|
7743
|
+
const ring1 = toRing(polygon1);
|
|
7744
|
+
const ring2 = toRing(polygon2);
|
|
7745
|
+
const getArea = (ring) => {
|
|
7746
|
+
let area2 = 0;
|
|
7747
|
+
for (let i = 0; i < ring.length - 1; i++) {
|
|
7748
|
+
area2 += ring[i][0] * ring[i + 1][1] - ring[i + 1][0] * ring[i][1];
|
|
7749
|
+
}
|
|
7750
|
+
return Math.abs(area2) * 0.5;
|
|
7751
|
+
};
|
|
7752
|
+
const area1 = getArea(ring1);
|
|
7753
|
+
if (area1 <= 1e-12) return 0;
|
|
7754
|
+
const intersection = import_polygon_clipping.default.intersection(
|
|
7755
|
+
[ring1],
|
|
7756
|
+
[ring2]
|
|
7757
|
+
);
|
|
7758
|
+
if (!intersection.length) return 0;
|
|
7759
|
+
let intersectionArea = 0;
|
|
7760
|
+
for (const polygon3 of intersection) {
|
|
7761
|
+
if (!polygon3.length) continue;
|
|
7762
|
+
intersectionArea += getArea(polygon3[0]);
|
|
7763
|
+
for (let i = 1; i < polygon3.length; i++) {
|
|
7764
|
+
intersectionArea -= getArea(polygon3[i]);
|
|
7765
|
+
}
|
|
7766
|
+
}
|
|
7767
|
+
return Math.max(0, Math.min(100, intersectionArea / area1 * 100));
|
|
7768
|
+
}
|
|
6009
7769
|
|
|
6010
7770
|
// src/utils/updateLine.mjs
|
|
6011
7771
|
import * as THREE4 from "three";
|
|
@@ -12591,15 +14351,12 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
|
|
|
12591
14351
|
) {
|
|
12592
14352
|
let tol = array[k].type == "door frame" ? 0.5 : 0.5;
|
|
12593
14353
|
let boxVecK = getObbLongSideDirection(array[k].obb);
|
|
12594
|
-
let
|
|
12595
|
-
let
|
|
12596
|
-
let f =
|
|
12597
|
-
[obbPointsK[0], obbPointsK[1], obbPointsK[2], obbPointsK[3]],
|
|
12598
|
-
[obbPointsClone[0], obbPointsClone[1], obbPointsClone[2], obbPointsClone[3]]
|
|
12599
|
-
);
|
|
14354
|
+
let polygonK = array[k].path.map((point2) => new THREE8.Vector3(point2[0], point2[1], 0));
|
|
14355
|
+
let polygonJ = cloneData.path.map((point2) => new THREE8.Vector3(point2[0], point2[1], 0));
|
|
14356
|
+
let f = getPolygonIntersectionRatio(polygonK, polygonJ);
|
|
12600
14357
|
if (boxVecJ.length > 0.2 && boxVecK.length > 0.2 || f > 0.3) {
|
|
12601
14358
|
let isPPPP = isParallel(boxVecJ.direction, boxVecK.direction, tol);
|
|
12602
|
-
if ((!isPPPP || !isPPPP.parallel) && f <
|
|
14359
|
+
if ((!isPPPP || !isPPPP.parallel) && f < 80) {
|
|
12603
14360
|
continue;
|
|
12604
14361
|
}
|
|
12605
14362
|
}
|
|
@@ -12642,9 +14399,7 @@ var getMergeMeaning = (allProjectionResults, wallLines, wallVerifyType, averageP
|
|
|
12642
14399
|
cloneData.mapPosition.set(`${array[k].positionArr[0].x},${array[k].positionArr[0].y},${array[k].positionArr[0].z}`, threePointsStr);
|
|
12643
14400
|
}
|
|
12644
14401
|
let tmpPoints = cloneData.points.map((p) => [p.x, p.y]);
|
|
12645
|
-
|
|
12646
|
-
tmpPoints = voxelDownsample2DForContour(tmpPoints, 0.1);
|
|
12647
|
-
}
|
|
14402
|
+
tmpPoints = voxelDownsample2DForContour(tmpPoints, 0.1);
|
|
12648
14403
|
cloneData.path = computeContour(tmpPoints);
|
|
12649
14404
|
const centerData = getCenterAndPointHeight(cloneData.points);
|
|
12650
14405
|
cloneData.h = centerData.h;
|