@vulcan-energy/mcp-helper 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,2096 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
3
27
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
28
 
29
+ // ../node_modules/polygon-clipping/dist/polygon-clipping.umd.js
30
+ var require_polygon_clipping_umd = __commonJS({
31
+ "../node_modules/polygon-clipping/dist/polygon-clipping.umd.js"(exports, module) {
32
+ (function(global, factory) {
33
+ typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.polygonClipping = factory());
34
+ })(exports, function() {
35
+ "use strict";
36
+ function __generator(thisArg, body) {
37
+ var _ = {
38
+ label: 0,
39
+ sent: function() {
40
+ if (t[0] & 1) throw t[1];
41
+ return t[1];
42
+ },
43
+ trys: [],
44
+ ops: []
45
+ }, f, y, t, g;
46
+ return g = {
47
+ next: verb(0),
48
+ "throw": verb(1),
49
+ "return": verb(2)
50
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
51
+ return this;
52
+ }), g;
53
+ function verb(n) {
54
+ return function(v) {
55
+ return step([n, v]);
56
+ };
57
+ }
58
+ function step(op) {
59
+ if (f) throw new TypeError("Generator is already executing.");
60
+ while (_) try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
62
+ if (y = 0, t) op = [op[0] & 2, t.value];
63
+ switch (op[0]) {
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [0];
78
+ continue;
79
+ case 7:
80
+ op = _.ops.pop();
81
+ _.trys.pop();
82
+ continue;
83
+ default:
84
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
85
+ _ = 0;
86
+ continue;
87
+ }
88
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
89
+ _.label = op[1];
90
+ break;
91
+ }
92
+ if (op[0] === 6 && _.label < t[1]) {
93
+ _.label = t[1];
94
+ t = op;
95
+ break;
96
+ }
97
+ if (t && _.label < t[2]) {
98
+ _.label = t[2];
99
+ _.ops.push(op);
100
+ break;
101
+ }
102
+ if (t[2]) _.ops.pop();
103
+ _.trys.pop();
104
+ continue;
105
+ }
106
+ op = body.call(thisArg, _);
107
+ } catch (e) {
108
+ op = [6, e];
109
+ y = 0;
110
+ } finally {
111
+ f = t = 0;
112
+ }
113
+ if (op[0] & 5) throw op[1];
114
+ return {
115
+ value: op[0] ? op[1] : void 0,
116
+ done: true
117
+ };
118
+ }
119
+ }
120
+ var Node = (
121
+ /** @class */
122
+ /* @__PURE__ */ function() {
123
+ function Node2(key, data) {
124
+ this.next = null;
125
+ this.key = key;
126
+ this.data = data;
127
+ this.left = null;
128
+ this.right = null;
129
+ }
130
+ return Node2;
131
+ }()
132
+ );
133
+ function DEFAULT_COMPARE(a, b) {
134
+ return a > b ? 1 : a < b ? -1 : 0;
135
+ }
136
+ function splay(i, t, comparator) {
137
+ var N = new Node(null, null);
138
+ var l = N;
139
+ var r = N;
140
+ while (true) {
141
+ var cmp2 = comparator(i, t.key);
142
+ if (cmp2 < 0) {
143
+ if (t.left === null) break;
144
+ if (comparator(i, t.left.key) < 0) {
145
+ var y = t.left;
146
+ t.left = y.right;
147
+ y.right = t;
148
+ t = y;
149
+ if (t.left === null) break;
150
+ }
151
+ r.left = t;
152
+ r = t;
153
+ t = t.left;
154
+ } else if (cmp2 > 0) {
155
+ if (t.right === null) break;
156
+ if (comparator(i, t.right.key) > 0) {
157
+ var y = t.right;
158
+ t.right = y.left;
159
+ y.left = t;
160
+ t = y;
161
+ if (t.right === null) break;
162
+ }
163
+ l.right = t;
164
+ l = t;
165
+ t = t.right;
166
+ } else break;
167
+ }
168
+ l.right = t.left;
169
+ r.left = t.right;
170
+ t.left = N.right;
171
+ t.right = N.left;
172
+ return t;
173
+ }
174
+ function insert(i, data, t, comparator) {
175
+ var node = new Node(i, data);
176
+ if (t === null) {
177
+ node.left = node.right = null;
178
+ return node;
179
+ }
180
+ t = splay(i, t, comparator);
181
+ var cmp2 = comparator(i, t.key);
182
+ if (cmp2 < 0) {
183
+ node.left = t.left;
184
+ node.right = t;
185
+ t.left = null;
186
+ } else if (cmp2 >= 0) {
187
+ node.right = t.right;
188
+ node.left = t;
189
+ t.right = null;
190
+ }
191
+ return node;
192
+ }
193
+ function split(key, v, comparator) {
194
+ var left = null;
195
+ var right = null;
196
+ if (v) {
197
+ v = splay(key, v, comparator);
198
+ var cmp2 = comparator(v.key, key);
199
+ if (cmp2 === 0) {
200
+ left = v.left;
201
+ right = v.right;
202
+ } else if (cmp2 < 0) {
203
+ right = v.right;
204
+ v.right = null;
205
+ left = v;
206
+ } else {
207
+ left = v.left;
208
+ v.left = null;
209
+ right = v;
210
+ }
211
+ }
212
+ return {
213
+ left,
214
+ right
215
+ };
216
+ }
217
+ function merge(left, right, comparator) {
218
+ if (right === null) return left;
219
+ if (left === null) return right;
220
+ right = splay(left.key, right, comparator);
221
+ right.left = left;
222
+ return right;
223
+ }
224
+ function printRow(root, prefix, isTail, out, printNode) {
225
+ if (root) {
226
+ out("" + prefix + (isTail ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ") + printNode(root) + "\n");
227
+ var indent = prefix + (isTail ? " " : "\u2502 ");
228
+ if (root.left) printRow(root.left, indent, false, out, printNode);
229
+ if (root.right) printRow(root.right, indent, true, out, printNode);
230
+ }
231
+ }
232
+ var Tree = (
233
+ /** @class */
234
+ function() {
235
+ function Tree2(comparator) {
236
+ if (comparator === void 0) {
237
+ comparator = DEFAULT_COMPARE;
238
+ }
239
+ this._root = null;
240
+ this._size = 0;
241
+ this._comparator = comparator;
242
+ }
243
+ Tree2.prototype.insert = function(key, data) {
244
+ this._size++;
245
+ return this._root = insert(key, data, this._root, this._comparator);
246
+ };
247
+ Tree2.prototype.add = function(key, data) {
248
+ var node = new Node(key, data);
249
+ if (this._root === null) {
250
+ node.left = node.right = null;
251
+ this._size++;
252
+ this._root = node;
253
+ }
254
+ var comparator = this._comparator;
255
+ var t = splay(key, this._root, comparator);
256
+ var cmp2 = comparator(key, t.key);
257
+ if (cmp2 === 0) this._root = t;
258
+ else {
259
+ if (cmp2 < 0) {
260
+ node.left = t.left;
261
+ node.right = t;
262
+ t.left = null;
263
+ } else if (cmp2 > 0) {
264
+ node.right = t.right;
265
+ node.left = t;
266
+ t.right = null;
267
+ }
268
+ this._size++;
269
+ this._root = node;
270
+ }
271
+ return this._root;
272
+ };
273
+ Tree2.prototype.remove = function(key) {
274
+ this._root = this._remove(key, this._root, this._comparator);
275
+ };
276
+ Tree2.prototype._remove = function(i, t, comparator) {
277
+ var x;
278
+ if (t === null) return null;
279
+ t = splay(i, t, comparator);
280
+ var cmp2 = comparator(i, t.key);
281
+ if (cmp2 === 0) {
282
+ if (t.left === null) {
283
+ x = t.right;
284
+ } else {
285
+ x = splay(i, t.left, comparator);
286
+ x.right = t.right;
287
+ }
288
+ this._size--;
289
+ return x;
290
+ }
291
+ return t;
292
+ };
293
+ Tree2.prototype.pop = function() {
294
+ var node = this._root;
295
+ if (node) {
296
+ while (node.left) node = node.left;
297
+ this._root = splay(node.key, this._root, this._comparator);
298
+ this._root = this._remove(node.key, this._root, this._comparator);
299
+ return {
300
+ key: node.key,
301
+ data: node.data
302
+ };
303
+ }
304
+ return null;
305
+ };
306
+ Tree2.prototype.findStatic = function(key) {
307
+ var current = this._root;
308
+ var compare = this._comparator;
309
+ while (current) {
310
+ var cmp2 = compare(key, current.key);
311
+ if (cmp2 === 0) return current;
312
+ else if (cmp2 < 0) current = current.left;
313
+ else current = current.right;
314
+ }
315
+ return null;
316
+ };
317
+ Tree2.prototype.find = function(key) {
318
+ if (this._root) {
319
+ this._root = splay(key, this._root, this._comparator);
320
+ if (this._comparator(key, this._root.key) !== 0) return null;
321
+ }
322
+ return this._root;
323
+ };
324
+ Tree2.prototype.contains = function(key) {
325
+ var current = this._root;
326
+ var compare = this._comparator;
327
+ while (current) {
328
+ var cmp2 = compare(key, current.key);
329
+ if (cmp2 === 0) return true;
330
+ else if (cmp2 < 0) current = current.left;
331
+ else current = current.right;
332
+ }
333
+ return false;
334
+ };
335
+ Tree2.prototype.forEach = function(visitor, ctx) {
336
+ var current = this._root;
337
+ var Q = [];
338
+ var done = false;
339
+ while (!done) {
340
+ if (current !== null) {
341
+ Q.push(current);
342
+ current = current.left;
343
+ } else {
344
+ if (Q.length !== 0) {
345
+ current = Q.pop();
346
+ visitor.call(ctx, current);
347
+ current = current.right;
348
+ } else done = true;
349
+ }
350
+ }
351
+ return this;
352
+ };
353
+ Tree2.prototype.range = function(low, high, fn, ctx) {
354
+ var Q = [];
355
+ var compare = this._comparator;
356
+ var node = this._root;
357
+ var cmp2;
358
+ while (Q.length !== 0 || node) {
359
+ if (node) {
360
+ Q.push(node);
361
+ node = node.left;
362
+ } else {
363
+ node = Q.pop();
364
+ cmp2 = compare(node.key, high);
365
+ if (cmp2 > 0) {
366
+ break;
367
+ } else if (compare(node.key, low) >= 0) {
368
+ if (fn.call(ctx, node)) return this;
369
+ }
370
+ node = node.right;
371
+ }
372
+ }
373
+ return this;
374
+ };
375
+ Tree2.prototype.keys = function() {
376
+ var keys = [];
377
+ this.forEach(function(_a) {
378
+ var key = _a.key;
379
+ return keys.push(key);
380
+ });
381
+ return keys;
382
+ };
383
+ Tree2.prototype.values = function() {
384
+ var values = [];
385
+ this.forEach(function(_a) {
386
+ var data = _a.data;
387
+ return values.push(data);
388
+ });
389
+ return values;
390
+ };
391
+ Tree2.prototype.min = function() {
392
+ if (this._root) return this.minNode(this._root).key;
393
+ return null;
394
+ };
395
+ Tree2.prototype.max = function() {
396
+ if (this._root) return this.maxNode(this._root).key;
397
+ return null;
398
+ };
399
+ Tree2.prototype.minNode = function(t) {
400
+ if (t === void 0) {
401
+ t = this._root;
402
+ }
403
+ if (t) while (t.left) t = t.left;
404
+ return t;
405
+ };
406
+ Tree2.prototype.maxNode = function(t) {
407
+ if (t === void 0) {
408
+ t = this._root;
409
+ }
410
+ if (t) while (t.right) t = t.right;
411
+ return t;
412
+ };
413
+ Tree2.prototype.at = function(index2) {
414
+ var current = this._root;
415
+ var done = false;
416
+ var i = 0;
417
+ var Q = [];
418
+ while (!done) {
419
+ if (current) {
420
+ Q.push(current);
421
+ current = current.left;
422
+ } else {
423
+ if (Q.length > 0) {
424
+ current = Q.pop();
425
+ if (i === index2) return current;
426
+ i++;
427
+ current = current.right;
428
+ } else done = true;
429
+ }
430
+ }
431
+ return null;
432
+ };
433
+ Tree2.prototype.next = function(d) {
434
+ var root = this._root;
435
+ var successor = null;
436
+ if (d.right) {
437
+ successor = d.right;
438
+ while (successor.left) successor = successor.left;
439
+ return successor;
440
+ }
441
+ var comparator = this._comparator;
442
+ while (root) {
443
+ var cmp2 = comparator(d.key, root.key);
444
+ if (cmp2 === 0) break;
445
+ else if (cmp2 < 0) {
446
+ successor = root;
447
+ root = root.left;
448
+ } else root = root.right;
449
+ }
450
+ return successor;
451
+ };
452
+ Tree2.prototype.prev = function(d) {
453
+ var root = this._root;
454
+ var predecessor = null;
455
+ if (d.left !== null) {
456
+ predecessor = d.left;
457
+ while (predecessor.right) predecessor = predecessor.right;
458
+ return predecessor;
459
+ }
460
+ var comparator = this._comparator;
461
+ while (root) {
462
+ var cmp2 = comparator(d.key, root.key);
463
+ if (cmp2 === 0) break;
464
+ else if (cmp2 < 0) root = root.left;
465
+ else {
466
+ predecessor = root;
467
+ root = root.right;
468
+ }
469
+ }
470
+ return predecessor;
471
+ };
472
+ Tree2.prototype.clear = function() {
473
+ this._root = null;
474
+ this._size = 0;
475
+ return this;
476
+ };
477
+ Tree2.prototype.toList = function() {
478
+ return toList(this._root);
479
+ };
480
+ Tree2.prototype.load = function(keys, values, presort) {
481
+ if (values === void 0) {
482
+ values = [];
483
+ }
484
+ if (presort === void 0) {
485
+ presort = false;
486
+ }
487
+ var size = keys.length;
488
+ var comparator = this._comparator;
489
+ if (presort) sort(keys, values, 0, size - 1, comparator);
490
+ if (this._root === null) {
491
+ this._root = loadRecursive(keys, values, 0, size);
492
+ this._size = size;
493
+ } else {
494
+ var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);
495
+ size = this._size + size;
496
+ this._root = sortedListToBST({
497
+ head: mergedList
498
+ }, 0, size);
499
+ }
500
+ return this;
501
+ };
502
+ Tree2.prototype.isEmpty = function() {
503
+ return this._root === null;
504
+ };
505
+ Object.defineProperty(Tree2.prototype, "size", {
506
+ get: function() {
507
+ return this._size;
508
+ },
509
+ enumerable: true,
510
+ configurable: true
511
+ });
512
+ Object.defineProperty(Tree2.prototype, "root", {
513
+ get: function() {
514
+ return this._root;
515
+ },
516
+ enumerable: true,
517
+ configurable: true
518
+ });
519
+ Tree2.prototype.toString = function(printNode) {
520
+ if (printNode === void 0) {
521
+ printNode = function(n) {
522
+ return String(n.key);
523
+ };
524
+ }
525
+ var out = [];
526
+ printRow(this._root, "", true, function(v) {
527
+ return out.push(v);
528
+ }, printNode);
529
+ return out.join("");
530
+ };
531
+ Tree2.prototype.update = function(key, newKey, newData) {
532
+ var comparator = this._comparator;
533
+ var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;
534
+ if (comparator(key, newKey) < 0) {
535
+ right = insert(newKey, newData, right, comparator);
536
+ } else {
537
+ left = insert(newKey, newData, left, comparator);
538
+ }
539
+ this._root = merge(left, right, comparator);
540
+ };
541
+ Tree2.prototype.split = function(key) {
542
+ return split(key, this._root, this._comparator);
543
+ };
544
+ Tree2.prototype[Symbol.iterator] = function() {
545
+ var current, Q, done;
546
+ return __generator(this, function(_a) {
547
+ switch (_a.label) {
548
+ case 0:
549
+ current = this._root;
550
+ Q = [];
551
+ done = false;
552
+ _a.label = 1;
553
+ case 1:
554
+ if (!!done) return [3, 6];
555
+ if (!(current !== null)) return [3, 2];
556
+ Q.push(current);
557
+ current = current.left;
558
+ return [3, 5];
559
+ case 2:
560
+ if (!(Q.length !== 0)) return [3, 4];
561
+ current = Q.pop();
562
+ return [4, current];
563
+ case 3:
564
+ _a.sent();
565
+ current = current.right;
566
+ return [3, 5];
567
+ case 4:
568
+ done = true;
569
+ _a.label = 5;
570
+ case 5:
571
+ return [3, 1];
572
+ case 6:
573
+ return [
574
+ 2
575
+ /*return*/
576
+ ];
577
+ }
578
+ });
579
+ };
580
+ return Tree2;
581
+ }()
582
+ );
583
+ function loadRecursive(keys, values, start, end) {
584
+ var size = end - start;
585
+ if (size > 0) {
586
+ var middle = start + Math.floor(size / 2);
587
+ var key = keys[middle];
588
+ var data = values[middle];
589
+ var node = new Node(key, data);
590
+ node.left = loadRecursive(keys, values, start, middle);
591
+ node.right = loadRecursive(keys, values, middle + 1, end);
592
+ return node;
593
+ }
594
+ return null;
595
+ }
596
+ function createList(keys, values) {
597
+ var head = new Node(null, null);
598
+ var p = head;
599
+ for (var i = 0; i < keys.length; i++) {
600
+ p = p.next = new Node(keys[i], values[i]);
601
+ }
602
+ p.next = null;
603
+ return head.next;
604
+ }
605
+ function toList(root) {
606
+ var current = root;
607
+ var Q = [];
608
+ var done = false;
609
+ var head = new Node(null, null);
610
+ var p = head;
611
+ while (!done) {
612
+ if (current) {
613
+ Q.push(current);
614
+ current = current.left;
615
+ } else {
616
+ if (Q.length > 0) {
617
+ current = p = p.next = Q.pop();
618
+ current = current.right;
619
+ } else done = true;
620
+ }
621
+ }
622
+ p.next = null;
623
+ return head.next;
624
+ }
625
+ function sortedListToBST(list, start, end) {
626
+ var size = end - start;
627
+ if (size > 0) {
628
+ var middle = start + Math.floor(size / 2);
629
+ var left = sortedListToBST(list, start, middle);
630
+ var root = list.head;
631
+ root.left = left;
632
+ list.head = list.head.next;
633
+ root.right = sortedListToBST(list, middle + 1, end);
634
+ return root;
635
+ }
636
+ return null;
637
+ }
638
+ function mergeLists(l1, l2, compare) {
639
+ var head = new Node(null, null);
640
+ var p = head;
641
+ var p1 = l1;
642
+ var p2 = l2;
643
+ while (p1 !== null && p2 !== null) {
644
+ if (compare(p1.key, p2.key) < 0) {
645
+ p.next = p1;
646
+ p1 = p1.next;
647
+ } else {
648
+ p.next = p2;
649
+ p2 = p2.next;
650
+ }
651
+ p = p.next;
652
+ }
653
+ if (p1 !== null) {
654
+ p.next = p1;
655
+ } else if (p2 !== null) {
656
+ p.next = p2;
657
+ }
658
+ return head.next;
659
+ }
660
+ function sort(keys, values, left, right, compare) {
661
+ if (left >= right) return;
662
+ var pivot = keys[left + right >> 1];
663
+ var i = left - 1;
664
+ var j = right + 1;
665
+ while (true) {
666
+ do
667
+ i++;
668
+ while (compare(keys[i], pivot) < 0);
669
+ do
670
+ j--;
671
+ while (compare(keys[j], pivot) > 0);
672
+ if (i >= j) break;
673
+ var tmp = keys[i];
674
+ keys[i] = keys[j];
675
+ keys[j] = tmp;
676
+ tmp = values[i];
677
+ values[i] = values[j];
678
+ values[j] = tmp;
679
+ }
680
+ sort(keys, values, left, j, compare);
681
+ sort(keys, values, j + 1, right, compare);
682
+ }
683
+ const isInBbox = (bbox, point) => {
684
+ return bbox.ll.x <= point.x && point.x <= bbox.ur.x && bbox.ll.y <= point.y && point.y <= bbox.ur.y;
685
+ };
686
+ const getBboxOverlap = (b1, b2) => {
687
+ 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;
688
+ const lowerX = b1.ll.x < b2.ll.x ? b2.ll.x : b1.ll.x;
689
+ const upperX = b1.ur.x < b2.ur.x ? b1.ur.x : b2.ur.x;
690
+ const lowerY = b1.ll.y < b2.ll.y ? b2.ll.y : b1.ll.y;
691
+ const upperY = b1.ur.y < b2.ur.y ? b1.ur.y : b2.ur.y;
692
+ return {
693
+ ll: {
694
+ x: lowerX,
695
+ y: lowerY
696
+ },
697
+ ur: {
698
+ x: upperX,
699
+ y: upperY
700
+ }
701
+ };
702
+ };
703
+ let epsilon$1 = Number.EPSILON;
704
+ if (epsilon$1 === void 0) epsilon$1 = Math.pow(2, -52);
705
+ const EPSILON_SQ = epsilon$1 * epsilon$1;
706
+ const cmp = (a, b) => {
707
+ if (-epsilon$1 < a && a < epsilon$1) {
708
+ if (-epsilon$1 < b && b < epsilon$1) {
709
+ return 0;
710
+ }
711
+ }
712
+ const ab = a - b;
713
+ if (ab * ab < EPSILON_SQ * a * b) {
714
+ return 0;
715
+ }
716
+ return a < b ? -1 : 1;
717
+ };
718
+ class PtRounder {
719
+ constructor() {
720
+ this.reset();
721
+ }
722
+ reset() {
723
+ this.xRounder = new CoordRounder();
724
+ this.yRounder = new CoordRounder();
725
+ }
726
+ round(x, y) {
727
+ return {
728
+ x: this.xRounder.round(x),
729
+ y: this.yRounder.round(y)
730
+ };
731
+ }
732
+ }
733
+ class CoordRounder {
734
+ constructor() {
735
+ this.tree = new Tree();
736
+ this.round(0);
737
+ }
738
+ // Note: this can rounds input values backwards or forwards.
739
+ // You might ask, why not restrict this to just rounding
740
+ // forwards? Wouldn't that allow left endpoints to always
741
+ // remain left endpoints during splitting (never change to
742
+ // right). No - it wouldn't, because we snap intersections
743
+ // to endpoints (to establish independence from the segment
744
+ // angle for t-intersections).
745
+ round(coord) {
746
+ const node = this.tree.add(coord);
747
+ const prevNode = this.tree.prev(node);
748
+ if (prevNode !== null && cmp(node.key, prevNode.key) === 0) {
749
+ this.tree.remove(coord);
750
+ return prevNode.key;
751
+ }
752
+ const nextNode = this.tree.next(node);
753
+ if (nextNode !== null && cmp(node.key, nextNode.key) === 0) {
754
+ this.tree.remove(coord);
755
+ return nextNode.key;
756
+ }
757
+ return coord;
758
+ }
759
+ }
760
+ const rounder = new PtRounder();
761
+ const epsilon = 11102230246251565e-32;
762
+ const splitter = 134217729;
763
+ const resulterrbound = (3 + 8 * epsilon) * epsilon;
764
+ function sum(elen, e, flen, f, h) {
765
+ let Q, Qnew, hh, bvirt;
766
+ let enow = e[0];
767
+ let fnow = f[0];
768
+ let eindex = 0;
769
+ let findex = 0;
770
+ if (fnow > enow === fnow > -enow) {
771
+ Q = enow;
772
+ enow = e[++eindex];
773
+ } else {
774
+ Q = fnow;
775
+ fnow = f[++findex];
776
+ }
777
+ let hindex = 0;
778
+ if (eindex < elen && findex < flen) {
779
+ if (fnow > enow === fnow > -enow) {
780
+ Qnew = enow + Q;
781
+ hh = Q - (Qnew - enow);
782
+ enow = e[++eindex];
783
+ } else {
784
+ Qnew = fnow + Q;
785
+ hh = Q - (Qnew - fnow);
786
+ fnow = f[++findex];
787
+ }
788
+ Q = Qnew;
789
+ if (hh !== 0) {
790
+ h[hindex++] = hh;
791
+ }
792
+ while (eindex < elen && findex < flen) {
793
+ if (fnow > enow === fnow > -enow) {
794
+ Qnew = Q + enow;
795
+ bvirt = Qnew - Q;
796
+ hh = Q - (Qnew - bvirt) + (enow - bvirt);
797
+ enow = e[++eindex];
798
+ } else {
799
+ Qnew = Q + fnow;
800
+ bvirt = Qnew - Q;
801
+ hh = Q - (Qnew - bvirt) + (fnow - bvirt);
802
+ fnow = f[++findex];
803
+ }
804
+ Q = Qnew;
805
+ if (hh !== 0) {
806
+ h[hindex++] = hh;
807
+ }
808
+ }
809
+ }
810
+ while (eindex < elen) {
811
+ Qnew = Q + enow;
812
+ bvirt = Qnew - Q;
813
+ hh = Q - (Qnew - bvirt) + (enow - bvirt);
814
+ enow = e[++eindex];
815
+ Q = Qnew;
816
+ if (hh !== 0) {
817
+ h[hindex++] = hh;
818
+ }
819
+ }
820
+ while (findex < flen) {
821
+ Qnew = Q + fnow;
822
+ bvirt = Qnew - Q;
823
+ hh = Q - (Qnew - bvirt) + (fnow - bvirt);
824
+ fnow = f[++findex];
825
+ Q = Qnew;
826
+ if (hh !== 0) {
827
+ h[hindex++] = hh;
828
+ }
829
+ }
830
+ if (Q !== 0 || hindex === 0) {
831
+ h[hindex++] = Q;
832
+ }
833
+ return hindex;
834
+ }
835
+ function estimate(elen, e) {
836
+ let Q = e[0];
837
+ for (let i = 1; i < elen; i++) Q += e[i];
838
+ return Q;
839
+ }
840
+ function vec(n) {
841
+ return new Float64Array(n);
842
+ }
843
+ const ccwerrboundA = (3 + 16 * epsilon) * epsilon;
844
+ const ccwerrboundB = (2 + 12 * epsilon) * epsilon;
845
+ const ccwerrboundC = (9 + 64 * epsilon) * epsilon * epsilon;
846
+ const B = vec(4);
847
+ const C1 = vec(8);
848
+ const C2 = vec(12);
849
+ const D = vec(16);
850
+ const u = vec(4);
851
+ function orient2dadapt(ax, ay, bx, by, cx, cy, detsum) {
852
+ let acxtail, acytail, bcxtail, bcytail;
853
+ let bvirt, c, ahi, alo, bhi, blo, _i, _j, _0, s1, s0, t1, t0, u3;
854
+ const acx = ax - cx;
855
+ const bcx = bx - cx;
856
+ const acy = ay - cy;
857
+ const bcy = by - cy;
858
+ s1 = acx * bcy;
859
+ c = splitter * acx;
860
+ ahi = c - (c - acx);
861
+ alo = acx - ahi;
862
+ c = splitter * bcy;
863
+ bhi = c - (c - bcy);
864
+ blo = bcy - bhi;
865
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
866
+ t1 = acy * bcx;
867
+ c = splitter * acy;
868
+ ahi = c - (c - acy);
869
+ alo = acy - ahi;
870
+ c = splitter * bcx;
871
+ bhi = c - (c - bcx);
872
+ blo = bcx - bhi;
873
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
874
+ _i = s0 - t0;
875
+ bvirt = s0 - _i;
876
+ B[0] = s0 - (_i + bvirt) + (bvirt - t0);
877
+ _j = s1 + _i;
878
+ bvirt = _j - s1;
879
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
880
+ _i = _0 - t1;
881
+ bvirt = _0 - _i;
882
+ B[1] = _0 - (_i + bvirt) + (bvirt - t1);
883
+ u3 = _j + _i;
884
+ bvirt = u3 - _j;
885
+ B[2] = _j - (u3 - bvirt) + (_i - bvirt);
886
+ B[3] = u3;
887
+ let det = estimate(4, B);
888
+ let errbound = ccwerrboundB * detsum;
889
+ if (det >= errbound || -det >= errbound) {
890
+ return det;
891
+ }
892
+ bvirt = ax - acx;
893
+ acxtail = ax - (acx + bvirt) + (bvirt - cx);
894
+ bvirt = bx - bcx;
895
+ bcxtail = bx - (bcx + bvirt) + (bvirt - cx);
896
+ bvirt = ay - acy;
897
+ acytail = ay - (acy + bvirt) + (bvirt - cy);
898
+ bvirt = by - bcy;
899
+ bcytail = by - (bcy + bvirt) + (bvirt - cy);
900
+ if (acxtail === 0 && acytail === 0 && bcxtail === 0 && bcytail === 0) {
901
+ return det;
902
+ }
903
+ errbound = ccwerrboundC * detsum + resulterrbound * Math.abs(det);
904
+ det += acx * bcytail + bcy * acxtail - (acy * bcxtail + bcx * acytail);
905
+ if (det >= errbound || -det >= errbound) return det;
906
+ s1 = acxtail * bcy;
907
+ c = splitter * acxtail;
908
+ ahi = c - (c - acxtail);
909
+ alo = acxtail - ahi;
910
+ c = splitter * bcy;
911
+ bhi = c - (c - bcy);
912
+ blo = bcy - bhi;
913
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
914
+ t1 = acytail * bcx;
915
+ c = splitter * acytail;
916
+ ahi = c - (c - acytail);
917
+ alo = acytail - ahi;
918
+ c = splitter * bcx;
919
+ bhi = c - (c - bcx);
920
+ blo = bcx - bhi;
921
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
922
+ _i = s0 - t0;
923
+ bvirt = s0 - _i;
924
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
925
+ _j = s1 + _i;
926
+ bvirt = _j - s1;
927
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
928
+ _i = _0 - t1;
929
+ bvirt = _0 - _i;
930
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
931
+ u3 = _j + _i;
932
+ bvirt = u3 - _j;
933
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
934
+ u[3] = u3;
935
+ const C1len = sum(4, B, 4, u, C1);
936
+ s1 = acx * bcytail;
937
+ c = splitter * acx;
938
+ ahi = c - (c - acx);
939
+ alo = acx - ahi;
940
+ c = splitter * bcytail;
941
+ bhi = c - (c - bcytail);
942
+ blo = bcytail - bhi;
943
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
944
+ t1 = acy * bcxtail;
945
+ c = splitter * acy;
946
+ ahi = c - (c - acy);
947
+ alo = acy - ahi;
948
+ c = splitter * bcxtail;
949
+ bhi = c - (c - bcxtail);
950
+ blo = bcxtail - bhi;
951
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
952
+ _i = s0 - t0;
953
+ bvirt = s0 - _i;
954
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
955
+ _j = s1 + _i;
956
+ bvirt = _j - s1;
957
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
958
+ _i = _0 - t1;
959
+ bvirt = _0 - _i;
960
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
961
+ u3 = _j + _i;
962
+ bvirt = u3 - _j;
963
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
964
+ u[3] = u3;
965
+ const C2len = sum(C1len, C1, 4, u, C2);
966
+ s1 = acxtail * bcytail;
967
+ c = splitter * acxtail;
968
+ ahi = c - (c - acxtail);
969
+ alo = acxtail - ahi;
970
+ c = splitter * bcytail;
971
+ bhi = c - (c - bcytail);
972
+ blo = bcytail - bhi;
973
+ s0 = alo * blo - (s1 - ahi * bhi - alo * bhi - ahi * blo);
974
+ t1 = acytail * bcxtail;
975
+ c = splitter * acytail;
976
+ ahi = c - (c - acytail);
977
+ alo = acytail - ahi;
978
+ c = splitter * bcxtail;
979
+ bhi = c - (c - bcxtail);
980
+ blo = bcxtail - bhi;
981
+ t0 = alo * blo - (t1 - ahi * bhi - alo * bhi - ahi * blo);
982
+ _i = s0 - t0;
983
+ bvirt = s0 - _i;
984
+ u[0] = s0 - (_i + bvirt) + (bvirt - t0);
985
+ _j = s1 + _i;
986
+ bvirt = _j - s1;
987
+ _0 = s1 - (_j - bvirt) + (_i - bvirt);
988
+ _i = _0 - t1;
989
+ bvirt = _0 - _i;
990
+ u[1] = _0 - (_i + bvirt) + (bvirt - t1);
991
+ u3 = _j + _i;
992
+ bvirt = u3 - _j;
993
+ u[2] = _j - (u3 - bvirt) + (_i - bvirt);
994
+ u[3] = u3;
995
+ const Dlen = sum(C2len, C2, 4, u, D);
996
+ return D[Dlen - 1];
997
+ }
998
+ function orient2d(ax, ay, bx, by, cx, cy) {
999
+ const detleft = (ay - cy) * (bx - cx);
1000
+ const detright = (ax - cx) * (by - cy);
1001
+ const det = detleft - detright;
1002
+ const detsum = Math.abs(detleft + detright);
1003
+ if (Math.abs(det) >= ccwerrboundA * detsum) return det;
1004
+ return -orient2dadapt(ax, ay, bx, by, cx, cy, detsum);
1005
+ }
1006
+ const crossProduct = (a, b) => a.x * b.y - a.y * b.x;
1007
+ const dotProduct = (a, b) => a.x * b.x + a.y * b.y;
1008
+ const compareVectorAngles = (basePt, endPt1, endPt2) => {
1009
+ const res = orient2d(basePt.x, basePt.y, endPt1.x, endPt1.y, endPt2.x, endPt2.y);
1010
+ if (res > 0) return -1;
1011
+ if (res < 0) return 1;
1012
+ return 0;
1013
+ };
1014
+ const length = (v) => Math.sqrt(dotProduct(v, v));
1015
+ const sineOfAngle = (pShared, pBase, pAngle) => {
1016
+ const vBase = {
1017
+ x: pBase.x - pShared.x,
1018
+ y: pBase.y - pShared.y
1019
+ };
1020
+ const vAngle = {
1021
+ x: pAngle.x - pShared.x,
1022
+ y: pAngle.y - pShared.y
1023
+ };
1024
+ return crossProduct(vAngle, vBase) / length(vAngle) / length(vBase);
1025
+ };
1026
+ const cosineOfAngle = (pShared, pBase, pAngle) => {
1027
+ const vBase = {
1028
+ x: pBase.x - pShared.x,
1029
+ y: pBase.y - pShared.y
1030
+ };
1031
+ const vAngle = {
1032
+ x: pAngle.x - pShared.x,
1033
+ y: pAngle.y - pShared.y
1034
+ };
1035
+ return dotProduct(vAngle, vBase) / length(vAngle) / length(vBase);
1036
+ };
1037
+ const horizontalIntersection = (pt, v, y) => {
1038
+ if (v.y === 0) return null;
1039
+ return {
1040
+ x: pt.x + v.x / v.y * (y - pt.y),
1041
+ y
1042
+ };
1043
+ };
1044
+ const verticalIntersection = (pt, v, x) => {
1045
+ if (v.x === 0) return null;
1046
+ return {
1047
+ x,
1048
+ y: pt.y + v.y / v.x * (x - pt.x)
1049
+ };
1050
+ };
1051
+ const intersection$1 = (pt1, v1, pt2, v2) => {
1052
+ if (v1.x === 0) return verticalIntersection(pt2, v2, pt1.x);
1053
+ if (v2.x === 0) return verticalIntersection(pt1, v1, pt2.x);
1054
+ if (v1.y === 0) return horizontalIntersection(pt2, v2, pt1.y);
1055
+ if (v2.y === 0) return horizontalIntersection(pt1, v1, pt2.y);
1056
+ const kross = crossProduct(v1, v2);
1057
+ if (kross == 0) return null;
1058
+ const ve = {
1059
+ x: pt2.x - pt1.x,
1060
+ y: pt2.y - pt1.y
1061
+ };
1062
+ const d1 = crossProduct(ve, v1) / kross;
1063
+ const d2 = crossProduct(ve, v2) / kross;
1064
+ const x1 = pt1.x + d2 * v1.x, x2 = pt2.x + d1 * v2.x;
1065
+ const y1 = pt1.y + d2 * v1.y, y2 = pt2.y + d1 * v2.y;
1066
+ const x = (x1 + x2) / 2;
1067
+ const y = (y1 + y2) / 2;
1068
+ return {
1069
+ x,
1070
+ y
1071
+ };
1072
+ };
1073
+ class SweepEvent {
1074
+ // for ordering sweep events in the sweep event queue
1075
+ static compare(a, b) {
1076
+ const ptCmp = SweepEvent.comparePoints(a.point, b.point);
1077
+ if (ptCmp !== 0) return ptCmp;
1078
+ if (a.point !== b.point) a.link(b);
1079
+ if (a.isLeft !== b.isLeft) return a.isLeft ? 1 : -1;
1080
+ return Segment.compare(a.segment, b.segment);
1081
+ }
1082
+ // for ordering points in sweep line order
1083
+ static comparePoints(aPt, bPt) {
1084
+ if (aPt.x < bPt.x) return -1;
1085
+ if (aPt.x > bPt.x) return 1;
1086
+ if (aPt.y < bPt.y) return -1;
1087
+ if (aPt.y > bPt.y) return 1;
1088
+ return 0;
1089
+ }
1090
+ // Warning: 'point' input will be modified and re-used (for performance)
1091
+ constructor(point, isLeft) {
1092
+ if (point.events === void 0) point.events = [this];
1093
+ else point.events.push(this);
1094
+ this.point = point;
1095
+ this.isLeft = isLeft;
1096
+ }
1097
+ link(other) {
1098
+ if (other.point === this.point) {
1099
+ throw new Error("Tried to link already linked events");
1100
+ }
1101
+ const otherEvents = other.point.events;
1102
+ for (let i = 0, iMax = otherEvents.length; i < iMax; i++) {
1103
+ const evt = otherEvents[i];
1104
+ this.point.events.push(evt);
1105
+ evt.point = this.point;
1106
+ }
1107
+ this.checkForConsuming();
1108
+ }
1109
+ /* Do a pass over our linked events and check to see if any pair
1110
+ * of segments match, and should be consumed. */
1111
+ checkForConsuming() {
1112
+ const numEvents = this.point.events.length;
1113
+ for (let i = 0; i < numEvents; i++) {
1114
+ const evt1 = this.point.events[i];
1115
+ if (evt1.segment.consumedBy !== void 0) continue;
1116
+ for (let j = i + 1; j < numEvents; j++) {
1117
+ const evt2 = this.point.events[j];
1118
+ if (evt2.consumedBy !== void 0) continue;
1119
+ if (evt1.otherSE.point.events !== evt2.otherSE.point.events) continue;
1120
+ evt1.segment.consume(evt2.segment);
1121
+ }
1122
+ }
1123
+ }
1124
+ getAvailableLinkedEvents() {
1125
+ const events = [];
1126
+ for (let i = 0, iMax = this.point.events.length; i < iMax; i++) {
1127
+ const evt = this.point.events[i];
1128
+ if (evt !== this && !evt.segment.ringOut && evt.segment.isInResult()) {
1129
+ events.push(evt);
1130
+ }
1131
+ }
1132
+ return events;
1133
+ }
1134
+ /**
1135
+ * Returns a comparator function for sorting linked events that will
1136
+ * favor the event that will give us the smallest left-side angle.
1137
+ * All ring construction starts as low as possible heading to the right,
1138
+ * so by always turning left as sharp as possible we'll get polygons
1139
+ * without uncessary loops & holes.
1140
+ *
1141
+ * The comparator function has a compute cache such that it avoids
1142
+ * re-computing already-computed values.
1143
+ */
1144
+ getLeftmostComparator(baseEvent) {
1145
+ const cache = /* @__PURE__ */ new Map();
1146
+ const fillCache = (linkedEvent) => {
1147
+ const nextEvent = linkedEvent.otherSE;
1148
+ cache.set(linkedEvent, {
1149
+ sine: sineOfAngle(this.point, baseEvent.point, nextEvent.point),
1150
+ cosine: cosineOfAngle(this.point, baseEvent.point, nextEvent.point)
1151
+ });
1152
+ };
1153
+ return (a, b) => {
1154
+ if (!cache.has(a)) fillCache(a);
1155
+ if (!cache.has(b)) fillCache(b);
1156
+ const {
1157
+ sine: asine,
1158
+ cosine: acosine
1159
+ } = cache.get(a);
1160
+ const {
1161
+ sine: bsine,
1162
+ cosine: bcosine
1163
+ } = cache.get(b);
1164
+ if (asine >= 0 && bsine >= 0) {
1165
+ if (acosine < bcosine) return 1;
1166
+ if (acosine > bcosine) return -1;
1167
+ return 0;
1168
+ }
1169
+ if (asine < 0 && bsine < 0) {
1170
+ if (acosine < bcosine) return -1;
1171
+ if (acosine > bcosine) return 1;
1172
+ return 0;
1173
+ }
1174
+ if (bsine < asine) return -1;
1175
+ if (bsine > asine) return 1;
1176
+ return 0;
1177
+ };
1178
+ }
1179
+ }
1180
+ let segmentId = 0;
1181
+ class Segment {
1182
+ /* This compare() function is for ordering segments in the sweep
1183
+ * line tree, and does so according to the following criteria:
1184
+ *
1185
+ * Consider the vertical line that lies an infinestimal step to the
1186
+ * right of the right-more of the two left endpoints of the input
1187
+ * segments. Imagine slowly moving a point up from negative infinity
1188
+ * in the increasing y direction. Which of the two segments will that
1189
+ * point intersect first? That segment comes 'before' the other one.
1190
+ *
1191
+ * If neither segment would be intersected by such a line, (if one
1192
+ * or more of the segments are vertical) then the line to be considered
1193
+ * is directly on the right-more of the two left inputs.
1194
+ */
1195
+ static compare(a, b) {
1196
+ const alx = a.leftSE.point.x;
1197
+ const blx = b.leftSE.point.x;
1198
+ const arx = a.rightSE.point.x;
1199
+ const brx = b.rightSE.point.x;
1200
+ if (brx < alx) return 1;
1201
+ if (arx < blx) return -1;
1202
+ const aly = a.leftSE.point.y;
1203
+ const bly = b.leftSE.point.y;
1204
+ const ary = a.rightSE.point.y;
1205
+ const bry = b.rightSE.point.y;
1206
+ if (alx < blx) {
1207
+ if (bly < aly && bly < ary) return 1;
1208
+ if (bly > aly && bly > ary) return -1;
1209
+ const aCmpBLeft = a.comparePoint(b.leftSE.point);
1210
+ if (aCmpBLeft < 0) return 1;
1211
+ if (aCmpBLeft > 0) return -1;
1212
+ const bCmpARight = b.comparePoint(a.rightSE.point);
1213
+ if (bCmpARight !== 0) return bCmpARight;
1214
+ return -1;
1215
+ }
1216
+ if (alx > blx) {
1217
+ if (aly < bly && aly < bry) return -1;
1218
+ if (aly > bly && aly > bry) return 1;
1219
+ const bCmpALeft = b.comparePoint(a.leftSE.point);
1220
+ if (bCmpALeft !== 0) return bCmpALeft;
1221
+ const aCmpBRight = a.comparePoint(b.rightSE.point);
1222
+ if (aCmpBRight < 0) return 1;
1223
+ if (aCmpBRight > 0) return -1;
1224
+ return 1;
1225
+ }
1226
+ if (aly < bly) return -1;
1227
+ if (aly > bly) return 1;
1228
+ if (arx < brx) {
1229
+ const bCmpARight = b.comparePoint(a.rightSE.point);
1230
+ if (bCmpARight !== 0) return bCmpARight;
1231
+ }
1232
+ if (arx > brx) {
1233
+ const aCmpBRight = a.comparePoint(b.rightSE.point);
1234
+ if (aCmpBRight < 0) return 1;
1235
+ if (aCmpBRight > 0) return -1;
1236
+ }
1237
+ if (arx !== brx) {
1238
+ const ay = ary - aly;
1239
+ const ax = arx - alx;
1240
+ const by = bry - bly;
1241
+ const bx = brx - blx;
1242
+ if (ay > ax && by < bx) return 1;
1243
+ if (ay < ax && by > bx) return -1;
1244
+ }
1245
+ if (arx > brx) return 1;
1246
+ if (arx < brx) return -1;
1247
+ if (ary < bry) return -1;
1248
+ if (ary > bry) return 1;
1249
+ if (a.id < b.id) return -1;
1250
+ if (a.id > b.id) return 1;
1251
+ return 0;
1252
+ }
1253
+ /* Warning: a reference to ringWindings input will be stored,
1254
+ * and possibly will be later modified */
1255
+ constructor(leftSE, rightSE, rings, windings) {
1256
+ this.id = ++segmentId;
1257
+ this.leftSE = leftSE;
1258
+ leftSE.segment = this;
1259
+ leftSE.otherSE = rightSE;
1260
+ this.rightSE = rightSE;
1261
+ rightSE.segment = this;
1262
+ rightSE.otherSE = leftSE;
1263
+ this.rings = rings;
1264
+ this.windings = windings;
1265
+ }
1266
+ static fromRing(pt1, pt2, ring) {
1267
+ let leftPt, rightPt, winding;
1268
+ const cmpPts = SweepEvent.comparePoints(pt1, pt2);
1269
+ if (cmpPts < 0) {
1270
+ leftPt = pt1;
1271
+ rightPt = pt2;
1272
+ winding = 1;
1273
+ } else if (cmpPts > 0) {
1274
+ leftPt = pt2;
1275
+ rightPt = pt1;
1276
+ winding = -1;
1277
+ } else throw new Error(`Tried to create degenerate segment at [${pt1.x}, ${pt1.y}]`);
1278
+ const leftSE = new SweepEvent(leftPt, true);
1279
+ const rightSE = new SweepEvent(rightPt, false);
1280
+ return new Segment(leftSE, rightSE, [ring], [winding]);
1281
+ }
1282
+ /* When a segment is split, the rightSE is replaced with a new sweep event */
1283
+ replaceRightSE(newRightSE) {
1284
+ this.rightSE = newRightSE;
1285
+ this.rightSE.segment = this;
1286
+ this.rightSE.otherSE = this.leftSE;
1287
+ this.leftSE.otherSE = this.rightSE;
1288
+ }
1289
+ bbox() {
1290
+ const y1 = this.leftSE.point.y;
1291
+ const y2 = this.rightSE.point.y;
1292
+ return {
1293
+ ll: {
1294
+ x: this.leftSE.point.x,
1295
+ y: y1 < y2 ? y1 : y2
1296
+ },
1297
+ ur: {
1298
+ x: this.rightSE.point.x,
1299
+ y: y1 > y2 ? y1 : y2
1300
+ }
1301
+ };
1302
+ }
1303
+ /* A vector from the left point to the right */
1304
+ vector() {
1305
+ return {
1306
+ x: this.rightSE.point.x - this.leftSE.point.x,
1307
+ y: this.rightSE.point.y - this.leftSE.point.y
1308
+ };
1309
+ }
1310
+ isAnEndpoint(pt) {
1311
+ 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;
1312
+ }
1313
+ /* Compare this segment with a point.
1314
+ *
1315
+ * A point P is considered to be colinear to a segment if there
1316
+ * exists a distance D such that if we travel along the segment
1317
+ * from one * endpoint towards the other a distance D, we find
1318
+ * ourselves at point P.
1319
+ *
1320
+ * Return value indicates:
1321
+ *
1322
+ * 1: point lies above the segment (to the left of vertical)
1323
+ * 0: point is colinear to segment
1324
+ * -1: point lies below the segment (to the right of vertical)
1325
+ */
1326
+ comparePoint(point) {
1327
+ if (this.isAnEndpoint(point)) return 0;
1328
+ const lPt = this.leftSE.point;
1329
+ const rPt = this.rightSE.point;
1330
+ const v = this.vector();
1331
+ if (lPt.x === rPt.x) {
1332
+ if (point.x === lPt.x) return 0;
1333
+ return point.x < lPt.x ? 1 : -1;
1334
+ }
1335
+ const yDist = (point.y - lPt.y) / v.y;
1336
+ const xFromYDist = lPt.x + yDist * v.x;
1337
+ if (point.x === xFromYDist) return 0;
1338
+ const xDist = (point.x - lPt.x) / v.x;
1339
+ const yFromXDist = lPt.y + xDist * v.y;
1340
+ if (point.y === yFromXDist) return 0;
1341
+ return point.y < yFromXDist ? -1 : 1;
1342
+ }
1343
+ /**
1344
+ * Given another segment, returns the first non-trivial intersection
1345
+ * between the two segments (in terms of sweep line ordering), if it exists.
1346
+ *
1347
+ * A 'non-trivial' intersection is one that will cause one or both of the
1348
+ * segments to be split(). As such, 'trivial' vs. 'non-trivial' intersection:
1349
+ *
1350
+ * * endpoint of segA with endpoint of segB --> trivial
1351
+ * * endpoint of segA with point along segB --> non-trivial
1352
+ * * endpoint of segB with point along segA --> non-trivial
1353
+ * * point along segA with point along segB --> non-trivial
1354
+ *
1355
+ * If no non-trivial intersection exists, return null
1356
+ * Else, return null.
1357
+ */
1358
+ getIntersection(other) {
1359
+ const tBbox = this.bbox();
1360
+ const oBbox = other.bbox();
1361
+ const bboxOverlap = getBboxOverlap(tBbox, oBbox);
1362
+ if (bboxOverlap === null) return null;
1363
+ const tlp = this.leftSE.point;
1364
+ const trp = this.rightSE.point;
1365
+ const olp = other.leftSE.point;
1366
+ const orp = other.rightSE.point;
1367
+ const touchesOtherLSE = isInBbox(tBbox, olp) && this.comparePoint(olp) === 0;
1368
+ const touchesThisLSE = isInBbox(oBbox, tlp) && other.comparePoint(tlp) === 0;
1369
+ const touchesOtherRSE = isInBbox(tBbox, orp) && this.comparePoint(orp) === 0;
1370
+ const touchesThisRSE = isInBbox(oBbox, trp) && other.comparePoint(trp) === 0;
1371
+ if (touchesThisLSE && touchesOtherLSE) {
1372
+ if (touchesThisRSE && !touchesOtherRSE) return trp;
1373
+ if (!touchesThisRSE && touchesOtherRSE) return orp;
1374
+ return null;
1375
+ }
1376
+ if (touchesThisLSE) {
1377
+ if (touchesOtherRSE) {
1378
+ if (tlp.x === orp.x && tlp.y === orp.y) return null;
1379
+ }
1380
+ return tlp;
1381
+ }
1382
+ if (touchesOtherLSE) {
1383
+ if (touchesThisRSE) {
1384
+ if (trp.x === olp.x && trp.y === olp.y) return null;
1385
+ }
1386
+ return olp;
1387
+ }
1388
+ if (touchesThisRSE && touchesOtherRSE) return null;
1389
+ if (touchesThisRSE) return trp;
1390
+ if (touchesOtherRSE) return orp;
1391
+ const pt = intersection$1(tlp, this.vector(), olp, other.vector());
1392
+ if (pt === null) return null;
1393
+ if (!isInBbox(bboxOverlap, pt)) return null;
1394
+ return rounder.round(pt.x, pt.y);
1395
+ }
1396
+ /**
1397
+ * Split the given segment into multiple segments on the given points.
1398
+ * * Each existing segment will retain its leftSE and a new rightSE will be
1399
+ * generated for it.
1400
+ * * A new segment will be generated which will adopt the original segment's
1401
+ * rightSE, and a new leftSE will be generated for it.
1402
+ * * If there are more than two points given to split on, new segments
1403
+ * in the middle will be generated with new leftSE and rightSE's.
1404
+ * * An array of the newly generated SweepEvents will be returned.
1405
+ *
1406
+ * Warning: input array of points is modified
1407
+ */
1408
+ split(point) {
1409
+ const newEvents = [];
1410
+ const alreadyLinked = point.events !== void 0;
1411
+ const newLeftSE = new SweepEvent(point, true);
1412
+ const newRightSE = new SweepEvent(point, false);
1413
+ const oldRightSE = this.rightSE;
1414
+ this.replaceRightSE(newRightSE);
1415
+ newEvents.push(newRightSE);
1416
+ newEvents.push(newLeftSE);
1417
+ const newSeg = new Segment(newLeftSE, oldRightSE, this.rings.slice(), this.windings.slice());
1418
+ if (SweepEvent.comparePoints(newSeg.leftSE.point, newSeg.rightSE.point) > 0) {
1419
+ newSeg.swapEvents();
1420
+ }
1421
+ if (SweepEvent.comparePoints(this.leftSE.point, this.rightSE.point) > 0) {
1422
+ this.swapEvents();
1423
+ }
1424
+ if (alreadyLinked) {
1425
+ newLeftSE.checkForConsuming();
1426
+ newRightSE.checkForConsuming();
1427
+ }
1428
+ return newEvents;
1429
+ }
1430
+ /* Swap which event is left and right */
1431
+ swapEvents() {
1432
+ const tmpEvt = this.rightSE;
1433
+ this.rightSE = this.leftSE;
1434
+ this.leftSE = tmpEvt;
1435
+ this.leftSE.isLeft = true;
1436
+ this.rightSE.isLeft = false;
1437
+ for (let i = 0, iMax = this.windings.length; i < iMax; i++) {
1438
+ this.windings[i] *= -1;
1439
+ }
1440
+ }
1441
+ /* Consume another segment. We take their rings under our wing
1442
+ * and mark them as consumed. Use for perfectly overlapping segments */
1443
+ consume(other) {
1444
+ let consumer = this;
1445
+ let consumee = other;
1446
+ while (consumer.consumedBy) consumer = consumer.consumedBy;
1447
+ while (consumee.consumedBy) consumee = consumee.consumedBy;
1448
+ const cmp2 = Segment.compare(consumer, consumee);
1449
+ if (cmp2 === 0) return;
1450
+ if (cmp2 > 0) {
1451
+ const tmp = consumer;
1452
+ consumer = consumee;
1453
+ consumee = tmp;
1454
+ }
1455
+ if (consumer.prev === consumee) {
1456
+ const tmp = consumer;
1457
+ consumer = consumee;
1458
+ consumee = tmp;
1459
+ }
1460
+ for (let i = 0, iMax = consumee.rings.length; i < iMax; i++) {
1461
+ const ring = consumee.rings[i];
1462
+ const winding = consumee.windings[i];
1463
+ const index2 = consumer.rings.indexOf(ring);
1464
+ if (index2 === -1) {
1465
+ consumer.rings.push(ring);
1466
+ consumer.windings.push(winding);
1467
+ } else consumer.windings[index2] += winding;
1468
+ }
1469
+ consumee.rings = null;
1470
+ consumee.windings = null;
1471
+ consumee.consumedBy = consumer;
1472
+ consumee.leftSE.consumedBy = consumer.leftSE;
1473
+ consumee.rightSE.consumedBy = consumer.rightSE;
1474
+ }
1475
+ /* The first segment previous segment chain that is in the result */
1476
+ prevInResult() {
1477
+ if (this._prevInResult !== void 0) return this._prevInResult;
1478
+ if (!this.prev) this._prevInResult = null;
1479
+ else if (this.prev.isInResult()) this._prevInResult = this.prev;
1480
+ else this._prevInResult = this.prev.prevInResult();
1481
+ return this._prevInResult;
1482
+ }
1483
+ beforeState() {
1484
+ if (this._beforeState !== void 0) return this._beforeState;
1485
+ if (!this.prev) this._beforeState = {
1486
+ rings: [],
1487
+ windings: [],
1488
+ multiPolys: []
1489
+ };
1490
+ else {
1491
+ const seg = this.prev.consumedBy || this.prev;
1492
+ this._beforeState = seg.afterState();
1493
+ }
1494
+ return this._beforeState;
1495
+ }
1496
+ afterState() {
1497
+ if (this._afterState !== void 0) return this._afterState;
1498
+ const beforeState = this.beforeState();
1499
+ this._afterState = {
1500
+ rings: beforeState.rings.slice(0),
1501
+ windings: beforeState.windings.slice(0),
1502
+ multiPolys: []
1503
+ };
1504
+ const ringsAfter = this._afterState.rings;
1505
+ const windingsAfter = this._afterState.windings;
1506
+ const mpsAfter = this._afterState.multiPolys;
1507
+ for (let i = 0, iMax = this.rings.length; i < iMax; i++) {
1508
+ const ring = this.rings[i];
1509
+ const winding = this.windings[i];
1510
+ const index2 = ringsAfter.indexOf(ring);
1511
+ if (index2 === -1) {
1512
+ ringsAfter.push(ring);
1513
+ windingsAfter.push(winding);
1514
+ } else windingsAfter[index2] += winding;
1515
+ }
1516
+ const polysAfter = [];
1517
+ const polysExclude = [];
1518
+ for (let i = 0, iMax = ringsAfter.length; i < iMax; i++) {
1519
+ if (windingsAfter[i] === 0) continue;
1520
+ const ring = ringsAfter[i];
1521
+ const poly = ring.poly;
1522
+ if (polysExclude.indexOf(poly) !== -1) continue;
1523
+ if (ring.isExterior) polysAfter.push(poly);
1524
+ else {
1525
+ if (polysExclude.indexOf(poly) === -1) polysExclude.push(poly);
1526
+ const index2 = polysAfter.indexOf(ring.poly);
1527
+ if (index2 !== -1) polysAfter.splice(index2, 1);
1528
+ }
1529
+ }
1530
+ for (let i = 0, iMax = polysAfter.length; i < iMax; i++) {
1531
+ const mp = polysAfter[i].multiPoly;
1532
+ if (mpsAfter.indexOf(mp) === -1) mpsAfter.push(mp);
1533
+ }
1534
+ return this._afterState;
1535
+ }
1536
+ /* Is this segment part of the final result? */
1537
+ isInResult() {
1538
+ if (this.consumedBy) return false;
1539
+ if (this._isInResult !== void 0) return this._isInResult;
1540
+ const mpsBefore = this.beforeState().multiPolys;
1541
+ const mpsAfter = this.afterState().multiPolys;
1542
+ switch (operation.type) {
1543
+ case "union": {
1544
+ const noBefores = mpsBefore.length === 0;
1545
+ const noAfters = mpsAfter.length === 0;
1546
+ this._isInResult = noBefores !== noAfters;
1547
+ break;
1548
+ }
1549
+ case "intersection": {
1550
+ let least;
1551
+ let most;
1552
+ if (mpsBefore.length < mpsAfter.length) {
1553
+ least = mpsBefore.length;
1554
+ most = mpsAfter.length;
1555
+ } else {
1556
+ least = mpsAfter.length;
1557
+ most = mpsBefore.length;
1558
+ }
1559
+ this._isInResult = most === operation.numMultiPolys && least < most;
1560
+ break;
1561
+ }
1562
+ case "xor": {
1563
+ const diff = Math.abs(mpsBefore.length - mpsAfter.length);
1564
+ this._isInResult = diff % 2 === 1;
1565
+ break;
1566
+ }
1567
+ case "difference": {
1568
+ const isJustSubject = (mps) => mps.length === 1 && mps[0].isSubject;
1569
+ this._isInResult = isJustSubject(mpsBefore) !== isJustSubject(mpsAfter);
1570
+ break;
1571
+ }
1572
+ default:
1573
+ throw new Error(`Unrecognized operation type found ${operation.type}`);
1574
+ }
1575
+ return this._isInResult;
1576
+ }
1577
+ }
1578
+ class RingIn {
1579
+ constructor(geomRing, poly, isExterior) {
1580
+ if (!Array.isArray(geomRing) || geomRing.length === 0) {
1581
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
1582
+ }
1583
+ this.poly = poly;
1584
+ this.isExterior = isExterior;
1585
+ this.segments = [];
1586
+ if (typeof geomRing[0][0] !== "number" || typeof geomRing[0][1] !== "number") {
1587
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
1588
+ }
1589
+ const firstPoint = rounder.round(geomRing[0][0], geomRing[0][1]);
1590
+ this.bbox = {
1591
+ ll: {
1592
+ x: firstPoint.x,
1593
+ y: firstPoint.y
1594
+ },
1595
+ ur: {
1596
+ x: firstPoint.x,
1597
+ y: firstPoint.y
1598
+ }
1599
+ };
1600
+ let prevPoint = firstPoint;
1601
+ for (let i = 1, iMax = geomRing.length; i < iMax; i++) {
1602
+ if (typeof geomRing[i][0] !== "number" || typeof geomRing[i][1] !== "number") {
1603
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
1604
+ }
1605
+ let point = rounder.round(geomRing[i][0], geomRing[i][1]);
1606
+ if (point.x === prevPoint.x && point.y === prevPoint.y) continue;
1607
+ this.segments.push(Segment.fromRing(prevPoint, point, this));
1608
+ if (point.x < this.bbox.ll.x) this.bbox.ll.x = point.x;
1609
+ if (point.y < this.bbox.ll.y) this.bbox.ll.y = point.y;
1610
+ if (point.x > this.bbox.ur.x) this.bbox.ur.x = point.x;
1611
+ if (point.y > this.bbox.ur.y) this.bbox.ur.y = point.y;
1612
+ prevPoint = point;
1613
+ }
1614
+ if (firstPoint.x !== prevPoint.x || firstPoint.y !== prevPoint.y) {
1615
+ this.segments.push(Segment.fromRing(prevPoint, firstPoint, this));
1616
+ }
1617
+ }
1618
+ getSweepEvents() {
1619
+ const sweepEvents = [];
1620
+ for (let i = 0, iMax = this.segments.length; i < iMax; i++) {
1621
+ const segment = this.segments[i];
1622
+ sweepEvents.push(segment.leftSE);
1623
+ sweepEvents.push(segment.rightSE);
1624
+ }
1625
+ return sweepEvents;
1626
+ }
1627
+ }
1628
+ class PolyIn {
1629
+ constructor(geomPoly, multiPoly) {
1630
+ if (!Array.isArray(geomPoly)) {
1631
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
1632
+ }
1633
+ this.exteriorRing = new RingIn(geomPoly[0], this, true);
1634
+ this.bbox = {
1635
+ ll: {
1636
+ x: this.exteriorRing.bbox.ll.x,
1637
+ y: this.exteriorRing.bbox.ll.y
1638
+ },
1639
+ ur: {
1640
+ x: this.exteriorRing.bbox.ur.x,
1641
+ y: this.exteriorRing.bbox.ur.y
1642
+ }
1643
+ };
1644
+ this.interiorRings = [];
1645
+ for (let i = 1, iMax = geomPoly.length; i < iMax; i++) {
1646
+ const ring = new RingIn(geomPoly[i], this, false);
1647
+ if (ring.bbox.ll.x < this.bbox.ll.x) this.bbox.ll.x = ring.bbox.ll.x;
1648
+ if (ring.bbox.ll.y < this.bbox.ll.y) this.bbox.ll.y = ring.bbox.ll.y;
1649
+ if (ring.bbox.ur.x > this.bbox.ur.x) this.bbox.ur.x = ring.bbox.ur.x;
1650
+ if (ring.bbox.ur.y > this.bbox.ur.y) this.bbox.ur.y = ring.bbox.ur.y;
1651
+ this.interiorRings.push(ring);
1652
+ }
1653
+ this.multiPoly = multiPoly;
1654
+ }
1655
+ getSweepEvents() {
1656
+ const sweepEvents = this.exteriorRing.getSweepEvents();
1657
+ for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
1658
+ const ringSweepEvents = this.interiorRings[i].getSweepEvents();
1659
+ for (let j = 0, jMax = ringSweepEvents.length; j < jMax; j++) {
1660
+ sweepEvents.push(ringSweepEvents[j]);
1661
+ }
1662
+ }
1663
+ return sweepEvents;
1664
+ }
1665
+ }
1666
+ class MultiPolyIn {
1667
+ constructor(geom, isSubject) {
1668
+ if (!Array.isArray(geom)) {
1669
+ throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
1670
+ }
1671
+ try {
1672
+ if (typeof geom[0][0][0] === "number") geom = [geom];
1673
+ } catch (ex) {
1674
+ }
1675
+ this.polys = [];
1676
+ this.bbox = {
1677
+ ll: {
1678
+ x: Number.POSITIVE_INFINITY,
1679
+ y: Number.POSITIVE_INFINITY
1680
+ },
1681
+ ur: {
1682
+ x: Number.NEGATIVE_INFINITY,
1683
+ y: Number.NEGATIVE_INFINITY
1684
+ }
1685
+ };
1686
+ for (let i = 0, iMax = geom.length; i < iMax; i++) {
1687
+ const poly = new PolyIn(geom[i], this);
1688
+ if (poly.bbox.ll.x < this.bbox.ll.x) this.bbox.ll.x = poly.bbox.ll.x;
1689
+ if (poly.bbox.ll.y < this.bbox.ll.y) this.bbox.ll.y = poly.bbox.ll.y;
1690
+ if (poly.bbox.ur.x > this.bbox.ur.x) this.bbox.ur.x = poly.bbox.ur.x;
1691
+ if (poly.bbox.ur.y > this.bbox.ur.y) this.bbox.ur.y = poly.bbox.ur.y;
1692
+ this.polys.push(poly);
1693
+ }
1694
+ this.isSubject = isSubject;
1695
+ }
1696
+ getSweepEvents() {
1697
+ const sweepEvents = [];
1698
+ for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
1699
+ const polySweepEvents = this.polys[i].getSweepEvents();
1700
+ for (let j = 0, jMax = polySweepEvents.length; j < jMax; j++) {
1701
+ sweepEvents.push(polySweepEvents[j]);
1702
+ }
1703
+ }
1704
+ return sweepEvents;
1705
+ }
1706
+ }
1707
+ class RingOut {
1708
+ /* Given the segments from the sweep line pass, compute & return a series
1709
+ * of closed rings from all the segments marked to be part of the result */
1710
+ static factory(allSegments) {
1711
+ const ringsOut = [];
1712
+ for (let i = 0, iMax = allSegments.length; i < iMax; i++) {
1713
+ const segment = allSegments[i];
1714
+ if (!segment.isInResult() || segment.ringOut) continue;
1715
+ let prevEvent = null;
1716
+ let event = segment.leftSE;
1717
+ let nextEvent = segment.rightSE;
1718
+ const events = [event];
1719
+ const startingPoint = event.point;
1720
+ const intersectionLEs = [];
1721
+ while (true) {
1722
+ prevEvent = event;
1723
+ event = nextEvent;
1724
+ events.push(event);
1725
+ if (event.point === startingPoint) break;
1726
+ while (true) {
1727
+ const availableLEs = event.getAvailableLinkedEvents();
1728
+ if (availableLEs.length === 0) {
1729
+ const firstPt = events[0].point;
1730
+ const lastPt = events[events.length - 1].point;
1731
+ throw new Error(`Unable to complete output ring starting at [${firstPt.x}, ${firstPt.y}]. Last matching segment found ends at [${lastPt.x}, ${lastPt.y}].`);
1732
+ }
1733
+ if (availableLEs.length === 1) {
1734
+ nextEvent = availableLEs[0].otherSE;
1735
+ break;
1736
+ }
1737
+ let indexLE = null;
1738
+ for (let j = 0, jMax = intersectionLEs.length; j < jMax; j++) {
1739
+ if (intersectionLEs[j].point === event.point) {
1740
+ indexLE = j;
1741
+ break;
1742
+ }
1743
+ }
1744
+ if (indexLE !== null) {
1745
+ const intersectionLE = intersectionLEs.splice(indexLE)[0];
1746
+ const ringEvents = events.splice(intersectionLE.index);
1747
+ ringEvents.unshift(ringEvents[0].otherSE);
1748
+ ringsOut.push(new RingOut(ringEvents.reverse()));
1749
+ continue;
1750
+ }
1751
+ intersectionLEs.push({
1752
+ index: events.length,
1753
+ point: event.point
1754
+ });
1755
+ const comparator = event.getLeftmostComparator(prevEvent);
1756
+ nextEvent = availableLEs.sort(comparator)[0].otherSE;
1757
+ break;
1758
+ }
1759
+ }
1760
+ ringsOut.push(new RingOut(events));
1761
+ }
1762
+ return ringsOut;
1763
+ }
1764
+ constructor(events) {
1765
+ this.events = events;
1766
+ for (let i = 0, iMax = events.length; i < iMax; i++) {
1767
+ events[i].segment.ringOut = this;
1768
+ }
1769
+ this.poly = null;
1770
+ }
1771
+ getGeom() {
1772
+ let prevPt = this.events[0].point;
1773
+ const points = [prevPt];
1774
+ for (let i = 1, iMax = this.events.length - 1; i < iMax; i++) {
1775
+ const pt2 = this.events[i].point;
1776
+ const nextPt2 = this.events[i + 1].point;
1777
+ if (compareVectorAngles(pt2, prevPt, nextPt2) === 0) continue;
1778
+ points.push(pt2);
1779
+ prevPt = pt2;
1780
+ }
1781
+ if (points.length === 1) return null;
1782
+ const pt = points[0];
1783
+ const nextPt = points[1];
1784
+ if (compareVectorAngles(pt, prevPt, nextPt) === 0) points.shift();
1785
+ points.push(points[0]);
1786
+ const step = this.isExteriorRing() ? 1 : -1;
1787
+ const iStart = this.isExteriorRing() ? 0 : points.length - 1;
1788
+ const iEnd = this.isExteriorRing() ? points.length : -1;
1789
+ const orderedPoints = [];
1790
+ for (let i = iStart; i != iEnd; i += step) orderedPoints.push([points[i].x, points[i].y]);
1791
+ return orderedPoints;
1792
+ }
1793
+ isExteriorRing() {
1794
+ if (this._isExteriorRing === void 0) {
1795
+ const enclosing = this.enclosingRing();
1796
+ this._isExteriorRing = enclosing ? !enclosing.isExteriorRing() : true;
1797
+ }
1798
+ return this._isExteriorRing;
1799
+ }
1800
+ enclosingRing() {
1801
+ if (this._enclosingRing === void 0) {
1802
+ this._enclosingRing = this._calcEnclosingRing();
1803
+ }
1804
+ return this._enclosingRing;
1805
+ }
1806
+ /* Returns the ring that encloses this one, if any */
1807
+ _calcEnclosingRing() {
1808
+ let leftMostEvt = this.events[0];
1809
+ for (let i = 1, iMax = this.events.length; i < iMax; i++) {
1810
+ const evt = this.events[i];
1811
+ if (SweepEvent.compare(leftMostEvt, evt) > 0) leftMostEvt = evt;
1812
+ }
1813
+ let prevSeg = leftMostEvt.segment.prevInResult();
1814
+ let prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
1815
+ while (true) {
1816
+ if (!prevSeg) return null;
1817
+ if (!prevPrevSeg) return prevSeg.ringOut;
1818
+ if (prevPrevSeg.ringOut !== prevSeg.ringOut) {
1819
+ if (prevPrevSeg.ringOut.enclosingRing() !== prevSeg.ringOut) {
1820
+ return prevSeg.ringOut;
1821
+ } else return prevSeg.ringOut.enclosingRing();
1822
+ }
1823
+ prevSeg = prevPrevSeg.prevInResult();
1824
+ prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
1825
+ }
1826
+ }
1827
+ }
1828
+ class PolyOut {
1829
+ constructor(exteriorRing) {
1830
+ this.exteriorRing = exteriorRing;
1831
+ exteriorRing.poly = this;
1832
+ this.interiorRings = [];
1833
+ }
1834
+ addInterior(ring) {
1835
+ this.interiorRings.push(ring);
1836
+ ring.poly = this;
1837
+ }
1838
+ getGeom() {
1839
+ const geom = [this.exteriorRing.getGeom()];
1840
+ if (geom[0] === null) return null;
1841
+ for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
1842
+ const ringGeom = this.interiorRings[i].getGeom();
1843
+ if (ringGeom === null) continue;
1844
+ geom.push(ringGeom);
1845
+ }
1846
+ return geom;
1847
+ }
1848
+ }
1849
+ class MultiPolyOut {
1850
+ constructor(rings) {
1851
+ this.rings = rings;
1852
+ this.polys = this._composePolys(rings);
1853
+ }
1854
+ getGeom() {
1855
+ const geom = [];
1856
+ for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
1857
+ const polyGeom = this.polys[i].getGeom();
1858
+ if (polyGeom === null) continue;
1859
+ geom.push(polyGeom);
1860
+ }
1861
+ return geom;
1862
+ }
1863
+ _composePolys(rings) {
1864
+ const polys = [];
1865
+ for (let i = 0, iMax = rings.length; i < iMax; i++) {
1866
+ const ring = rings[i];
1867
+ if (ring.poly) continue;
1868
+ if (ring.isExteriorRing()) polys.push(new PolyOut(ring));
1869
+ else {
1870
+ const enclosingRing = ring.enclosingRing();
1871
+ if (!enclosingRing.poly) polys.push(new PolyOut(enclosingRing));
1872
+ enclosingRing.poly.addInterior(ring);
1873
+ }
1874
+ }
1875
+ return polys;
1876
+ }
1877
+ }
1878
+ class SweepLine {
1879
+ constructor(queue) {
1880
+ let comparator = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Segment.compare;
1881
+ this.queue = queue;
1882
+ this.tree = new Tree(comparator);
1883
+ this.segments = [];
1884
+ }
1885
+ process(event) {
1886
+ const segment = event.segment;
1887
+ const newEvents = [];
1888
+ if (event.consumedBy) {
1889
+ if (event.isLeft) this.queue.remove(event.otherSE);
1890
+ else this.tree.remove(segment);
1891
+ return newEvents;
1892
+ }
1893
+ const node = event.isLeft ? this.tree.add(segment) : this.tree.find(segment);
1894
+ 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.`);
1895
+ let prevNode = node;
1896
+ let nextNode = node;
1897
+ let prevSeg = void 0;
1898
+ let nextSeg = void 0;
1899
+ while (prevSeg === void 0) {
1900
+ prevNode = this.tree.prev(prevNode);
1901
+ if (prevNode === null) prevSeg = null;
1902
+ else if (prevNode.key.consumedBy === void 0) prevSeg = prevNode.key;
1903
+ }
1904
+ while (nextSeg === void 0) {
1905
+ nextNode = this.tree.next(nextNode);
1906
+ if (nextNode === null) nextSeg = null;
1907
+ else if (nextNode.key.consumedBy === void 0) nextSeg = nextNode.key;
1908
+ }
1909
+ if (event.isLeft) {
1910
+ let prevMySplitter = null;
1911
+ if (prevSeg) {
1912
+ const prevInter = prevSeg.getIntersection(segment);
1913
+ if (prevInter !== null) {
1914
+ if (!segment.isAnEndpoint(prevInter)) prevMySplitter = prevInter;
1915
+ if (!prevSeg.isAnEndpoint(prevInter)) {
1916
+ const newEventsFromSplit = this._splitSafely(prevSeg, prevInter);
1917
+ for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
1918
+ newEvents.push(newEventsFromSplit[i]);
1919
+ }
1920
+ }
1921
+ }
1922
+ }
1923
+ let nextMySplitter = null;
1924
+ if (nextSeg) {
1925
+ const nextInter = nextSeg.getIntersection(segment);
1926
+ if (nextInter !== null) {
1927
+ if (!segment.isAnEndpoint(nextInter)) nextMySplitter = nextInter;
1928
+ if (!nextSeg.isAnEndpoint(nextInter)) {
1929
+ const newEventsFromSplit = this._splitSafely(nextSeg, nextInter);
1930
+ for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
1931
+ newEvents.push(newEventsFromSplit[i]);
1932
+ }
1933
+ }
1934
+ }
1935
+ }
1936
+ if (prevMySplitter !== null || nextMySplitter !== null) {
1937
+ let mySplitter = null;
1938
+ if (prevMySplitter === null) mySplitter = nextMySplitter;
1939
+ else if (nextMySplitter === null) mySplitter = prevMySplitter;
1940
+ else {
1941
+ const cmpSplitters = SweepEvent.comparePoints(prevMySplitter, nextMySplitter);
1942
+ mySplitter = cmpSplitters <= 0 ? prevMySplitter : nextMySplitter;
1943
+ }
1944
+ this.queue.remove(segment.rightSE);
1945
+ newEvents.push(segment.rightSE);
1946
+ const newEventsFromSplit = segment.split(mySplitter);
1947
+ for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
1948
+ newEvents.push(newEventsFromSplit[i]);
1949
+ }
1950
+ }
1951
+ if (newEvents.length > 0) {
1952
+ this.tree.remove(segment);
1953
+ newEvents.push(event);
1954
+ } else {
1955
+ this.segments.push(segment);
1956
+ segment.prev = prevSeg;
1957
+ }
1958
+ } else {
1959
+ if (prevSeg && nextSeg) {
1960
+ const inter = prevSeg.getIntersection(nextSeg);
1961
+ if (inter !== null) {
1962
+ if (!prevSeg.isAnEndpoint(inter)) {
1963
+ const newEventsFromSplit = this._splitSafely(prevSeg, inter);
1964
+ for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
1965
+ newEvents.push(newEventsFromSplit[i]);
1966
+ }
1967
+ }
1968
+ if (!nextSeg.isAnEndpoint(inter)) {
1969
+ const newEventsFromSplit = this._splitSafely(nextSeg, inter);
1970
+ for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
1971
+ newEvents.push(newEventsFromSplit[i]);
1972
+ }
1973
+ }
1974
+ }
1975
+ }
1976
+ this.tree.remove(segment);
1977
+ }
1978
+ return newEvents;
1979
+ }
1980
+ /* Safely split a segment that is currently in the datastructures
1981
+ * IE - a segment other than the one that is currently being processed. */
1982
+ _splitSafely(seg, pt) {
1983
+ this.tree.remove(seg);
1984
+ const rightSE = seg.rightSE;
1985
+ this.queue.remove(rightSE);
1986
+ const newEvents = seg.split(pt);
1987
+ newEvents.push(rightSE);
1988
+ if (seg.consumedBy === void 0) this.tree.add(seg);
1989
+ return newEvents;
1990
+ }
1991
+ }
1992
+ const POLYGON_CLIPPING_MAX_QUEUE_SIZE = typeof process !== "undefined" && process.env.POLYGON_CLIPPING_MAX_QUEUE_SIZE || 1e6;
1993
+ const POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS = typeof process !== "undefined" && process.env.POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS || 1e6;
1994
+ class Operation {
1995
+ run(type, geom, moreGeoms) {
1996
+ operation.type = type;
1997
+ rounder.reset();
1998
+ const multipolys = [new MultiPolyIn(geom, true)];
1999
+ for (let i = 0, iMax = moreGeoms.length; i < iMax; i++) {
2000
+ multipolys.push(new MultiPolyIn(moreGeoms[i], false));
2001
+ }
2002
+ operation.numMultiPolys = multipolys.length;
2003
+ if (operation.type === "difference") {
2004
+ const subject = multipolys[0];
2005
+ let i = 1;
2006
+ while (i < multipolys.length) {
2007
+ if (getBboxOverlap(multipolys[i].bbox, subject.bbox) !== null) i++;
2008
+ else multipolys.splice(i, 1);
2009
+ }
2010
+ }
2011
+ if (operation.type === "intersection") {
2012
+ for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
2013
+ const mpA = multipolys[i];
2014
+ for (let j = i + 1, jMax = multipolys.length; j < jMax; j++) {
2015
+ if (getBboxOverlap(mpA.bbox, multipolys[j].bbox) === null) return [];
2016
+ }
2017
+ }
2018
+ }
2019
+ const queue = new Tree(SweepEvent.compare);
2020
+ for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
2021
+ const sweepEvents = multipolys[i].getSweepEvents();
2022
+ for (let j = 0, jMax = sweepEvents.length; j < jMax; j++) {
2023
+ queue.insert(sweepEvents[j]);
2024
+ if (queue.size > POLYGON_CLIPPING_MAX_QUEUE_SIZE) {
2025
+ throw new Error("Infinite loop when putting segment endpoints in a priority queue (queue size too big).");
2026
+ }
2027
+ }
2028
+ }
2029
+ const sweepLine = new SweepLine(queue);
2030
+ let prevQueueSize = queue.size;
2031
+ let node = queue.pop();
2032
+ while (node) {
2033
+ const evt = node.key;
2034
+ if (queue.size === prevQueueSize) {
2035
+ const seg = evt.segment;
2036
+ 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.`);
2037
+ }
2038
+ if (queue.size > POLYGON_CLIPPING_MAX_QUEUE_SIZE) {
2039
+ throw new Error("Infinite loop when passing sweep line over endpoints (queue size too big).");
2040
+ }
2041
+ if (sweepLine.segments.length > POLYGON_CLIPPING_MAX_SWEEPLINE_SEGMENTS) {
2042
+ throw new Error("Infinite loop when passing sweep line over endpoints (too many sweep line segments).");
2043
+ }
2044
+ const newEvents = sweepLine.process(evt);
2045
+ for (let i = 0, iMax = newEvents.length; i < iMax; i++) {
2046
+ const evt2 = newEvents[i];
2047
+ if (evt2.consumedBy === void 0) queue.insert(evt2);
2048
+ }
2049
+ prevQueueSize = queue.size;
2050
+ node = queue.pop();
2051
+ }
2052
+ rounder.reset();
2053
+ const ringsOut = RingOut.factory(sweepLine.segments);
2054
+ const result = new MultiPolyOut(ringsOut);
2055
+ return result.getGeom();
2056
+ }
2057
+ }
2058
+ const operation = new Operation();
2059
+ const union = function(geom) {
2060
+ for (var _len = arguments.length, moreGeoms = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2061
+ moreGeoms[_key - 1] = arguments[_key];
2062
+ }
2063
+ return operation.run("union", geom, moreGeoms);
2064
+ };
2065
+ const intersection = function(geom) {
2066
+ for (var _len2 = arguments.length, moreGeoms = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2067
+ moreGeoms[_key2 - 1] = arguments[_key2];
2068
+ }
2069
+ return operation.run("intersection", geom, moreGeoms);
2070
+ };
2071
+ const xor = function(geom) {
2072
+ for (var _len3 = arguments.length, moreGeoms = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
2073
+ moreGeoms[_key3 - 1] = arguments[_key3];
2074
+ }
2075
+ return operation.run("xor", geom, moreGeoms);
2076
+ };
2077
+ const difference = function(subjectGeom) {
2078
+ for (var _len4 = arguments.length, clippingGeoms = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2079
+ clippingGeoms[_key4 - 1] = arguments[_key4];
2080
+ }
2081
+ return operation.run("difference", subjectGeom, clippingGeoms);
2082
+ };
2083
+ var index = {
2084
+ union,
2085
+ intersection,
2086
+ xor,
2087
+ difference
2088
+ };
2089
+ return index;
2090
+ });
2091
+ }
2092
+ });
2093
+
5
2094
  // ../hem-target-runtime/src/hem/isolatedRustWorker.ts
