@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,286 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/cells.ts
|
|
6
|
+
var cells_exports = {};
|
|
7
|
+
__export(cells_exports, {
|
|
8
|
+
Axis: () => Axis,
|
|
9
|
+
Cells: () => Cells,
|
|
10
|
+
Grid: () => Grid,
|
|
11
|
+
area: () => area,
|
|
12
|
+
cellLoops: () => cellLoops,
|
|
13
|
+
inside: () => inside,
|
|
14
|
+
onEdge: () => onEdge,
|
|
15
|
+
rectLoops: () => rectLoops,
|
|
16
|
+
rectangles: () => rectangles,
|
|
17
|
+
simplify: () => simplify
|
|
18
|
+
});
|
|
19
|
+
var Axis = class {
|
|
20
|
+
constructor(values, scale = 1) {
|
|
21
|
+
this.scale = scale;
|
|
22
|
+
const keyed = /* @__PURE__ */ new Map();
|
|
23
|
+
for (const v of values) {
|
|
24
|
+
const k = this.key(v);
|
|
25
|
+
if (!keyed.has(k)) keyed.set(k, v);
|
|
26
|
+
}
|
|
27
|
+
this.at = [...keyed.entries()].sort((a, b) => a[0] - b[0]).map(([, v]) => v);
|
|
28
|
+
this.at.forEach((v, i) => this.index.set(this.key(v), i));
|
|
29
|
+
}
|
|
30
|
+
scale;
|
|
31
|
+
at;
|
|
32
|
+
index = /* @__PURE__ */ new Map();
|
|
33
|
+
key(v) {
|
|
34
|
+
return Math.round(v * this.scale * 1e3);
|
|
35
|
+
}
|
|
36
|
+
/** The index of a cut. Throws for a value the grid was not cut at, which is a bug. */
|
|
37
|
+
i(v) {
|
|
38
|
+
const i = this.index.get(this.key(v));
|
|
39
|
+
if (i === void 0) throw new Error(`No cut at ${v}`);
|
|
40
|
+
return i;
|
|
41
|
+
}
|
|
42
|
+
get length() {
|
|
43
|
+
return this.at.length;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var Grid = class _Grid {
|
|
47
|
+
constructor(xs, ys) {
|
|
48
|
+
this.xs = xs;
|
|
49
|
+
this.ys = ys;
|
|
50
|
+
}
|
|
51
|
+
xs;
|
|
52
|
+
ys;
|
|
53
|
+
/**
|
|
54
|
+
* Cut at every edge of these rectangles and corner of these loops.
|
|
55
|
+
* `scale` is how many millimetres one unit is, so cuts closer than a
|
|
56
|
+
* micrometre merge (1 for millimetres, 500 for version 1 cells).
|
|
57
|
+
*/
|
|
58
|
+
static of(rects, loops = [], scale = 1) {
|
|
59
|
+
const xs = [...rects.flatMap((r) => [r.x, r.x + r.w]), ...loops.flat().map((p) => p[0])];
|
|
60
|
+
const ys = [...rects.flatMap((r) => [r.y, r.y + r.h]), ...loops.flat().map((p) => p[1])];
|
|
61
|
+
return new _Grid(new Axis(xs, scale), new Axis(ys, scale));
|
|
62
|
+
}
|
|
63
|
+
/** The cells these rectangles cover. Each must sit on the grid's cuts. */
|
|
64
|
+
cells(rects) {
|
|
65
|
+
const c = new Cells();
|
|
66
|
+
for (const r of rects) {
|
|
67
|
+
const [i0, i1, j0, j1] = [this.xs.i(r.x), this.xs.i(r.x + r.w), this.ys.i(r.y), this.ys.i(r.y + r.h)];
|
|
68
|
+
for (let i = i0; i < i1; i++) for (let j = j0; j < j1; j++) c.add(i, j);
|
|
69
|
+
}
|
|
70
|
+
return c;
|
|
71
|
+
}
|
|
72
|
+
point([i, j]) {
|
|
73
|
+
return [this.xs.at[i], this.ys.at[j]];
|
|
74
|
+
}
|
|
75
|
+
rect(r) {
|
|
76
|
+
const x = this.xs.at[r.x];
|
|
77
|
+
const y = this.ys.at[r.y];
|
|
78
|
+
return { x, y, w: this.xs.at[r.x + r.w] - x, h: this.ys.at[r.y + r.h] - y };
|
|
79
|
+
}
|
|
80
|
+
/** How large a block of cells is, in real units. */
|
|
81
|
+
area(r) {
|
|
82
|
+
return (this.xs.at[r.x + r.w] - this.xs.at[r.x]) * (this.ys.at[r.y + r.h] - this.ys.at[r.y]);
|
|
83
|
+
}
|
|
84
|
+
/** The cells whose centres are inside an outline and outside its holes. */
|
|
85
|
+
inside(outline, holes) {
|
|
86
|
+
const out = new Cells();
|
|
87
|
+
for (let i = 0; i + 1 < this.xs.length; i++)
|
|
88
|
+
for (let j = 0; j + 1 < this.ys.length; j++) {
|
|
89
|
+
const c = [(this.xs.at[i] + this.xs.at[i + 1]) / 2, (this.ys.at[j] + this.ys.at[j + 1]) / 2];
|
|
90
|
+
if (inside(c, outline) && !holes.some((h) => inside(c, h))) out.add(i, j);
|
|
91
|
+
}
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
function rectLoops(rects, scale = 1) {
|
|
96
|
+
const g = Grid.of(rects, [], scale);
|
|
97
|
+
return cellLoops(g.cells(rects)).map((loop) => loop.map((p) => g.point(p)));
|
|
98
|
+
}
|
|
99
|
+
var Cells = class _Cells {
|
|
100
|
+
set = /* @__PURE__ */ new Set();
|
|
101
|
+
add(x, y) {
|
|
102
|
+
this.set.add(`${x},${y}`);
|
|
103
|
+
}
|
|
104
|
+
delete(x, y) {
|
|
105
|
+
this.set.delete(`${x},${y}`);
|
|
106
|
+
}
|
|
107
|
+
has(x, y) {
|
|
108
|
+
return this.set.has(`${x},${y}`);
|
|
109
|
+
}
|
|
110
|
+
get size() {
|
|
111
|
+
return this.set.size;
|
|
112
|
+
}
|
|
113
|
+
*[Symbol.iterator]() {
|
|
114
|
+
for (const k of this.set) {
|
|
115
|
+
const [x, y] = k.split(",").map(Number);
|
|
116
|
+
yield [x, y];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
static of(rects) {
|
|
120
|
+
const c = new _Cells();
|
|
121
|
+
for (const r of rects) for (let i = 0; i < r.w; i++) for (let j = 0; j < r.h; j++) c.add(r.x + i, r.y + j);
|
|
122
|
+
return c;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function cellLoops(cells) {
|
|
126
|
+
const next = /* @__PURE__ */ new Map();
|
|
127
|
+
const push = (a, b) => {
|
|
128
|
+
const k = `${a[0]},${a[1]}`;
|
|
129
|
+
next.set(k, [...next.get(k) ?? [], b]);
|
|
130
|
+
};
|
|
131
|
+
for (const [x, y] of cells) {
|
|
132
|
+
if (!cells.has(x, y - 1)) push([x, y], [x + 1, y]);
|
|
133
|
+
if (!cells.has(x + 1, y)) push([x + 1, y], [x + 1, y + 1]);
|
|
134
|
+
if (!cells.has(x, y + 1)) push([x + 1, y + 1], [x, y + 1]);
|
|
135
|
+
if (!cells.has(x - 1, y)) push([x, y + 1], [x, y]);
|
|
136
|
+
}
|
|
137
|
+
const loops = [];
|
|
138
|
+
const take = (k, prev) => {
|
|
139
|
+
const list = next.get(k);
|
|
140
|
+
if (!list?.length) return void 0;
|
|
141
|
+
let i = 0;
|
|
142
|
+
if (list.length > 1 && prev) {
|
|
143
|
+
const [px, py] = k.split(",").map(Number);
|
|
144
|
+
const din = [px - prev[0], py - prev[1]];
|
|
145
|
+
const right = [-din[1], din[0]];
|
|
146
|
+
const j = list.findIndex((p2) => p2[0] - px === right[0] && p2[1] - py === right[1]);
|
|
147
|
+
if (j >= 0) i = j;
|
|
148
|
+
}
|
|
149
|
+
const [p] = list.splice(i, 1);
|
|
150
|
+
if (!list.length) next.delete(k);
|
|
151
|
+
return p;
|
|
152
|
+
};
|
|
153
|
+
while (next.size) {
|
|
154
|
+
const startKey = [...next.keys()].sort((a, b) => {
|
|
155
|
+
const [ax, ay] = a.split(",").map(Number);
|
|
156
|
+
const [bx, by] = b.split(",").map(Number);
|
|
157
|
+
return ay - by || ax - bx;
|
|
158
|
+
})[0];
|
|
159
|
+
const start = startKey.split(",").map(Number);
|
|
160
|
+
const loop = [start];
|
|
161
|
+
let prev = null;
|
|
162
|
+
let cur = start;
|
|
163
|
+
for (; ; ) {
|
|
164
|
+
const p = take(`${cur[0]},${cur[1]}`, prev);
|
|
165
|
+
if (!p || p[0] === start[0] && p[1] === start[1]) break;
|
|
166
|
+
loop.push(p);
|
|
167
|
+
prev = cur;
|
|
168
|
+
cur = p;
|
|
169
|
+
}
|
|
170
|
+
loops.push(simplify(loop));
|
|
171
|
+
}
|
|
172
|
+
return loops.sort((a, b) => Math.abs(area(b)) - Math.abs(area(a)));
|
|
173
|
+
}
|
|
174
|
+
function simplify(loop) {
|
|
175
|
+
const out = [];
|
|
176
|
+
const n = loop.length;
|
|
177
|
+
for (let i = 0; i < n; i++) {
|
|
178
|
+
const a = loop[(i + n - 1) % n];
|
|
179
|
+
const b = loop[i];
|
|
180
|
+
const c = loop[(i + 1) % n];
|
|
181
|
+
const cross = (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0]);
|
|
182
|
+
if (cross !== 0) out.push(b);
|
|
183
|
+
}
|
|
184
|
+
return out;
|
|
185
|
+
}
|
|
186
|
+
function area(loop) {
|
|
187
|
+
let s = 0;
|
|
188
|
+
for (let i = 0; i < loop.length; i++) {
|
|
189
|
+
const [x1, y1] = loop[i];
|
|
190
|
+
const [x2, y2] = loop[(i + 1) % loop.length];
|
|
191
|
+
s += x1 * y2 - x2 * y1;
|
|
192
|
+
}
|
|
193
|
+
return s / 2;
|
|
194
|
+
}
|
|
195
|
+
function onEdge(p, loop, eps = 1e-6) {
|
|
196
|
+
return loop.some((a, i) => {
|
|
197
|
+
const b = loop[(i + 1) % loop.length];
|
|
198
|
+
const dx = b[0] - a[0];
|
|
199
|
+
const dy = b[1] - a[1];
|
|
200
|
+
const len2 = dx * dx + dy * dy;
|
|
201
|
+
const t = len2 ? Math.max(0, Math.min(1, ((p[0] - a[0]) * dx + (p[1] - a[1]) * dy) / len2)) : 0;
|
|
202
|
+
return Math.hypot(p[0] - (a[0] + t * dx), p[1] - (a[1] + t * dy)) <= eps;
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function inside(p, loop) {
|
|
206
|
+
let hit = false;
|
|
207
|
+
for (let i = 0, j = loop.length - 1; i < loop.length; j = i++) {
|
|
208
|
+
const [xi, yi] = loop[i];
|
|
209
|
+
const [xj, yj] = loop[j];
|
|
210
|
+
if (yi > p[1] !== yj > p[1] && p[0] < (xj - xi) * (p[1] - yi) / (yj - yi) + xi) hit = !hit;
|
|
211
|
+
}
|
|
212
|
+
return hit;
|
|
213
|
+
}
|
|
214
|
+
function rectangles(cells, grid) {
|
|
215
|
+
const left = new Cells();
|
|
216
|
+
for (const [x, y] of cells) left.add(x, y);
|
|
217
|
+
const out = [];
|
|
218
|
+
const taken = new Cells();
|
|
219
|
+
while (left.size) {
|
|
220
|
+
const r = largest(left, out.length ? taken : null, grid);
|
|
221
|
+
if (!r) break;
|
|
222
|
+
out.push(r);
|
|
223
|
+
for (let i = 0; i < r.w; i++)
|
|
224
|
+
for (let j = 0; j < r.h; j++) {
|
|
225
|
+
left.delete(r.x + i, r.y + j);
|
|
226
|
+
taken.add(r.x + i, r.y + j);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
function largest(cells, touching, grid) {
|
|
232
|
+
const size = (r) => grid ? grid.area(r) : r.w * r.h;
|
|
233
|
+
let x0 = Infinity;
|
|
234
|
+
let y0 = Infinity;
|
|
235
|
+
let x1 = -Infinity;
|
|
236
|
+
let y1 = -Infinity;
|
|
237
|
+
for (const [x, y] of cells) {
|
|
238
|
+
x0 = Math.min(x0, x);
|
|
239
|
+
y0 = Math.min(y0, y);
|
|
240
|
+
x1 = Math.max(x1, x + 1);
|
|
241
|
+
y1 = Math.max(y1, y + 1);
|
|
242
|
+
}
|
|
243
|
+
const W = x1 - x0;
|
|
244
|
+
const H = y1 - y0;
|
|
245
|
+
const sum = new Int32Array((W + 1) * (H + 1));
|
|
246
|
+
const at = (i, j) => j * (W + 1) + i;
|
|
247
|
+
for (let j = 1; j <= H; j++)
|
|
248
|
+
for (let i = 1; i <= W; i++)
|
|
249
|
+
sum[at(i, j)] = (cells.has(x0 + i - 1, y0 + j - 1) ? 1 : 0) + sum[at(i - 1, j)] + sum[at(i, j - 1)] - sum[at(i - 1, j - 1)];
|
|
250
|
+
const full = (i, j, w, h) => sum[at(i + w, j + h)] - sum[at(i, j + h)] - sum[at(i + w, j)] + sum[at(i, j)] === w * h;
|
|
251
|
+
const touches = (r) => {
|
|
252
|
+
if (!touching) return true;
|
|
253
|
+
for (let i = 0; i < r.w; i++) if (touching.has(r.x + i, r.y - 1) || touching.has(r.x + i, r.y + r.h)) return true;
|
|
254
|
+
for (let j = 0; j < r.h; j++) if (touching.has(r.x - 1, r.y + j) || touching.has(r.x + r.w, r.y + j)) return true;
|
|
255
|
+
return false;
|
|
256
|
+
};
|
|
257
|
+
let best = null;
|
|
258
|
+
for (let j = 0; j < H; j++)
|
|
259
|
+
for (let i = 0; i < W; i++) {
|
|
260
|
+
if (!cells.has(x0 + i, y0 + j)) continue;
|
|
261
|
+
for (let h = 1; j + h <= H; h++) {
|
|
262
|
+
if (!full(i, j, 1, h)) break;
|
|
263
|
+
for (let w = 1; i + w <= W; w++) {
|
|
264
|
+
if (!full(i, j, w, h)) break;
|
|
265
|
+
const r = { x: x0 + i, y: y0 + j, w, h };
|
|
266
|
+
if (best && size(r) <= size(best)) continue;
|
|
267
|
+
if (touches(r)) best = r;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return best;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export {
|
|
275
|
+
Axis,
|
|
276
|
+
Grid,
|
|
277
|
+
rectLoops,
|
|
278
|
+
Cells,
|
|
279
|
+
cellLoops,
|
|
280
|
+
simplify,
|
|
281
|
+
area,
|
|
282
|
+
onEdge,
|
|
283
|
+
inside,
|
|
284
|
+
rectangles,
|
|
285
|
+
cells_exports
|
|
286
|
+
};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import {
|
|
2
|
+
COVERING_KINDS,
|
|
3
|
+
DEVICE_LOOKS,
|
|
4
|
+
DOOR_OPERATIONS,
|
|
5
|
+
FRAME_MATERIALS,
|
|
6
|
+
FURNITURE_KINDS,
|
|
7
|
+
LEAVES,
|
|
8
|
+
LIGHT_MOUNTS,
|
|
9
|
+
PLAN_VERSION,
|
|
10
|
+
WINDOW_OPERATIONS,
|
|
11
|
+
isGlazed
|
|
12
|
+
} from "./chunk-6Q4JIXFQ.js";
|
|
13
|
+
|
|
14
|
+
// src/validate.ts
|
|
15
|
+
var PlanError = class extends Error {
|
|
16
|
+
};
|
|
17
|
+
var LIMITS = {
|
|
18
|
+
storeys: 12,
|
|
19
|
+
walls: 1500,
|
|
20
|
+
spaces: 300,
|
|
21
|
+
points: 400,
|
|
22
|
+
openings: 600,
|
|
23
|
+
coverings: 6,
|
|
24
|
+
placements: 500,
|
|
25
|
+
radiators: 300,
|
|
26
|
+
furniture: 400,
|
|
27
|
+
dimensions: 200,
|
|
28
|
+
/** 200 m, in millimetres. */
|
|
29
|
+
site: 2e5,
|
|
30
|
+
name: 80
|
|
31
|
+
};
|
|
32
|
+
var ID = /^[A-Za-z0-9_-]{1,64}$/;
|
|
33
|
+
var REF = /^\S{1,220}$/;
|
|
34
|
+
var COLOUR = /^#[0-9a-fA-F]{6}$/;
|
|
35
|
+
function fail(path, message) {
|
|
36
|
+
throw new PlanError(`${path}: ${message}`);
|
|
37
|
+
}
|
|
38
|
+
function obj(v, path) {
|
|
39
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) fail(path, "must be an object");
|
|
40
|
+
return v;
|
|
41
|
+
}
|
|
42
|
+
function arr(v, path, max) {
|
|
43
|
+
if (!Array.isArray(v)) fail(path, "must be a list");
|
|
44
|
+
if (v.length > max) fail(path, `at most ${max} entries`);
|
|
45
|
+
return v;
|
|
46
|
+
}
|
|
47
|
+
function int(v, path, min, max) {
|
|
48
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v < min || v > max)
|
|
49
|
+
fail(path, `must be a whole number from ${min} to ${max}`);
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
function id(v, path) {
|
|
53
|
+
if (typeof v !== "string" || !ID.test(v)) fail(path, "must be 1 to 64 letters, digits, - or _");
|
|
54
|
+
return v;
|
|
55
|
+
}
|
|
56
|
+
function name(v, path) {
|
|
57
|
+
if (typeof v !== "string") fail(path, "must be text");
|
|
58
|
+
const s = v.trim();
|
|
59
|
+
if (!s || s.length > LIMITS.name) fail(path, `must be 1 to ${LIMITS.name} characters`);
|
|
60
|
+
return s;
|
|
61
|
+
}
|
|
62
|
+
function oneOf(v, list, path) {
|
|
63
|
+
if (!list.includes(v)) fail(path, `must be one of ${list.join(", ")}`);
|
|
64
|
+
return v;
|
|
65
|
+
}
|
|
66
|
+
function unique(seen, v, path) {
|
|
67
|
+
if (seen.has(v)) fail(path, `'${v}' is used twice`);
|
|
68
|
+
seen.add(v);
|
|
69
|
+
}
|
|
70
|
+
function validatePlan(raw) {
|
|
71
|
+
const p = obj(raw, "plan");
|
|
72
|
+
if (p.version !== PLAN_VERSION) fail("plan.version", `must be ${PLAN_VERSION}`);
|
|
73
|
+
if (p.unit !== "mm") fail("plan.unit", "must be mm");
|
|
74
|
+
const siteRaw = obj(p.site, "plan.site");
|
|
75
|
+
const site = {
|
|
76
|
+
w: int(siteRaw.w, "plan.site.w", 1, LIMITS.site),
|
|
77
|
+
h: int(siteRaw.h, "plan.site.h", 1, LIMITS.site)
|
|
78
|
+
};
|
|
79
|
+
const snap = int(p.snap, "plan.snap", 1, 1e4);
|
|
80
|
+
const reach = 1e4;
|
|
81
|
+
const point = (v, path) => {
|
|
82
|
+
const a = arr(v, path, 2);
|
|
83
|
+
if (a.length !== 2) fail(path, "must be [x, y]");
|
|
84
|
+
return [int(a[0], `${path}[0]`, -reach, site.w + reach), int(a[1], `${path}[1]`, -reach, site.h + reach)];
|
|
85
|
+
};
|
|
86
|
+
const loop = (v, path) => {
|
|
87
|
+
const pts = arr(v, path, LIMITS.points).map((q, i) => point(q, `${path}[${i}]`));
|
|
88
|
+
if (pts.length < 3) fail(path, "needs at least 3 corners");
|
|
89
|
+
return pts;
|
|
90
|
+
};
|
|
91
|
+
const storeyIds = /* @__PURE__ */ new Set();
|
|
92
|
+
const levels = /* @__PURE__ */ new Set();
|
|
93
|
+
const spaceIds = /* @__PURE__ */ new Set();
|
|
94
|
+
const refs = /* @__PURE__ */ new Set();
|
|
95
|
+
const storeys = arr(p.storeys, "plan.storeys", LIMITS.storeys).map((sRaw, si) => {
|
|
96
|
+
const sp = `plan.storeys[${si}]`;
|
|
97
|
+
const s = obj(sRaw, sp);
|
|
98
|
+
const sid = id(s.id, `${sp}.id`);
|
|
99
|
+
unique(storeyIds, sid, `${sp}.id`);
|
|
100
|
+
const level = int(s.level, `${sp}.level`, -5, 20);
|
|
101
|
+
if (levels.has(level)) fail(`${sp}.level`, `two storeys cannot share level ${level}`);
|
|
102
|
+
levels.add(level);
|
|
103
|
+
const elevation = int(s.elevation, `${sp}.elevation`, -5e4, 2e5);
|
|
104
|
+
const height = int(s.height, `${sp}.height`, 1e3, 2e4);
|
|
105
|
+
const elementIds = /* @__PURE__ */ new Set();
|
|
106
|
+
const walls = arr(s.walls, `${sp}.walls`, LIMITS.walls).map((wRaw, wi) => {
|
|
107
|
+
const wp = `${sp}.walls[${wi}]`;
|
|
108
|
+
const w = obj(wRaw, wp);
|
|
109
|
+
const wid = id(w.id, `${wp}.id`);
|
|
110
|
+
unique(elementIds, wid, `${wp}.id`);
|
|
111
|
+
const a = point(w.a, `${wp}.a`);
|
|
112
|
+
const b = point(w.b, `${wp}.b`);
|
|
113
|
+
if (a[0] === b[0] && a[1] === b[1]) fail(wp, "its ends are the same point");
|
|
114
|
+
return {
|
|
115
|
+
id: wid,
|
|
116
|
+
a,
|
|
117
|
+
b,
|
|
118
|
+
thickness: int(w.thickness, `${wp}.thickness`, 10, 2e3),
|
|
119
|
+
height: int(w.height, `${wp}.height`, 100, 2e4)
|
|
120
|
+
};
|
|
121
|
+
});
|
|
122
|
+
const wallById = new Map(walls.map((w) => [w.id, w]));
|
|
123
|
+
const spaces = arr(s.spaces, `${sp}.spaces`, LIMITS.spaces).map((rRaw, ri) => {
|
|
124
|
+
const rp = `${sp}.spaces[${ri}]`;
|
|
125
|
+
const r = obj(rRaw, rp);
|
|
126
|
+
const rid = id(r.id, `${rp}.id`);
|
|
127
|
+
unique(spaceIds, rid, `${rp}.id`);
|
|
128
|
+
const out = {
|
|
129
|
+
id: rid,
|
|
130
|
+
name: name(r.name, `${rp}.name`),
|
|
131
|
+
kind: oneOf(r.kind, ["room", "outdoor", "paved", "pool"], `${rp}.kind`),
|
|
132
|
+
outline: loop(r.outline, `${rp}.outline`)
|
|
133
|
+
};
|
|
134
|
+
if (r.holes !== void 0) {
|
|
135
|
+
const holes = arr(r.holes, `${rp}.holes`, 20).map((h, hi) => loop(h, `${rp}.holes[${hi}]`));
|
|
136
|
+
if (holes.length) out.holes = holes;
|
|
137
|
+
}
|
|
138
|
+
if (r.rects !== void 0) {
|
|
139
|
+
const rects = arr(r.rects, `${rp}.rects`, 9).map((qRaw, qi) => {
|
|
140
|
+
const qp = `${rp}.rects[${qi}]`;
|
|
141
|
+
const q = obj(qRaw, qp);
|
|
142
|
+
return {
|
|
143
|
+
x: int(q.x, `${qp}.x`, -reach, site.w + reach),
|
|
144
|
+
y: int(q.y, `${qp}.y`, -reach, site.h + reach),
|
|
145
|
+
w: int(q.w, `${qp}.w`, 1, site.w + reach),
|
|
146
|
+
h: int(q.h, `${qp}.h`, 1, site.h + reach)
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
if (rects.length) out.rects = rects;
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
});
|
|
153
|
+
const glazed = /* @__PURE__ */ new Map();
|
|
154
|
+
const openings = arr(s.openings, `${sp}.openings`, LIMITS.openings).map((oRaw, oi) => {
|
|
155
|
+
const op = `${sp}.openings[${oi}]`;
|
|
156
|
+
const o = obj(oRaw, op);
|
|
157
|
+
const oid = id(o.id, `${op}.id`);
|
|
158
|
+
unique(elementIds, oid, `${op}.id`);
|
|
159
|
+
const wall = wallById.get(id(o.wall, `${op}.wall`));
|
|
160
|
+
if (!wall) fail(`${op}.wall`, `no wall '${o.wall}' on this storey`);
|
|
161
|
+
const length = Math.round(Math.hypot(wall.b[0] - wall.a[0], wall.b[1] - wall.a[1]));
|
|
162
|
+
const at = int(o.at, `${op}.at`, 0, length - 1);
|
|
163
|
+
const width = int(o.width, `${op}.width`, 1, length - at);
|
|
164
|
+
const base = { id: oid, wall: wall.id, at, width };
|
|
165
|
+
const kind = oneOf(o.kind, ["door", "window", "gap"], `${op}.kind`);
|
|
166
|
+
if (kind === "gap") return { ...base, kind };
|
|
167
|
+
const sill = int(o.sill, `${op}.sill`, 0, 2e4);
|
|
168
|
+
const head = int(o.head, `${op}.head`, sill + 1, 2e4);
|
|
169
|
+
const glass = kind === "door" ? {
|
|
170
|
+
kind,
|
|
171
|
+
operation: oneOf(o.operation, DOOR_OPERATIONS, `${op}.operation`),
|
|
172
|
+
leaf: oneOf(o.leaf, LEAVES, `${op}.leaf`)
|
|
173
|
+
} : { kind, operation: oneOf(o.operation, WINDOW_OPERATIONS, `${op}.operation`) };
|
|
174
|
+
const out = { ...base, ...glass, sill, head };
|
|
175
|
+
if (o.hinge !== void 0) out.hinge = oneOf(o.hinge, ["start", "end"], `${op}.hinge`);
|
|
176
|
+
if (o.opens !== void 0) out.opens = oneOf(o.opens, ["left", "right"], `${op}.opens`);
|
|
177
|
+
if (o.frame !== void 0) {
|
|
178
|
+
const f = obj(o.frame, `${op}.frame`);
|
|
179
|
+
const frame = {};
|
|
180
|
+
if (f.material !== void 0) frame.material = oneOf(f.material, FRAME_MATERIALS, `${op}.frame.material`);
|
|
181
|
+
if (f.colour !== void 0) {
|
|
182
|
+
if (typeof f.colour !== "string" || !COLOUR.test(f.colour)) fail(`${op}.frame.colour`, "must be #rrggbb");
|
|
183
|
+
frame.colour = f.colour.toLowerCase();
|
|
184
|
+
}
|
|
185
|
+
if (frame.material || frame.colour) out.frame = frame;
|
|
186
|
+
}
|
|
187
|
+
if (o.coverings !== void 0) {
|
|
188
|
+
const list = arr(o.coverings, `${op}.coverings`, LIMITS.coverings);
|
|
189
|
+
if (list.length && !isGlazed(out)) fail(`${op}.coverings`, "only glass can be covered");
|
|
190
|
+
const ids = /* @__PURE__ */ new Set();
|
|
191
|
+
const coverings = list.map((cRaw, ci) => {
|
|
192
|
+
const cp = `${op}.coverings[${ci}]`;
|
|
193
|
+
const c = obj(cRaw, cp);
|
|
194
|
+
const cid = id(c.id, `${cp}.id`);
|
|
195
|
+
unique(ids, cid, `${cp}.id`);
|
|
196
|
+
return {
|
|
197
|
+
id: cid,
|
|
198
|
+
kind: oneOf(c.kind, COVERING_KINDS, `${cp}.kind`),
|
|
199
|
+
side: oneOf(c.side, ["inside", "outside"], `${cp}.side`)
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
if (coverings.length) out.coverings = coverings;
|
|
203
|
+
}
|
|
204
|
+
if (isGlazed(out)) glazed.set(oid, new Set((out.coverings ?? []).map((c) => c.id)));
|
|
205
|
+
return out;
|
|
206
|
+
});
|
|
207
|
+
const openingIds = new Set(openings.map((o) => o.id));
|
|
208
|
+
const radiators = arr(s.radiators, `${sp}.radiators`, LIMITS.radiators).map((rRaw, ri) => {
|
|
209
|
+
const rp = `${sp}.radiators[${ri}]`;
|
|
210
|
+
const r = obj(rRaw, rp);
|
|
211
|
+
const rid = id(r.id, `${rp}.id`);
|
|
212
|
+
unique(elementIds, rid, `${rp}.id`);
|
|
213
|
+
const a = point(r.a, `${rp}.a`);
|
|
214
|
+
const b = point(r.b, `${rp}.b`);
|
|
215
|
+
if (a[0] === b[0] && a[1] === b[1]) fail(rp, "its ends are the same point");
|
|
216
|
+
return { id: rid, a, b, side: oneOf(r.side, ["left", "right"], `${rp}.side`) };
|
|
217
|
+
});
|
|
218
|
+
const furnitureIds = /* @__PURE__ */ new Set();
|
|
219
|
+
const furniture = arr(s.furniture, `${sp}.furniture`, LIMITS.furniture).map((uRaw, ui) => {
|
|
220
|
+
const up = `${sp}.furniture[${ui}]`;
|
|
221
|
+
const u = obj(uRaw, up);
|
|
222
|
+
const uid = id(u.id, `${up}.id`);
|
|
223
|
+
unique(furnitureIds, uid, `${up}.id`);
|
|
224
|
+
const x = int(u.x, `${up}.x`, 0, site.w - 1);
|
|
225
|
+
const y = int(u.y, `${up}.y`, 0, site.h - 1);
|
|
226
|
+
const out = {
|
|
227
|
+
id: uid,
|
|
228
|
+
kind: oneOf(u.kind, FURNITURE_KINDS, `${up}.kind`),
|
|
229
|
+
x,
|
|
230
|
+
y,
|
|
231
|
+
w: int(u.w, `${up}.w`, 1, site.w - x),
|
|
232
|
+
d: int(u.d, `${up}.d`, 1, site.h - y)
|
|
233
|
+
};
|
|
234
|
+
if (u.height !== void 0) out.height = int(u.height, `${up}.height`, 100, 3e3);
|
|
235
|
+
if (u.back !== void 0) out.back = oneOf(u.back, ["up", "down", "left", "right"], `${up}.back`);
|
|
236
|
+
return out;
|
|
237
|
+
});
|
|
238
|
+
const placements = arr(s.placements, `${sp}.placements`, LIMITS.placements).map((plRaw, pi) => {
|
|
239
|
+
const pp = `${sp}.placements[${pi}]`;
|
|
240
|
+
const pl = obj(plRaw, pp);
|
|
241
|
+
if (typeof pl.ref !== "string" || !REF.test(pl.ref)) fail(`${pp}.ref`, "must be a device reference");
|
|
242
|
+
unique(refs, pl.ref, `${pp}.ref`);
|
|
243
|
+
const out = { ref: pl.ref, x: int(pl.x, `${pp}.x`, 0, site.w), y: int(pl.y, `${pp}.y`, 0, site.h) };
|
|
244
|
+
if (pl.host !== void 0) {
|
|
245
|
+
const h = obj(pl.host, `${pp}.host`);
|
|
246
|
+
const oid = id(h.opening, `${pp}.host.opening`);
|
|
247
|
+
if (!openingIds.has(oid)) fail(`${pp}.host.opening`, `no opening '${oid}' on this storey`);
|
|
248
|
+
out.host = { opening: oid };
|
|
249
|
+
if (h.covering !== void 0) {
|
|
250
|
+
const cid = id(h.covering, `${pp}.host.covering`);
|
|
251
|
+
if (!glazed.get(oid)?.has(cid)) fail(`${pp}.host.covering`, `'${oid}' has no covering '${cid}'`);
|
|
252
|
+
out.host.covering = cid;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
if (pl.color !== void 0) {
|
|
256
|
+
if (typeof pl.color !== "string" || !COLOUR.test(pl.color)) fail(`${pp}.color`, "must be #rrggbb");
|
|
257
|
+
out.color = pl.color.toLowerCase();
|
|
258
|
+
}
|
|
259
|
+
if (pl.length !== void 0) out.length = int(pl.length, `${pp}.length`, 1, 2e4);
|
|
260
|
+
if (pl.axis !== void 0) out.axis = oneOf(pl.axis, ["h", "v"], `${pp}.axis`);
|
|
261
|
+
if (pl.mount !== void 0) out.mount = oneOf(pl.mount, LIGHT_MOUNTS, `${pp}.mount`);
|
|
262
|
+
if (pl.look !== void 0) out.look = oneOf(pl.look, DEVICE_LOOKS, `${pp}.look`);
|
|
263
|
+
if (pl.circuitRooms !== void 0)
|
|
264
|
+
out.circuitRooms = arr(pl.circuitRooms, `${pp}.circuitRooms`, 50).map(
|
|
265
|
+
(c, ci) => id(c, `${pp}.circuitRooms[${ci}]`)
|
|
266
|
+
);
|
|
267
|
+
return out;
|
|
268
|
+
});
|
|
269
|
+
const dimensionIds = /* @__PURE__ */ new Set();
|
|
270
|
+
const dimensions = s.dimensions === void 0 ? [] : arr(s.dimensions, `${sp}.dimensions`, LIMITS.dimensions).map((dRaw, di) => {
|
|
271
|
+
const dp = `${sp}.dimensions[${di}]`;
|
|
272
|
+
const d = obj(dRaw, dp);
|
|
273
|
+
const did = id(d.id, `${dp}.id`);
|
|
274
|
+
unique(dimensionIds, did, `${dp}.id`);
|
|
275
|
+
const a = point(d.a, `${dp}.a`);
|
|
276
|
+
const b = point(d.b, `${dp}.b`);
|
|
277
|
+
if (a[0] === b[0] && a[1] === b[1]) fail(dp, "its ends are the same point");
|
|
278
|
+
return { id: did, a, b };
|
|
279
|
+
});
|
|
280
|
+
return {
|
|
281
|
+
id: sid,
|
|
282
|
+
name: name(s.name, `${sp}.name`),
|
|
283
|
+
level,
|
|
284
|
+
elevation,
|
|
285
|
+
height,
|
|
286
|
+
walls,
|
|
287
|
+
spaces,
|
|
288
|
+
openings,
|
|
289
|
+
radiators,
|
|
290
|
+
furniture,
|
|
291
|
+
placements,
|
|
292
|
+
...dimensions.length ? { dimensions } : {}
|
|
293
|
+
};
|
|
294
|
+
});
|
|
295
|
+
storeys.forEach(
|
|
296
|
+
(s, si) => s.placements.forEach(
|
|
297
|
+
(pl, pi) => pl.circuitRooms?.forEach((rid, ci) => {
|
|
298
|
+
if (!spaceIds.has(rid)) fail(`plan.storeys[${si}].placements[${pi}].circuitRooms[${ci}]`, `no space '${rid}'`);
|
|
299
|
+
})
|
|
300
|
+
)
|
|
301
|
+
);
|
|
302
|
+
return { version: PLAN_VERSION, unit: "mm", site, snap, storeys };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export {
|
|
306
|
+
PlanError,
|
|
307
|
+
validatePlan
|
|
308
|
+
};
|