@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,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
inside
|
|
3
|
+
} from "./chunk-OCAFB7M7.js";
|
|
4
|
+
import {
|
|
5
|
+
__export
|
|
6
|
+
} from "./chunk-MLKGABMK.js";
|
|
7
|
+
|
|
8
|
+
// src/edges.ts
|
|
9
|
+
var edges_exports = {};
|
|
10
|
+
__export(edges_exports, {
|
|
11
|
+
along: () => along,
|
|
12
|
+
inRoom: () => inRoom,
|
|
13
|
+
lineOf: () => lineOf,
|
|
14
|
+
overlapLength: () => overlapLength,
|
|
15
|
+
pointAt: () => pointAt,
|
|
16
|
+
wallLinesOf: () => wallLinesOf
|
|
17
|
+
});
|
|
18
|
+
var gcd = (a, b) => b ? gcd(b, a % b) : Math.abs(a);
|
|
19
|
+
function lineOf(a, b) {
|
|
20
|
+
let dx = b[0] - a[0];
|
|
21
|
+
let dy = b[1] - a[1];
|
|
22
|
+
if (!dx && !dy) return null;
|
|
23
|
+
const g = gcd(Math.abs(dx), Math.abs(dy));
|
|
24
|
+
dx /= g;
|
|
25
|
+
dy /= g;
|
|
26
|
+
if (dx < 0 || dx === 0 && dy < 0) {
|
|
27
|
+
dx = -dx;
|
|
28
|
+
dy = -dy;
|
|
29
|
+
}
|
|
30
|
+
const off = dx * a[1] - dy * a[0];
|
|
31
|
+
return { d: [dx, dy], off, key: `${dx},${dy},${off}` };
|
|
32
|
+
}
|
|
33
|
+
var along = (l, p) => l.d[0] * p[0] + l.d[1] * p[1];
|
|
34
|
+
function pointAt(l, t) {
|
|
35
|
+
const n = l.d[0] * l.d[0] + l.d[1] * l.d[1];
|
|
36
|
+
return [Math.round((t * l.d[0] - l.off * l.d[1]) / n), Math.round((t * l.d[1] + l.off * l.d[0]) / n)];
|
|
37
|
+
}
|
|
38
|
+
function overlapLength(a, b) {
|
|
39
|
+
const la = lineOf(a[0], a[1]);
|
|
40
|
+
const lb = lineOf(b[0], b[1]);
|
|
41
|
+
if (!la || !lb || la.key !== lb.key) return 0;
|
|
42
|
+
const [a0, a1] = [along(la, a[0]), along(la, a[1])].sort((x, y) => x - y);
|
|
43
|
+
const [b0, b1] = [along(la, b[0]), along(la, b[1])].sort((x, y) => x - y);
|
|
44
|
+
const t = Math.max(0, Math.min(a1, b1) - Math.max(a0, b0));
|
|
45
|
+
return t / Math.hypot(la.d[0], la.d[1]);
|
|
46
|
+
}
|
|
47
|
+
function inRoom(p, loops) {
|
|
48
|
+
const [outline, ...holes] = loops;
|
|
49
|
+
return !!outline && inside(p, outline) && !holes.some((h) => inside(p, h));
|
|
50
|
+
}
|
|
51
|
+
function wallLinesOf(rooms) {
|
|
52
|
+
const groups = /* @__PURE__ */ new Map();
|
|
53
|
+
for (const loops of rooms)
|
|
54
|
+
for (const loop of loops)
|
|
55
|
+
loop.forEach((a, i) => {
|
|
56
|
+
const b = loop[(i + 1) % loop.length];
|
|
57
|
+
const l = lineOf(a, b);
|
|
58
|
+
if (!l) return;
|
|
59
|
+
const g = groups.get(l.key) ?? { l, spans: [] };
|
|
60
|
+
const [t0, t1] = [along(l, a), along(l, b)].sort((x, y) => x - y);
|
|
61
|
+
g.spans.push([t0, t1]);
|
|
62
|
+
groups.set(l.key, g);
|
|
63
|
+
});
|
|
64
|
+
const inAny = (p) => rooms.some((loops) => inRoom(p, loops));
|
|
65
|
+
const out = [];
|
|
66
|
+
for (const { l, spans } of groups.values()) {
|
|
67
|
+
const cuts = [...new Set(spans.flat())].sort((x, y) => x - y);
|
|
68
|
+
const n = Math.hypot(l.d[0], l.d[1]);
|
|
69
|
+
const nx = -l.d[1] / n * 0.5;
|
|
70
|
+
const ny = l.d[0] / n * 0.5;
|
|
71
|
+
const axis = l.d[1] === 0 ? "h" : l.d[0] === 0 ? "v" : null;
|
|
72
|
+
let cur = null;
|
|
73
|
+
const flush = () => {
|
|
74
|
+
if (!cur) return;
|
|
75
|
+
const a = pointAt(l, cur.t0);
|
|
76
|
+
const b = pointAt(l, cur.t1);
|
|
77
|
+
out.push({
|
|
78
|
+
axis,
|
|
79
|
+
line: axis === "h" ? a[1] : axis === "v" ? a[0] : 0,
|
|
80
|
+
start: axis === "h" ? a[0] : axis === "v" ? a[1] : 0,
|
|
81
|
+
end: axis === "h" ? b[0] : axis === "v" ? b[1] : 0,
|
|
82
|
+
a,
|
|
83
|
+
b,
|
|
84
|
+
inner: cur.inner,
|
|
85
|
+
order: [
|
|
86
|
+
axis === "h" ? 0 : axis === "v" ? 1 : 2,
|
|
87
|
+
axis ? axis === "h" ? a[1] : a[0] : 0,
|
|
88
|
+
axis ? 0 : l.off,
|
|
89
|
+
cur.t0
|
|
90
|
+
]
|
|
91
|
+
});
|
|
92
|
+
cur = null;
|
|
93
|
+
};
|
|
94
|
+
for (let i = 0; i + 1 < cuts.length; i++) {
|
|
95
|
+
const [t0, t1] = [cuts[i], cuts[i + 1]];
|
|
96
|
+
if (!spans.some(([s, e]) => s <= t0 && t1 <= e)) {
|
|
97
|
+
flush();
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const t = (t0 + t1) / 2;
|
|
101
|
+
const mid = [(t * l.d[0] - l.off * l.d[1]) / (n * n), (t * l.d[1] + l.off * l.d[0]) / (n * n)];
|
|
102
|
+
const inner = inAny([mid[0] + nx, mid[1] + ny]) && inAny([mid[0] - nx, mid[1] - ny]);
|
|
103
|
+
if (cur && cur.t1 === t0 && cur.inner === inner) cur.t1 = t1;
|
|
104
|
+
else {
|
|
105
|
+
flush();
|
|
106
|
+
cur = { t0, t1, inner };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
flush();
|
|
110
|
+
}
|
|
111
|
+
out.sort((x, y) => {
|
|
112
|
+
for (let i = 0; i < 4; i++) if (x.order[i] !== y.order[i]) return x.order[i] - y.order[i];
|
|
113
|
+
return 0;
|
|
114
|
+
});
|
|
115
|
+
return out.map(({ order: _order, ...w }) => w);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export {
|
|
119
|
+
lineOf,
|
|
120
|
+
along,
|
|
121
|
+
pointAt,
|
|
122
|
+
overlapLength,
|
|
123
|
+
inRoom,
|
|
124
|
+
wallLinesOf,
|
|
125
|
+
edges_exports
|
|
126
|
+
};
|
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
import {
|
|
2
|
+
overlapLength,
|
|
3
|
+
wallLinesOf
|
|
4
|
+
} from "./chunk-EHYUT42U.js";
|
|
5
|
+
import {
|
|
6
|
+
Grid,
|
|
7
|
+
area,
|
|
8
|
+
rectLoops,
|
|
9
|
+
rectangles
|
|
10
|
+
} from "./chunk-OCAFB7M7.js";
|
|
11
|
+
import {
|
|
12
|
+
DEFAULTS,
|
|
13
|
+
DOOR_OPERATIONS,
|
|
14
|
+
PLAN_VERSION,
|
|
15
|
+
WINDOW_OPERATIONS,
|
|
16
|
+
isGlazed
|
|
17
|
+
} from "./chunk-6Q4JIXFQ.js";
|
|
18
|
+
import {
|
|
19
|
+
HOUSE_GRID,
|
|
20
|
+
HOUSE_V1,
|
|
21
|
+
roomRects
|
|
22
|
+
} from "./chunk-L3Z5LJAA.js";
|
|
23
|
+
|
|
24
|
+
// src/convert.ts
|
|
25
|
+
var CELL = HOUSE_GRID * 1e3;
|
|
26
|
+
var mm = (cells2) => Math.round(cells2 * CELL);
|
|
27
|
+
var cells = (v) => v / CELL;
|
|
28
|
+
var mmRect = (q) => ({ x: mm(q.x), y: mm(q.y), w: mm(q.w), h: mm(q.h) });
|
|
29
|
+
function toWallSide(axis, side) {
|
|
30
|
+
return axis === "h" ? side === "up" ? "left" : "right" : side === "right" ? "left" : "right";
|
|
31
|
+
}
|
|
32
|
+
function fromWallSide(axis, side) {
|
|
33
|
+
return axis === "h" ? side === "left" ? "up" : "down" : side === "left" ? "right" : "left";
|
|
34
|
+
}
|
|
35
|
+
var axisOf = (a, b) => a[1] === b[1] ? "h" : a[0] === b[0] ? "v" : null;
|
|
36
|
+
function roomLoops(r) {
|
|
37
|
+
if (r.outline) return [r.outline.map(([x, y]) => [mm(x), mm(y)])];
|
|
38
|
+
return rectLoops(roomRects(r).map(mmRect));
|
|
39
|
+
}
|
|
40
|
+
function wallLines(floor) {
|
|
41
|
+
return wallLinesOf(floor.rooms.filter((r) => r.kind === "room").map(roomLoops));
|
|
42
|
+
}
|
|
43
|
+
var lineEnds = (l) => [l.a, l.b];
|
|
44
|
+
function overlap(a, b) {
|
|
45
|
+
return overlapLength([a.a, a.b], [b.a, b.b]);
|
|
46
|
+
}
|
|
47
|
+
function specFor(floor, shape) {
|
|
48
|
+
return (floor.walls ?? []).map((w) => {
|
|
49
|
+
const a = [mm(w.x), mm(w.y)];
|
|
50
|
+
const b = w.to ? [mm(w.to[0]), mm(w.to[1])] : w.axis === "h" ? [mm(w.x + w.len), mm(w.y)] : [mm(w.x), mm(w.y + w.len)];
|
|
51
|
+
return { w, o: overlap({ a, b }, shape) };
|
|
52
|
+
}).filter((x) => x.o > 0).sort((x, y) => y.o - x.o)[0]?.w;
|
|
53
|
+
}
|
|
54
|
+
function drawnWall(d) {
|
|
55
|
+
let a = [mm(d.a[0]), mm(d.a[1])];
|
|
56
|
+
let b = [mm(d.b[0]), mm(d.b[1])];
|
|
57
|
+
const axis = axisOf(a, b);
|
|
58
|
+
if (axis && b[axis === "h" ? 0 : 1] < a[axis === "h" ? 0 : 1]) [a, b] = [b, a];
|
|
59
|
+
return { id: d.id, a, b, thickness: d.thickness, height: d.height };
|
|
60
|
+
}
|
|
61
|
+
function makeWalls(floor, prev) {
|
|
62
|
+
const reserved = new Set(
|
|
63
|
+
[...floor.openings, ...floor.radiators ?? [], ...floor.drawnWalls ?? []].map((x) => x.id)
|
|
64
|
+
);
|
|
65
|
+
const used = /* @__PURE__ */ new Set();
|
|
66
|
+
const walls = [];
|
|
67
|
+
for (const l of wallLines(floor)) {
|
|
68
|
+
const [a, b] = lineEnds(l);
|
|
69
|
+
const shape = { a, b };
|
|
70
|
+
const before = prev.filter((w) => !used.has(w.id)).map((w) => ({ w, o: overlap(w, shape) })).filter((x) => x.o > 0).sort((x, y) => y.o - x.o)[0]?.w;
|
|
71
|
+
const taken = (x) => used.has(x) || reserved.has(x);
|
|
72
|
+
const kind = l.axis ?? "s";
|
|
73
|
+
let id = before && !reserved.has(before.id) ? before.id : `w${kind}${a[0]}_${a[1]}`;
|
|
74
|
+
for (let n = 2; taken(id); n++) id = `w${kind}${a[0]}_${a[1]}_${n}`;
|
|
75
|
+
used.add(id);
|
|
76
|
+
const spec = specFor(floor, shape);
|
|
77
|
+
walls.push({
|
|
78
|
+
id,
|
|
79
|
+
a,
|
|
80
|
+
b,
|
|
81
|
+
thickness: spec?.thickness ?? before?.thickness ?? (l.inner ? DEFAULTS.innerWall : DEFAULTS.outerWall),
|
|
82
|
+
height: spec?.height ?? before?.height ?? DEFAULTS.wallHeight
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
for (const d of floor.drawnWalls ?? []) walls.push(drawnWall(d));
|
|
86
|
+
return walls;
|
|
87
|
+
}
|
|
88
|
+
function host(o, walls) {
|
|
89
|
+
const [s, e] = o.axis === "h" ? [o.x, o.x + o.len] : [o.y, o.y + o.len];
|
|
90
|
+
const line = o.axis === "h" ? mm(o.y) : mm(o.x);
|
|
91
|
+
for (const w of walls) {
|
|
92
|
+
if (axisOf(w.a, w.b) !== o.axis) continue;
|
|
93
|
+
const k = o.axis === "h" ? 1 : 0;
|
|
94
|
+
const i = o.axis === "h" ? 0 : 1;
|
|
95
|
+
if (w.a[k] !== line) continue;
|
|
96
|
+
if (mm(s) >= w.a[i] && mm(e) <= w.b[i]) return { wall: w, at: mm(s) - w.a[i] };
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
function makeOpening(o, wall, at, prev) {
|
|
101
|
+
const base = { id: o.id, wall: wall.id, at, width: mm(o.len) };
|
|
102
|
+
if (o.type === "open") return { ...base, kind: "gap" };
|
|
103
|
+
const swing = (x) => x.kind !== "gap";
|
|
104
|
+
const old = prev && swing(prev) ? prev : void 0;
|
|
105
|
+
const sides = () => ({
|
|
106
|
+
hinge: o.hinge ?? "start",
|
|
107
|
+
opens: toWallSide(o.axis, o.opens ?? (o.axis === "h" ? "down" : "right"))
|
|
108
|
+
});
|
|
109
|
+
const spec = o.spec;
|
|
110
|
+
const kind = o.type === "window" ? "window" : "door";
|
|
111
|
+
const same = spec?.kind === kind ? spec : void 0;
|
|
112
|
+
const kept = {
|
|
113
|
+
frame: spec && "frame" in spec ? spec.frame : old?.frame,
|
|
114
|
+
coverings: spec && "coverings" in spec ? spec.coverings?.map((c) => ({ ...c })) : old?.coverings
|
|
115
|
+
};
|
|
116
|
+
if (o.type === "window") {
|
|
117
|
+
const was2 = old?.kind === "window" ? old : void 0;
|
|
118
|
+
const op2 = WINDOW_OPERATIONS.find((x) => x === same?.operation);
|
|
119
|
+
const win = {
|
|
120
|
+
...base,
|
|
121
|
+
kind: "window",
|
|
122
|
+
operation: op2 ?? was2?.operation ?? "casement",
|
|
123
|
+
sill: same?.sill ?? was2?.sill ?? DEFAULTS.windowSill,
|
|
124
|
+
head: same?.head ?? was2?.head ?? DEFAULTS.windowHead,
|
|
125
|
+
...kept,
|
|
126
|
+
...o.hinge !== void 0 || o.opens !== void 0 ? sides() : {}
|
|
127
|
+
};
|
|
128
|
+
return tidyOpening(win);
|
|
129
|
+
}
|
|
130
|
+
const sliding = o.type === "slider";
|
|
131
|
+
const glass = sliding || o.glass === true;
|
|
132
|
+
const slides = (x) => x === "sliding" || x === "lift-slide";
|
|
133
|
+
const fits = (x) => !!x && slides(x.operation) === sliding && x.leaf !== "solid" === glass;
|
|
134
|
+
const was = old?.kind === "door" && fits(old) ? old : void 0;
|
|
135
|
+
const op = DOOR_OPERATIONS.find((x) => x === same?.operation && slides(x) === sliding);
|
|
136
|
+
const leaf = same?.leaf !== void 0 && same.leaf !== "solid" === glass ? same.leaf : void 0;
|
|
137
|
+
const door = {
|
|
138
|
+
...base,
|
|
139
|
+
kind: "door",
|
|
140
|
+
operation: op ?? was?.operation ?? (sliding ? "sliding" : "swing"),
|
|
141
|
+
leaf: leaf ?? was?.leaf ?? (glass ? "glazed" : "solid"),
|
|
142
|
+
sill: same?.sill ?? was?.sill ?? 0,
|
|
143
|
+
head: same?.head ?? was?.head ?? DEFAULTS.doorHead,
|
|
144
|
+
...kept,
|
|
145
|
+
...sides()
|
|
146
|
+
};
|
|
147
|
+
return tidyOpening(door);
|
|
148
|
+
}
|
|
149
|
+
function tidyOpening(o) {
|
|
150
|
+
if (!isGlazed(o) || !o.coverings?.length) delete o.coverings;
|
|
151
|
+
if (o.frame === void 0 || !o.frame.material && !o.frame.colour) delete o.frame;
|
|
152
|
+
if (o.hinge === void 0) delete o.hinge;
|
|
153
|
+
if (o.opens === void 0) delete o.opens;
|
|
154
|
+
return o;
|
|
155
|
+
}
|
|
156
|
+
function makeSpace(r) {
|
|
157
|
+
if (r.outline) {
|
|
158
|
+
const outline2 = r.outline.map(([x, y]) => [mm(x), mm(y)]);
|
|
159
|
+
if (area(outline2) < 0) outline2.reverse();
|
|
160
|
+
return { id: r.id, name: r.name, kind: r.kind, outline: outline2 };
|
|
161
|
+
}
|
|
162
|
+
const rects = roomRects(r).map(mmRect);
|
|
163
|
+
const [outline, ...holes] = rectLoops(rects);
|
|
164
|
+
const s = { id: r.id, name: r.name, kind: r.kind, outline };
|
|
165
|
+
if (holes.length) s.holes = holes;
|
|
166
|
+
if (r.parts?.length) s.rects = rects;
|
|
167
|
+
return s;
|
|
168
|
+
}
|
|
169
|
+
function fromV1(p, previous) {
|
|
170
|
+
const dropped = [];
|
|
171
|
+
const storeys = p.floors.map((f) => {
|
|
172
|
+
const before = previous?.storeys.find((s) => s.id === f.id);
|
|
173
|
+
const walls = makeWalls(f, before?.walls ?? []);
|
|
174
|
+
const openings = [];
|
|
175
|
+
for (const o of f.openings) {
|
|
176
|
+
const h = host(o, walls);
|
|
177
|
+
if (!h) {
|
|
178
|
+
dropped.push(`${f.name}: ${o.type} ${o.id}`);
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
openings.push(
|
|
182
|
+
makeOpening(
|
|
183
|
+
o,
|
|
184
|
+
h.wall,
|
|
185
|
+
h.at,
|
|
186
|
+
before?.openings.find((x) => x.id === o.id)
|
|
187
|
+
)
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
const byId = new Map(openings.map((o) => [o.id, o]));
|
|
191
|
+
const hosts = /* @__PURE__ */ new Map();
|
|
192
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
193
|
+
const onGlass = f.placements.filter((pl) => {
|
|
194
|
+
const o = pl.opening ? byId.get(pl.opening) : void 0;
|
|
195
|
+
return !!o && isGlazed(o);
|
|
196
|
+
});
|
|
197
|
+
for (const pl of onGlass) {
|
|
198
|
+
const o = byId.get(pl.opening);
|
|
199
|
+
const chosen = pl.covering && o.coverings?.some((c) => c.id === pl.covering) ? pl.covering : void 0;
|
|
200
|
+
const taken = (c) => claimed.has(`${o.id}/${c}`);
|
|
201
|
+
if (chosen && !taken(chosen)) {
|
|
202
|
+
hosts.set(pl.ref, { opening: o.id, covering: chosen });
|
|
203
|
+
claimed.add(`${o.id}/${chosen}`);
|
|
204
|
+
continue;
|
|
205
|
+
}
|
|
206
|
+
const was = before?.placements.find((x) => x.ref === pl.ref)?.host;
|
|
207
|
+
if (pl.covering === void 0 && was?.opening === o.id && !taken(was.covering ?? "") && was.covering && o.coverings?.some((c) => c.id === was.covering)) {
|
|
208
|
+
hosts.set(pl.ref, { opening: o.id, covering: was.covering });
|
|
209
|
+
claimed.add(`${o.id}/${was.covering}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const pl of onGlass) {
|
|
213
|
+
if (hosts.has(pl.ref)) continue;
|
|
214
|
+
const o = byId.get(pl.opening);
|
|
215
|
+
const list = o.coverings ??= [];
|
|
216
|
+
const free = list.filter((c2) => !claimed.has(`${o.id}/${c2.id}`));
|
|
217
|
+
let c = free.find((x) => x.kind === "shutter") ?? free[0];
|
|
218
|
+
if (!c) {
|
|
219
|
+
let n = list.length + 1;
|
|
220
|
+
while (list.some((x) => x.id === `c${n}`)) n++;
|
|
221
|
+
c = { id: `c${n}`, kind: "shutter", side: "outside" };
|
|
222
|
+
list.push(c);
|
|
223
|
+
}
|
|
224
|
+
claimed.add(`${o.id}/${c.id}`);
|
|
225
|
+
hosts.set(pl.ref, { opening: o.id, covering: c.id });
|
|
226
|
+
}
|
|
227
|
+
const placements = f.placements.map((pl) => {
|
|
228
|
+
const out = { ref: pl.ref, x: mm(pl.x), y: mm(pl.y) };
|
|
229
|
+
const h = hosts.get(pl.ref);
|
|
230
|
+
if (h) out.host = h;
|
|
231
|
+
if (pl.color !== void 0) out.color = pl.color;
|
|
232
|
+
if (pl.circuitRooms !== void 0) out.circuitRooms = [...pl.circuitRooms];
|
|
233
|
+
if (pl.length !== void 0) out.length = mm(pl.length);
|
|
234
|
+
if (pl.axis !== void 0) out.axis = pl.axis;
|
|
235
|
+
if (pl.mount !== void 0) out.mount = pl.mount;
|
|
236
|
+
if (pl.look !== void 0) out.look = pl.look;
|
|
237
|
+
return out;
|
|
238
|
+
});
|
|
239
|
+
const radiators = (f.radiators ?? []).map((r) => {
|
|
240
|
+
const a = [mm(r.x), mm(r.y)];
|
|
241
|
+
const b = r.axis === "h" ? [mm(r.x + r.len), mm(r.y)] : [mm(r.x), mm(r.y + r.len)];
|
|
242
|
+
return { id: r.id, a, b, side: toWallSide(r.axis, r.side) };
|
|
243
|
+
});
|
|
244
|
+
const furniture = (f.furniture ?? []).map((u) => {
|
|
245
|
+
const out = { id: u.id, kind: u.kind, x: mm(u.x), y: mm(u.y), w: mm(u.w), d: mm(u.d) };
|
|
246
|
+
if (u.height !== void 0) out.height = Math.round(u.height * 1e3);
|
|
247
|
+
if (u.back !== void 0) out.back = u.back;
|
|
248
|
+
return out;
|
|
249
|
+
});
|
|
250
|
+
const height = before?.height ?? DEFAULTS.storeyHeight;
|
|
251
|
+
return {
|
|
252
|
+
id: f.id,
|
|
253
|
+
name: f.name,
|
|
254
|
+
level: f.level,
|
|
255
|
+
elevation: before && before.level === f.level ? before.elevation : f.level * DEFAULTS.storeyHeight,
|
|
256
|
+
height,
|
|
257
|
+
walls,
|
|
258
|
+
spaces: f.rooms.map(makeSpace),
|
|
259
|
+
openings,
|
|
260
|
+
radiators,
|
|
261
|
+
furniture,
|
|
262
|
+
placements,
|
|
263
|
+
...f.dimensions?.length ? {
|
|
264
|
+
dimensions: f.dimensions.map((d) => ({
|
|
265
|
+
id: d.id,
|
|
266
|
+
a: [mm(d.a[0]), mm(d.a[1])],
|
|
267
|
+
b: [mm(d.b[0]), mm(d.b[1])]
|
|
268
|
+
}))
|
|
269
|
+
} : {}
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
return {
|
|
273
|
+
plan: {
|
|
274
|
+
version: PLAN_VERSION,
|
|
275
|
+
unit: "mm",
|
|
276
|
+
site: { w: mm(p.plot.w), h: mm(p.plot.h) },
|
|
277
|
+
snap: previous?.snap ?? CELL,
|
|
278
|
+
storeys
|
|
279
|
+
},
|
|
280
|
+
dropped
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
function sameCells(a, b) {
|
|
284
|
+
if (a.size !== b.size) return false;
|
|
285
|
+
for (const [x, y] of a) if (!b.has(x, y)) return false;
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
function isRectangle(loop) {
|
|
289
|
+
return loop.length === 4 && loop.every((p, i) => !!axisOf(p, loop[(i + 1) % 4]));
|
|
290
|
+
}
|
|
291
|
+
function roomOf(s) {
|
|
292
|
+
const holes = s.holes ?? [];
|
|
293
|
+
if (!s.rects && !holes.length && !isRectangle(s.outline)) {
|
|
294
|
+
const xs = s.outline.map((p) => p[0]);
|
|
295
|
+
const ys = s.outline.map((p) => p[1]);
|
|
296
|
+
const [x0, y0] = [Math.min(...xs), Math.min(...ys)];
|
|
297
|
+
return {
|
|
298
|
+
id: s.id,
|
|
299
|
+
name: s.name,
|
|
300
|
+
kind: s.kind,
|
|
301
|
+
x: cells(x0),
|
|
302
|
+
y: cells(y0),
|
|
303
|
+
w: cells(Math.max(...xs) - x0),
|
|
304
|
+
h: cells(Math.max(...ys) - y0),
|
|
305
|
+
outline: s.outline.map(([x, y]) => [cells(x), cells(y)])
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
const g = Grid.of(s.rects ?? [], [s.outline, ...holes]);
|
|
309
|
+
const shape = g.inside(s.outline, holes);
|
|
310
|
+
let hint;
|
|
311
|
+
try {
|
|
312
|
+
if (s.rects && sameCells(g.cells(s.rects), shape)) hint = s.rects;
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
const rects = hint ?? rectangles(shape, g).map((r) => g.rect(r));
|
|
316
|
+
const [main, ...parts] = rects.map((q) => ({ x: cells(q.x), y: cells(q.y), w: cells(q.w), h: cells(q.h) }));
|
|
317
|
+
const room = { id: s.id, name: s.name, kind: s.kind, ...main ?? { x: 0, y: 0, w: 1, h: 1 } };
|
|
318
|
+
if (parts.length) room.parts = parts;
|
|
319
|
+
return room;
|
|
320
|
+
}
|
|
321
|
+
function openingOf(o, wall) {
|
|
322
|
+
const axis = axisOf(wall.a, wall.b);
|
|
323
|
+
if (!axis) return null;
|
|
324
|
+
const i = axis === "h" ? 0 : 1;
|
|
325
|
+
const dir = Math.sign(wall.b[i] - wall.a[i]) || 1;
|
|
326
|
+
const s = dir > 0 ? wall.a[i] + o.at : wall.a[i] - o.at - o.width;
|
|
327
|
+
const at = cells(s);
|
|
328
|
+
const len = cells(o.width);
|
|
329
|
+
const out = axis === "h" ? { id: o.id, type: "door", axis, x: at, y: cells(wall.a[1]), len } : { id: o.id, type: "door", axis, x: cells(wall.a[0]), y: at, len };
|
|
330
|
+
if (o.kind === "gap") return { ...out, type: "open" };
|
|
331
|
+
if (o.kind === "window") out.type = "window";
|
|
332
|
+
else if (o.operation === "sliding" || o.operation === "lift-slide") out.type = "slider";
|
|
333
|
+
else if (o.leaf !== "solid") out.glass = true;
|
|
334
|
+
const spec = { kind: o.kind, operation: o.operation, sill: o.sill, head: o.head };
|
|
335
|
+
if (o.kind === "door") spec.leaf = o.leaf;
|
|
336
|
+
if (o.frame) spec.frame = { ...o.frame };
|
|
337
|
+
if (isGlazed(o)) spec.coverings = (o.coverings ?? []).map((c) => ({ ...c }));
|
|
338
|
+
out.spec = spec;
|
|
339
|
+
if (o.hinge === "end") out.hinge = "end";
|
|
340
|
+
if (o.opens) {
|
|
341
|
+
const side = fromWallSide(axis, o.opens);
|
|
342
|
+
if (side !== (axis === "h" ? "down" : "right")) out.opens = side;
|
|
343
|
+
}
|
|
344
|
+
return out;
|
|
345
|
+
}
|
|
346
|
+
function toV1(p) {
|
|
347
|
+
const floors = p.storeys.map((s) => {
|
|
348
|
+
const walls = new Map(s.walls.map((w) => [w.id, w]));
|
|
349
|
+
const openings = [];
|
|
350
|
+
for (const o of s.openings) {
|
|
351
|
+
const w = walls.get(o.wall);
|
|
352
|
+
const v = w ? openingOf(o, w) : null;
|
|
353
|
+
if (v) openings.push(v);
|
|
354
|
+
}
|
|
355
|
+
const floor = {
|
|
356
|
+
id: s.id,
|
|
357
|
+
name: s.name,
|
|
358
|
+
level: s.level,
|
|
359
|
+
rooms: s.spaces.map(roomOf),
|
|
360
|
+
openings,
|
|
361
|
+
placements: s.placements.map((pl) => {
|
|
362
|
+
const out = { ref: pl.ref, x: cells(pl.x), y: cells(pl.y) };
|
|
363
|
+
if (pl.host) out.opening = pl.host.opening;
|
|
364
|
+
if (pl.host?.covering) out.covering = pl.host.covering;
|
|
365
|
+
if (pl.color !== void 0) out.color = pl.color;
|
|
366
|
+
if (pl.circuitRooms !== void 0) out.circuitRooms = [...pl.circuitRooms];
|
|
367
|
+
if (pl.length !== void 0) out.length = cells(pl.length);
|
|
368
|
+
if (pl.axis !== void 0) out.axis = pl.axis;
|
|
369
|
+
if (pl.mount !== void 0) out.mount = pl.mount;
|
|
370
|
+
if (pl.look !== void 0) out.look = pl.look;
|
|
371
|
+
return out;
|
|
372
|
+
})
|
|
373
|
+
};
|
|
374
|
+
const radiators = s.radiators.flatMap((r) => {
|
|
375
|
+
const axis = axisOf(r.a, r.b);
|
|
376
|
+
if (!axis) return [];
|
|
377
|
+
const i = axis === "h" ? 0 : 1;
|
|
378
|
+
const lo = Math.min(r.a[i], r.b[i]);
|
|
379
|
+
const len = cells(Math.abs(r.b[i] - r.a[i]));
|
|
380
|
+
const side = r.b[i] >= r.a[i] ? r.side : r.side === "left" ? "right" : "left";
|
|
381
|
+
return [
|
|
382
|
+
axis === "h" ? { id: r.id, axis, x: cells(lo), y: cells(r.a[1]), len, side: fromWallSide(axis, side) } : { id: r.id, axis, x: cells(r.a[0]), y: cells(lo), len, side: fromWallSide(axis, side) }
|
|
383
|
+
];
|
|
384
|
+
});
|
|
385
|
+
if (radiators.length) floor.radiators = radiators;
|
|
386
|
+
const furniture = s.furniture.map((u) => {
|
|
387
|
+
const out = {
|
|
388
|
+
id: u.id,
|
|
389
|
+
kind: u.kind,
|
|
390
|
+
x: cells(u.x),
|
|
391
|
+
y: cells(u.y),
|
|
392
|
+
w: cells(u.w),
|
|
393
|
+
d: cells(u.d)
|
|
394
|
+
};
|
|
395
|
+
if (u.height !== void 0) out.height = Math.round(u.height / 10) / 100;
|
|
396
|
+
if (u.back !== void 0) out.back = u.back;
|
|
397
|
+
return out;
|
|
398
|
+
});
|
|
399
|
+
if (furniture.length) floor.furniture = furniture;
|
|
400
|
+
const fromRooms = wallLines(floor).map((l) => {
|
|
401
|
+
const [a, b] = lineEnds(l);
|
|
402
|
+
return { a, b };
|
|
403
|
+
});
|
|
404
|
+
const drawn = s.walls.filter((w) => !fromRooms.some((l) => overlap(l, w) > 0));
|
|
405
|
+
if (drawn.length)
|
|
406
|
+
floor.drawnWalls = drawn.map((w) => ({
|
|
407
|
+
id: w.id,
|
|
408
|
+
a: [cells(w.a[0]), cells(w.a[1])],
|
|
409
|
+
b: [cells(w.b[0]), cells(w.b[1])],
|
|
410
|
+
thickness: w.thickness,
|
|
411
|
+
height: w.height
|
|
412
|
+
}));
|
|
413
|
+
const specs = s.walls.flatMap((w) => {
|
|
414
|
+
if (drawn.includes(w)) return [];
|
|
415
|
+
const axis = axisOf(w.a, w.b);
|
|
416
|
+
if (!axis) {
|
|
417
|
+
return [
|
|
418
|
+
{
|
|
419
|
+
axis: "h",
|
|
420
|
+
x: cells(w.a[0]),
|
|
421
|
+
y: cells(w.a[1]),
|
|
422
|
+
len: 0,
|
|
423
|
+
to: [cells(w.b[0]), cells(w.b[1])],
|
|
424
|
+
thickness: w.thickness,
|
|
425
|
+
height: w.height
|
|
426
|
+
}
|
|
427
|
+
];
|
|
428
|
+
}
|
|
429
|
+
const i = axis === "h" ? 0 : 1;
|
|
430
|
+
const lo = Math.min(w.a[i], w.b[i]);
|
|
431
|
+
const len = cells(Math.abs(w.b[i] - w.a[i]));
|
|
432
|
+
const at = axis === "h" ? { x: cells(lo), y: cells(w.a[1]) } : { x: cells(w.a[0]), y: cells(lo) };
|
|
433
|
+
return [{ axis, ...at, len, thickness: w.thickness, height: w.height }];
|
|
434
|
+
});
|
|
435
|
+
if (specs.length) floor.walls = specs;
|
|
436
|
+
if (s.dimensions?.length)
|
|
437
|
+
floor.dimensions = s.dimensions.map((d) => ({
|
|
438
|
+
id: d.id,
|
|
439
|
+
a: [cells(d.a[0]), cells(d.a[1])],
|
|
440
|
+
b: [cells(d.b[0]), cells(d.b[1])]
|
|
441
|
+
}));
|
|
442
|
+
return floor;
|
|
443
|
+
});
|
|
444
|
+
return {
|
|
445
|
+
version: HOUSE_V1,
|
|
446
|
+
grid: HOUSE_GRID,
|
|
447
|
+
plot: { w: cells(p.site.w), h: cells(p.site.h) },
|
|
448
|
+
floors
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export {
|
|
453
|
+
CELL,
|
|
454
|
+
wallLines,
|
|
455
|
+
fromV1,
|
|
456
|
+
toV1
|
|
457
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__export
|
|
3
|
+
} from "./chunk-MLKGABMK.js";
|
|
4
|
+
|
|
5
|
+
// src/v1.ts
|
|
6
|
+
var v1_exports = {};
|
|
7
|
+
__export(v1_exports, {
|
|
8
|
+
DEVICE_LOOKS: () => DEVICE_LOOKS,
|
|
9
|
+
FURNITURE_KINDS: () => FURNITURE_KINDS,
|
|
10
|
+
HOUSE_GRID: () => HOUSE_GRID,
|
|
11
|
+
HOUSE_V1: () => HOUSE_V1,
|
|
12
|
+
LIGHT_MOUNTS: () => LIGHT_MOUNTS,
|
|
13
|
+
overlaps: () => overlaps,
|
|
14
|
+
roomRects: () => roomRects,
|
|
15
|
+
touches: () => touches
|
|
16
|
+
});
|
|
17
|
+
var HOUSE_V1 = 1;
|
|
18
|
+
var HOUSE_GRID = 0.5;
|
|
19
|
+
function roomRects(r) {
|
|
20
|
+
return [{ x: r.x, y: r.y, w: r.w, h: r.h }, ...r.parts ?? []];
|
|
21
|
+
}
|
|
22
|
+
var overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
23
|
+
var touches = (a, b) => {
|
|
24
|
+
const alongX = Math.min(a.x + a.w, b.x + b.w) - Math.max(a.x, b.x);
|
|
25
|
+
const alongY = Math.min(a.y + a.h, b.y + b.h) - Math.max(a.y, b.y);
|
|
26
|
+
return (a.y + a.h === b.y || b.y + b.h === a.y) && alongX >= 1 || (a.x + a.w === b.x || b.x + b.w === a.x) && alongY >= 1;
|
|
27
|
+
};
|
|
28
|
+
var LIGHT_MOUNTS = ["ceiling", "wall", "floor", "table", "pool"];
|
|
29
|
+
var DEVICE_LOOKS = ["outlet", "tv", "fridge", "washer", "dehumidifier", "vacuum", "mower", "tap"];
|
|
30
|
+
var FURNITURE_KINDS = [
|
|
31
|
+
"table",
|
|
32
|
+
"cabinet",
|
|
33
|
+
"island",
|
|
34
|
+
"bed",
|
|
35
|
+
"sofa",
|
|
36
|
+
"shelves",
|
|
37
|
+
"rug",
|
|
38
|
+
"bath",
|
|
39
|
+
"shower",
|
|
40
|
+
"toilet",
|
|
41
|
+
"basin",
|
|
42
|
+
"lounger",
|
|
43
|
+
"parasol",
|
|
44
|
+
"planter",
|
|
45
|
+
"pergola"
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export {
|
|
49
|
+
HOUSE_V1,
|
|
50
|
+
HOUSE_GRID,
|
|
51
|
+
roomRects,
|
|
52
|
+
overlaps,
|
|
53
|
+
touches,
|
|
54
|
+
LIGHT_MOUNTS,
|
|
55
|
+
DEVICE_LOOKS,
|
|
56
|
+
FURNITURE_KINDS,
|
|
57
|
+
v1_exports
|
|
58
|
+
};
|