6
2095
  function installIsolatedRustWorker(scope) {
7
2096
  let child;
@@ -178,15 +2267,61 @@ async function runHeatingProfile(input, profile, run) {
178
2267
  // ../hem-target-runtime/src/hem/targets.ts
179
2268
  var WRAPPERS = {
180
2269
  fhs: {
2270
+ /** Wire name the target preparation artifacts accept. */
181
2271
  profile: "fhs",
2272
+ /** Community defaults template the family's bundles pin for preparation. */
2273
+ preparationDefaults: "defaults_template.json",
2274
+ /** Schema dialect the editor reads; separate from the wire profile. */
2275
+ schemaMode: "fhs",
182
2276
  modes: ["actual", "actual-fee", "notional", "notional-fee"],
2277
+ /** Modes of a scenario that selects no model wrapper. */
2278
+ defaultModes: ["actual"],
183
2279
  scenarioModes: {
184
2280
  fhs_assumptions: ["actual"],
185
2281
  fhs_compliance: ["actual", "actual-fee", "notional", "notional-fee"]
186
2282
  },
187
- pythonModule: "bin.fhs",
2283
+ /** The run-mode name users see, per scenario wrapper. */
2284
+ scenarioLabels: { fhs_assumptions: "Single run", fhs_compliance: "Compliance" },
2285
+ /** How the run's results are read; written to target-run.json. */
2286
+ resultsKind: "fhs",
188
2287
  coreDistribution: "hem-core",
189
- wrapperDistribution: "hem-fhs-wrapper"
2288
+ wrapperDistribution: "hem-fhs-wrapper",
2289
+ /** Further pinned distributions; each target pins their version and commit in `components`. */
2290
+ componentDistributions: [],
2291
+ /** Systems take HEM Database products, picked in the editor's product slots. */
2292
+ hemDatabaseProducts: false,
2293
+ /** The scenario wrapper an agent's single-model run uses when the caller names none. */
2294
+ singleRunWrapper: "fhs_compliance",
2295
+ /** Fabric from construction bands on an existing building (the editor's `constructionBands` rule). */
2296
+ constructionBands: false,
2297
+ /** A scenario may pick its own weather file. */
2298
+ customWeather: true
2299
+ },
2300
+ epc: {
2301
+ /** vulcan-model-transform `ModelProfile::Epc`. */
2302
+ profile: "epc",
2303
+ /** The shared template plus the HEM:EPC fields with no Vulcan source. */
2304
+ preparationDefaults: "defaults_template_epc.json",
2305
+ /** The full-input schema is a Core-shaped input (pydantic unions), not the FHS dialect. */
2306
+ schemaMode: "core",
2307
+ /** `quick` is the main EPC run only (upstream --skip-smart-metric --skip-fees-metric); `full` adds the smart and FEES runs. */
2308
+ modes: ["quick", "full"],
2309
+ defaultModes: ["quick"],
2310
+ scenarioModes: {
2311
+ epc_quick: ["quick"],
2312
+ epc_full: ["full"]
2313
+ },
2314
+ scenarioLabels: { epc_quick: "Rating and energy", epc_full: "Full EPC" },
2315
+ resultsKind: "epc",
2316
+ coreDistribution: "hem-core",
2317
+ wrapperDistribution: "hem-epc-wrapper",
2318
+ componentDistributions: ["hem-epc-orchestrator", "hemie", "hem-db-client"],
2319
+ hemDatabaseProducts: true,
2320
+ singleRunWrapper: "epc_quick",
2321
+ // An existing building converts to HEMIE, whose fabric is the age band and constructions.
2322
+ constructionBands: true,
2323
+ // The Orchestrator runs on its pinned weather (pythonTarget.ts).
2324
+ customWeather: false
190
2325
  }
191
2326
  };
192
2327
  function targetWrapper(target) {
@@ -194,13 +2329,36 @@ function targetWrapper(target) {
194
2329
  if (!wrapper) throw new Error(`Unsupported HEM wrapper: ${target.wrapper}`);
195
2330
  return wrapper;
196
2331
  }
197
- function assertRustTargetVersions(target, engineVersion, wrapperVersion) {
2332
+ var RUNTIMES_WITHOUT_COMMITS = /* @__PURE__ */ new Set(["rust-fhs-a7-62d3df70-c5ba2673-v1"]);
2333
+ function assertRustTargetVersions(target, engineVersion, wrapperVersion, engineCommit, wrapperCommit) {
198
2334
  if (engineVersion !== target.engineVersion || wrapperVersion !== target.wrapperVersion) throw new Error("Rust runtime version mismatch");
2335
+ if (RUNTIMES_WITHOUT_COMMITS.has(target.id)) return;
2336
+ if (engineCommit !== target.engineCommit || wrapperCommit !== target.wrapperCommit) throw new Error("Rust runtime commit mismatch");
199
2337
  }
200
2338
  var HEM_TARGETS = [
2339
+ // The Rust a9 that ECaaS runs in production (epb-ecaas-api e1c090e, lambda/Cargo.lock). Its wrapper
2340
+ // schema equals the Python a9 one, so it keeps that conversion profile's wire name. It is built
2341
+ // with the carried patch set fhs-a9-schema-v1 (targetSchemaCorrections.ts); build and parity:
2342
+ // docs/development/HEM_Rust_A9_Target.md.
2343
+ {
2344
+ id: "rust-fhs-a9-9e41af89-f2c2425f-v1",
2345
+ label: "HEM:FHS 1.0.0a9",
2346
+ runtime: "rust",
2347
+ version: "1.0.0a9",
2348
+ engineVersion: "1.0.0a9",
2349
+ wrapperVersion: "1.0.0a9",
2350
+ wrapper: "fhs",
2351
+ engineCommit: "9e41af890cc62a1cec08957340231c3591956dac",
2352
+ wrapperCommit: "f2c2425f00870e1611750bd2ac1be20132301e0d",
2353
+ conversionProfile: "python_fhs_a9",
2354
+ // Measured, example_semi_detached in wasm-browser-cli at load 13-19 (13 November): actual mode
2355
+ // 5.9-9.0 s, all four modes 48.3-48.6 s (docs/development/HEM_Rust_A9_Target.md).
2356
+ status: "provisional",
2357
+ typicalRunMinutes: { fhs_assumptions: 0.15, fhs_compliance: 0.8 }
2358
+ },
201
2359
  {
202
2360
  id: "rust-fhs-a7-62d3df70-c5ba2673-v1",
203
- label: "Rust HEM:FHS 1.0.0a7",
2361
+ label: "HEM:FHS 1.0.0a7",
204
2362
  runtime: "rust",
205
2363
  version: "1.0.0a7",
206
2364
  engineVersion: "1.0.0a7",
@@ -208,36 +2366,42 @@ var HEM_TARGETS = [
208
2366
  wrapper: "fhs",
209
2367
  engineCommit: "62d3df705690f33b3fc3e905c9971d4f3743bf2e",
210
2368
  wrapperCommit: "c5ba2673fbd886cfe4fb528f61b376bdf406ebbd",
211
- conversionProfile: "current_rust_fhs"
212
- },
213
- {
214
- id: "python-fhs-a9-918addad-b9b90138-v1",
215
- label: "Python HEM:FHS 1.0.0a9",
216
- runtime: "python",
217
- version: "1.0.0a9",
218
- engineVersion: "1.0.0a9",
219
- wrapperVersion: "1.0.0a9",
220
- wrapper: "fhs",
221
- engineCommit: "918addad2f9ffbcd9c7a4ed73497d047210be2d2",
222
- wrapperCommit: "b9b901382feb0e5d27f969532842250147fb4068",
223
- conversionProfile: "python_fhs_a9"
224
- },
2369
+ conversionProfile: "current_rust_fhs",
2370
+ // Actual mode: house_two_storey 7.4 s and 8.1 s through wasm-browser-cli at load 16-20 (13 November). Compliance not measured.
2371
+ status: "legacy",
2372
+ typicalRunMinutes: { fhs_assumptions: 0.12 }
2373
+ }
2374
+ ];
2375
+ var RECOMMENDED_HEM_TARGET = HEM_TARGETS[0].id;
2376
+ var UNRELEASED_HEM_TARGETS = [
225
2377
  {
226
- id: "python-fhs-a8-f2ab6cf7-8ca182b0-v1",
227
- label: "Python HEM:FHS 1.0.0a8",
2378
+ id: "python-epc-0.13.2-6367f1ec-18032feb-v1",
2379
+ label: "HEM:EPC 0.13.2",
228
2380
  runtime: "python",
229
- version: "1.0.0a8",
230
- engineVersion: "1.0.0a8",
231
- wrapperVersion: "1.0.0a8",
232
- wrapper: "fhs",
233
- engineCommit: "f2ab6cf78860c36d260cb21396b747cc372f2c9d",
234
- wrapperCommit: "8ca182b0171a3a928059a9c0ec0145ecefe3f4e9",
235
- conversionProfile: "python_fhs_a8"
2381
+ version: "0.13.2",
2382
+ engineVersion: "2.0.0a4",
2383
+ wrapperVersion: "0.13.2",
2384
+ wrapper: "epc",
2385
+ engineCommit: "6367f1ecb101c7f72a2006a921c732c790b0d338",
2386
+ wrapperCommit: "18032feb59294b323fc28af4fb032d34bd44bf67",
2387
+ conversionProfile: "epc_full_input_v1",
2388
+ components: {
2389
+ "hem-epc-orchestrator": { version: "0.13.2a0", commit: "993463233ad0c416e83c4de3b84889280d3c4619" },
2390
+ hemie: { version: "0.18.1", commit: "2876e2ec1c7bad2b738c9c3b3685d86860a91f41" },
2391
+ "hem-db-client": { version: "1.0.0a10", commit: "9eeb026dd52a612197b5552ca113d8121fa72679" }
2392
+ },
2393
+ // db-client/data/*.csv at the hem-db-client commit.
2394
+ productDataSha256: "d0acf4ebf050e80f3dc576ffbb1295ebeb1176e9fd4a9ec1d151a9e8f4df7457",
2395
+ // Quick, measured: house_two_storey 491-535 s in wasm-browser-cli (HEM_EPC_Integration_Plan.md, Status).
2396
+ // Full, estimated: 35 min natively at the measured 2.4-2.6x browser ratio (same plan, Measured).
2397
+ status: "provisional",
2398
+ typicalRunMinutes: { epc_quick: 9, epc_full: 90 },
2399
+ estimatedRunMinutes: ["epc_full"]
236
2400
  }
237
2401
  ];
238
- var RECOMMENDED_HEM_TARGET = HEM_TARGETS[0].id;
2402
+ var findHemTarget = (id) => [...HEM_TARGETS, ...UNRELEASED_HEM_TARGETS].find((target) => target.id === id);
239
2403
  function resolveHemTarget(id) {
240
- const target = HEM_TARGETS.find((target2) => target2.id === id);
2404
+ const target = findHemTarget(id);
241
2405
  if (!target) throw new Error(`HEM target '${id}' is unavailable. Select a supported target explicitly; saved runs are never upgraded automatically.`);
242
2406
  return target;
243
2407
  }
@@ -247,9 +2411,11 @@ function modelArtifacts(manifest2) {
247
2411
  return manifest2.artifacts.filter((artifact) => !artifact.path.startsWith("source/") && !artifact.path.startsWith("notices/") && !converter.includes(artifact.path));
248
2412
  }
249
2413
  function validateTargetManifest(manifest2, target) {
250
- if (manifest2.bundleId !== target.id || manifest2.protocol !== 1 || manifest2.engineCommit !== target.engineCommit || manifest2.wrapperCommit !== target.wrapperCommit || manifest2.conversionProfile !== target.conversionProfile) {
2414
+ if (manifest2.bundleId !== target.id || manifest2.protocol !== 1 || manifest2.engineCommit !== target.engineCommit || manifest2.wrapperCommit !== target.wrapperCommit || manifest2.conversionProfile !== target.conversionProfile || JSON.stringify(sortedComponents(manifest2.components)) !== JSON.stringify(sortedComponents(target.components)) || manifest2.productDataSha256 !== target.productDataSha256) {
251
2415
  throw new Error(`Target manifest identity mismatch for ${target.id}`);
252
2416
  }
2417
+ const wrapper = targetWrapper(target);
2418
+ if (JSON.stringify(Object.keys(target.components ?? {}).sort()) !== JSON.stringify([...wrapper.componentDistributions].sort())) throw new Error(`${target.id} must pin exactly the ${target.wrapper.toUpperCase()} component distributions`);
253
2419
  const paths = /* @__PURE__ */ new Set();
254
2420
  const sizesByHash = /* @__PURE__ */ new Map();
255
2421
  const isRelativePath = (path) => typeof path === "string" && /^[a-zA-Z0-9_./+-]+$/.test(path) && path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
@@ -266,7 +2432,10 @@ function validateTargetManifest(manifest2, target) {
266
2432
  if (path.startsWith("source/") || path.startsWith("notices/")) throw new Error(`Runtime/preparation cannot reference reserved source/notice material: ${path}`);
267
2433
  if (!paths.has(path)) throw new Error(`Target manifest is missing required artifact ${path}`);
268
2434
  }
269
- if (!manifest2.modes.length || new Set(manifest2.modes).size !== manifest2.modes.length || manifest2.modes.some((mode) => !targetWrapper(target).modes.includes(mode))) throw new Error("Unsupported or duplicate FHS calculation modes");
2435
+ if (!manifest2.modes.length || new Set(manifest2.modes).size !== manifest2.modes.length || manifest2.modes.some((mode) => !wrapper.modes.includes(mode))) throw new Error(`Unsupported or duplicate ${target.wrapper.toUpperCase()} calculation modes`);
2436
+ const { data } = manifest2.runtime;
2437
+ if (!!data !== !!target.productDataSha256) throw new Error("Runtime product data and its pinned hash must be declared together");
2438
+ if (data && (target.runtime !== "python" || data.startsWith("source/") || data.startsWith("notices/") || !data.endsWith("/") || !isRelativePath(data.slice(0, -1)) || !manifest2.artifacts.some((artifact) => artifact.path.startsWith(data)))) throw new Error("Runtime product data must be a non-empty relative Python bundle directory ending in /");
270
2439
  if (target.runtime === "rust") {
271
2440
  if (!manifest2.runtime.wasm) throw new Error("Rust target manifest is missing its runtime WASM artifact");
272
2441
  if (manifest2.modes.some((mode) => mode !== "actual") && manifest2.modes.length !== targetWrapper(target).modes.length) throw new Error("Rust target modes require actual alone or the complete compliance set");
@@ -278,11 +2447,15 @@ function validateTargetManifest(manifest2, target) {
278
2447
  for (const file of ["pyodide.asm.js", "pyodide.asm.wasm", "pyodide-lock.json", "python_stdlib.zip"]) {
279
2448
  if (!paths.has(`${index}${file}`)) throw new Error(`Python runtime is missing pinned artifact ${index}${file}`);
280
2449
  }
281
- if (requiredVersions?.[targetWrapper(target).coreDistribution] !== target.engineVersion || requiredVersions?.[targetWrapper(target).wrapperDistribution] !== target.wrapperVersion) {
2450
+ if (requiredVersions?.[wrapper.coreDistribution] !== target.engineVersion || requiredVersions?.[wrapper.wrapperDistribution] !== target.wrapperVersion) {
282
2451
  throw new Error(`Python runtime must pin matching engine ${target.engineVersion} and wrapper ${target.wrapperVersion} distributions`);
283
2452
  }
2453
+ for (const [distribution, { version }] of Object.entries(target.components ?? {})) {
2454
+ if (requiredVersions?.[distribution] !== version) throw new Error(`Python runtime must pin ${distribution} ${version}`);
2455
+ }
284
2456
  }
285
2457
  }
2458
+ var sortedComponents = (components) => Object.entries(components ?? {}).sort(([a], [b]) => a.localeCompare(b));
286
2459
 
287
2460
  // ../hem-target-runtime/src/hem/targetAssets.ts
288
2461
  var CACHE = "vulcan-hem-artifacts-v1";
@@ -421,13 +2594,215 @@ var TargetAssets = class _TargetAssets {
421
2594
  }
422
2595
  };
423
2596
 
2597
+ // ../community/packages/geometry-editor/src/lib/hemieFabric.ts
2598
+ var ENGLAND_AREAS = new Set("AL B BA BB BD BH BL BN BR BS CB CM CO CR CT CV CW DA DE DH DL DN DT DY E EC EN EX FY GL GU HA HD HG HP HU HX IG IP KT L LA LE LN LS LU M ME MK N NE NG NN NR NW OL OX PE PL PO PR RG RH RM S SE SG SK SL SM SN SO SP SR SS ST SW TA TF TN TQ TR TS TW UB W WA WC WD WF WN WR WS WV YO".split(" "));
2599
+
2600
+ // ../community/packages/geometry-editor/src/lib/zoneDerivation.ts
2601
+ var import_polygon_clipping2 = __toESM(require_polygon_clipping_umd(), 1);
2602
+
2603
+ // ../community/packages/geometry-editor/src/lib/polygonSync.ts
2604
+ var import_polygon_clipping = __toESM(require_polygon_clipping_umd(), 1);
2605
+
2606
+ // ../community/packages/geometry-editor-host/src/schemaPort.ts
2607
+ function unavailable(operation) {
2608
+ throw new Error(`Geometry schema ${operation} is unavailable`);
2609
+ }
2610
+ var unavailableGeometrySchemaPort = Object.freeze({
2611
+ availability: "unavailable",
2612
+ preload: async () => unavailable("preload"),
2613
+ getRootSchema: () => unavailable("root lookup"),
2614
+ getElementSubschema: () => unavailable("element lookup"),
2615
+ getBaseFieldsForElementType: () => unavailable("base-field lookup"),
2616
+ getApplianceKeys: () => unavailable("appliance-key lookup"),
2617
+ getStrictestIntegerKeysForElementType: () => unavailable("numeric-typing lookup"),
2618
+ getSchemaSubtypeForElementData: () => unavailable("subtype lookup"),
2619
+ getConditionalRequiredFields: () => unavailable("conditional-required lookup"),
2620
+ validateProperty: () => unavailable("property validation"),
2621
+ findParameter: () => unavailable("parameter lookup")
2622
+ });
2623
+
2624
+ // ../community/packages/geometry-editor/src/lib/roofCutouts.ts
2625
+ var import_polygon_clipping4 = __toESM(require_polygon_clipping_umd(), 1);
2626
+
2627
+ // ../community/packages/geometry-editor/src/lib/geometry3dMapper.ts
2628
+ var import_polygon_clipping3 = __toESM(require_polygon_clipping_umd(), 1);
2629
+
2630
+ // ../community/packages/geometry-editor/src/lib/assemblyCalculator.ts
2631
+ var H_RI = 5.13;
2632
+ var H_CI_UPWARDS = 5;
2633
+ var H_CI_HORIZONTAL = 2.5;
2634
+ var H_CI_DOWNWARDS = 0.7;
2635
+ var H_CE = 20;
2636
+ var H_RE = 4.14;
2637
+ var R_SI_HORIZONTAL = 1 / (H_RI + H_CI_HORIZONTAL);
2638
+ var R_SI_UPWARDS = 1 / (H_RI + H_CI_UPWARDS);
2639
+ var R_SI_DOWNWARDS = 1 / (H_RI + H_CI_DOWNWARDS);
2640
+ var R_SE = 1 / (H_CE + H_RE);
2641
+
2642
+ // ../community/packages/geometry-editor/src/lib/assemblyMassHeuristic.ts
2643
+ var FHS_MASS_DISTRIBUTION_CLASS_BY_CODE = {
2644
+ I: "I: Mass concentrated at internal side",
2645
+ E: "E: Mass concentrated at external side",
2646
+ IE: "IE: Mass divided over internal and external side",
2647
+ D: "D: Mass equally distributed",
2648
+ M: "M: Mass concentrated inside"
2649
+ };
2650
+ var FHS_MASS_DISTRIBUTION_CLASS_VALUES = new Set(
2651
+ Object.values(FHS_MASS_DISTRIBUTION_CLASS_BY_CODE)
2652
+ );
2653
+
2654
+ // ../community/packages/geometry-editor/src/lib/assemblyAppliedUi.ts
2655
+ var MASS_CLASS_MEANINGS = {
2656
+ I: "Mass mainly on the room side (e.g. external insulation).",
2657
+ E: "Mass mainly on the external side (e.g. internal insulation).",
2658
+ IE: "Mass on both sides of the insulation (e.g. filled cavity).",
2659
+ D: "Evenly distributed or negligible mass (e.g. uninsulated solid, lightweight).",
2660
+ M: "Mass near the middle (insulation both sides of the structural leaf)."
2661
+ };
2662
+ var FHS_MASS_CLASS_COMMENTARY = {
2663
+ "I: Mass concentrated at internal side": MASS_CLASS_MEANINGS.I,
2664
+ "E: Mass concentrated at external side": MASS_CLASS_MEANINGS.E,
2665
+ "IE: Mass divided over internal and external side": MASS_CLASS_MEANINGS.IE,
2666
+ "D: Mass equally distributed": MASS_CLASS_MEANINGS.D,
2667
+ "M: Mass concentrated inside": MASS_CLASS_MEANINGS.M
2668
+ };
2669
+
2670
+ // ../community/packages/geometry-editor/src/lib/overrideProvenance.ts
2671
+ var SLOPED_WIDTH_OVERRIDE_DESCRIPTOR = {
2672
+ flag: "_widthUserOverride",
2673
+ key: "_width_user_override",
2674
+ positiveSense: true,
2675
+ since: 1
2676
+ };
2677
+ var SLOPED_HEIGHT_OVERRIDE_DESCRIPTOR = {
2678
+ flag: "_heightUserOverride",
2679
+ key: "_height_user_override",
2680
+ positiveSense: true,
2681
+ since: 1
2682
+ };
2683
+ var PV_BASE_HEIGHT_OVERRIDE_DESCRIPTOR = {
2684
+ flag: "_baseHeightUserOverride",
2685
+ key: "_pv_base_height_user_override",
2686
+ positiveSense: true,
2687
+ since: 1
2688
+ };
2689
+ var PV_PITCH_OVERRIDE_DESCRIPTOR = {
2690
+ flag: "_pitchUserOverride",
2691
+ key: "_pv_pitch_user_override",
2692
+ positiveSense: true,
2693
+ since: 1
2694
+ };
2695
+ var PV_ORIENTATION_OVERRIDE_DESCRIPTOR = {
2696
+ flag: "_orientationUserOverride",
2697
+ key: "_pv_orientation_user_override",
2698
+ positiveSense: true,
2699
+ since: 1
2700
+ };
2701
+ var ELEMENT_NAME_AUTO_SYNC_DESCRIPTOR = {
2702
+ flag: "_nameAutoSync",
2703
+ key: "_name_auto_sync",
2704
+ positiveSense: false,
2705
+ since: 1,
2706
+ absentIsAuthoritative: false
2707
+ };
2708
+ var GROUND_TOTAL_AREA_OVERRIDE_DESCRIPTOR = {
2709
+ flag: "_totalAreaUserOverride",
2710
+ key: "_ground_total_area_manual",
2711
+ positiveSense: true,
2712
+ since: 2
2713
+ };
2714
+ var WINDOW_SECURITY_RISK_OVERRIDE_DESCRIPTOR = {
2715
+ flag: "_windowSecurityRiskUserOverride",
2716
+ key: "_window_security_risk_user_override",
2717
+ positiveSense: true,
2718
+ since: 3
2719
+ };
2720
+ var ZONE_FLOOR_AREA_OVERRIDE_DESCRIPTOR = {
2721
+ flag: "_floorAreaUserOverride",
2722
+ key: "_floor_area_user_override",
2723
+ positiveSense: true,
2724
+ since: 1
2725
+ };
2726
+ var ZONE_HEIGHT_OVERRIDE_DESCRIPTOR = {
2727
+ flag: "_heightUserOverride",
2728
+ key: "_height_user_override",
2729
+ positiveSense: true,
2730
+ since: 1
2731
+ };
2732
+ var FLOOR_HEIGHT_OVERRIDE_DESCRIPTOR = {
2733
+ flag: "heightUserOverride",
2734
+ key: "FloorHeightOverride",
2735
+ positiveSense: true,
2736
+ since: 0
2737
+ };
2738
+ var FLOOR_BASE_HEIGHT_OVERRIDE_DESCRIPTOR = {
2739
+ flag: "baseHeightUserOverride",
2740
+ key: "FloorBaseHeightOverride",
2741
+ positiveSense: true,
2742
+ since: 0
2743
+ };
2744
+ var SPACE_LABEL_NAME_AUTO_SYNC_DESCRIPTOR = {
2745
+ flag: "_nameAutoSync",
2746
+ key: "_name_auto_sync",
2747
+ positiveSense: false,
2748
+ since: 1,
2749
+ absentIsAuthoritative: false
2750
+ };
2751
+ var OVERRIDE_PROVENANCE_REGISTRY = {
2752
+ element: [
2753
+ SLOPED_WIDTH_OVERRIDE_DESCRIPTOR,
2754
+ SLOPED_HEIGHT_OVERRIDE_DESCRIPTOR,
2755
+ PV_BASE_HEIGHT_OVERRIDE_DESCRIPTOR,
2756
+ PV_PITCH_OVERRIDE_DESCRIPTOR,
2757
+ PV_ORIENTATION_OVERRIDE_DESCRIPTOR,
2758
+ ELEMENT_NAME_AUTO_SYNC_DESCRIPTOR,
2759
+ GROUND_TOTAL_AREA_OVERRIDE_DESCRIPTOR,
2760
+ WINDOW_SECURITY_RISK_OVERRIDE_DESCRIPTOR
2761
+ ],
2762
+ zone: [
2763
+ ZONE_FLOOR_AREA_OVERRIDE_DESCRIPTOR,
2764
+ ZONE_HEIGHT_OVERRIDE_DESCRIPTOR
2765
+ ],
2766
+ floor: [FLOOR_HEIGHT_OVERRIDE_DESCRIPTOR, FLOOR_BASE_HEIGHT_OVERRIDE_DESCRIPTOR],
2767
+ spaceLabel: [SPACE_LABEL_NAME_AUTO_SYNC_DESCRIPTOR]
2768
+ };
2769
+ var EXTRA_JSON_OVERRIDE_MARKER_KEYS = [
2770
+ ...new Set([
2771
+ ...OVERRIDE_PROVENANCE_REGISTRY.element,
2772
+ ...OVERRIDE_PROVENANCE_REGISTRY.spaceLabel
2773
+ ].map((descriptor) => descriptor.key))
2774
+ ];
2775
+
2776
+ // ../community/packages/geometry-editor/src/lib/globalSettingsValidation.ts
2777
+ var R_SI_UPWARDS2 = 1 / (5.13 + 5);
2778
+ var R_SE2 = 1 / (20 + 4.14);
2779
+ var TARGET_INPUT_ROWS = [
2780
+ "HasElectricitySmartMeter",
2781
+ "IsExistingBuilding",
2782
+ "Ventilation_cross_vent_possible",
2783
+ "Appliances_has_dryer",
2784
+ "Appliances_has_dishwasher",
2785
+ "Appliances_has_separate_fridge_or_freezer"
2786
+ ];
2787
+ var TARGET_INPUT_ROW_SET = new Set(TARGET_INPUT_ROWS);
2788
+
2789
+ // ../hem-target-runtime/src/hem/pythonFailureMessage.ts
2790
+ var TargetRunError = class extends Error {
2791
+ constructor(message, failure, traceback) {
2792
+ super(message);
2793
+ this.failure = failure;
2794
+ this.traceback = traceback;
2795
+ }
2796
+ };
2797
+
424
2798
  // ../hem-target-runtime/src/hem/preparedRun.ts
425
- async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, write2, progress) {
2799
+ async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, write2, progress, check) {
426
2800
  if (manifest2.bundleId !== bundleId) throw new Error("Worker target identity mismatch");
427
2801
  if (!jobs.length) throw new Error("Batch has no prepared jobs");
428
2802
  const allowedModes = new Set(manifest2.modes);
2803
+ const { resultsKind } = targetWrapper(resolveHemTarget(manifest2.bundleId));
429
2804
  const reservedNames = /* @__PURE__ */ new Set(["model.json", "source.csv", "weather.epw", "target-run.json"]);
430
- for (const [index, job] of jobs.entries()) {
2805
+ for (const job of jobs) {
431
2806
  if (!/^[a-zA-Z0-9_./ -]+$/.test(job.outputDirectory) || job.outputDirectory.split("/").some((segment) => segment === "..") || !job.outputDirectory.startsWith("output/")) throw new Error("Invalid run output path");
432
2807
  if (!job.modes.length || job.modes.some((mode) => !allowedModes.has(mode))) throw new Error("Unsupported calculation mode for selected target");
433
2808
  if (job.archiveDirectory && (!job.archiveDirectory.startsWith(`${job.outputDirectory}/`) || job.archiveDirectory.split("/").some((segment) => segment === ".."))) throw new Error("Invalid archive path");
@@ -435,10 +2810,35 @@ async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, wr
435
2810
  parseHeatingProfile(job.heatingProfile);
436
2811
  if (job.modes.length !== 1 || job.modes[0] !== "actual") throw new Error("Heating profiles require actual alone; they are not FHS compliance calculations");
437
2812
  }
2813
+ }
2814
+ const scenario = (job) => `Scenario ${job.name}${job.parameterFiles?.length ? ` (${job.parameterFiles.join(", ")})` : ""}`;
2815
+ const traceback = (error) => error instanceof TargetRunError ? { traceback: error.traceback } : {};
2816
+ if (check) {
2817
+ const failures = [];
2818
+ for (const [index, job] of jobs.entries()) {
2819
+ progress(index, jobs.length, "Checking");
2820
+ try {
2821
+ await check(job.input);
2822
+ } catch (error) {
2823
+ failures.push({ job, error, message: error instanceof Error ? error.message : String(error) });
2824
+ }
2825
+ }
2826
+ for (const { job, error, message } of failures) {
2827
+ const archive = job.archiveDirectory ?? job.outputDirectory;
2828
+ const record = { target: manifest2, jobId, name: job.name, modes: job.modes, status: "failed", check: true, error: message };
2829
+ await write2(`${archive}/model.json`, job.input);
2830
+ await write2(`${archive}/target-run.json`, JSON.stringify({ ...record, ...traceback(error) }));
2831
+ if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...record, archive }));
2832
+ }
2833
+ if (failures.length) {
2834
+ throw Object.assign(new Error(failures.map(({ job, message }) => `${scenario(job)}: ${message}`).join("\n")), { cause: failures[0].error });
2835
+ }
2836
+ }
2837
+ for (const [index, job] of jobs.entries()) {
438
2838
  const archive = job.archiveDirectory ?? job.outputDirectory;
439
2839
  const inputSha256 = await sha256(new TextEncoder().encode(job.input));
440
2840
  if (job.weather && (!job.weather.epw.trim() || await sha256(new TextEncoder().encode(job.weather.epw)) !== job.weather.sha256)) throw new Error("Prepared weather hash mismatch or empty EPW");
441
- const provenance = { ...job.weather ? { weather: { path: job.weather.path, sha256: job.weather.sha256 } } : {}, ...job.heatingProfile ? { calculationKind: "operating-sensitivity", heatingProfile: job.heatingProfile } : {}, target: manifest2, inputSha256, ...job.preparedBy ? { preparedBy: job.preparedBy } : {}, modes: job.modes, jobId, ...job.startedAt ? { startedAt: job.startedAt } : {}, name: job.name, ...job.warnings?.length ? { warnings: job.warnings } : {} };
2841
+ const provenance = { ...job.weather ? { weather: { path: job.weather.path, sha256: job.weather.sha256 } } : {}, ...job.heatingProfile ? { calculationKind: "operating-sensitivity", heatingProfile: job.heatingProfile } : {}, target: manifest2, resultsKind, inputSha256, ...job.preparedBy ? { preparedBy: job.preparedBy } : {}, modes: job.modes, jobId, ...job.startedAt ? { startedAt: job.startedAt } : {}, name: job.name, ...job.warnings?.length ? { warnings: job.warnings } : {} };
442
2842
  try {
443
2843
  await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "running" }));
444
2844
  if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "running", archive }));
