@vulcan-energy/mcp-helper 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/dist/bin/vulcan-mcp-helper.js +36 -34
- package/dist/hem-target-runtime/browser-adapter.mjs +49 -10
- package/dist/hem-target-runtime/host.mjs +124 -32
- package/dist/hem-target-runtime/preparation.mjs +19241 -11263
- package/dist/hem-target-runtime/python-worker.mjs +3192 -689
- package/dist/hem-target-runtime/release-manifests.mjs +73 -29
- package/dist/hem-target-runtime/rust-worker.mjs +2939 -51
- package/dist/server.js +35 -33
- package/package.json +1 -1
- package/wasm/wasm_version.json +9 -9
- package/wasm/wasm_wrapper.js +6 -6
- package/wasm/wasm_wrapper_bg.wasm +0 -0
|
@@ -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
|
-
|
|
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,50 +2329,90 @@ function targetWrapper(target) {
|
|
|
194
2329
|
if (!wrapper) throw new Error(`Unsupported HEM wrapper: ${target.wrapper}`);
|
|
195
2330
|
return wrapper;
|
|
196
2331
|
}
|
|
197
|
-
|
|
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. v2: v1's pins and patch set plus the design_heat_loss export.
|
|
201
2343
|
{
|
|
202
|
-
id: "rust-fhs-
|
|
203
|
-
label: "
|
|
2344
|
+
id: "rust-fhs-a9-9e41af89-f2c2425f-v2",
|
|
2345
|
+
label: "HEM:FHS 1.0.0a9",
|
|
204
2346
|
runtime: "rust",
|
|
205
|
-
version: "1.0.0a7",
|
|
206
|
-
engineVersion: "1.0.0a7",
|
|
207
|
-
wrapperVersion: "1.0.0a7",
|
|
208
|
-
wrapper: "fhs",
|
|
209
|
-
engineCommit: "62d3df705690f33b3fc3e905c9971d4f3743bf2e",
|
|
210
|
-
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
2347
|
version: "1.0.0a9",
|
|
218
2348
|
engineVersion: "1.0.0a9",
|
|
219
2349
|
wrapperVersion: "1.0.0a9",
|
|
220
2350
|
wrapper: "fhs",
|
|
221
|
-
engineCommit: "
|
|
222
|
-
wrapperCommit: "
|
|
223
|
-
conversionProfile: "python_fhs_a9"
|
|
2351
|
+
engineCommit: "9e41af890cc62a1cec08957340231c3591956dac",
|
|
2352
|
+
wrapperCommit: "f2c2425f00870e1611750bd2ac1be20132301e0d",
|
|
2353
|
+
conversionProfile: "python_fhs_a9",
|
|
2354
|
+
arealHeatCapacity: { classes: "full_depth", numberTypes: ["BuildingElementAdjacentConditionedSpace", "BuildingElementAdjacentUnconditionedSpace_Simple"] },
|
|
2355
|
+
// Measured, example_semi_detached at load 15-21 (15 November): Quick sim click to headline in
|
|
2356
|
+
// the app 7.1-8.6 s (engine 4.9 s, results write 0.7 s); wasm-browser-cli 5.2-7.1 s.
|
|
2357
|
+
// Compliance, all four modes: 48.3-48.6 s in wasm-browser-cli at load 13-19 (13 November).
|
|
2358
|
+
// Method: docs/development/HEM_Rust_A9_Target.md, "Run time".
|
|
2359
|
+
status: "provisional",
|
|
2360
|
+
typicalRunMinutes: { fhs_assumptions: 0.15, fhs_compliance: 0.8 }
|
|
224
2361
|
},
|
|
225
2362
|
{
|
|
226
|
-
id: "
|
|
227
|
-
label: "
|
|
228
|
-
runtime: "
|
|
229
|
-
version: "1.0.
|
|
230
|
-
engineVersion: "1.0.
|
|
231
|
-
wrapperVersion: "1.0.
|
|
2363
|
+
id: "rust-fhs-a7-62d3df70-c5ba2673-v1",
|
|
2364
|
+
label: "HEM:FHS 1.0.0a7",
|
|
2365
|
+
runtime: "rust",
|
|
2366
|
+
version: "1.0.0a7",
|
|
2367
|
+
engineVersion: "1.0.0a7",
|
|
2368
|
+
wrapperVersion: "1.0.0a7",
|
|
232
2369
|
wrapper: "fhs",
|
|
233
|
-
engineCommit: "
|
|
234
|
-
wrapperCommit: "
|
|
235
|
-
conversionProfile: "
|
|
2370
|
+
engineCommit: "62d3df705690f33b3fc3e905c9971d4f3743bf2e",
|
|
2371
|
+
wrapperCommit: "c5ba2673fbd886cfe4fb528f61b376bdf406ebbd",
|
|
2372
|
+
conversionProfile: "current_rust_fhs",
|
|
2373
|
+
arealHeatCapacity: { classes: "surface", numberTypes: [] },
|
|
2374
|
+
// Actual mode, example_semi_detached at load 17-22 (15 November): Quick sim click to headline in
|
|
2375
|
+
// the app 7.9-8.7 s; wasm-browser-cli 6.1-7.1 s. Compliance not measured.
|
|
2376
|
+
status: "legacy",
|
|
2377
|
+
typicalRunMinutes: { fhs_assumptions: 0.12 }
|
|
236
2378
|
}
|
|
237
2379
|
];
|
|
238
2380
|
var RECOMMENDED_HEM_TARGET = HEM_TARGETS[0].id;
|
|
2381
|
+
var HEM_EPC_0_13_2 = {
|
|
2382
|
+
id: "python-epc-0.13.2-6367f1ec-18032feb-v1",
|
|
2383
|
+
label: "HEM:EPC 0.13.2",
|
|
2384
|
+
runtime: "python",
|
|
2385
|
+
version: "0.13.2",
|
|
2386
|
+
engineVersion: "2.0.0a4",
|
|
2387
|
+
wrapperVersion: "0.13.2",
|
|
2388
|
+
wrapper: "epc",
|
|
2389
|
+
engineCommit: "6367f1ecb101c7f72a2006a921c732c790b0d338",
|
|
2390
|
+
wrapperCommit: "18032feb59294b323fc28af4fb032d34bd44bf67",
|
|
2391
|
+
conversionProfile: "epc_full_input_v1",
|
|
2392
|
+
arealHeatCapacity: { classes: "full_depth", numberTypes: "all" },
|
|
2393
|
+
components: {
|
|
2394
|
+
"hem-epc-orchestrator": { version: "0.13.2a0", commit: "993463233ad0c416e83c4de3b84889280d3c4619" },
|
|
2395
|
+
hemie: { version: "0.18.1", commit: "2876e2ec1c7bad2b738c9c3b3685d86860a91f41" },
|
|
2396
|
+
"hem-db-client": { version: "1.0.0a10", commit: "9eeb026dd52a612197b5552ca113d8121fa72679" }
|
|
2397
|
+
},
|
|
2398
|
+
// db-client/data/*.csv at the hem-db-client commit.
|
|
2399
|
+
productDataSha256: "d0acf4ebf050e80f3dc576ffbb1295ebeb1176e9fd4a9ec1d151a9e8f4df7457",
|
|
2400
|
+
// Quick, measured in wasm-browser-cli at load 9-20 (15 November, UAT bundle on main): house_two_storey
|
|
2401
|
+
// new build 473 s, as an existing building 365 s (HEM_EPC_Integration_Plan.md, Status).
|
|
2402
|
+
// Full, estimated: 35 min natively at the measured 2.4-2.6x browser ratio (same plan, Measured).
|
|
2403
|
+
status: "preview",
|
|
2404
|
+
typicalRunMinutes: { epc_quick: 8, epc_full: 90 },
|
|
2405
|
+
estimatedRunMinutes: ["epc_full"]
|
|
2406
|
+
};
|
|
2407
|
+
var UNRELEASED_HEM_TARGETS = [
|
|
2408
|
+
HEM_EPC_0_13_2,
|
|
2409
|
+
// The same pins with the HEM Core engine patch set (scripts/hem-targets/stage-python-core.mjs):
|
|
2410
|
+
// byte-identical outputs, faster passive-duct runs. A short-term fix; not the default until the owner's UAT.
|
|
2411
|
+
{ ...HEM_EPC_0_13_2, id: "python-epc-0.13.2-6367f1ec-18032feb-v2", label: "HEM:EPC 0.13.2 (faster)" }
|
|
2412
|
+
];
|
|
2413
|
+
var findHemTarget = (id) => [...HEM_TARGETS, ...UNRELEASED_HEM_TARGETS].find((target) => target.id === id);
|
|
239
2414
|
function resolveHemTarget(id) {
|
|
240
|
-
const target =
|
|
2415
|
+
const target = findHemTarget(id);
|
|
241
2416
|
if (!target) throw new Error(`HEM target '${id}' is unavailable. Select a supported target explicitly; saved runs are never upgraded automatically.`);
|
|
242
2417
|
return target;
|
|
243
2418
|
}
|
|
@@ -247,9 +2422,11 @@ function modelArtifacts(manifest2) {
|
|
|
247
2422
|
return manifest2.artifacts.filter((artifact) => !artifact.path.startsWith("source/") && !artifact.path.startsWith("notices/") && !converter.includes(artifact.path));
|
|
248
2423
|
}
|
|
249
2424
|
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) {
|
|
2425
|
+
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
2426
|
throw new Error(`Target manifest identity mismatch for ${target.id}`);
|
|
252
2427
|
}
|
|
2428
|
+
const wrapper = targetWrapper(target);
|
|
2429
|
+
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
2430
|
const paths = /* @__PURE__ */ new Set();
|
|
254
2431
|
const sizesByHash = /* @__PURE__ */ new Map();
|
|
255
2432
|
const isRelativePath = (path) => typeof path === "string" && /^[a-zA-Z0-9_./+-]+$/.test(path) && path.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
@@ -266,7 +2443,10 @@ function validateTargetManifest(manifest2, target) {
|
|
|
266
2443
|
if (path.startsWith("source/") || path.startsWith("notices/")) throw new Error(`Runtime/preparation cannot reference reserved source/notice material: ${path}`);
|
|
267
2444
|
if (!paths.has(path)) throw new Error(`Target manifest is missing required artifact ${path}`);
|
|
268
2445
|
}
|
|
269
|
-
if (!manifest2.modes.length || new Set(manifest2.modes).size !== manifest2.modes.length || manifest2.modes.some((mode) => !
|
|
2446
|
+
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`);
|
|
2447
|
+
const { data } = manifest2.runtime;
|
|
2448
|
+
if (!!data !== !!target.productDataSha256) throw new Error("Runtime product data and its pinned hash must be declared together");
|
|
2449
|
+
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
2450
|
if (target.runtime === "rust") {
|
|
271
2451
|
if (!manifest2.runtime.wasm) throw new Error("Rust target manifest is missing its runtime WASM artifact");
|
|
272
2452
|
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 +2458,15 @@ function validateTargetManifest(manifest2, target) {
|
|
|
278
2458
|
for (const file of ["pyodide.asm.js", "pyodide.asm.wasm", "pyodide-lock.json", "python_stdlib.zip"]) {
|
|
279
2459
|
if (!paths.has(`${index}${file}`)) throw new Error(`Python runtime is missing pinned artifact ${index}${file}`);
|
|
280
2460
|
}
|
|
281
|
-
if (requiredVersions?.[
|
|
2461
|
+
if (requiredVersions?.[wrapper.coreDistribution] !== target.engineVersion || requiredVersions?.[wrapper.wrapperDistribution] !== target.wrapperVersion) {
|
|
282
2462
|
throw new Error(`Python runtime must pin matching engine ${target.engineVersion} and wrapper ${target.wrapperVersion} distributions`);
|
|
283
2463
|
}
|
|
2464
|
+
for (const [distribution, { version }] of Object.entries(target.components ?? {})) {
|
|
2465
|
+
if (requiredVersions?.[distribution] !== version) throw new Error(`Python runtime must pin ${distribution} ${version}`);
|
|
2466
|
+
}
|
|
284
2467
|
}
|
|
285
2468
|
}
|
|
2469
|
+
var sortedComponents = (components) => Object.entries(components ?? {}).sort(([a], [b]) => a.localeCompare(b));
|
|
286
2470
|
|
|
287
2471
|
// ../hem-target-runtime/src/hem/targetAssets.ts
|
|
288
2472
|
var CACHE = "vulcan-hem-artifacts-v1";
|
|
@@ -421,32 +2605,685 @@ var TargetAssets = class _TargetAssets {
|
|
|
421
2605
|
}
|
|
422
2606
|
};
|
|
423
2607
|
|
|
2608
|
+
// ../hem-target-runtime/src/hem/workspaceName.ts
|
|
2609
|
+
var NON_PORTABLE_NAME_CHARACTERS = /[<>:"|?*]/;
|
|
2610
|
+
var hasControlCharacter = (name) => [...name].some((character) => character.charCodeAt(0) < 32);
|
|
2611
|
+
function isWorkspaceName(name) {
|
|
2612
|
+
return typeof name === "string" && name.trim() !== "" && !/[\\/]/.test(name) && !NON_PORTABLE_NAME_CHARACTERS.test(name) && !hasControlCharacter(name) && !name.startsWith(".") && !/[. ]$/.test(name);
|
|
2613
|
+
}
|
|
2614
|
+
function isRunOutputPath(path) {
|
|
2615
|
+
const segments = path.split("/");
|
|
2616
|
+
return segments[0] === "output" && segments.length > 1 && segments.slice(1).every(isWorkspaceName);
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
// ../community/packages/geometry-editor/src/lib/issueTarget.ts
|
|
2620
|
+
var issuePathSegments = (path) => (path ?? "").split("/").filter(Boolean).map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
2621
|
+
|
|
2622
|
+
// ../community/packages/geometry-editor/src/lib/hemieFabric.ts
|
|
2623
|
+
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(" "));
|
|
2624
|
+
var HEMIE_NATION = "HEMIE_nation";
|
|
2625
|
+
var ROOF_DETAILS = ["ceiling_thickness", "ceiling_thermal_conductivity", "joist_depth", "percentage_area_of_timber_joists", "insulation_thermal_conductivity"];
|
|
2626
|
+
var LOFT_DETAILS = [...ROOF_DETAILS, "rafter_depth", "percentage_area_of_timber_rafters", "roof_characteristics", "air_gap_thermal_resistance"];
|
|
2627
|
+
var WALL_FINISHES = {
|
|
2628
|
+
Brick: "BrickFinish",
|
|
2629
|
+
Render: "RenderFinish",
|
|
2630
|
+
Timber: "TimberFinish",
|
|
2631
|
+
"Metal (uncoated)": "MetalUncoatedFinish",
|
|
2632
|
+
"Metal (coated)": "MetalCoatedFinish",
|
|
2633
|
+
"Fibre-cement": "FibreCementWallFinish",
|
|
2634
|
+
"Composite panels (metal skins)": "CompositePanelsFinish"
|
|
2635
|
+
};
|
|
2636
|
+
var ROOF_FINISHES = {
|
|
2637
|
+
"Concrete roof tile": "ConcreteRoofTileFinish",
|
|
2638
|
+
"Clay tile": "ClayTileFinish",
|
|
2639
|
+
Slate: "SlateFinish",
|
|
2640
|
+
Asphalt: "AsphaltFinish",
|
|
2641
|
+
Timber: "TimberFinish",
|
|
2642
|
+
"Metal (uncoated)": "MetalUncoatedFinish",
|
|
2643
|
+
"Metal (coated)": "MetalCoatedFinish",
|
|
2644
|
+
"Fibre-cement": "FibreCementRoofFinish",
|
|
2645
|
+
"Composite panels (metal skins)": "CompositePanelsFinish"
|
|
2646
|
+
};
|
|
2647
|
+
var DOOR_FINISHES = {
|
|
2648
|
+
Timber: "TimberFinish",
|
|
2649
|
+
"Metal (uncoated)": "MetalUncoatedFinish",
|
|
2650
|
+
"Metal (coated)": "MetalCoatedFinish",
|
|
2651
|
+
"Composite panels (metal skins)": "CompositePanelsFinish"
|
|
2652
|
+
};
|
|
2653
|
+
var PARK_HOME_WALL_FINISHES = {
|
|
2654
|
+
"uPVC vinyl / Plastic": "ParkHomePlasticFinish",
|
|
2655
|
+
"Stucco / Aggregate paint": "ParkHomePaintFinish",
|
|
2656
|
+
"Timber / Wood cladding": "ParkHomeTimberFinish",
|
|
2657
|
+
"CanExel / Engineered HDF": "ParkHomeHDFFinish"
|
|
2658
|
+
};
|
|
2659
|
+
var SURFACE_FINISHES = {
|
|
2660
|
+
external_wall: WALL_FINISHES,
|
|
2661
|
+
external_door: DOOR_FINISHES,
|
|
2662
|
+
park_home_wall: PARK_HOME_WALL_FINISHES,
|
|
2663
|
+
flat_roof: ROOF_FINISHES,
|
|
2664
|
+
unheated_pitched_roof: ROOF_FINISHES,
|
|
2665
|
+
heated_pitched_roof: ROOF_FINISHES,
|
|
2666
|
+
mini_flat_roof: ROOF_FINISHES,
|
|
2667
|
+
mini_pitched_roof: ROOF_FINISHES,
|
|
2668
|
+
park_home_flat_roof: ROOF_FINISHES,
|
|
2669
|
+
park_home_pitched_roof: ROOF_FINISHES
|
|
2670
|
+
};
|
|
2671
|
+
var OUTSIDE_SURFACE_TYPES = /* @__PURE__ */ new Set([...Object.keys(SURFACE_FINISHES), "above_external_area_floor", "park_home_floor", "thatched_roof"]);
|
|
2672
|
+
var words = (value) => value.charAt(0).toUpperCase() + value.slice(1).replace(/_/g, " ");
|
|
2673
|
+
var CONSTRUCTION_TYPE_LABELS = {
|
|
2674
|
+
not_edge_insulated_ground_attached_floor: "Ground floor, no edge insulation",
|
|
2675
|
+
edge_insulated_ground_attached_floor: "Ground floor, edge insulated"
|
|
2676
|
+
};
|
|
2677
|
+
var hemieConstructionTypeLabel = (type) => CONSTRUCTION_TYPE_LABELS[type] ?? words(type);
|
|
2678
|
+
|
|
2679
|
+
// ../community/packages/geometry-editor/src/lib/zoneDerivation.ts
|
|
2680
|
+
var import_polygon_clipping2 = __toESM(require_polygon_clipping_umd(), 1);
|
|
2681
|
+
|
|
2682
|
+
// ../community/packages/geometry-editor/src/lib/polygonSync.ts
|
|
2683
|
+
var import_polygon_clipping = __toESM(require_polygon_clipping_umd(), 1);
|
|
2684
|
+
|
|
2685
|
+
// ../community/packages/geometry-editor/src/lib/roofCutouts.ts
|
|
2686
|
+
var import_polygon_clipping4 = __toESM(require_polygon_clipping_umd(), 1);
|
|
2687
|
+
|
|
2688
|
+
// ../community/packages/geometry-editor/src/lib/geometry3dMapper.ts
|
|
2689
|
+
var import_polygon_clipping3 = __toESM(require_polygon_clipping_umd(), 1);
|
|
2690
|
+
|
|
2691
|
+
// ../community/packages/geometry-editor/src/lib/assemblyCalculator.ts
|
|
2692
|
+
var H_RI = 5.13;
|
|
2693
|
+
var H_CI_UPWARDS = 5;
|
|
2694
|
+
var H_CI_HORIZONTAL = 2.5;
|
|
2695
|
+
var H_CI_DOWNWARDS = 0.7;
|
|
2696
|
+
var H_CE = 20;
|
|
2697
|
+
var H_RE = 4.14;
|
|
2698
|
+
var R_SI_HORIZONTAL = 1 / (H_RI + H_CI_HORIZONTAL);
|
|
2699
|
+
var R_SI_UPWARDS = 1 / (H_RI + H_CI_UPWARDS);
|
|
2700
|
+
var R_SI_DOWNWARDS = 1 / (H_RI + H_CI_DOWNWARDS);
|
|
2701
|
+
var R_SE = 1 / (H_CE + H_RE);
|
|
2702
|
+
|
|
2703
|
+
// ../community/packages/geometry-editor/src/lib/assemblyMassHeuristic.ts
|
|
2704
|
+
var FHS_MASS_DISTRIBUTION_CLASS_BY_CODE = {
|
|
2705
|
+
I: "I: Mass concentrated at internal side",
|
|
2706
|
+
E: "E: Mass concentrated at external side",
|
|
2707
|
+
IE: "IE: Mass divided over internal and external side",
|
|
2708
|
+
D: "D: Mass equally distributed",
|
|
2709
|
+
M: "M: Mass concentrated inside"
|
|
2710
|
+
};
|
|
2711
|
+
var FHS_MASS_DISTRIBUTION_CLASS_VALUES = new Set(
|
|
2712
|
+
Object.values(FHS_MASS_DISTRIBUTION_CLASS_BY_CODE)
|
|
2713
|
+
);
|
|
2714
|
+
|
|
2715
|
+
// ../community/packages/geometry-editor/src/lib/assemblyAppliedUi.ts
|
|
2716
|
+
var MASS_CLASS_MEANINGS = {
|
|
2717
|
+
I: "Mass mainly on the room side (e.g. external insulation).",
|
|
2718
|
+
E: "Mass mainly on the external side (e.g. internal insulation).",
|
|
2719
|
+
IE: "Mass on both sides of the insulation (e.g. filled cavity).",
|
|
2720
|
+
D: "Evenly distributed or negligible mass (e.g. uninsulated solid, lightweight).",
|
|
2721
|
+
M: "Mass near the middle (insulation both sides of the structural leaf)."
|
|
2722
|
+
};
|
|
2723
|
+
var FHS_MASS_CLASS_COMMENTARY = {
|
|
2724
|
+
"I: Mass concentrated at internal side": MASS_CLASS_MEANINGS.I,
|
|
2725
|
+
"E: Mass concentrated at external side": MASS_CLASS_MEANINGS.E,
|
|
2726
|
+
"IE: Mass divided over internal and external side": MASS_CLASS_MEANINGS.IE,
|
|
2727
|
+
"D: Mass equally distributed": MASS_CLASS_MEANINGS.D,
|
|
2728
|
+
"M: Mass concentrated inside": MASS_CLASS_MEANINGS.M
|
|
2729
|
+
};
|
|
2730
|
+
|
|
2731
|
+
// ../community/packages/geometry-editor-host/src/schemaPort.ts
|
|
2732
|
+
var A7_AREAL_HEAT_CAPACITY_INPUT = Object.freeze({ classes: "surface", numberTypes: Object.freeze([]) });
|
|
2733
|
+
function unavailable(operation) {
|
|
2734
|
+
throw new Error(`Geometry schema ${operation} is unavailable`);
|
|
2735
|
+
}
|
|
2736
|
+
var unavailableGeometrySchemaPort = Object.freeze({
|
|
2737
|
+
availability: "unavailable",
|
|
2738
|
+
preload: async () => unavailable("preload"),
|
|
2739
|
+
getRootSchema: () => unavailable("root lookup"),
|
|
2740
|
+
getElementSubschema: () => unavailable("element lookup"),
|
|
2741
|
+
getBaseFieldsForElementType: () => unavailable("base-field lookup"),
|
|
2742
|
+
getApplianceKeys: () => unavailable("appliance-key lookup"),
|
|
2743
|
+
getStrictestIntegerKeysForElementType: () => unavailable("numeric-typing lookup"),
|
|
2744
|
+
getSchemaSubtypeForElementData: () => unavailable("subtype lookup"),
|
|
2745
|
+
getConditionalRequiredFields: () => unavailable("conditional-required lookup"),
|
|
2746
|
+
validateProperty: () => unavailable("property validation"),
|
|
2747
|
+
findParameter: () => unavailable("parameter lookup")
|
|
2748
|
+
});
|
|
2749
|
+
|
|
2750
|
+
// ../community/packages/geometry-editor/src/lib/overrideProvenance.ts
|
|
2751
|
+
var SLOPED_WIDTH_OVERRIDE_DESCRIPTOR = {
|
|
2752
|
+
flag: "_widthUserOverride",
|
|
2753
|
+
key: "_width_user_override",
|
|
2754
|
+
positiveSense: true,
|
|
2755
|
+
since: 1
|
|
2756
|
+
};
|
|
2757
|
+
var SLOPED_HEIGHT_OVERRIDE_DESCRIPTOR = {
|
|
2758
|
+
flag: "_heightUserOverride",
|
|
2759
|
+
key: "_height_user_override",
|
|
2760
|
+
positiveSense: true,
|
|
2761
|
+
since: 1
|
|
2762
|
+
};
|
|
2763
|
+
var PV_BASE_HEIGHT_OVERRIDE_DESCRIPTOR = {
|
|
2764
|
+
flag: "_baseHeightUserOverride",
|
|
2765
|
+
key: "_pv_base_height_user_override",
|
|
2766
|
+
positiveSense: true,
|
|
2767
|
+
since: 1
|
|
2768
|
+
};
|
|
2769
|
+
var PV_PITCH_OVERRIDE_DESCRIPTOR = {
|
|
2770
|
+
flag: "_pitchUserOverride",
|
|
2771
|
+
key: "_pv_pitch_user_override",
|
|
2772
|
+
positiveSense: true,
|
|
2773
|
+
since: 1
|
|
2774
|
+
};
|
|
2775
|
+
var PV_ORIENTATION_OVERRIDE_DESCRIPTOR = {
|
|
2776
|
+
flag: "_orientationUserOverride",
|
|
2777
|
+
key: "_pv_orientation_user_override",
|
|
2778
|
+
positiveSense: true,
|
|
2779
|
+
since: 1
|
|
2780
|
+
};
|
|
2781
|
+
var ELEMENT_NAME_AUTO_SYNC_DESCRIPTOR = {
|
|
2782
|
+
flag: "_nameAutoSync",
|
|
2783
|
+
key: "_name_auto_sync",
|
|
2784
|
+
positiveSense: false,
|
|
2785
|
+
since: 1,
|
|
2786
|
+
absentIsAuthoritative: false
|
|
2787
|
+
};
|
|
2788
|
+
var GROUND_TOTAL_AREA_OVERRIDE_DESCRIPTOR = {
|
|
2789
|
+
flag: "_totalAreaUserOverride",
|
|
2790
|
+
key: "_ground_total_area_manual",
|
|
2791
|
+
positiveSense: true,
|
|
2792
|
+
since: 2
|
|
2793
|
+
};
|
|
2794
|
+
var WINDOW_SECURITY_RISK_OVERRIDE_DESCRIPTOR = {
|
|
2795
|
+
flag: "_windowSecurityRiskUserOverride",
|
|
2796
|
+
key: "_window_security_risk_user_override",
|
|
2797
|
+
positiveSense: true,
|
|
2798
|
+
since: 3
|
|
2799
|
+
};
|
|
2800
|
+
var ZONE_FLOOR_AREA_OVERRIDE_DESCRIPTOR = {
|
|
2801
|
+
flag: "_floorAreaUserOverride",
|
|
2802
|
+
key: "_floor_area_user_override",
|
|
2803
|
+
positiveSense: true,
|
|
2804
|
+
since: 1
|
|
2805
|
+
};
|
|
2806
|
+
var ZONE_HEIGHT_OVERRIDE_DESCRIPTOR = {
|
|
2807
|
+
flag: "_heightUserOverride",
|
|
2808
|
+
key: "_height_user_override",
|
|
2809
|
+
positiveSense: true,
|
|
2810
|
+
since: 1
|
|
2811
|
+
};
|
|
2812
|
+
var FLOOR_HEIGHT_OVERRIDE_DESCRIPTOR = {
|
|
2813
|
+
flag: "heightUserOverride",
|
|
2814
|
+
key: "FloorHeightOverride",
|
|
2815
|
+
positiveSense: true,
|
|
2816
|
+
since: 0
|
|
2817
|
+
};
|
|
2818
|
+
var FLOOR_BASE_HEIGHT_OVERRIDE_DESCRIPTOR = {
|
|
2819
|
+
flag: "baseHeightUserOverride",
|
|
2820
|
+
key: "FloorBaseHeightOverride",
|
|
2821
|
+
positiveSense: true,
|
|
2822
|
+
since: 0
|
|
2823
|
+
};
|
|
2824
|
+
var SPACE_LABEL_NAME_AUTO_SYNC_DESCRIPTOR = {
|
|
2825
|
+
flag: "_nameAutoSync",
|
|
2826
|
+
key: "_name_auto_sync",
|
|
2827
|
+
positiveSense: false,
|
|
2828
|
+
since: 1,
|
|
2829
|
+
absentIsAuthoritative: false
|
|
2830
|
+
};
|
|
2831
|
+
var OVERRIDE_PROVENANCE_REGISTRY = {
|
|
2832
|
+
element: [
|
|
2833
|
+
SLOPED_WIDTH_OVERRIDE_DESCRIPTOR,
|
|
2834
|
+
SLOPED_HEIGHT_OVERRIDE_DESCRIPTOR,
|
|
2835
|
+
PV_BASE_HEIGHT_OVERRIDE_DESCRIPTOR,
|
|
2836
|
+
PV_PITCH_OVERRIDE_DESCRIPTOR,
|
|
2837
|
+
PV_ORIENTATION_OVERRIDE_DESCRIPTOR,
|
|
2838
|
+
ELEMENT_NAME_AUTO_SYNC_DESCRIPTOR,
|
|
2839
|
+
GROUND_TOTAL_AREA_OVERRIDE_DESCRIPTOR,
|
|
2840
|
+
WINDOW_SECURITY_RISK_OVERRIDE_DESCRIPTOR
|
|
2841
|
+
],
|
|
2842
|
+
zone: [
|
|
2843
|
+
ZONE_FLOOR_AREA_OVERRIDE_DESCRIPTOR,
|
|
2844
|
+
ZONE_HEIGHT_OVERRIDE_DESCRIPTOR
|
|
2845
|
+
],
|
|
2846
|
+
floor: [FLOOR_HEIGHT_OVERRIDE_DESCRIPTOR, FLOOR_BASE_HEIGHT_OVERRIDE_DESCRIPTOR],
|
|
2847
|
+
spaceLabel: [SPACE_LABEL_NAME_AUTO_SYNC_DESCRIPTOR]
|
|
2848
|
+
};
|
|
2849
|
+
var EXTRA_JSON_OVERRIDE_MARKER_KEYS = [
|
|
2850
|
+
...new Set([
|
|
2851
|
+
...OVERRIDE_PROVENANCE_REGISTRY.element,
|
|
2852
|
+
...OVERRIDE_PROVENANCE_REGISTRY.spaceLabel
|
|
2853
|
+
].map((descriptor) => descriptor.key))
|
|
2854
|
+
];
|
|
2855
|
+
|
|
2856
|
+
// ../community/packages/geometry-editor/src/lib/globalSettingsValidation.ts
|
|
2857
|
+
var R_SI_UPWARDS2 = 1 / (5.13 + 5);
|
|
2858
|
+
var R_SE2 = 1 / (20 + 4.14);
|
|
2859
|
+
var DWELLING_FIELD_KEYS = /* @__PURE__ */ new Set([
|
|
2860
|
+
"Postcode",
|
|
2861
|
+
"PartO_active_cooling_required",
|
|
2862
|
+
"GroundFloorArea",
|
|
2863
|
+
"HeatingControlType",
|
|
2864
|
+
"PartGcompliance",
|
|
2865
|
+
"ColdWaterSource",
|
|
2866
|
+
"BuildingLength",
|
|
2867
|
+
"BuildingWidth",
|
|
2868
|
+
"KitchenExtractorHoodExternal",
|
|
2869
|
+
"HasElectricitySmartMeter",
|
|
2870
|
+
"ElectricitySmartMeterGUID"
|
|
2871
|
+
]);
|
|
2872
|
+
function globalSettingsFieldSection(key) {
|
|
2873
|
+
if (key === "DefaultsPath" || key.startsWith("DefaultAssembly") || key.startsWith("FabricRow_") || key === "HEMIE_age_band" || key.startsWith("HEMIE_construction_")) return "fabric";
|
|
2874
|
+
if (key === "TargetBundleId" || key === "IsExistingBuilding" || key.startsWith("HEMIE_")) return "target";
|
|
2875
|
+
if (key.startsWith("AirPermeability_test_")) return "airTightness";
|
|
2876
|
+
if (key.startsWith("Ventilation_") || key === "AirPermeability_ventilation_zone_height") return "ventilation";
|
|
2877
|
+
if (key === "JunctionPsiDefaultsPath" || key.startsWith("DetailedBridgePsiProfile")) return "thermalBridging";
|
|
2878
|
+
if (key.startsWith("General_") || key.startsWith("NumberOf") || key.startsWith("Appliances_") || DWELLING_FIELD_KEYS.has(key)) return "dwelling";
|
|
2879
|
+
return null;
|
|
2880
|
+
}
|
|
2881
|
+
var METADATA_INPUT_LABELS = {
|
|
2882
|
+
NumberOfBedrooms: "Number of bedrooms",
|
|
2883
|
+
NumberOfWetRooms: "Number of wet rooms",
|
|
2884
|
+
GroundFloorArea: "Ground floor area (m\xB2)",
|
|
2885
|
+
HeatingControlType: "Heating control type",
|
|
2886
|
+
PartGcompliance: "Part G compliance",
|
|
2887
|
+
PartO_active_cooling_required: "Part O active cooling required",
|
|
2888
|
+
AirPermeability_test_pressure: "Test pressure",
|
|
2889
|
+
AirPermeability_test_result: "Test result",
|
|
2890
|
+
AirPermeability_ventilation_zone_height: "Ventilation zone height (m)",
|
|
2891
|
+
Ventilation_shield_class: "Shield class",
|
|
2892
|
+
Ventilation_terrain_class: "Terrain class",
|
|
2893
|
+
Ventilation_altitude: "Altitude (m)",
|
|
2894
|
+
Ventilation_ventilation_zone_base_height: "Ventilation zone base height (m)",
|
|
2895
|
+
Ventilation_noise_nuisance: "Noise nuisance",
|
|
2896
|
+
BuildingLength: "Building length (m)",
|
|
2897
|
+
BuildingWidth: "Building width (m)",
|
|
2898
|
+
NumberOfHotTappedRooms: "Number of hot-tapped rooms",
|
|
2899
|
+
NumberOfUtilityRooms: "Number of utility rooms",
|
|
2900
|
+
NumberOfBathrooms: "Number of bathrooms",
|
|
2901
|
+
NumberOfSanitaryAccommodations: "Number of sanitary accommodations",
|
|
2902
|
+
NumberOfHabitableRooms: "Number of habitable rooms",
|
|
2903
|
+
KitchenExtractorHoodExternal: "Kitchen cooker hood extracts to outside",
|
|
2904
|
+
General_build_type: "Build type",
|
|
2905
|
+
General_built_form: "SAP built form",
|
|
2906
|
+
General_storeys_in_dwelling: "Storeys in dwelling",
|
|
2907
|
+
General_storey_of_dwelling: "Storey of dwelling",
|
|
2908
|
+
General_storeys_in_building: "Storeys in building",
|
|
2909
|
+
HasElectricitySmartMeter: "Electricity smart meter",
|
|
2910
|
+
ElectricitySmartMeterGUID: "Smart meter GUID",
|
|
2911
|
+
IsExistingBuilding: "Existing building",
|
|
2912
|
+
Ventilation_cross_vent_possible: "Cross ventilation possible",
|
|
2913
|
+
Appliances_has_dryer: "Has a clothes dryer",
|
|
2914
|
+
Appliances_has_dishwasher: "Has a dishwasher",
|
|
2915
|
+
Appliances_has_separate_fridge_or_freezer: "Has a separate fridge or freezer"
|
|
2916
|
+
};
|
|
2917
|
+
var TARGET_INPUT_ROWS = [
|
|
2918
|
+
"HasElectricitySmartMeter",
|
|
2919
|
+
"IsExistingBuilding",
|
|
2920
|
+
"Ventilation_cross_vent_possible",
|
|
2921
|
+
"Appliances_has_dryer",
|
|
2922
|
+
"Appliances_has_dishwasher",
|
|
2923
|
+
"Appliances_has_separate_fridge_or_freezer"
|
|
2924
|
+
];
|
|
2925
|
+
var TARGET_INPUT_ROW_SET = new Set(TARGET_INPUT_ROWS);
|
|
2926
|
+
|
|
2927
|
+
// ../community/packages/geometry-editor/src/lib/buildErrorDisplay.ts
|
|
2928
|
+
var SECTION_LOCATIONS = {
|
|
2929
|
+
fabric: "Global Settings > Fabric",
|
|
2930
|
+
target: "Global Settings",
|
|
2931
|
+
dwelling: "Global Settings > Dwelling details",
|
|
2932
|
+
airTightness: "Global Settings > Air Tightness",
|
|
2933
|
+
ventilation: "Global Settings > Ventilation environment",
|
|
2934
|
+
thermalBridging: "Global Settings > Thermal bridging"
|
|
2935
|
+
};
|
|
2936
|
+
var VENTILATION_SETTINGS = /* @__PURE__ */ new Set(["cross_vent_possible", "terrain_class", "altitude", "shield_class", "noise_nuisance", "ventilation_zone_base_height"]);
|
|
2937
|
+
var settingsRow = (segments) => {
|
|
2938
|
+
if (segments[0] === "Metadata") return segments[1];
|
|
2939
|
+
if (segments[0] !== "InfiltrationVentilation") return void 0;
|
|
2940
|
+
if (segments[1] === "Leaks") {
|
|
2941
|
+
return segments[2] === "ventilation_zone_height" ? "AirPermeability_ventilation_zone_height" : "AirPermeability_test_result";
|
|
2942
|
+
}
|
|
2943
|
+
return segments[1] && VENTILATION_SETTINGS.has(segments[1]) ? `Ventilation_${segments[1]}` : void 0;
|
|
2944
|
+
};
|
|
2945
|
+
var titleCaseToken = (token) => token.replace(/_/g, " ").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/\s+/g, " ").trim().replace(/\b\w/g, (c) => c.toUpperCase());
|
|
2946
|
+
var pointerSegments = issuePathSegments;
|
|
2947
|
+
var buildErrorLocation = (path) => {
|
|
2948
|
+
const segments = pointerSegments(path);
|
|
2949
|
+
const zoneIdx = segments.indexOf("Zone");
|
|
2950
|
+
const elementIdx = segments.indexOf("BuildingElement");
|
|
2951
|
+
if (zoneIdx >= 0 && segments[zoneIdx + 1]) {
|
|
2952
|
+
const zone = segments[zoneIdx + 1];
|
|
2953
|
+
if (elementIdx >= 0 && segments[elementIdx + 1]) {
|
|
2954
|
+
return {
|
|
2955
|
+
location: `${zone} > ${segments[elementIdx + 1]}`,
|
|
2956
|
+
field: segments[elementIdx + 2]
|
|
2957
|
+
};
|
|
2958
|
+
}
|
|
2959
|
+
return {
|
|
2960
|
+
location: zone,
|
|
2961
|
+
field: segments[zoneIdx + 2]
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
if (segments[0] === "Metadata" && segments[1]?.startsWith("HEMIE_")) {
|
|
2965
|
+
const constructionType = segments[1].match(/^HEMIE_construction_(.+)$/)?.[1];
|
|
2966
|
+
return {
|
|
2967
|
+
location: segments[1] === HEMIE_NATION ? "Global Settings > Dwelling details" : `Global Settings > Fabric${constructionType ? ` > ${hemieConstructionTypeLabel(constructionType)}` : ""}`
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
const row = settingsRow(segments);
|
|
2971
|
+
const section = row ? globalSettingsFieldSection(row) : null;
|
|
2972
|
+
if (section) return { location: SECTION_LOCATIONS[section] };
|
|
2973
|
+
if (segments.length >= 2) {
|
|
2974
|
+
return {
|
|
2975
|
+
location: `${titleCaseToken(segments[0])} > ${titleCaseToken(segments[1])}`,
|
|
2976
|
+
field: segments[2]
|
|
2977
|
+
};
|
|
2978
|
+
}
|
|
2979
|
+
if (segments.length === 1) {
|
|
2980
|
+
return { location: titleCaseToken(segments[0]) };
|
|
2981
|
+
}
|
|
2982
|
+
return { location: "Model" };
|
|
2983
|
+
};
|
|
2984
|
+
var compactPathLabel = (segments) => {
|
|
2985
|
+
if (segments.length === 0) return "model";
|
|
2986
|
+
return segments.map(titleCaseToken).join(" > ");
|
|
2987
|
+
};
|
|
2988
|
+
var requiredFieldFromMessage = (message) => {
|
|
2989
|
+
const match = message.match(/^"([^"]+)" is a required property$/);
|
|
2990
|
+
return match?.[1] ? titleCaseToken(match[1]) : null;
|
|
2991
|
+
};
|
|
2992
|
+
var minimumFromMessage = (message) => {
|
|
2993
|
+
const match = message.match(/^(.+?) is less than the minimum of (.+)$/);
|
|
2994
|
+
return match?.[2]?.trim() || null;
|
|
2995
|
+
};
|
|
2996
|
+
var maximumFromMessage = (message) => {
|
|
2997
|
+
const match = message.match(/^(.+?) is greater than the maximum of (.+)$/);
|
|
2998
|
+
return match?.[2]?.trim() || null;
|
|
2999
|
+
};
|
|
3000
|
+
var unexpectedFieldsFromMessage = (message) => {
|
|
3001
|
+
const match = message.match(/were unexpected\)$/);
|
|
3002
|
+
if (!match) return null;
|
|
3003
|
+
const fields = [...message.matchAll(/'([^']+)'/g)].flatMap((m) => m[1] ? [m[1]] : []);
|
|
3004
|
+
if (fields.length === 0) return null;
|
|
3005
|
+
const shown = fields.slice(0, 5).map(titleCaseToken).join(", ");
|
|
3006
|
+
return fields.length > 5 ? `${shown}, and ${fields.length - 5} more` : shown;
|
|
3007
|
+
};
|
|
3008
|
+
var isSchemaKeywordError = (item) => Boolean(item.keyword || item.schemaPath);
|
|
3009
|
+
var formatBuildErrorForDisplay = (item) => {
|
|
3010
|
+
const pathSegments = pointerSegments(item.path);
|
|
3011
|
+
const { location, field } = buildErrorLocation(item.path);
|
|
3012
|
+
const fieldLabel = field ? titleCaseToken(field) : void 0;
|
|
3013
|
+
const keyword = item.keyword || "";
|
|
3014
|
+
const requiredField = requiredFieldFromMessage(item.message);
|
|
3015
|
+
const minimum = minimumFromMessage(item.message);
|
|
3016
|
+
const maximum = maximumFromMessage(item.message);
|
|
3017
|
+
const unexpectedFields = unexpectedFieldsFromMessage(item.message);
|
|
3018
|
+
const explicitUserMessage = item.userMessage?.trim();
|
|
3019
|
+
const unstatedInput = item.code === "E_EPC_REQUIRED_INPUT" && pathSegments[0] === "Metadata" && pathSegments[1] ? METADATA_INPUT_LABELS[pathSegments[1]] : void 0;
|
|
3020
|
+
let userMessage;
|
|
3021
|
+
if (explicitUserMessage) {
|
|
3022
|
+
userMessage = explicitUserMessage;
|
|
3023
|
+
} else if (unstatedInput) {
|
|
3024
|
+
const label = /^[A-Z][a-z]/.test(unstatedInput) && !/^Part\b/.test(unstatedInput) ? unstatedInput[0].toLowerCase() + unstatedInput.slice(1) : unstatedInput;
|
|
3025
|
+
userMessage = TARGET_INPUT_ROW_SET.has(pathSegments[1]) ? `Choose yes or no for ${label}.` : `Enter ${label}.`;
|
|
3026
|
+
} else if (location === "Appliances" && (item.message.includes("is not allowed for {}") || item.message.includes("has less than"))) {
|
|
3027
|
+
userMessage = "Add at least one appliance entry.";
|
|
3028
|
+
} else if (pathSegments[0] === "HotWaterDemand" && (item.message.includes("has less than") || keyword === "minProperties")) {
|
|
3029
|
+
userMessage = "Add at least one hot water outlet.";
|
|
3030
|
+
} else if (pathSegments[0] === "Zone" && pathSegments[2] === "Lighting" && pathSegments.length === 3 && item.message.startsWith("null ")) {
|
|
3031
|
+
userMessage = "Add at least one light to this zone.";
|
|
3032
|
+
} else if (pathSegments[0] === "InfiltrationVentilation" && pathSegments[1] === "MechanicalVentilation" && (item.message.includes("schemas listed in the 'oneOf' keyword") || keyword === "oneOf" || keyword === "anyOf")) {
|
|
3033
|
+
userMessage = "Add ventilation position details: height, orientation, and pitch.";
|
|
3034
|
+
} else if (requiredField || keyword === "required") {
|
|
3035
|
+
userMessage = requiredField ? `Add ${requiredField}.` : "Add the missing required field.";
|
|
3036
|
+
} else if (minimum || keyword === "minimum" || keyword === "exclusiveMinimum") {
|
|
3037
|
+
userMessage = `${fieldLabel || "Value"} must be at least ${minimum || "the allowed minimum"}.`;
|
|
3038
|
+
} else if (maximum || keyword === "maximum" || keyword === "exclusiveMaximum") {
|
|
3039
|
+
userMessage = `${fieldLabel || "Value"} must be no more than ${maximum || "the allowed maximum"}.`;
|
|
3040
|
+
} else if (item.message.includes("has less than") || keyword === "minProperties") {
|
|
3041
|
+
userMessage = `Add at least one entry for ${compactPathLabel(pathSegments)}.`;
|
|
3042
|
+
} else if (item.message.includes("schemas listed in the 'oneOf' keyword") || keyword === "oneOf" || keyword === "anyOf") {
|
|
3043
|
+
userMessage = fieldLabel ? `${fieldLabel} does not match an allowed option.` : `${compactPathLabel(pathSegments)} matches none of the forms this HEM version takes. Check its type and the inputs it states.`;
|
|
3044
|
+
} else if (unexpectedFields || keyword === "unevaluatedProperties" || keyword === "additionalProperties") {
|
|
3045
|
+
userMessage = unexpectedFields ? `Remove fields not allowed here: ${unexpectedFields}.` : "Remove fields that are not allowed here.";
|
|
3046
|
+
} else if (keyword === "const" || keyword === "allOf" || item.message.includes("is not allowed for")) {
|
|
3047
|
+
userMessage = location === "Appliances" ? "Check the appliance entries against the selected schema." : "These settings conflict with the selected schema.";
|
|
3048
|
+
} else if (!isSchemaKeywordError(item)) {
|
|
3049
|
+
userMessage = item.message.split("\n")[0];
|
|
3050
|
+
} else {
|
|
3051
|
+
userMessage = fieldLabel ? `Check ${fieldLabel}.` : "Check this section.";
|
|
3052
|
+
}
|
|
3053
|
+
return { item, location, field, userMessage, pathSegments };
|
|
3054
|
+
};
|
|
3055
|
+
var isNoisyUnexpectedPropertiesError = (error) => error.item.keyword === "unevaluatedProperties" || error.item.keyword === "additionalProperties" || error.item.message.includes("Unevaluated properties are not allowed") || error.item.message.includes("Additional properties are not allowed");
|
|
3056
|
+
var filterDisplayBuildErrors = (errors) => {
|
|
3057
|
+
const concreteErrorParents = /* @__PURE__ */ new Set();
|
|
3058
|
+
for (const error of errors) {
|
|
3059
|
+
if (isNoisyUnexpectedPropertiesError(error)) continue;
|
|
3060
|
+
if (error.pathSegments.length > 1) {
|
|
3061
|
+
concreteErrorParents.add(error.pathSegments.slice(0, -1).join("/"));
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
const converterFailed = errors.some((error) => !isSchemaKeywordError(error.item) && !error.item.severity);
|
|
3065
|
+
return errors.filter((error) => {
|
|
3066
|
+
if (converterFailed && isSchemaKeywordError(error.item) && error.pathSegments.length <= 1 && (error.item.keyword === "anyOf" || error.item.keyword === "oneOf")) return false;
|
|
3067
|
+
if (!isNoisyUnexpectedPropertiesError(error)) return true;
|
|
3068
|
+
return !concreteErrorParents.has(error.pathSegments.join("/"));
|
|
3069
|
+
});
|
|
3070
|
+
};
|
|
3071
|
+
var collapseDerivedBuildErrors = (errors, resolve) => {
|
|
3072
|
+
const rows = errors.map((error) => ({ ...error, target: resolve(error.item.path), derived: [] }));
|
|
3073
|
+
const sourceRowByOwner = /* @__PURE__ */ new Map();
|
|
3074
|
+
for (const row of rows) {
|
|
3075
|
+
if (!isSchemaKeywordError(row.item) && !row.item.severity && row.target.section === "Zone" && !sourceRowByOwner.has(row.target.ownerKey)) {
|
|
3076
|
+
sourceRowByOwner.set(row.target.ownerKey, row);
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
return rows.filter((row) => {
|
|
3080
|
+
const sourceRow = isSchemaKeywordError(row.item) ? sourceRowByOwner.get(row.target.ownerKey) : void 0;
|
|
3081
|
+
if (!sourceRow) return true;
|
|
3082
|
+
sourceRow.derived.push(row);
|
|
3083
|
+
return false;
|
|
3084
|
+
});
|
|
3085
|
+
};
|
|
3086
|
+
var displayBuildErrorRows = (items, resolve) => collapseDerivedBuildErrors(filterDisplayBuildErrors(items.map(formatBuildErrorForDisplay)), resolve);
|
|
3087
|
+
|
|
3088
|
+
// ../hem-target-runtime/src/hem/pythonFailureMessage.ts
|
|
3089
|
+
var MAX_DETAIL_LINE = 200;
|
|
3090
|
+
var TargetRunError = class extends Error {
|
|
3091
|
+
constructor(message, failure, traceback, report) {
|
|
3092
|
+
super(message);
|
|
3093
|
+
this.failure = failure;
|
|
3094
|
+
this.traceback = traceback;
|
|
3095
|
+
this.report = report;
|
|
3096
|
+
}
|
|
3097
|
+
};
|
|
3098
|
+
var pointer = (segments) => segments.map((segment) => `/${segment.replace(/~/g, "~0").replace(/\//g, "~1")}`).join("");
|
|
3099
|
+
var segmentsOf = (path) => path.split("/").slice(1).map((segment) => segment.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
3100
|
+
function authored(segments, provenance) {
|
|
3101
|
+
for (let length = segments.length; length >= Math.max(segments.length - 1, 1); length -= 1) {
|
|
3102
|
+
const source = provenance[pointer(segments.slice(0, length))];
|
|
3103
|
+
if (source !== void 0) return [...segmentsOf(source), ...segments.slice(length)];
|
|
3104
|
+
}
|
|
3105
|
+
return void 0;
|
|
3106
|
+
}
|
|
3107
|
+
function wallNamed(model, message) {
|
|
3108
|
+
const [, storey, edge] = message.match(/for wall 'storey(\d+)_wall(\d+)'/) ?? [];
|
|
3109
|
+
if (storey === void 0) return void 0;
|
|
3110
|
+
const parts = model.Zone?.building_parts ?? {};
|
|
3111
|
+
const found = Object.entries(parts).flatMap(([part, { walls = [] }]) => walls.flatMap((wall, index) => wall.storey_index === Number(storey) && wall.floorplan_index === Number(edge) ? [pointer(["Zone", "building_parts", part, "walls", String(index)])] : []));
|
|
3112
|
+
return found.length === 1 ? found[0] : void 0;
|
|
3113
|
+
}
|
|
3114
|
+
var SYSTEM_SECTIONS = /* @__PURE__ */ new Set(["HotWaterSource", "HeatSourceWet", "SpaceHeatSystem", "SpaceCoolSystem"]);
|
|
3115
|
+
function walk(input, loc, type) {
|
|
3116
|
+
const segments = [];
|
|
3117
|
+
let node = input;
|
|
3118
|
+
let building = false;
|
|
3119
|
+
let arm;
|
|
3120
|
+
for (const [index, raw] of loc.entries()) {
|
|
3121
|
+
const key = String(raw);
|
|
3122
|
+
const present = node !== null && typeof node === "object" && Object.prototype.hasOwnProperty.call(node, key);
|
|
3123
|
+
if (present) {
|
|
3124
|
+
segments.push(key);
|
|
3125
|
+
node = node[key];
|
|
3126
|
+
if (node?.model_type === "hemie" && !SYSTEM_SECTIONS.has(segments[0])) building = true;
|
|
3127
|
+
} else if (index === loc.length - 1) {
|
|
3128
|
+
segments.push(key);
|
|
3129
|
+
return { segments, building, arm, missing: type === "missing" };
|
|
3130
|
+
} else arm ?? (arm = { place: pointer(segments), tag: key, hemieInput: node?.model_type !== void 0 });
|
|
3131
|
+
}
|
|
3132
|
+
return { segments, building, arm, missing: false };
|
|
3133
|
+
}
|
|
3134
|
+
function chosenArms(all) {
|
|
3135
|
+
const key = (error) => `${pointer(error.segments)}
|
|
3136
|
+
${error.msg}`;
|
|
3137
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
3138
|
+
for (const [index, error] of all.entries()) {
|
|
3139
|
+
if (error.type !== "extra_forbidden" || error.segments[error.segments.length - 1] !== "model_type") continue;
|
|
3140
|
+
dropped.add(index);
|
|
3141
|
+
const parent = pointer(error.segments.slice(0, -1));
|
|
3142
|
+
for (let previous = index - 1; previous >= 0; previous -= 1) {
|
|
3143
|
+
const candidate = all[previous];
|
|
3144
|
+
if (!pointer(candidate.segments).startsWith(parent) || candidate.arm?.tag !== error.arm?.tag) break;
|
|
3145
|
+
const copyElsewhere = all.some((other, at) => at !== previous && !dropped.has(at) && key(other) === key(candidate));
|
|
3146
|
+
if (!candidate.missing && !copyElsewhere) break;
|
|
3147
|
+
dropped.add(previous);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3151
|
+
const kept = all.filter((_, index) => !dropped.has(index));
|
|
3152
|
+
const walked = (kept.length ? kept : all).filter((error) => !seen.has(key(error)) && seen.add(key(error)));
|
|
3153
|
+
const arms = /* @__PURE__ */ new Map();
|
|
3154
|
+
for (const { arm } of walked) {
|
|
3155
|
+
if (!arm) continue;
|
|
3156
|
+
const place = arms.get(arm.place) ?? /* @__PURE__ */ new Map();
|
|
3157
|
+
const container = /^(dict|list)\[/.test(arm.tag);
|
|
3158
|
+
const entry = place.get(arm.tag) ?? { count: 0, stated: arm.hemieInput !== container };
|
|
3159
|
+
entry.count += 1;
|
|
3160
|
+
place.set(arm.tag, entry);
|
|
3161
|
+
arms.set(arm.place, place);
|
|
3162
|
+
}
|
|
3163
|
+
const best = new Map([...arms].map(([place, tags]) => [place, [...tags].sort(([, a], [, b]) => Number(b.stated) - Number(a.stated) || a.count - b.count)[0][0]]));
|
|
3164
|
+
return walked.filter(({ arm }) => !arm || best.get(arm.place) === arm.tag);
|
|
3165
|
+
}
|
|
3166
|
+
var STAGE_TEXT = {
|
|
3167
|
+
input_check: "the input check",
|
|
3168
|
+
product_lookup: "the product lookup",
|
|
3169
|
+
existing_building_conversion: "the existing building conversion",
|
|
3170
|
+
preprocessing: "preparation",
|
|
3171
|
+
core: "the simulation",
|
|
3172
|
+
metrics: "the rating calculation",
|
|
3173
|
+
unclassified: "the calculation"
|
|
3174
|
+
};
|
|
3175
|
+
var firstLine = (text) => (text.trim().split("\n")[0] ?? "").replace(/^Value error, /, "").slice(0, MAX_DETAIL_LINE);
|
|
3176
|
+
var SYNTHESISED_FIELDS = /* @__PURE__ */ new Set(["model_type", "reference_building_part", "storey_index", "floorplan_index"]);
|
|
3177
|
+
var CODE_FAULTS = /* @__PURE__ */ new Set(["TypeError", "KeyError", "AttributeError", "IndexError", "NameError", "AssertionError", "UnboundLocalError"]);
|
|
3178
|
+
var VULCAN_FAULT = "Vulcan could not convert this existing building for the EPC calculation. This is a fault in Vulcan, not in your model. Report it to Vulcan support with this model.";
|
|
3179
|
+
var BUILDING_SECTIONS = { Zone: "the building", InfiltrationVentilation: "ventilation and air tightness", ExternalConditions: "shading" };
|
|
3180
|
+
function buildingPlace(segments) {
|
|
3181
|
+
const parts = [];
|
|
3182
|
+
for (let i = 1; i < segments.length - 1; i += 1) {
|
|
3183
|
+
const [key, next] = [segments[i], segments[i + 1]];
|
|
3184
|
+
if (key === "building_parts") {
|
|
3185
|
+
parts.push(`building part ${next}`);
|
|
3186
|
+
i += 1;
|
|
3187
|
+
} else if (/^\d+$/.test(next)) {
|
|
3188
|
+
parts.push(`${key.replace(/_/g, " ").replace(/s$/, "")} ${Number(next) + 1}`);
|
|
3189
|
+
i += 1;
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
return parts.length ? parts.join(", ") : BUILDING_SECTIONS[segments[0]] ?? segments[0];
|
|
3193
|
+
}
|
|
3194
|
+
var readable = (field, text) => text.replace(
|
|
3195
|
+
/^Input should be (.*?)\.?$/,
|
|
3196
|
+
(_, rule) => `${field.replace(/_/g, " ").replace(/^\w/, (c) => c.toUpperCase())} must be ${rule}.`
|
|
3197
|
+
);
|
|
3198
|
+
function targetRunError(report, input, provenance = {}) {
|
|
3199
|
+
const model = JSON.parse(input);
|
|
3200
|
+
const walked = chosenArms((report.errors ?? []).map((error) => ({ ...walk(model, error.loc, error.type), type: error.type, msg: error.msg })));
|
|
3201
|
+
const notes = /* @__PURE__ */ new Set();
|
|
3202
|
+
const issues = [];
|
|
3203
|
+
for (const { segments: converted, building, missing, msg } of walked) {
|
|
3204
|
+
const field = converted[converted.length - 1] ?? "";
|
|
3205
|
+
const segments = building && !SYNTHESISED_FIELDS.has(field) ? authored(converted, provenance) ?? converted : converted;
|
|
3206
|
+
const located = segments !== converted;
|
|
3207
|
+
if (building && SYNTHESISED_FIELDS.has(field)) notes.add(VULCAN_FAULT);
|
|
3208
|
+
else if (building && !located) {
|
|
3209
|
+
const reason = missing ? `${field.replace(/_/g, " ")} is missing` : readable(field, firstLine(msg ?? "")).replace(/\.$/, "");
|
|
3210
|
+
notes.add(`The EPC calculation could not use this existing building: ${reason} (${buildingPlace(segments)}). Check the elements it is built from; if they are correct, report it to Vulcan support.`);
|
|
3211
|
+
} else issues.push(missing ? { path: pointer(segments.slice(0, -1)), keyword: "required", message: `"${field}" is a required property` } : { path: pointer(segments), message: readable(field, firstLine(msg ?? "")) });
|
|
3212
|
+
}
|
|
3213
|
+
const conversionStage = report.stage === "existing_building_conversion";
|
|
3214
|
+
const wall = !walked.length && conversionStage ? wallNamed(model, report.message) : void 0;
|
|
3215
|
+
const wallSource = wall && provenance[wall];
|
|
3216
|
+
if (wallSource && /wall area is less than zero/.test(report.message)) {
|
|
3217
|
+
issues.push({ path: wallSource, message: "The windows, doors and bay in this wall take more than its area. Make them smaller, or check the wall length and height." });
|
|
3218
|
+
} else if (!walked.length && conversionStage) {
|
|
3219
|
+
notes.add(CODE_FAULTS.has(report.kind) ? VULCAN_FAULT : `The EPC calculation could not use this existing building: ${firstLine(report.message)}. Check the elements it is built from; if they are correct, report it to Vulcan support.`);
|
|
3220
|
+
}
|
|
3221
|
+
const cause = notes.size ? "conversion" : issues.length || ["input_check", "product_lookup"].includes(report.stage) ? "input" : "simulation";
|
|
3222
|
+
if (!notes.size && !issues.length) {
|
|
3223
|
+
notes.add(cause === "input" ? `The EPC calculation stopped at ${STAGE_TEXT[report.stage]}: ${firstLine(report.message)}` : `The EPC calculation stopped during ${STAGE_TEXT[report.stage]}: ${firstLine(report.message)}. Report it to Vulcan support with this model if it happens again.`);
|
|
3224
|
+
}
|
|
3225
|
+
const rows = displayBuildErrorRows(issues.map((issue) => ({ source: "schema", ...issue })), () => ({ ownerKey: "" }));
|
|
3226
|
+
const message = [...notes, ...rows.length ? [`The EPC calculation found ${rows.length === 1 ? "an error" : `${rows.length} errors`} in the model. ${rows.map((row) => `${row.location}: ${row.userMessage}`).join(" ")}`] : []].join(" ");
|
|
3227
|
+
return new TargetRunError(message, { stage: report.stage, kind: report.kind, cause, issues, notes: [...notes] }, report.traceback, report);
|
|
3228
|
+
}
|
|
3229
|
+
|
|
424
3230
|
// ../hem-target-runtime/src/hem/preparedRun.ts
|
|
425
|
-
|
|
3231
|
+
function rustTargetRun(module) {
|
|
3232
|
+
const detailed = typeof module.run_target_input_detailed === "function" ? module.run_target_input_detailed : void 0;
|
|
3233
|
+
return (detailedHeating) => detailedHeating && detailed || module.run_target_input;
|
|
3234
|
+
}
|
|
3235
|
+
async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, write2, progress, check) {
|
|
426
3236
|
if (manifest2.bundleId !== bundleId) throw new Error("Worker target identity mismatch");
|
|
427
3237
|
if (!jobs.length) throw new Error("Batch has no prepared jobs");
|
|
428
3238
|
const allowedModes = new Set(manifest2.modes);
|
|
3239
|
+
const { resultsKind } = targetWrapper(resolveHemTarget(manifest2.bundleId));
|
|
429
3240
|
const reservedNames = /* @__PURE__ */ new Set(["model.json", "source.csv", "weather.epw", "target-run.json"]);
|
|
430
|
-
for (const
|
|
431
|
-
if (
|
|
3241
|
+
for (const job of jobs) {
|
|
3242
|
+
if (!isRunOutputPath(job.outputDirectory)) throw new Error(`Invalid run output path: ${JSON.stringify(job.outputDirectory)}`);
|
|
432
3243
|
if (!job.modes.length || job.modes.some((mode) => !allowedModes.has(mode))) throw new Error("Unsupported calculation mode for selected target");
|
|
433
|
-
if (job.archiveDirectory && (!job.archiveDirectory.startsWith(`${job.outputDirectory}/`) || job.archiveDirectory
|
|
3244
|
+
if (job.archiveDirectory && (!job.archiveDirectory.startsWith(`${job.outputDirectory}/`) || !isRunOutputPath(job.archiveDirectory))) throw new Error(`Invalid archive path: ${JSON.stringify(job.archiveDirectory)}`);
|
|
434
3245
|
if (job.heatingProfile) {
|
|
435
3246
|
parseHeatingProfile(job.heatingProfile);
|
|
436
3247
|
if (job.modes.length !== 1 || job.modes[0] !== "actual") throw new Error("Heating profiles require actual alone; they are not FHS compliance calculations");
|
|
437
3248
|
}
|
|
3249
|
+
}
|
|
3250
|
+
const scenario = (job) => `Scenario ${job.name}${job.parameterFiles?.length ? ` (${job.parameterFiles.join(", ")})` : ""}`;
|
|
3251
|
+
const traceback = (error) => error instanceof TargetRunError ? { traceback: error.traceback } : {};
|
|
3252
|
+
const located = (error, job) => error instanceof TargetRunError && error.report && job.provenance ? targetRunError(error.report, job.input, job.provenance) : error;
|
|
3253
|
+
if (check) {
|
|
3254
|
+
const failures = [];
|
|
3255
|
+
for (const [index, job] of jobs.entries()) {
|
|
3256
|
+
progress(index, jobs.length, "Checking");
|
|
3257
|
+
try {
|
|
3258
|
+
await check(job.input);
|
|
3259
|
+
} catch (caught) {
|
|
3260
|
+
const error = located(caught, job);
|
|
3261
|
+
failures.push({ job, error, message: error instanceof Error ? error.message : String(error) });
|
|
3262
|
+
}
|
|
3263
|
+
}
|
|
3264
|
+
for (const { job, error, message } of failures) {
|
|
3265
|
+
const archive = job.archiveDirectory ?? job.outputDirectory;
|
|
3266
|
+
const record = { target: manifest2, jobId, name: job.name, modes: job.modes, status: "failed", check: true, error: message };
|
|
3267
|
+
await write2(`${archive}/model.json`, job.input);
|
|
3268
|
+
await write2(`${archive}/target-run.json`, JSON.stringify({ ...record, ...traceback(error) }));
|
|
3269
|
+
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...record, archive }));
|
|
3270
|
+
}
|
|
3271
|
+
if (failures.length) {
|
|
3272
|
+
throw Object.assign(new Error(failures.map(({ job, message }) => `${scenario(job)}: ${message}`).join("\n")), { cause: failures[0].error });
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
for (const [index, job] of jobs.entries()) {
|
|
438
3276
|
const archive = job.archiveDirectory ?? job.outputDirectory;
|
|
439
3277
|
const inputSha256 = await sha256(new TextEncoder().encode(job.input));
|
|
440
3278
|
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 } : {} };
|
|
3279
|
+
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
3280
|
try {
|
|
443
3281
|
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "running" }));
|
|
444
|
-
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "running", archive }));
|
|
445
3282
|
await write2(`${archive}/model.json`, job.input);
|
|
446
3283
|
if (job.sourceCsv) await write2(`${archive}/source.csv`, job.sourceCsv);
|
|
447
3284
|
if (job.weather) await write2(`${archive}/weather.epw`, job.weather.epw);
|
|
448
3285
|
progress(index, jobs.length);
|
|
449
|
-
const files = await execute(job.input, job.modes, job.weather, job.heatingProfile);
|
|
3286
|
+
const files = await execute(job.input, job.modes, job.weather, job.heatingProfile, job.detailedHeating);
|
|
450
3287
|
const names = Object.keys(files);
|
|
451
3288
|
if (!names.length) throw new Error("Calculation produced no result files");
|
|
452
3289
|
for (const [name, content] of Object.entries(files)) {
|
|
@@ -454,26 +3291,44 @@ async function executePreparedJobs(manifest2, bundleId, jobId, jobs, execute, wr
|
|
|
454
3291
|
await write2(`${archive}/${name}`, content);
|
|
455
3292
|
}
|
|
456
3293
|
if (archive !== job.outputDirectory) {
|
|
3294
|
+
await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "running", archive }));
|
|
457
3295
|
for (const [name, content] of Object.entries(files)) await write2(`${job.outputDirectory}/${name}`, content);
|
|
458
|
-
await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names, archive }));
|
|
459
3296
|
}
|
|
460
3297
|
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names }));
|
|
461
|
-
|
|
3298
|
+
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "complete", files: names, archive }));
|
|
3299
|
+
} catch (caught) {
|
|
3300
|
+
const error = located(caught, job);
|
|
462
3301
|
const message = error instanceof Error ? error.message : String(error);
|
|
463
|
-
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message }));
|
|
3302
|
+
await write2(`${archive}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message, ...traceback(error) }));
|
|
464
3303
|
if (archive !== job.outputDirectory) await write2(`${job.outputDirectory}/target-run.json`, JSON.stringify({ ...provenance, status: "failed", error: message, archive }));
|
|
465
|
-
|
|
466
|
-
throw new Error(`Scenario ${job.name}${files}: ${message}`);
|
|
3304
|
+
throw Object.assign(new Error(`${scenario(job)}: ${message}`), { cause: error });
|
|
467
3305
|
}
|
|
468
3306
|
}
|
|
469
3307
|
}
|
|
470
3308
|
|
|
3309
|
+
// ../hem-target-runtime/src/hem/designHeatLoss.ts
|
|
3310
|
+
var PINNED_WEATHER_NAME = "Bedford";
|
|
3311
|
+
var NO_DESIGN_HEAT_LOSS_EXPORT = "This HEM target build cannot compute the design heat loss. Released targets do not have it yet.";
|
|
3312
|
+
function computeDesignHeatLoss(module, fhsModelJson, weather) {
|
|
3313
|
+
if (typeof module.design_heat_loss !== "function" || typeof module.run_target_stage !== "function") {
|
|
3314
|
+
return { status: "unavailable", reason: NO_DESIGN_HEAT_LOSS_EXPORT };
|
|
3315
|
+
}
|
|
3316
|
+
const stage = JSON.parse(module.run_target_stage(fhsModelJson, "preprocess", weather?.epw));
|
|
3317
|
+
if (stage.status !== "calculated") throw new Error(stage.error ?? "FHS preprocessing failed");
|
|
3318
|
+
const names = Object.keys(stage.files ?? {}).filter((name) => name.endsWith("__preproc.json"));
|
|
3319
|
+
if (names.length !== 1) throw new Error("FHS preprocessing did not return exactly one core input");
|
|
3320
|
+
const coreInput = stage.files[names[0]];
|
|
3321
|
+
const loss = JSON.parse(module.design_heat_loss(coreInput));
|
|
3322
|
+
if (loss.status === "failed") throw new Error(loss.error ?? "Design heat loss failed");
|
|
3323
|
+
return { status: "ready", model: JSON.parse(coreInput), designHeatLoss: { ...loss, weatherName: weather?.name ?? PINNED_WEATHER_NAME } };
|
|
3324
|
+
}
|
|
3325
|
+
|
|
471
3326
|
// ../hem-target-runtime/src/workers/workerProtocol.ts
|
|
472
3327
|
var FS_REQUEST_TYPE = "file_system";
|
|
473
3328
|
var FS_RESPONSE_TYPE = "file_system_response";
|
|
474
3329
|
|
|
475
3330
|
// ../hem-target-runtime/src/workers/batchWorkerFileSystemBridge.ts
|
|
476
|
-
var DEFAULT_ACKNOWLEDGEMENT_TIMEOUT_MS =
|
|
3331
|
+
var DEFAULT_ACKNOWLEDGEMENT_TIMEOUT_MS = 5 * 6e4;
|
|
477
3332
|
var BatchWorkerFileSystemAcknowledgements = class {
|
|
478
3333
|
constructor(timeoutMs = DEFAULT_ACKNOWLEDGEMENT_TIMEOUT_MS) {
|
|
479
3334
|
this.timeoutMs = timeoutMs;
|
|
@@ -508,9 +3363,10 @@ var BatchWorkerFileSystemAcknowledgements = class {
|
|
|
508
3363
|
settled: false
|
|
509
3364
|
};
|
|
510
3365
|
entry.timer = setTimeout(() => {
|
|
3366
|
+
const limit = this.timeoutMs >= 6e4 ? `${Math.round(this.timeoutMs / 6e4)} minutes` : `${Math.round(this.timeoutMs / 1e3)} seconds`;
|
|
511
3367
|
this.settleFailure(
|
|
512
3368
|
request.messageId,
|
|
513
|
-
|
|
3369
|
+
`${request.operation === "write_file" ? "Saving" : "Deleting"} '${request.path}' did not finish within ${limit}. Check that the workspace folder is still available, then run again.`
|
|
514
3370
|
);
|
|
515
3371
|
}, this.timeoutMs);
|
|
516
3372
|
this.pending.set(request.messageId, entry);
|
|
@@ -575,6 +3431,7 @@ var runInput;
|
|
|
575
3431
|
var supportsWeather = false;
|
|
576
3432
|
var runStage;
|
|
577
3433
|
var busy = false;
|
|
3434
|
+
var hem;
|
|
578
3435
|
var acknowledgements = new BatchWorkerFileSystemAcknowledgements();
|
|
579
3436
|
var send = (message) => self.postMessage(message);
|
|
580
3437
|
async function write(path, content) {
|
|
@@ -600,12 +3457,13 @@ async function initialize(bundle) {
|
|
|
600
3457
|
url
|
|
601
3458
|
);
|
|
602
3459
|
await module.default({ module_or_path: await bytes(bundle.runtime.wasm) });
|
|
603
|
-
assertRustTargetVersions(target, module.metadata_hem_core_version?.(), module.metadata_fhs_wrapper_version?.());
|
|
3460
|
+
assertRustTargetVersions(target, module.metadata_hem_core_version?.(), module.metadata_fhs_wrapper_version?.(), module.metadata_hem_core_commit?.(), module.metadata_fhs_wrapper_commit?.());
|
|
604
3461
|
if (typeof module.initialize_rayon_thread_pool !== "function") throw new Error("Pinned Rust runtime lacks worker pool initialization");
|
|
605
3462
|
await module.initialize_rayon_thread_pool(1);
|
|
606
3463
|
supportsWeather = module.target_weather_protocol_version?.() === 1;
|
|
607
3464
|
if (typeof module.run_target_input !== "function") throw new Error("Pinned runtime does not support prepared target jobs");
|
|
608
|
-
runInput = module
|
|
3465
|
+
runInput = rustTargetRun(module);
|
|
3466
|
+
hem = module;
|
|
609
3467
|
runStage = module.target_heating_profile_protocol_version?.() === 1 && typeof module.run_target_stage === "function" ? module.run_target_stage : void 0;
|
|
610
3468
|
} finally {
|
|
611
3469
|
URL.revokeObjectURL(url);
|
|
@@ -628,7 +3486,7 @@ else self.onmessage = async ({ data }) => {
|
|
|
628
3486
|
if (data.type === "initialize") await initialize(data.manifest);
|
|
629
3487
|
else if (data.type === "run_prepared_batch") {
|
|
630
3488
|
if (!manifest || !runInput) throw new Error("Rust target is not initialized");
|
|
631
|
-
await executePreparedJobs(manifest, data.targetBundleId, data.jobId, data.jobs, async (input, modes, weather, heatingProfile) => {
|
|
3489
|
+
await executePreparedJobs(manifest, data.targetBundleId, data.jobId, data.jobs, async (input, modes, weather, heatingProfile, detailedHeating) => {
|
|
632
3490
|
if (heatingProfile) {
|
|
633
3491
|
if (!runStage) throw new Error("Pinned Rust bundle lacks heating profile protocol 1; rebuild and qualify its adapter");
|
|
634
3492
|
const stage = async (data2, step) => {
|
|
@@ -639,11 +3497,15 @@ else self.onmessage = async ({ data }) => {
|
|
|
639
3497
|
return runHeatingProfile(input, heatingProfile, stage);
|
|
640
3498
|
}
|
|
641
3499
|
if (weather && !supportsWeather) throw new Error("Pinned Rust runtime does not implement custom EPW protocol 1; rebuild and qualify its bundle");
|
|
642
|
-
const
|
|
3500
|
+
const run = runInput(detailedHeating);
|
|
3501
|
+
const result = JSON.parse(weather ? run(input, "model", JSON.stringify(modes), weather.epw) : run(input, "model", JSON.stringify(modes)));
|
|
643
3502
|
if (result.status !== "calculated") throw new Error(result.error ?? "Rust calculation failed");
|
|
644
3503
|
return result.files;
|
|
645
3504
|
}, write, (completed, total) => send({ type: "progress", jobId: data.jobId, progress: { completed, total } }));
|
|
646
3505
|
send({ type: "complete", jobId: data.jobId, targetBundleId: manifest.bundleId, result: { status: "success", targetBundleId: manifest.bundleId } });
|
|
3506
|
+
} else if (data.type === "design_heat_loss") {
|
|
3507
|
+
if (!manifest || !hem) throw new Error("Rust target is not initialized");
|
|
3508
|
+
send({ type: "design_heat_loss_result", jobId: data.jobId, result: computeDesignHeatLoss(hem, data.input) });
|
|
647
3509
|
} else throw new Error("Unknown Rust target message");
|
|
648
3510
|
} catch (error) {
|
|
649
3511
|
send({ type: data.type === "initialize" ? "init_error" : "error", jobId: data.jobId, error: error instanceof Error ? error.message : String(error) });
|
|
@@ -651,3 +3513,29 @@ else self.onmessage = async ({ data }) => {
|
|
|
651
3513
|
busy = false;
|
|
652
3514
|
}
|
|
653
3515
|
};
|
|
3516
|
+
/*! Bundled license information:
|
|
3517
|
+
|
|
3518
|
+
polygon-clipping/dist/polygon-clipping.umd.js:
|
|
3519
|
+
(**
|
|
3520
|
+
* splaytree v3.1.2
|
|
3521
|
+
* Fast Splay tree for Node and browser
|
|
3522
|
+
*
|
|
3523
|
+
* @author Alexander Milevski <info@w8r.name>
|
|
3524
|
+
* @license MIT
|
|
3525
|
+
* @preserve
|
|
3526
|
+
*)
|
|
3527
|
+
(*! *****************************************************************************
|
|
3528
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3529
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
3530
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
3531
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
3532
|
+
|
|
3533
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
3534
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
3535
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
3536
|
+
MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
3537
|
+
|
|
3538
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
3539
|
+
and limitations under the License.
|
|
3540
|
+
***************************************************************************** *)
|
|
3541
|
+
*/
|