@nubisco/bim 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -2
- package/dist/cells-G6pIWvCF.d.ts +110 -0
- package/dist/cells.d.ts +2 -0
- package/dist/cells.js +25 -0
- package/dist/chunk-6Q4JIXFQ.js +54 -0
- package/dist/chunk-7YR7CGBI.js +1115 -0
- package/dist/chunk-EHYUT42U.js +126 -0
- package/dist/chunk-I47MDCHW.js +457 -0
- package/dist/chunk-L3Z5LJAA.js +58 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-OCAFB7M7.js +286 -0
- package/dist/chunk-SFKOZPPS.js +308 -0
- package/dist/chunk-TE5NK6DO.js +686 -0
- package/dist/chunk-TVNU2NAO.js +47 -0
- package/dist/convert.d.ts +39 -0
- package/dist/convert.js +17 -0
- package/dist/edges-CnXyFuCX.d.ts +67 -0
- package/dist/edges.d.ts +2 -0
- package/dist/edges.js +18 -0
- package/dist/history.d.ts +33 -0
- package/dist/history.js +7 -0
- package/dist/ifc-read.d.ts +61 -0
- package/dist/ifc-read.js +17 -0
- package/dist/ifc.d.ts +60 -0
- package/dist/ifc.js +20 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +81 -0
- package/dist/v1-CnwNIVI8.d.ts +260 -0
- package/dist/v1.d.ts +2 -0
- package/dist/v1.js +21 -0
- package/dist/v2.d.ts +198 -0
- package/dist/v2.js +27 -0
- package/dist/validate.d.ts +13 -0
- package/dist/validate.js +10 -0
- package/package.json +110 -4
|
@@ -0,0 +1,1115 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PlanError,
|
|
3
|
+
validatePlan
|
|
4
|
+
} from "./chunk-SFKOZPPS.js";
|
|
5
|
+
import {
|
|
6
|
+
area
|
|
7
|
+
} from "./chunk-OCAFB7M7.js";
|
|
8
|
+
import {
|
|
9
|
+
FURNITURE_HEIGHT,
|
|
10
|
+
FURNITURE_NAME
|
|
11
|
+
} from "./chunk-TE5NK6DO.js";
|
|
12
|
+
import {
|
|
13
|
+
COVERING_KINDS,
|
|
14
|
+
DEFAULTS,
|
|
15
|
+
DOOR_OPERATIONS,
|
|
16
|
+
FRAME_MATERIALS,
|
|
17
|
+
FURNITURE_KINDS,
|
|
18
|
+
LEAVES,
|
|
19
|
+
PLAN_VERSION,
|
|
20
|
+
WINDOW_OPERATIONS
|
|
21
|
+
} from "./chunk-6Q4JIXFQ.js";
|
|
22
|
+
|
|
23
|
+
// src/ifc-read.ts
|
|
24
|
+
var IfcError = class extends Error {
|
|
25
|
+
};
|
|
26
|
+
function decodeString(s) {
|
|
27
|
+
let out = "";
|
|
28
|
+
for (let i = 0; i < s.length; i++) {
|
|
29
|
+
const c = s[i];
|
|
30
|
+
if (c === "'" && s[i + 1] === "'") {
|
|
31
|
+
out += "'";
|
|
32
|
+
i++;
|
|
33
|
+
} else if (c === "\\") {
|
|
34
|
+
if (s.startsWith("\\\\", i)) {
|
|
35
|
+
out += "\\";
|
|
36
|
+
i++;
|
|
37
|
+
} else if (s.startsWith("\\X2\\", i) || s.startsWith("\\X4\\", i)) {
|
|
38
|
+
const w = s[i + 2] === "2" ? 4 : 8;
|
|
39
|
+
const end = s.indexOf("\\X0\\", i + 4);
|
|
40
|
+
const hex = s.slice(i + 4, end < 0 ? s.length : end);
|
|
41
|
+
for (let j = 0; j + w <= hex.length; j += w) out += String.fromCodePoint(parseInt(hex.slice(j, j + w), 16));
|
|
42
|
+
i = end < 0 ? s.length : end + 3;
|
|
43
|
+
} else if (s.startsWith("\\X\\", i)) {
|
|
44
|
+
out += String.fromCharCode(parseInt(s.slice(i + 3, i + 5), 16));
|
|
45
|
+
i += 4;
|
|
46
|
+
} else if (s.startsWith("\\S\\", i)) {
|
|
47
|
+
out += String.fromCharCode(s.charCodeAt(i + 3) + 128);
|
|
48
|
+
i += 3;
|
|
49
|
+
} else if (/^\\P[A-I]\\/.test(s.slice(i, i + 4))) i += 3;
|
|
50
|
+
else out += c;
|
|
51
|
+
} else out += c;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function parseStep(text) {
|
|
56
|
+
const start = text.search(/\bDATA\s*;/);
|
|
57
|
+
if (start < 0 || !/ISO-10303-21/.test(text.slice(0, 200))) throw new IfcError("This is not an IFC file.");
|
|
58
|
+
let i = text.indexOf(";", start) + 1;
|
|
59
|
+
const n = text.length;
|
|
60
|
+
const out = /* @__PURE__ */ new Map();
|
|
61
|
+
const ws = () => {
|
|
62
|
+
for (; ; ) {
|
|
63
|
+
while (i < n && /\s/.test(text[i])) i++;
|
|
64
|
+
if (text.startsWith("/*", i)) {
|
|
65
|
+
const e = text.indexOf("*/", i + 2);
|
|
66
|
+
i = e < 0 ? n : e + 2;
|
|
67
|
+
} else return;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const value = () => {
|
|
71
|
+
ws();
|
|
72
|
+
const c = text[i];
|
|
73
|
+
if (c === "$" || c === "*") {
|
|
74
|
+
i++;
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
if (c === "#") {
|
|
78
|
+
const m = /^#(\d+)/.exec(text.slice(i, i + 20));
|
|
79
|
+
i += m[0].length;
|
|
80
|
+
return { ref: Number(m[1]) };
|
|
81
|
+
}
|
|
82
|
+
if (c === "'" || c === '"') {
|
|
83
|
+
let j = i + 1;
|
|
84
|
+
for (; ; ) {
|
|
85
|
+
const q = text.indexOf(c, j);
|
|
86
|
+
if (q < 0) throw new IfcError("A string in the file never ends.");
|
|
87
|
+
if (c === "'" && text[q + 1] === "'") j = q + 2;
|
|
88
|
+
else {
|
|
89
|
+
const raw = text.slice(i + 1, q);
|
|
90
|
+
i = q + 1;
|
|
91
|
+
return c === "'" ? decodeString(raw) : raw;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (c === "(") {
|
|
96
|
+
i++;
|
|
97
|
+
const list = [];
|
|
98
|
+
ws();
|
|
99
|
+
if (text[i] === ")") {
|
|
100
|
+
i++;
|
|
101
|
+
return list;
|
|
102
|
+
}
|
|
103
|
+
for (; ; ) {
|
|
104
|
+
list.push(value());
|
|
105
|
+
ws();
|
|
106
|
+
if (text[i] === ",") i++;
|
|
107
|
+
else if (text[i] === ")") {
|
|
108
|
+
i++;
|
|
109
|
+
return list;
|
|
110
|
+
} else throw new IfcError(`The file is malformed near character ${i}.`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (c === ".") {
|
|
114
|
+
const e = text.indexOf(".", i + 1);
|
|
115
|
+
const v = text.slice(i + 1, e);
|
|
116
|
+
i = e + 1;
|
|
117
|
+
return { e: v };
|
|
118
|
+
}
|
|
119
|
+
const num = /^[-+]?(\d+\.?\d*([eE][-+]?\d+)?|\.\d+)/.exec(text.slice(i, i + 40));
|
|
120
|
+
if (num) {
|
|
121
|
+
i += num[0].length;
|
|
122
|
+
return Number(num[0]);
|
|
123
|
+
}
|
|
124
|
+
const name = /^[A-Za-z_][A-Za-z0-9_]*/.exec(text.slice(i, i + 80));
|
|
125
|
+
if (name) {
|
|
126
|
+
i += name[0].length;
|
|
127
|
+
ws();
|
|
128
|
+
if (text[i] !== "(") throw new IfcError(`The file is malformed near character ${i}.`);
|
|
129
|
+
i++;
|
|
130
|
+
const v = value();
|
|
131
|
+
ws();
|
|
132
|
+
i++;
|
|
133
|
+
return { t: name[0].toUpperCase(), v };
|
|
134
|
+
}
|
|
135
|
+
throw new IfcError(`The file is malformed near character ${i}.`);
|
|
136
|
+
};
|
|
137
|
+
for (; ; ) {
|
|
138
|
+
ws();
|
|
139
|
+
if (i >= n || text.startsWith("ENDSEC", i)) break;
|
|
140
|
+
const head = /^#(\d+)\s*=\s*/.exec(text.slice(i, i + 40));
|
|
141
|
+
if (!head) throw new IfcError(`The file is malformed near character ${i}.`);
|
|
142
|
+
i += head[0].length;
|
|
143
|
+
const type = /^[A-Za-z_][A-Za-z0-9_]*/.exec(text.slice(i, i + 80));
|
|
144
|
+
if (!type) {
|
|
145
|
+
value();
|
|
146
|
+
ws();
|
|
147
|
+
if (text[i] === ";") i++;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
i += type[0].length;
|
|
151
|
+
const args = value();
|
|
152
|
+
ws();
|
|
153
|
+
if (text[i] === ";") i++;
|
|
154
|
+
out.set(Number(head[1]), {
|
|
155
|
+
id: Number(head[1]),
|
|
156
|
+
type: type[0].toUpperCase(),
|
|
157
|
+
args: Array.isArray(args) ? args : []
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
var IDENTITY = { x: [1, 0, 0], y: [0, 1, 0], z: [0, 0, 1], o: [0, 0, 0] };
|
|
163
|
+
var add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
164
|
+
var scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
165
|
+
var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
166
|
+
var cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
167
|
+
var norm = (a) => {
|
|
168
|
+
const l = Math.hypot(...a);
|
|
169
|
+
return l ? scale(a, 1 / l) : a;
|
|
170
|
+
};
|
|
171
|
+
var apply = (m, p) => add(m.o, add(scale(m.x, p[0]), add(scale(m.y, p[1]), scale(m.z, p[2]))));
|
|
172
|
+
var turn = (m, d) => add(scale(m.x, d[0]), add(scale(m.y, d[1]), scale(m.z, d[2])));
|
|
173
|
+
var compose = (a, b) => ({ x: turn(a, b.x), y: turn(a, b.y), z: turn(a, b.z), o: apply(a, b.o) });
|
|
174
|
+
function frame(o, z, x) {
|
|
175
|
+
const zz = norm(z);
|
|
176
|
+
let xx = norm(add(x, scale(zz, -dot(x, zz))));
|
|
177
|
+
if (!Math.hypot(...xx)) xx = Math.abs(zz[0]) < 0.9 ? norm(cross([0, 1, 0], zz)) : norm(cross(zz, [0, 0, 1]));
|
|
178
|
+
return { x: xx, y: cross(zz, xx), z: zz, o };
|
|
179
|
+
}
|
|
180
|
+
var WALLS = /* @__PURE__ */ new Set(["IFCWALL", "IFCWALLSTANDARDCASE", "IFCWALLELEMENTEDCASE"]);
|
|
181
|
+
var FURNISHING = /* @__PURE__ */ new Set(["IFCFURNITURE", "IFCFURNISHINGELEMENT", "IFCSANITARYTERMINAL", "IFCSYSTEMFURNITUREELEMENT"]);
|
|
182
|
+
var ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
183
|
+
var SANITARY_KIND = {
|
|
184
|
+
BATH: "bath",
|
|
185
|
+
SHOWER: "shower",
|
|
186
|
+
TOILETPAN: "toilet",
|
|
187
|
+
WASHHANDBASIN: "basin",
|
|
188
|
+
TABLE: "table",
|
|
189
|
+
BED: "bed",
|
|
190
|
+
SOFA: "sofa",
|
|
191
|
+
SHELF: "shelves"
|
|
192
|
+
};
|
|
193
|
+
var FURNITURE_WORDS = [
|
|
194
|
+
[/island/i, "island"],
|
|
195
|
+
[/\b(bed|cot)\b/i, "bed"],
|
|
196
|
+
[/sofa|couch|settee/i, "sofa"],
|
|
197
|
+
[/shel(f|ves)|bookcase/i, "shelves"],
|
|
198
|
+
[/table|desk/i, "table"],
|
|
199
|
+
[/\bbath(tub)?\b/i, "bath"],
|
|
200
|
+
[/shower/i, "shower"],
|
|
201
|
+
[/toilet|\bwc\b/i, "toilet"],
|
|
202
|
+
[/basin|sink/i, "basin"],
|
|
203
|
+
[/rug|carpet/i, "rug"],
|
|
204
|
+
[/lounger/i, "lounger"],
|
|
205
|
+
[/parasol|umbrella/i, "parasol"],
|
|
206
|
+
[/planter|plant/i, "planter"],
|
|
207
|
+
[/pergola/i, "pergola"]
|
|
208
|
+
];
|
|
209
|
+
function fromIfc(text) {
|
|
210
|
+
const ents = parseStep(text);
|
|
211
|
+
const notes = [];
|
|
212
|
+
const get = (v) => v && typeof v === "object" && "ref" in v ? ents.get(v.ref) : void 0;
|
|
213
|
+
const num = (v) => {
|
|
214
|
+
if (typeof v === "number") return v;
|
|
215
|
+
if (v && typeof v === "object" && "t" in v) return num(v.v);
|
|
216
|
+
return null;
|
|
217
|
+
};
|
|
218
|
+
const str = (v) => {
|
|
219
|
+
if (typeof v === "string") return v;
|
|
220
|
+
if (v && typeof v === "object" && "t" in v) return str(v.v);
|
|
221
|
+
return null;
|
|
222
|
+
};
|
|
223
|
+
const en = (v) => v && typeof v === "object" && "e" in v ? v.e : null;
|
|
224
|
+
const list = (v) => Array.isArray(v) ? v : [];
|
|
225
|
+
const byType = (...types) => [...ents.values()].filter((e) => types.includes(e.type));
|
|
226
|
+
const unitMm = (u) => {
|
|
227
|
+
if (!u) return null;
|
|
228
|
+
if (u.type === "IFCSIUNIT") {
|
|
229
|
+
if (en(u.args[1]) !== "LENGTHUNIT") return null;
|
|
230
|
+
const prefix = { MILLI: 1e-3, CENTI: 0.01, DECI: 0.1, KILO: 1e3 };
|
|
231
|
+
return 1e3 * (prefix[en(u.args[2]) ?? ""] ?? 1);
|
|
232
|
+
}
|
|
233
|
+
if (u.type === "IFCCONVERSIONBASEDUNIT" || u.type === "IFCCONVERSIONBASEDUNITWITHOFFSET") {
|
|
234
|
+
if (en(u.args[1]) !== "LENGTHUNIT") return null;
|
|
235
|
+
const measure = get(u.args[3]);
|
|
236
|
+
const k = num(measure?.args[0]);
|
|
237
|
+
const base = unitMm(get(measure?.args[1]));
|
|
238
|
+
return k !== null && base !== null ? k * base : null;
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
};
|
|
242
|
+
const project = byType("IFCPROJECT")[0];
|
|
243
|
+
if (!project) throw new IfcError("The file has no IfcProject, so it is not a building model.");
|
|
244
|
+
let K = 1e3;
|
|
245
|
+
for (const u of list(get(project.args[8])?.args[0])) {
|
|
246
|
+
const k = unitMm(get(u));
|
|
247
|
+
if (k !== null) K = k;
|
|
248
|
+
}
|
|
249
|
+
const mm = (v) => Math.round(v * K);
|
|
250
|
+
const point3 = (v) => {
|
|
251
|
+
const c = list(get(v)?.args[0]).map((x) => num(x) ?? 0);
|
|
252
|
+
return [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0];
|
|
253
|
+
};
|
|
254
|
+
const dir3 = (v, fallback) => {
|
|
255
|
+
const d = get(v);
|
|
256
|
+
if (!d) return fallback;
|
|
257
|
+
const c = list(d.args[0]).map((x) => num(x) ?? 0);
|
|
258
|
+
return [c[0] ?? 0, c[1] ?? 0, c[2] ?? 0];
|
|
259
|
+
};
|
|
260
|
+
const axis = (v) => {
|
|
261
|
+
const a = get(v);
|
|
262
|
+
if (!a) return IDENTITY;
|
|
263
|
+
if (a.type === "IFCAXIS2PLACEMENT2D") return frame(point3(a.args[0]), [0, 0, 1], dir3(a.args[1], [1, 0, 0]));
|
|
264
|
+
if (a.type === "IFCAXIS2PLACEMENT3D")
|
|
265
|
+
return frame(point3(a.args[0]), dir3(a.args[1], [0, 0, 1]), dir3(a.args[2], [1, 0, 0]));
|
|
266
|
+
return IDENTITY;
|
|
267
|
+
};
|
|
268
|
+
const placed = /* @__PURE__ */ new Map();
|
|
269
|
+
const placement = (v, depth = 0) => {
|
|
270
|
+
const p = get(v);
|
|
271
|
+
if (!p || depth > 50) return IDENTITY;
|
|
272
|
+
const seen = placed.get(p.id);
|
|
273
|
+
if (seen) return seen;
|
|
274
|
+
const m = p.type === "IFCLOCALPLACEMENT" ? compose(placement(p.args[0], depth + 1), axis(p.args[1])) : IDENTITY;
|
|
275
|
+
placed.set(p.id, m);
|
|
276
|
+
return m;
|
|
277
|
+
};
|
|
278
|
+
const operator = (v) => {
|
|
279
|
+
const t = get(v);
|
|
280
|
+
if (!t) return IDENTITY;
|
|
281
|
+
const k = num(t.args[3]) ?? 1;
|
|
282
|
+
const x = dir3(t.args[0], [1, 0, 0]);
|
|
283
|
+
const z = t.type === "IFCCARTESIANTRANSFORMATIONOPERATOR3D" ? dir3(t.args[4], [0, 0, 1]) : [0, 0, 1];
|
|
284
|
+
const f = frame(point3(t.args[2]), z, x);
|
|
285
|
+
return { x: scale(f.x, k), y: scale(f.y, k), z: scale(f.z, k), o: f.o };
|
|
286
|
+
};
|
|
287
|
+
const curve = (v, depth = 0) => {
|
|
288
|
+
const c = get(v);
|
|
289
|
+
if (!c || depth > 20) return [];
|
|
290
|
+
const pts = (l) => l.map((p) => point3(p)).map((p) => [p[0], p[1]]);
|
|
291
|
+
switch (c.type) {
|
|
292
|
+
case "IFCPOLYLINE":
|
|
293
|
+
return pts(list(c.args[0]));
|
|
294
|
+
case "IFCINDEXEDPOLYCURVE": {
|
|
295
|
+
const coords = list(get(c.args[0])?.args[0]).map((q) => list(q).map((x) => num(x) ?? 0));
|
|
296
|
+
const segs = list(c.args[1]);
|
|
297
|
+
if (!segs.length) return coords.map((q) => [q[0], q[1]]);
|
|
298
|
+
const out = [];
|
|
299
|
+
for (const s of segs) {
|
|
300
|
+
const idx = s && typeof s === "object" && "t" in s ? list(s.v) : list(s);
|
|
301
|
+
for (const k of idx) {
|
|
302
|
+
const q = coords[(num(k) ?? 1) - 1];
|
|
303
|
+
if (!q) continue;
|
|
304
|
+
const last = out[out.length - 1];
|
|
305
|
+
if (!last || last[0] !== q[0] || last[1] !== q[1]) out.push([q[0], q[1]]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
case "IFCCOMPOSITECURVE":
|
|
311
|
+
return list(c.args[0]).flatMap((s) => curve(get(s)?.args[2], depth + 1));
|
|
312
|
+
case "IFCTRIMMEDCURVE": {
|
|
313
|
+
const basis = get(c.args[0]);
|
|
314
|
+
const ends = [list(c.args[1]), list(c.args[2])].map((trim) => {
|
|
315
|
+
const pt = trim.find((x) => get(x)?.type === "IFCCARTESIANPOINT");
|
|
316
|
+
if (pt) return point3(pt);
|
|
317
|
+
const t = trim.map(num).find((x) => x !== null);
|
|
318
|
+
if (basis?.type === "IFCLINE" && t !== void 0 && t !== null) {
|
|
319
|
+
const vec = get(basis.args[1]);
|
|
320
|
+
const d = dir3(vec?.args[0], [1, 0, 0]);
|
|
321
|
+
return add(point3(basis.args[0]), scale(d, t * (num(vec?.args[1]) ?? 1)));
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
});
|
|
325
|
+
return ends.every((e) => e) ? ends.map((e) => [e[0], e[1]]) : [];
|
|
326
|
+
}
|
|
327
|
+
case "IFCCIRCLE": {
|
|
328
|
+
const m = axis(c.args[0]);
|
|
329
|
+
const r = num(c.args[1]) ?? 0;
|
|
330
|
+
return Array.from({ length: 16 }, (_, i) => {
|
|
331
|
+
const p = apply(m, [r * Math.cos(i * Math.PI / 8), r * Math.sin(i * Math.PI / 8), 0]);
|
|
332
|
+
return [p[0], p[1]];
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
return [];
|
|
337
|
+
};
|
|
338
|
+
const closed = (pts) => {
|
|
339
|
+
const out = pts.filter((p, i) => i === 0 || p[0] !== pts[i - 1][0] || p[1] !== pts[i - 1][1]);
|
|
340
|
+
if (out.length > 1 && out[0][0] === out[out.length - 1][0] && out[0][1] === out[out.length - 1][1]) out.pop();
|
|
341
|
+
return out;
|
|
342
|
+
};
|
|
343
|
+
const profile = (v) => {
|
|
344
|
+
const p = get(v);
|
|
345
|
+
if (!p) return null;
|
|
346
|
+
if (/^IFC(ROUNDED)?RECTANGLE(HOLLOW)?PROFILEDEF$/.test(p.type)) {
|
|
347
|
+
const m = axis(p.args[2]);
|
|
348
|
+
const w = num(p.args[3]) ?? 0;
|
|
349
|
+
const d = num(p.args[4]) ?? 0;
|
|
350
|
+
const corners = [
|
|
351
|
+
[-w / 2, -d / 2, 0],
|
|
352
|
+
[w / 2, -d / 2, 0],
|
|
353
|
+
[w / 2, d / 2, 0],
|
|
354
|
+
[-w / 2, d / 2, 0]
|
|
355
|
+
];
|
|
356
|
+
return {
|
|
357
|
+
outer: corners.map((q) => apply(m, q)).map((q) => [q[0], q[1]]),
|
|
358
|
+
holes: [],
|
|
359
|
+
rect: { m, w, d }
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
if (p.type === "IFCCIRCLEPROFILEDEF") {
|
|
363
|
+
const m = axis(p.args[2]);
|
|
364
|
+
const r = num(p.args[3]) ?? 0;
|
|
365
|
+
const outer = Array.from({ length: 16 }, (_, i) => {
|
|
366
|
+
const q = apply(m, [r * Math.cos(i * Math.PI / 8), r * Math.sin(i * Math.PI / 8), 0]);
|
|
367
|
+
return [q[0], q[1]];
|
|
368
|
+
});
|
|
369
|
+
return { outer, holes: [] };
|
|
370
|
+
}
|
|
371
|
+
if (p.type === "IFCARBITRARYCLOSEDPROFILEDEF" || p.type === "IFCARBITRARYPROFILEDEFWITHVOIDS") {
|
|
372
|
+
const outer = closed(curve(p.args[2]));
|
|
373
|
+
const holes = p.type === "IFCARBITRARYPROFILEDEFWITHVOIDS" ? list(p.args[3]).map((c) => closed(curve(c))) : [];
|
|
374
|
+
return outer.length >= 3 ? { outer, holes: holes.filter((h) => h.length >= 3) } : null;
|
|
375
|
+
}
|
|
376
|
+
return null;
|
|
377
|
+
};
|
|
378
|
+
const solids = (item, m, out, depth = 0) => {
|
|
379
|
+
if (!item || depth > 20) return;
|
|
380
|
+
switch (item.type) {
|
|
381
|
+
case "IFCEXTRUDEDAREASOLID": {
|
|
382
|
+
const pr = profile(item.args[0]);
|
|
383
|
+
if (!pr) return;
|
|
384
|
+
const pos = compose(m, axis(item.args[1]));
|
|
385
|
+
const dir = norm(turn(pos, dir3(item.args[2], [0, 0, 1])));
|
|
386
|
+
const depthV = num(item.args[3]) ?? 0;
|
|
387
|
+
if (Math.abs(dir[2]) < 0.99) return;
|
|
388
|
+
const xy = (q) => {
|
|
389
|
+
const w = apply(pos, [q[0], q[1], 0]);
|
|
390
|
+
return [w[0], w[1]];
|
|
391
|
+
};
|
|
392
|
+
const za = pos.o[2];
|
|
393
|
+
const zb = za + dir[2] * depthV;
|
|
394
|
+
out.push({
|
|
395
|
+
outer: pr.outer.map(xy),
|
|
396
|
+
holes: pr.holes.map((h) => h.map(xy)),
|
|
397
|
+
z0: Math.min(za, zb),
|
|
398
|
+
z1: Math.max(za, zb),
|
|
399
|
+
rect: pr.rect ? { m: compose(pos, pr.rect.m), w: pr.rect.w, d: pr.rect.d } : void 0
|
|
400
|
+
});
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
case "IFCBOOLEANCLIPPINGRESULT":
|
|
404
|
+
case "IFCBOOLEANRESULT":
|
|
405
|
+
if (en(item.args[0]) !== "INTERSECTION") solids(get(item.args[1]), m, out, depth + 1);
|
|
406
|
+
return;
|
|
407
|
+
case "IFCMAPPEDITEM": {
|
|
408
|
+
const map = get(item.args[0]);
|
|
409
|
+
const target = compose(m, compose(operator(item.args[1]), axis(map?.args[0])));
|
|
410
|
+
for (const it of list(get(map?.args[1])?.args[3])) solids(get(it), target, out, depth + 1);
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
case "IFCTRIANGULATEDFACESET":
|
|
414
|
+
case "IFCPOLYGONALFACESET":
|
|
415
|
+
case "IFCFACETEDBREP": {
|
|
416
|
+
let pts = [];
|
|
417
|
+
if (item.type === "IFCFACETEDBREP") {
|
|
418
|
+
for (const f of list(get(item.args[0])?.args[0]))
|
|
419
|
+
for (const b of list(get(f)?.args[0]))
|
|
420
|
+
for (const q of list(get(get(b)?.args[0])?.args[0])) pts.push(point3(q));
|
|
421
|
+
} else pts = list(get(item.args[0])?.args[0]).map((q) => list(q).map((x) => num(x) ?? 0));
|
|
422
|
+
if (pts.length < 3) return;
|
|
423
|
+
const w = pts.map((q) => apply(m, q));
|
|
424
|
+
out.push({
|
|
425
|
+
outer: hull(w.map((q) => [q[0], q[1]])),
|
|
426
|
+
holes: [],
|
|
427
|
+
z0: Math.min(...w.map((q) => q[2])),
|
|
428
|
+
z1: Math.max(...w.map((q) => q[2]))
|
|
429
|
+
});
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
const body = (p) => {
|
|
435
|
+
const m = placement(p.args[5]);
|
|
436
|
+
const reps = list(get(p.args[6])?.args[2]).map(get).filter((r) => !!r);
|
|
437
|
+
const pick = (id) => reps.filter((r) => (str(r.args[1]) ?? "").toLowerCase() === id);
|
|
438
|
+
for (const r of [...pick("body"), ...pick("footprint"), ...reps]) {
|
|
439
|
+
const out = [];
|
|
440
|
+
for (const it of list(r.args[3])) solids(get(it), m, out);
|
|
441
|
+
if (out.length) return out;
|
|
442
|
+
}
|
|
443
|
+
return [];
|
|
444
|
+
};
|
|
445
|
+
const axisLine = (p) => {
|
|
446
|
+
const m = placement(p.args[5]);
|
|
447
|
+
for (const r of list(get(p.args[6])?.args[2]).map(get)) {
|
|
448
|
+
if ((str(r?.args[1]) ?? "").toLowerCase() !== "axis") continue;
|
|
449
|
+
for (const it of list(r?.args[3])) {
|
|
450
|
+
const pts = curve(it);
|
|
451
|
+
if (pts.length >= 2) {
|
|
452
|
+
const w = [pts[0], pts[pts.length - 1]].map((q) => apply(m, [q[0], q[1], 0]));
|
|
453
|
+
return w.map((q) => [q[0], q[1]]);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
return [];
|
|
458
|
+
};
|
|
459
|
+
const parent = /* @__PURE__ */ new Map();
|
|
460
|
+
const children = (rel, from, to) => {
|
|
461
|
+
for (const r of byType(rel)) {
|
|
462
|
+
const target = get(r.args[from]);
|
|
463
|
+
if (!target) continue;
|
|
464
|
+
for (const c of list(r.args[to])) {
|
|
465
|
+
const e = get(c);
|
|
466
|
+
if (e && !parent.has(e.id)) parent.set(e.id, target.id);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
children("IFCRELCONTAINEDINSPATIALSTRUCTURE", 5, 4);
|
|
471
|
+
children("IFCRELAGGREGATES", 4, 5);
|
|
472
|
+
children("IFCRELNESTS", 4, 5);
|
|
473
|
+
const voids = /* @__PURE__ */ new Map();
|
|
474
|
+
for (const r of byType("IFCRELVOIDSELEMENT")) {
|
|
475
|
+
const w = get(r.args[4]);
|
|
476
|
+
const o = get(r.args[5]);
|
|
477
|
+
if (w && o) voids.set(o.id, w.id);
|
|
478
|
+
}
|
|
479
|
+
const fills = /* @__PURE__ */ new Map();
|
|
480
|
+
for (const r of byType("IFCRELFILLSELEMENT")) {
|
|
481
|
+
const o = get(r.args[4]);
|
|
482
|
+
const f = get(r.args[5]);
|
|
483
|
+
if (o && f) fills.set(o.id, f.id);
|
|
484
|
+
}
|
|
485
|
+
const connected = /* @__PURE__ */ new Map();
|
|
486
|
+
for (const r of byType("IFCRELCONNECTSELEMENTS")) {
|
|
487
|
+
const a = get(r.args[5]);
|
|
488
|
+
const b = get(r.args[6]);
|
|
489
|
+
if (a && b) connected.set(a.id, [...connected.get(a.id) ?? [], b.id]);
|
|
490
|
+
}
|
|
491
|
+
const props = /* @__PURE__ */ new Map();
|
|
492
|
+
for (const r of byType("IFCRELDEFINESBYPROPERTIES")) {
|
|
493
|
+
const set = get(r.args[5]);
|
|
494
|
+
if (set?.type !== "IFCPROPERTYSET") continue;
|
|
495
|
+
const name = str(set.args[2]) ?? "";
|
|
496
|
+
const values = /* @__PURE__ */ new Map();
|
|
497
|
+
for (const pv of list(set.args[4]).map(get))
|
|
498
|
+
if (pv?.type === "IFCPROPERTYSINGLEVALUE") values.set(str(pv.args[0]) ?? "", pv.args[2]);
|
|
499
|
+
for (const o of list(r.args[4])) {
|
|
500
|
+
const e = get(o);
|
|
501
|
+
if (!e) continue;
|
|
502
|
+
if (!props.has(e.id)) props.set(e.id, /* @__PURE__ */ new Map());
|
|
503
|
+
props.get(e.id).set(name, values);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
const prop = (e, set, name) => props.get(e.id)?.get(set)?.get(name);
|
|
507
|
+
const layers = /* @__PURE__ */ new Map();
|
|
508
|
+
for (const r of byType("IFCRELASSOCIATESMATERIAL")) {
|
|
509
|
+
let mat = get(r.args[5]);
|
|
510
|
+
if (mat?.type === "IFCMATERIALLAYERSETUSAGE") mat = get(mat.args[0]);
|
|
511
|
+
if (mat?.type !== "IFCMATERIALLAYERSET") continue;
|
|
512
|
+
const t = list(mat.args[0]).reduce((s, l) => s + (num(get(l)?.args[1]) ?? 0), 0);
|
|
513
|
+
for (const o of list(r.args[4])) {
|
|
514
|
+
const e = get(o);
|
|
515
|
+
if (e && t > 0) layers.set(e.id, t);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
const storeyEnts = byType("IFCBUILDINGSTOREY");
|
|
519
|
+
if (!storeyEnts.length)
|
|
520
|
+
throw new IfcError("The file has no storeys (IfcBuildingStorey), so there is no floor to read.");
|
|
521
|
+
const elevation = (s) => num(s.args[9]) ?? placement(s.args[5]).o[2];
|
|
522
|
+
storeyEnts.sort((a, b) => elevation(a) - elevation(b));
|
|
523
|
+
const ground = storeyEnts.reduce((best, s) => Math.abs(elevation(s)) < Math.abs(elevation(best)) ? s : best);
|
|
524
|
+
const storeyOf = (e) => {
|
|
525
|
+
let id = e.id;
|
|
526
|
+
for (let k = 0; id !== void 0 && k < 50; k++) {
|
|
527
|
+
const x = ents.get(id);
|
|
528
|
+
if (x?.type === "IFCBUILDINGSTOREY") return x;
|
|
529
|
+
id = parent.get(id);
|
|
530
|
+
}
|
|
531
|
+
return void 0;
|
|
532
|
+
};
|
|
533
|
+
const takenSpace = /* @__PURE__ */ new Set();
|
|
534
|
+
const slug = (s, fallback, taken) => {
|
|
535
|
+
let base = s.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || fallback;
|
|
536
|
+
if (!ID.test(base)) base = fallback;
|
|
537
|
+
let id = base;
|
|
538
|
+
for (let n = 2; taken.has(id); n++) id = `${base}-${n}`;
|
|
539
|
+
taken.add(id);
|
|
540
|
+
return id;
|
|
541
|
+
};
|
|
542
|
+
const takenStorey = /* @__PURE__ */ new Set();
|
|
543
|
+
const gi = storeyEnts.indexOf(ground);
|
|
544
|
+
const floors = storeyEnts.map((s, i) => {
|
|
545
|
+
const name = (str(s.args[2]) || str(s.args[7]) || `Floor ${i - gi}`).slice(0, 80);
|
|
546
|
+
return {
|
|
547
|
+
ent: s,
|
|
548
|
+
z: elevation(s),
|
|
549
|
+
ids: /* @__PURE__ */ new Set(),
|
|
550
|
+
walls: [],
|
|
551
|
+
storey: {
|
|
552
|
+
id: slug(name, `storey-${i}`, takenStorey),
|
|
553
|
+
name,
|
|
554
|
+
level: i - gi,
|
|
555
|
+
elevation: mm(elevation(s)),
|
|
556
|
+
height: DEFAULTS.storeyHeight,
|
|
557
|
+
walls: [],
|
|
558
|
+
spaces: [],
|
|
559
|
+
openings: [],
|
|
560
|
+
radiators: [],
|
|
561
|
+
furniture: [],
|
|
562
|
+
placements: []
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
});
|
|
566
|
+
const floorOf = new Map(floors.map((f) => [f.ent.id, f]));
|
|
567
|
+
const floorFor = (e) => {
|
|
568
|
+
const s = storeyOf(e);
|
|
569
|
+
if (s && floorOf.has(s.id)) return floorOf.get(s.id);
|
|
570
|
+
const z = placement(e.args[5]).o[2];
|
|
571
|
+
return floors.filter((f) => f.z <= z + 1e-6).pop() ?? floors[0];
|
|
572
|
+
};
|
|
573
|
+
const elementId = (f, e, prefix) => {
|
|
574
|
+
const tag = str(e.args[7]);
|
|
575
|
+
if (tag && ID.test(tag) && !f.ids.has(tag)) {
|
|
576
|
+
f.ids.add(tag);
|
|
577
|
+
return tag;
|
|
578
|
+
}
|
|
579
|
+
let n = 1;
|
|
580
|
+
while (f.ids.has(`${prefix}${n}`)) n++;
|
|
581
|
+
f.ids.add(`${prefix}${n}`);
|
|
582
|
+
return `${prefix}${n}`;
|
|
583
|
+
};
|
|
584
|
+
const P = (q) => [q[0] * K, -q[1] * K];
|
|
585
|
+
const skipped = /* @__PURE__ */ new Map();
|
|
586
|
+
const skip = (what) => skipped.set(what, (skipped.get(what) ?? 0) + 1);
|
|
587
|
+
for (const e of [...ents.values()].filter((x) => WALLS.has(x.type))) {
|
|
588
|
+
const f = floorFor(e);
|
|
589
|
+
const parts = body(e);
|
|
590
|
+
const ax = axisLine(e).map(P);
|
|
591
|
+
let a = null;
|
|
592
|
+
let b = null;
|
|
593
|
+
let thickness = layers.get(e.id) !== void 0 ? layers.get(e.id) * K : null;
|
|
594
|
+
const part = parts[0];
|
|
595
|
+
if (ax.length === 2 && Math.hypot(ax[1][0] - ax[0][0], ax[1][1] - ax[0][1]) > 1) {
|
|
596
|
+
;
|
|
597
|
+
[a, b] = ax;
|
|
598
|
+
if (part) {
|
|
599
|
+
const u = unit2(a, b);
|
|
600
|
+
const n = [-u[1], u[0]];
|
|
601
|
+
const across = part.outer.map(P).map((q) => (q[0] - a[0]) * n[0] + (q[1] - a[1]) * n[1]);
|
|
602
|
+
const lo = Math.min(...across);
|
|
603
|
+
const hi = Math.max(...across);
|
|
604
|
+
if (hi - lo > 1) {
|
|
605
|
+
thickness = hi - lo;
|
|
606
|
+
const mid = (lo + hi) / 2;
|
|
607
|
+
a = [a[0] + n[0] * mid, a[1] + n[1] * mid];
|
|
608
|
+
b = [b[0] + n[0] * mid, b[1] + n[1] * mid];
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
} else if (part?.rect && parts.length === 1) {
|
|
612
|
+
const { m, w, d } = part.rect;
|
|
613
|
+
const long = w >= d;
|
|
614
|
+
const along = long ? m.x : m.y;
|
|
615
|
+
const half = (long ? w : d) / 2;
|
|
616
|
+
const s = add(m.o, scale(along, -half));
|
|
617
|
+
const t = add(m.o, scale(along, half));
|
|
618
|
+
a = P([s[0], s[1]]);
|
|
619
|
+
b = P([t[0], t[1]]);
|
|
620
|
+
thickness = (long ? d : w) * K;
|
|
621
|
+
} else if (part) {
|
|
622
|
+
const mid = middleLine(part.outer.map(P));
|
|
623
|
+
if (mid) {
|
|
624
|
+
;
|
|
625
|
+
[a, b] = mid.ends;
|
|
626
|
+
thickness = mid.width;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (!a || !b || Math.hypot(b[0] - a[0], b[1] - a[1]) < 10) {
|
|
630
|
+
skip("walls with no shape this reader understands");
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
const height = part ? (Math.max(...parts.map((q) => q.z1)) - Math.min(...parts.map((q) => q.z0))) * K : DEFAULTS.wallHeight;
|
|
634
|
+
const wall = {
|
|
635
|
+
id: elementId(f, e, "w"),
|
|
636
|
+
a: [Math.round(a[0]), Math.round(a[1])],
|
|
637
|
+
b: [Math.round(b[0]), Math.round(b[1])],
|
|
638
|
+
thickness: clampInt(thickness ?? 200, 10, 2e3),
|
|
639
|
+
height: clampInt(height, 100, 2e4)
|
|
640
|
+
};
|
|
641
|
+
f.storey.walls.push(wall);
|
|
642
|
+
f.walls.push({ wall, ent: e });
|
|
643
|
+
}
|
|
644
|
+
const curtain = byType("IFCCURTAINWALL").length;
|
|
645
|
+
if (curtain)
|
|
646
|
+
notes.push(`${curtain} curtain wall${curtain === 1 ? " was" : "s were"} left out: draw them as walls with windows.`);
|
|
647
|
+
const wallOf = /* @__PURE__ */ new Map();
|
|
648
|
+
for (const f of floors) for (const w of f.walls) wallOf.set(w.ent.id, { f, wall: w.wall });
|
|
649
|
+
for (const [openingId, wallId] of voids) {
|
|
650
|
+
const host = wallOf.get(wallId);
|
|
651
|
+
const op = ents.get(openingId);
|
|
652
|
+
if (!host || !op) continue;
|
|
653
|
+
const { f, wall } = host;
|
|
654
|
+
const fill = fills.has(openingId) ? ents.get(fills.get(openingId)) : void 0;
|
|
655
|
+
const len = Math.hypot(wall.b[0] - wall.a[0], wall.b[1] - wall.a[1]);
|
|
656
|
+
const u = unit2(wall.a, wall.b);
|
|
657
|
+
const along = (q) => (q[0] - wall.a[0]) * u[0] + (q[1] - wall.a[1]) * u[1];
|
|
658
|
+
const opParts = body(op);
|
|
659
|
+
const fillParts = fill ? body(fill) : [];
|
|
660
|
+
const span = (parts) => {
|
|
661
|
+
const ts = parts.flatMap((p) => p.outer.map(P)).map(along);
|
|
662
|
+
return ts.length ? [Math.max(0, Math.min(...ts)), Math.min(len, Math.max(...ts))] : null;
|
|
663
|
+
};
|
|
664
|
+
let s = span(opParts) ?? span(fillParts);
|
|
665
|
+
if (!s && fill) {
|
|
666
|
+
const o = placement(fill.args[5]).o;
|
|
667
|
+
const t0 = along(P([o[0], o[1]]));
|
|
668
|
+
const w = (num(fill.args[9]) ?? 0) * K;
|
|
669
|
+
s = [Math.max(0, t0), Math.min(len, t0 + w)];
|
|
670
|
+
}
|
|
671
|
+
if (!s || s[1] - s[0] < 50) {
|
|
672
|
+
skip(fill ? `${fill.type === "IFCDOOR" ? "doors" : "windows"} that fit no wall` : "openings that fit no wall");
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
const at = Math.round(s[0]);
|
|
676
|
+
const width = Math.min(Math.round(s[1] - s[0]), Math.floor(len) - at);
|
|
677
|
+
if (width < 1 || at >= Math.floor(len)) continue;
|
|
678
|
+
const zs = (fillParts.length ? fillParts : opParts).flatMap((p) => [p.z0, p.z1]);
|
|
679
|
+
let sill = zs.length ? Math.round((Math.min(...zs) - f.z) * K) : 0;
|
|
680
|
+
let head = zs.length ? Math.round((Math.max(...zs) - f.z) * K) : wall.height;
|
|
681
|
+
const pSill = num(fill ? prop(fill, "House_Opening", "SillHeight") : void 0);
|
|
682
|
+
const pHead = num(fill ? prop(fill, "House_Opening", "HeadHeight") : void 0);
|
|
683
|
+
if (pSill !== null) sill = Math.round(pSill * K);
|
|
684
|
+
if (pHead !== null) head = Math.round(pHead * K);
|
|
685
|
+
sill = Math.max(0, sill);
|
|
686
|
+
head = Math.max(sill + 1, head);
|
|
687
|
+
const base = { id: "", wall: wall.id, at, width };
|
|
688
|
+
let opening;
|
|
689
|
+
if (!fill || fill.type !== "IFCDOOR" && fill.type !== "IFCWINDOW") {
|
|
690
|
+
if (sill > 10 || head < wall.height - 10) {
|
|
691
|
+
skip("recesses and holes that are not doors or windows");
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
opening = { ...base, id: elementId(f, op, "o"), kind: "gap" };
|
|
695
|
+
} else {
|
|
696
|
+
const label = (n) => str(prop(fill, "House_Opening", n));
|
|
697
|
+
const ours = !!props.get(fill.id)?.has("House_Opening");
|
|
698
|
+
const opType = en(fill.args[11]);
|
|
699
|
+
const user = str(fill.args[12]) ?? "";
|
|
700
|
+
const fm = placement(fill.args[5]);
|
|
701
|
+
const backwards = fm.x[0] * u[0] + -fm.x[1] * u[1] < 0;
|
|
702
|
+
const side = (s2) => backwards ? s2 === "start" ? "end" : "start" : s2;
|
|
703
|
+
const frameMaterial = label("FrameMaterial");
|
|
704
|
+
const frameColour = label("FrameColour");
|
|
705
|
+
const frame2 = {};
|
|
706
|
+
if (frameMaterial && FRAME_MATERIALS.includes(frameMaterial))
|
|
707
|
+
frame2.material = frameMaterial;
|
|
708
|
+
if (frameColour && /^#[0-9a-fA-F]{6}$/.test(frameColour)) frame2.colour = frameColour.toLowerCase();
|
|
709
|
+
const hinge = label("Hinge");
|
|
710
|
+
const opens = label("Opens");
|
|
711
|
+
const extra = {
|
|
712
|
+
sill,
|
|
713
|
+
head,
|
|
714
|
+
...frame2.material || frame2.colour ? { frame: frame2 } : {},
|
|
715
|
+
...hinge === "start" || hinge === "end" ? { hinge } : {},
|
|
716
|
+
...opens === "left" || opens === "right" ? { opens } : {}
|
|
717
|
+
};
|
|
718
|
+
const id = elementId(f, fill, fill.type === "IFCDOOR" ? "d" : "win");
|
|
719
|
+
if (fill.type === "IFCDOOR") {
|
|
720
|
+
let operation = label("Operation");
|
|
721
|
+
let hingeFromType;
|
|
722
|
+
if (!ours && (!operation || !DOOR_OPERATIONS.includes(operation))) {
|
|
723
|
+
const t = opType ?? "";
|
|
724
|
+
operation = /SLIDING/.test(t) ? "sliding" : /FOLDING/.test(t) ? "folding" : /DOUBLE_DOOR_SINGLE_SWING|DOUBLE_SWING/.test(t) ? "double-swing" : t === "USERDEFINED" && /LIFT/.test(user) ? "lift-slide" : t === "USERDEFINED" && /POCKET/.test(user) ? "pocket" : "swing";
|
|
725
|
+
if (/_LEFT$/.test(t)) hingeFromType = side("start");
|
|
726
|
+
else if (/_RIGHT$/.test(t)) hingeFromType = side("end");
|
|
727
|
+
}
|
|
728
|
+
const leaf = label("Leaf");
|
|
729
|
+
opening = {
|
|
730
|
+
...base,
|
|
731
|
+
...extra,
|
|
732
|
+
...extra.hinge || !hingeFromType ? {} : { hinge: hingeFromType },
|
|
733
|
+
id,
|
|
734
|
+
kind: "door",
|
|
735
|
+
operation: operation && DOOR_OPERATIONS.includes(operation) ? operation : "swing",
|
|
736
|
+
leaf: leaf && LEAVES.includes(leaf) ? leaf : "solid"
|
|
737
|
+
};
|
|
738
|
+
} else {
|
|
739
|
+
const operation = label("Operation");
|
|
740
|
+
opening = {
|
|
741
|
+
...base,
|
|
742
|
+
...extra,
|
|
743
|
+
id,
|
|
744
|
+
kind: "window",
|
|
745
|
+
operation: operation && WINDOW_OPERATIONS.includes(operation) ? operation : "casement"
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
if (opening.kind === "window" || opening.leaf !== "solid") {
|
|
749
|
+
const taken = /* @__PURE__ */ new Set();
|
|
750
|
+
const coverings = [];
|
|
751
|
+
for (const cid of connected.get(fill.id) ?? []) {
|
|
752
|
+
const c = ents.get(cid);
|
|
753
|
+
if (c?.type !== "IFCSHADINGDEVICE") continue;
|
|
754
|
+
const kind = str(prop(c, "House_Covering", "Kind"));
|
|
755
|
+
const t = en(c.args[8]);
|
|
756
|
+
const k = kind && COVERING_KINDS.includes(kind) ? kind : t === "SHUTTER" ? "shutter" : t === "JALOUSIE" ? "external-blind" : t === "AWNING" ? "awning" : null;
|
|
757
|
+
if (!k || coverings.length >= 6) continue;
|
|
758
|
+
const sideLabel = str(prop(c, "House_Covering", "Side"));
|
|
759
|
+
const tag = str(c.args[7]);
|
|
760
|
+
let cId = tag && ID.test(tag) && !taken.has(tag) ? tag : "";
|
|
761
|
+
for (let n = 1; !cId || taken.has(cId); n++) cId = `c${n}`;
|
|
762
|
+
taken.add(cId);
|
|
763
|
+
coverings.push({ id: cId, kind: k, side: sideLabel === "inside" ? "inside" : "outside" });
|
|
764
|
+
}
|
|
765
|
+
if (coverings.length) opening.coverings = coverings;
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
f.storey.openings.push(opening);
|
|
769
|
+
}
|
|
770
|
+
const filled = new Set(fills.values());
|
|
771
|
+
const unhosted = byType("IFCDOOR", "IFCWINDOW").filter((d) => !filled.has(d.id)).length;
|
|
772
|
+
if (unhosted) skipped.set("doors and windows in no opening of a wall", unhosted);
|
|
773
|
+
for (const e of byType("IFCSPACE")) {
|
|
774
|
+
const f = floorFor(e);
|
|
775
|
+
const parts = body(e);
|
|
776
|
+
const part = parts.reduce(
|
|
777
|
+
(best, q) => !best || Math.abs(polyArea(q.outer)) > Math.abs(polyArea(best.outer)) ? q : best,
|
|
778
|
+
void 0
|
|
779
|
+
);
|
|
780
|
+
if (!part) {
|
|
781
|
+
skip("spaces with no shape");
|
|
782
|
+
continue;
|
|
783
|
+
}
|
|
784
|
+
const name = (str(e.args[7]) || str(e.args[2]) || "Room").trim().slice(0, 80) || "Room";
|
|
785
|
+
const type = en(e.args[9]);
|
|
786
|
+
const objectType = (str(e.args[4]) ?? "").toLowerCase();
|
|
787
|
+
const kind = objectType === "pool" ? "pool" : objectType === "paving" ? "paved" : type === "EXTERNAL" ? "outdoor" : "room";
|
|
788
|
+
const ring = (pts) => clockwise(tidyLoop(pts.map(P)));
|
|
789
|
+
const outline = ring(part.outer);
|
|
790
|
+
if (outline.length < 3) {
|
|
791
|
+
skip("spaces with no shape");
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
794
|
+
const space = { id: slug(name, "space", takenSpace), name, kind, outline };
|
|
795
|
+
const holes = part.holes.map(ring).filter((h) => h.length >= 3);
|
|
796
|
+
if (holes.length) space.holes = holes;
|
|
797
|
+
f.storey.spaces.push(space);
|
|
798
|
+
}
|
|
799
|
+
for (const e of byType("IFCSPACEHEATER")) {
|
|
800
|
+
const f = floorFor(e);
|
|
801
|
+
const parts = body(e);
|
|
802
|
+
const part = parts[0];
|
|
803
|
+
if (!part) {
|
|
804
|
+
skip("radiators with no shape");
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
let r;
|
|
808
|
+
if (part.rect && parts.length === 1) {
|
|
809
|
+
const m = placement(e.args[5]);
|
|
810
|
+
const o = P([m.o[0], m.o[1]]);
|
|
811
|
+
const x = [m.x[0], -m.x[1]];
|
|
812
|
+
const lx = Math.hypot(x[0], x[1]) || 1;
|
|
813
|
+
const len = Math.max(part.rect.w, part.rect.d) * K;
|
|
814
|
+
const c = part.rect.m.o;
|
|
815
|
+
const local = (c[0] - m.o[0]) * m.y[0] + (c[1] - m.o[1]) * m.y[1];
|
|
816
|
+
r = {
|
|
817
|
+
id: elementId(f, e, "r"),
|
|
818
|
+
a: [Math.round(o[0]), Math.round(o[1])],
|
|
819
|
+
b: [Math.round(o[0] + x[0] / lx * len), Math.round(o[1] + x[1] / lx * len)],
|
|
820
|
+
side: local >= 0 ? "left" : "right"
|
|
821
|
+
};
|
|
822
|
+
} else {
|
|
823
|
+
const mid = middleLine(part.outer.map(P));
|
|
824
|
+
if (!mid) continue;
|
|
825
|
+
r = {
|
|
826
|
+
id: elementId(f, e, "r"),
|
|
827
|
+
a: mid.ends[0].map(Math.round),
|
|
828
|
+
b: mid.ends[1].map(Math.round),
|
|
829
|
+
side: "left"
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
if (r.a[0] === r.b[0] && r.a[1] === r.b[1]) continue;
|
|
833
|
+
f.storey.radiators.push(r);
|
|
834
|
+
}
|
|
835
|
+
const byName = new Map(Object.entries(FURNITURE_NAME).map(([k, v]) => [v.toLowerCase(), k]));
|
|
836
|
+
for (const e of [...ents.values()].filter((x) => FURNISHING.has(x.type))) {
|
|
837
|
+
const f = floorFor(e);
|
|
838
|
+
const parts = body(e);
|
|
839
|
+
if (!parts.length) {
|
|
840
|
+
skip("furniture with no shape");
|
|
841
|
+
continue;
|
|
842
|
+
}
|
|
843
|
+
const pts = parts.flatMap((q) => q.outer.map(P));
|
|
844
|
+
const xs = pts.map((q) => q[0]);
|
|
845
|
+
const ys = pts.map((q) => q[1]);
|
|
846
|
+
const name = str(e.args[2]) ?? "";
|
|
847
|
+
const objectType = str(e.args[4]) ?? "";
|
|
848
|
+
const predefined = en(e.args[8]) ?? "";
|
|
849
|
+
const kind = byName.get(name.toLowerCase()) ?? byName.get(objectType.toLowerCase()) ?? SANITARY_KIND[predefined] ?? FURNITURE_WORDS.find(([re]) => re.test(`${name} ${objectType}`))?.[1] ?? "cabinet";
|
|
850
|
+
const x = Math.round(Math.min(...xs));
|
|
851
|
+
const y = Math.round(Math.min(...ys));
|
|
852
|
+
const u = {
|
|
853
|
+
id: elementId(f, e, "f"),
|
|
854
|
+
kind: FURNITURE_KINDS.includes(kind) ? kind : "cabinet",
|
|
855
|
+
x,
|
|
856
|
+
y,
|
|
857
|
+
w: Math.max(1, Math.round(Math.max(...xs)) - x),
|
|
858
|
+
d: Math.max(1, Math.round(Math.max(...ys)) - y)
|
|
859
|
+
};
|
|
860
|
+
const height = Math.round((Math.max(...parts.map((q) => q.z1)) - Math.min(...parts.map((q) => q.z0))) * K);
|
|
861
|
+
if (height >= 100 && height <= 3e3 && Math.abs(height - FURNITURE_HEIGHT[u.kind]) > 1) u.height = height;
|
|
862
|
+
f.storey.furniture.push(u);
|
|
863
|
+
}
|
|
864
|
+
for (const f of floors)
|
|
865
|
+
for (const s of f.storey.spaces) if (s.kind === "room") s.outline = toWallLines(s.outline, f.storey.walls);
|
|
866
|
+
floors.forEach((f, i) => {
|
|
867
|
+
const next = floors[i + 1];
|
|
868
|
+
const walls = Math.max(0, ...f.storey.walls.map((w) => w.height));
|
|
869
|
+
f.storey.height = clampInt(
|
|
870
|
+
next ? next.storey.elevation - f.storey.elevation : Math.max(DEFAULTS.storeyHeight, walls + 300),
|
|
871
|
+
1e3,
|
|
872
|
+
2e4
|
|
873
|
+
);
|
|
874
|
+
});
|
|
875
|
+
const levels = /* @__PURE__ */ new Map();
|
|
876
|
+
for (const f of floors) {
|
|
877
|
+
const twin = [...levels.values()].find((g) => g.storey.elevation === f.storey.elevation);
|
|
878
|
+
if (twin) {
|
|
879
|
+
notes.push(`"${f.storey.name}" is at the same height as "${twin.storey.name}", so it was joined to it.`);
|
|
880
|
+
twin.storey.walls.push(...f.storey.walls);
|
|
881
|
+
twin.storey.spaces.push(...f.storey.spaces);
|
|
882
|
+
twin.storey.openings.push(...f.storey.openings);
|
|
883
|
+
twin.storey.radiators.push(...f.storey.radiators);
|
|
884
|
+
twin.storey.furniture.push(...f.storey.furniture);
|
|
885
|
+
} else levels.set(f.storey.level, f);
|
|
886
|
+
}
|
|
887
|
+
const storeys = [...levels.values()].map((f) => f.storey);
|
|
888
|
+
const all = storeys.flatMap((s) => [
|
|
889
|
+
...s.walls.flatMap((w) => {
|
|
890
|
+
const h = w.thickness / 2;
|
|
891
|
+
return [w.a, w.b].flatMap((q) => [
|
|
892
|
+
[q[0] - h, q[1] - h],
|
|
893
|
+
[q[0] + h, q[1] + h]
|
|
894
|
+
]);
|
|
895
|
+
}),
|
|
896
|
+
...s.spaces.flatMap((x) => x.outline),
|
|
897
|
+
...s.radiators.flatMap((r) => [r.a, r.b]),
|
|
898
|
+
...s.furniture.flatMap((u) => [
|
|
899
|
+
[u.x, u.y],
|
|
900
|
+
[u.x + u.w, u.y + u.d]
|
|
901
|
+
])
|
|
902
|
+
]);
|
|
903
|
+
if (!all.length)
|
|
904
|
+
throw new IfcError("Nothing in the file could be read as part of a house: no walls, rooms or furniture.");
|
|
905
|
+
const site = byType("IFCSITE")[0];
|
|
906
|
+
const given = site ? {
|
|
907
|
+
w: num(prop(site, "House_Site", "Width")),
|
|
908
|
+
h: num(prop(site, "House_Site", "Depth")),
|
|
909
|
+
snap: num(prop(site, "House_Site", "Snap"))
|
|
910
|
+
} : null;
|
|
911
|
+
const minX = Math.min(...all.map((q) => q[0]));
|
|
912
|
+
const minY = Math.min(...all.map((q) => q[1]));
|
|
913
|
+
const MARGIN = 1e3;
|
|
914
|
+
const dx = minX < 0 || !given?.w ? Math.ceil((MARGIN - minX) / 500) * 500 : 0;
|
|
915
|
+
const dy = minY < 0 || !given?.h ? Math.ceil((MARGIN - minY) / 500) * 500 : 0;
|
|
916
|
+
const shift = (q) => [q[0] + dx, q[1] + dy];
|
|
917
|
+
if (dx || dy)
|
|
918
|
+
for (const s of storeys) {
|
|
919
|
+
for (const w of s.walls) Object.assign(w, { a: shift(w.a), b: shift(w.b) });
|
|
920
|
+
for (const x of s.spaces) {
|
|
921
|
+
x.outline = x.outline.map(shift);
|
|
922
|
+
if (x.holes) x.holes = x.holes.map((h) => h.map(shift));
|
|
923
|
+
}
|
|
924
|
+
for (const r of s.radiators) Object.assign(r, { a: shift(r.a), b: shift(r.b) });
|
|
925
|
+
for (const u of s.furniture) Object.assign(u, { x: u.x + dx, y: u.y + dy });
|
|
926
|
+
}
|
|
927
|
+
const maxX = Math.max(...all.map((q) => q[0])) + dx;
|
|
928
|
+
const maxY = Math.max(...all.map((q) => q[1])) + dy;
|
|
929
|
+
const fitW = Math.ceil((maxX + MARGIN) / 500) * 500;
|
|
930
|
+
const fitH = Math.ceil((maxY + MARGIN) / 500) * 500;
|
|
931
|
+
const siteSize = {
|
|
932
|
+
w: given?.w && !dx && mm(given.w) >= maxX ? mm(given.w) : fitW,
|
|
933
|
+
h: given?.h && !dy && mm(given.h) >= maxY ? mm(given.h) : fitH
|
|
934
|
+
};
|
|
935
|
+
if (siteSize.w > 2e5 || siteSize.h > 2e5)
|
|
936
|
+
throw new IfcError("What the file holds is more than 200 m across, more than a house plan can take.");
|
|
937
|
+
for (const s of storeys)
|
|
938
|
+
for (const u of s.furniture) {
|
|
939
|
+
u.x = clampInt(u.x, 0, siteSize.w - 1);
|
|
940
|
+
u.y = clampInt(u.y, 0, siteSize.h - 1);
|
|
941
|
+
u.w = clampInt(u.w, 1, siteSize.w - u.x);
|
|
942
|
+
u.d = clampInt(u.d, 1, siteSize.h - u.y);
|
|
943
|
+
}
|
|
944
|
+
const snap = given?.snap ? clampInt(mm(given.snap), 1, 1e4) : 10;
|
|
945
|
+
for (const [what, n] of skipped) notes.push(`Left out ${what}: ${n}.`);
|
|
946
|
+
const plan = { version: PLAN_VERSION, unit: "mm", site: siteSize, snap, storeys };
|
|
947
|
+
try {
|
|
948
|
+
return { plan: validatePlan(JSON.parse(JSON.stringify(plan))), notes };
|
|
949
|
+
} catch (e) {
|
|
950
|
+
if (e instanceof PlanError) throw new IfcError(`The file was read, but what it gave is not a plan: ${e.message}`);
|
|
951
|
+
throw e;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
var clampInt = (v, lo, hi) => Math.min(hi, Math.max(lo, Math.round(v)));
|
|
955
|
+
function unit2(a, b) {
|
|
956
|
+
const l = Math.hypot(b[0] - a[0], b[1] - a[1]) || 1;
|
|
957
|
+
return [(b[0] - a[0]) / l, (b[1] - a[1]) / l];
|
|
958
|
+
}
|
|
959
|
+
function polyArea(pts) {
|
|
960
|
+
let s = 0;
|
|
961
|
+
for (let i = 0; i < pts.length; i++) {
|
|
962
|
+
const [x1, y1] = pts[i];
|
|
963
|
+
const [x2, y2] = pts[(i + 1) % pts.length];
|
|
964
|
+
s += x1 * y2 - x2 * y1;
|
|
965
|
+
}
|
|
966
|
+
return s / 2;
|
|
967
|
+
}
|
|
968
|
+
function hull(pts) {
|
|
969
|
+
const p = [...pts].sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
970
|
+
if (p.length < 3) return p;
|
|
971
|
+
const turnOf = (o, a, b) => (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]);
|
|
972
|
+
const lower = [];
|
|
973
|
+
for (const q of p) {
|
|
974
|
+
while (lower.length >= 2 && turnOf(lower[lower.length - 2], lower[lower.length - 1], q) <= 0) lower.pop();
|
|
975
|
+
lower.push(q);
|
|
976
|
+
}
|
|
977
|
+
const upper = [];
|
|
978
|
+
for (const q of p.reverse()) {
|
|
979
|
+
while (upper.length >= 2 && turnOf(upper[upper.length - 2], upper[upper.length - 1], q) <= 0) upper.pop();
|
|
980
|
+
upper.push(q);
|
|
981
|
+
}
|
|
982
|
+
return [...lower.slice(0, -1), ...upper.slice(0, -1)];
|
|
983
|
+
}
|
|
984
|
+
function middleLine(pts) {
|
|
985
|
+
if (pts.length < 3) return null;
|
|
986
|
+
let best = -1;
|
|
987
|
+
let u = [1, 0];
|
|
988
|
+
pts.forEach((p, i) => {
|
|
989
|
+
const q = pts[(i + 1) % pts.length];
|
|
990
|
+
const l = Math.hypot(q[0] - p[0], q[1] - p[1]);
|
|
991
|
+
if (l > best) {
|
|
992
|
+
best = l;
|
|
993
|
+
u = [(q[0] - p[0]) / l, (q[1] - p[1]) / l];
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
if (u[0] < 0 || u[0] === 0 && u[1] < 0) u = [-u[0], -u[1]];
|
|
997
|
+
const n = [-u[1], u[0]];
|
|
998
|
+
const al = (q) => q[0] * u[0] + q[1] * u[1];
|
|
999
|
+
const ac = (q) => q[0] * n[0] + q[1] * n[1];
|
|
1000
|
+
const across = pts.map(ac);
|
|
1001
|
+
const lo = Math.min(...across);
|
|
1002
|
+
const hi = Math.max(...across);
|
|
1003
|
+
const mid = (lo + hi) / 2;
|
|
1004
|
+
const sides = [
|
|
1005
|
+
[Infinity, -Infinity],
|
|
1006
|
+
[Infinity, -Infinity]
|
|
1007
|
+
];
|
|
1008
|
+
pts.forEach((p, i) => {
|
|
1009
|
+
const q = pts[(i + 1) % pts.length];
|
|
1010
|
+
const l = Math.hypot(q[0] - p[0], q[1] - p[1]);
|
|
1011
|
+
if (!l || Math.abs(((q[0] - p[0]) * n[0] + (q[1] - p[1]) * n[1]) / l) > 0.035) return;
|
|
1012
|
+
const k = ac(p) < mid ? 0 : 1;
|
|
1013
|
+
sides[k] = [Math.min(sides[k][0], al(p), al(q)), Math.max(sides[k][1], al(p), al(q))];
|
|
1014
|
+
});
|
|
1015
|
+
const all = pts.map(al);
|
|
1016
|
+
const ok = sides.every((s) => s[0] <= s[1]);
|
|
1017
|
+
const t0 = ok ? (sides[0][0] + sides[1][0]) / 2 : Math.min(...all);
|
|
1018
|
+
const t1 = ok ? (sides[0][1] + sides[1][1]) / 2 : Math.max(...all);
|
|
1019
|
+
const at = (t) => [u[0] * t + n[0] * mid, u[1] * t + n[1] * mid];
|
|
1020
|
+
return { ends: [at(t0), at(t1)], width: hi - lo };
|
|
1021
|
+
}
|
|
1022
|
+
function tidyLoop(pts) {
|
|
1023
|
+
let out = pts.map((q) => [Math.round(q[0]), Math.round(q[1])]);
|
|
1024
|
+
out = out.filter((q, i) => {
|
|
1025
|
+
const p = out[(i + out.length - 1) % out.length];
|
|
1026
|
+
return q[0] !== p[0] || q[1] !== p[1];
|
|
1027
|
+
});
|
|
1028
|
+
for (let changed = true; changed && out.length > 3; ) {
|
|
1029
|
+
changed = false;
|
|
1030
|
+
for (let i = 0; i < out.length; i++) {
|
|
1031
|
+
const p = out[(i + out.length - 1) % out.length];
|
|
1032
|
+
const q = out[i];
|
|
1033
|
+
const r = out[(i + 1) % out.length];
|
|
1034
|
+
if ((q[0] - p[0]) * (r[1] - q[1]) - (q[1] - p[1]) * (r[0] - q[0]) === 0) {
|
|
1035
|
+
out.splice(i, 1);
|
|
1036
|
+
changed = true;
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return out;
|
|
1042
|
+
}
|
|
1043
|
+
function clockwise(pts) {
|
|
1044
|
+
return area(pts) < 0 ? [...pts].reverse() : pts;
|
|
1045
|
+
}
|
|
1046
|
+
function toWallLines(outline, walls) {
|
|
1047
|
+
const n = outline.length;
|
|
1048
|
+
const lines = outline.map((p, i) => {
|
|
1049
|
+
const q = outline[(i + 1) % n];
|
|
1050
|
+
const u = unit2(p, q);
|
|
1051
|
+
const len = Math.hypot(q[0] - p[0], q[1] - p[1]);
|
|
1052
|
+
let move = 0;
|
|
1053
|
+
let found = Infinity;
|
|
1054
|
+
for (const w of walls) {
|
|
1055
|
+
const wu = unit2(w.a, w.b);
|
|
1056
|
+
if (Math.abs(u[0] * wu[1] - u[1] * wu[0]) > 0.0175) continue;
|
|
1057
|
+
const nn = [-wu[1], wu[0]];
|
|
1058
|
+
const d = (p[0] - w.a[0]) * nn[0] + (p[1] - w.a[1]) * nn[1];
|
|
1059
|
+
const half = w.thickness / 2;
|
|
1060
|
+
if (Math.abs(Math.abs(d) - half) > Math.max(25, half * 0.15)) continue;
|
|
1061
|
+
const t = (x) => (x[0] - w.a[0]) * wu[0] + (x[1] - w.a[1]) * wu[1];
|
|
1062
|
+
const wl = Math.hypot(w.b[0] - w.a[0], w.b[1] - w.a[1]);
|
|
1063
|
+
const [e0, e1] = [t(p), t(q)].sort((x, y) => x - y);
|
|
1064
|
+
const overlap = Math.min(e1, wl + half) - Math.max(e0, -half);
|
|
1065
|
+
if (overlap < Math.min(len, wl) * 0.5) continue;
|
|
1066
|
+
if (Math.abs(d) < found) {
|
|
1067
|
+
found = Math.abs(d);
|
|
1068
|
+
move = -d * (nn[0] * -u[1] + nn[1] * u[0]);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const ln = [-u[1], u[0]];
|
|
1072
|
+
return { p: [p[0] + ln[0] * move, p[1] + ln[1] * move], u };
|
|
1073
|
+
});
|
|
1074
|
+
const out = lines.map((l, i) => {
|
|
1075
|
+
const prev = lines[(i + n - 1) % n];
|
|
1076
|
+
const den = prev.u[0] * l.u[1] - prev.u[1] * l.u[0];
|
|
1077
|
+
if (Math.abs(den) < 1e-9) return l.p;
|
|
1078
|
+
const t = ((l.p[0] - prev.p[0]) * l.u[1] - (l.p[1] - prev.p[1]) * l.u[0]) / den;
|
|
1079
|
+
return [prev.p[0] + prev.u[0] * t, prev.p[1] + prev.u[1] * t];
|
|
1080
|
+
});
|
|
1081
|
+
return clockwise(tidyLoop(out));
|
|
1082
|
+
}
|
|
1083
|
+
function adoptIds(plan, previous) {
|
|
1084
|
+
const storeyIds = new Set(plan.storeys.map((s) => s.id));
|
|
1085
|
+
const spaceIds = new Set(plan.storeys.flatMap((s) => s.spaces.map((x) => x.id)));
|
|
1086
|
+
for (const s of plan.storeys) {
|
|
1087
|
+
const was = previous.storeys.find((p) => p.level === s.level);
|
|
1088
|
+
if (!was) continue;
|
|
1089
|
+
if (was.id !== s.id && !storeyIds.has(was.id)) {
|
|
1090
|
+
storeyIds.delete(s.id);
|
|
1091
|
+
s.id = was.id;
|
|
1092
|
+
storeyIds.add(was.id);
|
|
1093
|
+
}
|
|
1094
|
+
const used = /* @__PURE__ */ new Set();
|
|
1095
|
+
for (const x of s.spaces) {
|
|
1096
|
+
const match = was.spaces.find(
|
|
1097
|
+
(q) => q.name.trim().toLowerCase() === x.name.trim().toLowerCase() && !used.has(q.id)
|
|
1098
|
+
);
|
|
1099
|
+
if (!match) continue;
|
|
1100
|
+
used.add(match.id);
|
|
1101
|
+
if (match.id === x.id || spaceIds.has(match.id)) continue;
|
|
1102
|
+
spaceIds.delete(x.id);
|
|
1103
|
+
x.id = match.id;
|
|
1104
|
+
spaceIds.add(match.id);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return plan;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
export {
|
|
1111
|
+
IfcError,
|
|
1112
|
+
parseStep,
|
|
1113
|
+
fromIfc,
|
|
1114
|
+
adoptIds
|
|
1115
|
+
};
|