@@ -460,10 +2860,9 @@ async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, wr
460
2860
  await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names }));
461
2861
  } catch (error) {
462
2862
  const message = error instanceof Error ? error.message : String(error);
463
- await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message }));
2863
+ await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message, ...traceback(error) }));
464
2864
  if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message, archive }));
465
- const files = job.parameterFiles?.length ? ` (${job.parameterFiles.join(", ")})` : "";
466
- throw new Error(`Scenario ${job.name}${files}: ${message}`);
2865
+ throw Object.assign(new Error(`${scenario(job)}: ${message}`), { cause: error });
467
2866
  }
468
2867
  }
469
2868
  }
@@ -600,7 +2999,7 @@ async function initialize(bundle) {
600
2999
  url
601
3000
  );
602
3001
  await module.default({ module_or_path: await bytes(bundle.runtime.wasm) });
603
- assertRustTargetVersions(target, module.metadata_hem_core_version?.(), module.metadata_fhs_wrapper_version?.());
3002
+ assertRustTargetVersions(target, module.metadata_hem_core_version?.(), module.metadata_fhs_wrapper_version?.(), module.metadata_hem_core_commit?.(), module.metadata_fhs_wrapper_commit?.());
604
3003
  if (typeof module.initialize_rayon_thread_pool !== "function") throw new Error("Pinned Rust runtime lacks worker pool initialization");
605
3004
  await module.initialize_rayon_thread_pool(1);
606
3005
  supportsWeather = module.target_weather_protocol_version?.() === 1;
@@ -651,3 +3050,29 @@ else self.onmessage = async ({ data }) => {
651
3050
  busy = false;
652
3051
  }
653
3052
  };
3053
+ /*! Bundled license information:
3054
+
3055
+ polygon-clipping/dist/polygon-clipping.umd.js:
3056
+ (**
3057
+ * splaytree v3.1.2
3058
+ * Fast Splay tree for Node and browser
3059
+ *
3060
+ * @author Alexander Milevski <info@w8r.name>
3061
+ * @license MIT
3062
+ * @preserve
3063
+ *)
3064
+ (*! *****************************************************************************
3065
+ Copyright (c) Microsoft Corporation. All rights reserved.
3066
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
3067
+ this file except in compliance with the License. You may obtain a copy of the
3068
+ License at http://www.apache.org/licenses/LICENSE-2.0
3069
+
3070
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
3071
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
3072
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
3073
+ MERCHANTABLITY OR NON-INFRINGEMENT.
3074
+
3075
+ See the Apache Version 2.0 License for specific language governing permissions
3076
+ and limitations under the License.
3077
+ ***************************************************************************** *)
3078
+ */