bimdown-cli 0.3.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/README.md +24 -3
  2. package/dist/chunk-4SKM4RHY.js +142 -0
  3. package/dist/chunk-4SKM4RHY.js.map +1 -0
  4. package/dist/chunk-4YHVOWS4.js +255 -0
  5. package/dist/chunk-4YHVOWS4.js.map +1 -0
  6. package/dist/chunk-AYAXRYGP.js +2129 -0
  7. package/dist/chunk-AYAXRYGP.js.map +1 -0
  8. package/dist/chunk-EC5MR5ZH.js +648 -0
  9. package/dist/chunk-EC5MR5ZH.js.map +1 -0
  10. package/dist/chunk-HS3PO2LB.js +487 -0
  11. package/dist/chunk-HS3PO2LB.js.map +1 -0
  12. package/dist/chunk-IQJA3EFO.js +179 -0
  13. package/dist/chunk-IQJA3EFO.js.map +1 -0
  14. package/dist/chunk-JY6KWRDB.js +80 -0
  15. package/dist/chunk-JY6KWRDB.js.map +1 -0
  16. package/dist/chunk-KWSGJUMZ.js +2501 -0
  17. package/dist/chunk-KWSGJUMZ.js.map +1 -0
  18. package/dist/chunk-LWYIPR64.js +35 -0
  19. package/dist/chunk-LWYIPR64.js.map +1 -0
  20. package/dist/chunk-OBY3UYCO.js +44 -0
  21. package/dist/chunk-OBY3UYCO.js.map +1 -0
  22. package/dist/chunk-XC6WHJRL.js +29 -0
  23. package/dist/chunk-XC6WHJRL.js.map +1 -0
  24. package/dist/chunk-XQU52JKB.js +187 -0
  25. package/dist/chunk-XQU52JKB.js.map +1 -0
  26. package/dist/clash-load-D3LNQR6G.js +941 -0
  27. package/dist/clash-load-D3LNQR6G.js.map +1 -0
  28. package/dist/cli.js +431 -0
  29. package/dist/cli.js.map +1 -0
  30. package/dist/dehydrate-ZHAGOI7Q.js +90 -0
  31. package/dist/dehydrate-ZHAGOI7Q.js.map +1 -0
  32. package/dist/diff-T2KOK2WR.js +89 -0
  33. package/dist/diff-T2KOK2WR.js.map +1 -0
  34. package/dist/engine-2TPWJVEQ.js +12 -0
  35. package/dist/engine-2TPWJVEQ.js.map +1 -0
  36. package/dist/hydrate-V24H7IF3.js +673 -0
  37. package/dist/hydrate-V24H7IF3.js.map +1 -0
  38. package/dist/import-ifc-RCZSXDA6.js +5324 -0
  39. package/dist/import-ifc-RCZSXDA6.js.map +1 -0
  40. package/dist/info-QC7YXWNX.js +92 -0
  41. package/dist/info-QC7YXWNX.js.map +1 -0
  42. package/dist/init-VWDML3UC.js +112 -0
  43. package/dist/init-VWDML3UC.js.map +1 -0
  44. package/dist/lib.d.ts +492 -0
  45. package/dist/lib.js +6528 -0
  46. package/dist/lib.js.map +1 -0
  47. package/dist/mep-W4HJI363.js +25 -0
  48. package/dist/mep-W4HJI363.js.map +1 -0
  49. package/dist/merge-ESOPDSA5.js +413 -0
  50. package/dist/merge-ESOPDSA5.js.map +1 -0
  51. package/dist/publish-3TAXQCUV.js +80 -0
  52. package/dist/publish-3TAXQCUV.js.map +1 -0
  53. package/dist/render-UEWYHPN6.js +1807 -0
  54. package/dist/render-UEWYHPN6.js.map +1 -0
  55. package/dist/resolve-topology-AQ2RO3W3.js +338 -0
  56. package/dist/resolve-topology-AQ2RO3W3.js.map +1 -0
  57. package/dist/spec/csv-schema/annotation/dimension.yaml +77 -0
  58. package/dist/spec/csv-schema/annotation/tag.yaml +44 -0
  59. package/dist/spec/csv-schema/annotation/text_note.yaml +52 -0
  60. package/dist/spec/csv-schema/architecture/ceiling.yaml +8 -1
  61. package/dist/spec/csv-schema/architecture/column.yaml +5 -1
  62. package/dist/spec/csv-schema/architecture/curtain_wall.yaml +45 -5
  63. package/dist/spec/csv-schema/architecture/door.yaml +5 -0
  64. package/dist/spec/csv-schema/architecture/furniture.yaml +28 -0
  65. package/dist/spec/csv-schema/architecture/opening.yaml +27 -6
  66. package/dist/spec/csv-schema/architecture/railing.yaml +35 -0
  67. package/dist/spec/csv-schema/architecture/roof.yaml +34 -1
  68. package/dist/spec/csv-schema/architecture/slab.yaml +19 -0
  69. package/dist/spec/csv-schema/architecture/space.yaml +11 -1
  70. package/dist/spec/csv-schema/architecture/stair.yaml +49 -0
  71. package/dist/spec/csv-schema/architecture/stair_landing.yaml +36 -0
  72. package/dist/spec/csv-schema/architecture/stair_run.yaml +31 -0
  73. package/dist/spec/csv-schema/architecture/wall.yaml +14 -1
  74. package/dist/spec/csv-schema/architecture/window.yaml +19 -0
  75. package/dist/spec/csv-schema/base/element.yaml +20 -11
  76. package/dist/spec/csv-schema/base/furniture_params.yaml +60 -0
  77. package/dist/spec/csv-schema/base/hosted_element.yaml +10 -2
  78. package/dist/spec/csv-schema/base/mep_connectable.yaml +23 -0
  79. package/dist/spec/csv-schema/base/mep_design.yaml +24 -0
  80. package/dist/spec/csv-schema/base/mep_insulated.yaml +9 -0
  81. package/dist/spec/csv-schema/base/mep_system_tag.yaml +12 -0
  82. package/dist/spec/csv-schema/base/point_element.yaml +1 -0
  83. package/dist/spec/csv-schema/base/section_profile.yaml +5 -0
  84. package/dist/spec/csv-schema/base/spatial_line_element.yaml +4 -2
  85. package/dist/spec/csv-schema/base/structural_section_profile.yaml +50 -0
  86. package/dist/spec/csv-schema/base/vertical_span.yaml +9 -3
  87. package/dist/spec/csv-schema/base/wall_bounded.yaml +21 -0
  88. package/dist/spec/csv-schema/grid.yaml +5 -0
  89. package/dist/spec/csv-schema/mep/cable_tray.yaml +10 -3
  90. package/dist/spec/csv-schema/mep/circuit.yaml +70 -0
  91. package/dist/spec/csv-schema/mep/conduit.yaml +2 -2
  92. package/dist/spec/csv-schema/mep/connector.yaml +112 -0
  93. package/dist/spec/csv-schema/mep/duct.yaml +10 -3
  94. package/dist/spec/csv-schema/mep/equipment.yaml +18 -1
  95. package/dist/spec/csv-schema/mep/mep_node.yaml +91 -2
  96. package/dist/spec/csv-schema/mep/mep_system.yaml +21 -0
  97. package/dist/spec/csv-schema/mep/pipe.yaml +27 -3
  98. package/dist/spec/csv-schema/mep/terminal.yaml +22 -1
  99. package/dist/spec/csv-schema/model_group.yaml +40 -0
  100. package/dist/spec/csv-schema/sheet/sheet.yaml +50 -0
  101. package/dist/spec/csv-schema/sheet/sheet_viewport.yaml +86 -0
  102. package/dist/spec/csv-schema/structure/beam.yaml +29 -1
  103. package/dist/spec/csv-schema/structure/beam_system.yaml +29 -0
  104. package/dist/spec/csv-schema/structure/brace.yaml +24 -1
  105. package/dist/spec/csv-schema/structure/foundation.yaml +40 -7
  106. package/dist/spec/csv-schema/structure/structure_column.yaml +19 -1
  107. package/dist/spec/csv-schema/structure/structure_slab.yaml +32 -0
  108. package/dist/spec/csv-schema/structure/structure_wall.yaml +22 -0
  109. package/dist/spec/csv-schema/types/beam_type.yaml +11 -0
  110. package/dist/spec/csv-schema/types/ceiling_type.yaml +6 -0
  111. package/dist/spec/csv-schema/types/column_type.yaml +12 -0
  112. package/dist/spec/csv-schema/types/curtain_wall_type.yaml +32 -0
  113. package/dist/spec/csv-schema/types/door_type.yaml +27 -0
  114. package/dist/spec/csv-schema/types/element_type.yaml +21 -0
  115. package/dist/spec/csv-schema/types/fenestration.yaml +16 -0
  116. package/dist/spec/csv-schema/types/foundation_type.yaml +36 -0
  117. package/dist/spec/csv-schema/types/furniture_type.yaml +11 -0
  118. package/dist/spec/csv-schema/types/layered_type.yaml +13 -0
  119. package/dist/spec/csv-schema/types/railing_type.yaml +40 -0
  120. package/dist/spec/csv-schema/types/roof_type.yaml +7 -0
  121. package/dist/spec/csv-schema/types/slab_type.yaml +9 -0
  122. package/dist/spec/csv-schema/types/type_layer.yaml +47 -0
  123. package/dist/spec/csv-schema/types/wall_type.yaml +6 -0
  124. package/dist/spec/csv-schema/types/window_type.yaml +31 -0
  125. package/dist/spec/csv-schema/underlay.yaml +73 -0
  126. package/dist/spec/csv-schema/view.yaml +36 -0
  127. package/dist/spec/duckdb-strategy.md +4 -3
  128. package/dist/spec/geojson-schema/readme.md +380 -0
  129. package/dist/spec/mep-port-conventions.md +190 -0
  130. package/dist/spec/migration-guide.md +1 -1
  131. package/dist/spec/project_metadata.schema.yaml +52 -4
  132. package/dist/spec/readme.md +356 -97
  133. package/dist/spec/starter-types/global/beam_type.csv +5 -0
  134. package/dist/spec/starter-types/global/ceiling_type.csv +3 -0
  135. package/dist/spec/starter-types/global/column_type.csv +5 -0
  136. package/dist/spec/starter-types/global/curtain_wall_type.csv +2 -0
  137. package/dist/spec/starter-types/global/door_type.csv +6 -0
  138. package/dist/spec/starter-types/global/foundation_type.csv +7 -0
  139. package/dist/spec/starter-types/global/furniture_type.csv +11 -0
  140. package/dist/spec/starter-types/global/railing_type.csv +5 -0
  141. package/dist/spec/starter-types/global/roof_type.csv +3 -0
  142. package/dist/spec/starter-types/global/slab_type.csv +4 -0
  143. package/dist/spec/starter-types/global/type_layer.csv +40 -0
  144. package/dist/spec/starter-types/global/wall_type.csv +8 -0
  145. package/dist/spec/starter-types/global/window_type.csv +6 -0
  146. package/dist/spec/svg-schema/readme.md +47 -1
  147. package/package.json +17 -5
  148. package/dist/index.js +0 -3366
  149. package/dist/index.js.map +0 -1
  150. package/dist/spec/csv-schema/base/mep_connected_segment.yaml +0 -17
  151. package/dist/spec/csv-schema/base/mep_system.yaml +0 -7
@@ -0,0 +1,941 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ roofInputFor,
4
+ solveRoof,
5
+ verticalThickness
6
+ } from "./chunk-HS3PO2LB.js";
7
+ import {
8
+ UNIT_TO_M,
9
+ metersToProject,
10
+ projectUnits
11
+ } from "./chunk-LWYIPR64.js";
12
+ import {
13
+ effectiveRows
14
+ } from "./chunk-XQU52JKB.js";
15
+ import {
16
+ MEP_CURVE_TABLES,
17
+ featuresById,
18
+ levelElevations,
19
+ num
20
+ } from "./chunk-IQJA3EFO.js";
21
+ import {
22
+ extractLineGeometry,
23
+ extractPointGeometry,
24
+ extractPolygonGeometry
25
+ } from "./chunk-4SKM4RHY.js";
26
+ import "./chunk-4YHVOWS4.js";
27
+ import {
28
+ readCsv
29
+ } from "./chunk-JY6KWRDB.js";
30
+ import {
31
+ discoverLayout,
32
+ listFiles
33
+ } from "./chunk-OBY3UYCO.js";
34
+
35
+ // src/mep/clash-load.ts
36
+ import { existsSync } from "fs";
37
+ import { join } from "path";
38
+
39
+ // src/mep/clash.ts
40
+ var EPS = 1e-9;
41
+ var CONTACT = 1e-6;
42
+ var add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
43
+ var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
44
+ var mul = (a, s) => [a[0] * s, a[1] * s, a[2] * s];
45
+ var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
46
+ 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]];
47
+ var len = (a) => Math.hypot(a[0], a[1], a[2]);
48
+ var lerp = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
49
+ var clamp = (v, lo, hi) => v < lo ? lo : v > hi ? hi : v;
50
+ var Z = [0, 0, 1];
51
+ function lineFrame(f, rotationDeg = 0) {
52
+ let right;
53
+ const h = Math.hypot(f[0], f[1]);
54
+ if (h < 1e-6) {
55
+ const t = rotationDeg * Math.PI / 180;
56
+ right = [Math.cos(t), Math.sin(t), 0];
57
+ } else {
58
+ right = [-f[1] / h, f[0] / h, 0];
59
+ }
60
+ return [f, right, cross(f, right)];
61
+ }
62
+ function lineSolid(a, b, shape, w, h, top = false, rotation = 0) {
63
+ const d = sub(b, a);
64
+ const L = len(d);
65
+ if (!(L > EPS) || !(w > 0)) return null;
66
+ const u = lineFrame(mul(d, 1 / L), rotation);
67
+ const round = shape === "round";
68
+ const hw = w / 2;
69
+ const hh = round ? hw : (h > 0 ? h : w) / 2;
70
+ let c = lerp(a, b, 0.5);
71
+ if (top) c = sub(c, mul(u[2], hh));
72
+ return { c, u, e: [L / 2, hw, hh], round };
73
+ }
74
+ function boxSolid(center, half, rotationDeg = 0) {
75
+ const t = rotationDeg * Math.PI / 180;
76
+ const c = Math.cos(t), s = Math.sin(t);
77
+ return { c: center, u: [[c, s, 0], [-s, c, 0], Z], e: [Math.abs(half[0]), Math.abs(half[1]), Math.abs(half[2])], round: false };
78
+ }
79
+ function support(s, n) {
80
+ if (s.round) {
81
+ const k = dot(n, s.u[0]);
82
+ return s.e[0] * Math.abs(k) + s.e[1] * Math.sqrt(Math.max(0, 1 - k * k));
83
+ }
84
+ return s.e[0] * Math.abs(dot(n, s.u[0])) + s.e[1] * Math.abs(dot(n, s.u[1])) + s.e[2] * Math.abs(dot(n, s.u[2]));
85
+ }
86
+ function sectionSupport(s, n) {
87
+ if (s.round) {
88
+ const k = dot(n, s.u[0]);
89
+ return s.e[1] * Math.sqrt(Math.max(0, 1 - k * k));
90
+ }
91
+ return s.e[1] * Math.abs(dot(n, s.u[1])) + s.e[2] * Math.abs(dot(n, s.u[2]));
92
+ }
93
+ function clampInto(s, p) {
94
+ const d = sub(p, s.c);
95
+ if (s.round) {
96
+ const ax = dot(d, s.u[0]);
97
+ const radial = sub(d, mul(s.u[0], ax));
98
+ const r = len(radial);
99
+ const rr = r > s.e[1] ? mul(radial, s.e[1] / r) : radial;
100
+ return add(add(s.c, mul(s.u[0], clamp(ax, -s.e[0], s.e[0]))), rr);
101
+ }
102
+ let out = s.c;
103
+ for (let k = 0; k < 3; k++) out = add(out, mul(s.u[k], clamp(dot(d, s.u[k]), -s.e[k], s.e[k])));
104
+ return out;
105
+ }
106
+ function segSegClosest(p1, q1, p2, q2) {
107
+ const d1 = sub(q1, p1), d2 = sub(q2, p2), r = sub(p1, p2);
108
+ const a = dot(d1, d1), e = dot(d2, d2), f = dot(d2, r);
109
+ let s = 0, t = 0;
110
+ if (a <= EPS && e <= EPS) {
111
+ } else if (a <= EPS) t = clamp(f / e, 0, 1);
112
+ else {
113
+ const c = dot(d1, r);
114
+ if (e <= EPS) s = clamp(-c / a, 0, 1);
115
+ else {
116
+ const b = dot(d1, d2);
117
+ const denom = a * e - b * b;
118
+ s = denom > EPS ? clamp((b * f - c * e) / denom, 0, 1) : 0;
119
+ t = (b * s + f) / e;
120
+ if (t < 0) {
121
+ t = 0;
122
+ s = clamp(-c / a, 0, 1);
123
+ } else if (t > 1) {
124
+ t = 1;
125
+ s = clamp((b - c) / a, 0, 1);
126
+ }
127
+ }
128
+ }
129
+ return [add(p1, mul(d1, s)), add(p2, mul(d2, t))];
130
+ }
131
+ var axisEnds = (s) => [sub(s.c, mul(s.u[0], s.e[0])), add(s.c, mul(s.u[0], s.e[0]))];
132
+ function coreClosest(cyl, other) {
133
+ const [p, q] = axisEnds(cyl);
134
+ if (other.round) {
135
+ const [r, s] = axisEnds(other);
136
+ return segSegClosest(p, q, r, s);
137
+ }
138
+ const box = { ...other, round: false };
139
+ const dist = (t) => {
140
+ const x2 = lerp(p, q, t);
141
+ return len(sub(x2, clampInto(box, x2)));
142
+ };
143
+ let lo = 0, hi = 1;
144
+ for (let i = 0; i < 40; i++) {
145
+ const m1 = lo + (hi - lo) / 3, m2 = hi - (hi - lo) / 3;
146
+ if (dist(m1) <= dist(m2)) hi = m2;
147
+ else lo = m1;
148
+ }
149
+ const x = lerp(p, q, (lo + hi) / 2);
150
+ return [x, clampInto(box, x)];
151
+ }
152
+ function satDepth(A, B) {
153
+ const axes = [...A.u, ...B.u];
154
+ for (const ua of A.u) {
155
+ for (const ub of B.u) {
156
+ const c = cross(ua, ub);
157
+ const l = len(c);
158
+ if (l > 1e-6) axes.push(mul(c, 1 / l));
159
+ }
160
+ }
161
+ if (A.round || B.round) {
162
+ const [p, q] = A.round ? coreClosest(A, B) : coreClosest(B, A);
163
+ const d2 = sub(q, p);
164
+ const l = len(d2);
165
+ if (l > 1e-9) axes.push(mul(d2, 1 / l));
166
+ }
167
+ const d = sub(B.c, A.c);
168
+ let best = Infinity;
169
+ for (const n of axes) {
170
+ const o = support(A, n) + support(B, n) - Math.abs(dot(d, n));
171
+ if (o < best) best = o;
172
+ }
173
+ return best;
174
+ }
175
+ function clipAxis(a, b, member, B, grow = 0) {
176
+ let t0 = 0, t1 = 1;
177
+ const d = sub(b, a);
178
+ for (let k = 0; k < 3; k++) {
179
+ const n = B.u[k];
180
+ const lim = B.e[k] + sectionSupport(member, n) + grow;
181
+ const p0 = dot(sub(a, B.c), n);
182
+ const dp = dot(d, n);
183
+ if (Math.abs(dp) < EPS) {
184
+ if (Math.abs(p0) > lim) return null;
185
+ continue;
186
+ }
187
+ let ta = (-lim - p0) / dp, tb = (lim - p0) / dp;
188
+ if (ta > tb) [ta, tb] = [tb, ta];
189
+ t0 = Math.max(t0, ta);
190
+ t1 = Math.min(t1, tb);
191
+ if (t0 > t1) return null;
192
+ }
193
+ return [t0, t1];
194
+ }
195
+ function inRing(p, ring) {
196
+ let inside = false;
197
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
198
+ const [xi, yi] = ring[i], [xj, yj] = ring[j];
199
+ if (yi > p[1] !== yj > p[1] && p[0] < (xj - xi) * (p[1] - yi) / (yj - yi) + xi) inside = !inside;
200
+ }
201
+ return inside;
202
+ }
203
+ function ringDistance(p, ring) {
204
+ let best = Infinity;
205
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
206
+ const [ax, ay] = ring[j], [bx, by] = ring[i];
207
+ const dx = bx - ax, dy = by - ay;
208
+ const l2 = dx * dx + dy * dy;
209
+ const t = l2 > EPS ? clamp(((p[0] - ax) * dx + (p[1] - ay) * dy) / l2, 0, 1) : 0;
210
+ best = Math.min(best, Math.hypot(p[0] - ax - dx * t, p[1] - ay - dy * t));
211
+ }
212
+ return best;
213
+ }
214
+ function ringCrossings(p, q, ring, out) {
215
+ const rx = q[0] - p[0], ry = q[1] - p[1];
216
+ for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
217
+ const [ax, ay] = ring[j], [bx, by] = ring[i];
218
+ const sx = bx - ax, sy = by - ay;
219
+ const den = rx * sy - ry * sx;
220
+ if (Math.abs(den) < EPS) continue;
221
+ const qx = ax - p[0], qy = ay - p[1];
222
+ const t = (qx * sy - qy * sx) / den;
223
+ const v = (qx * ry - qy * rx) / den;
224
+ if (t > 0 && t < 1 && v >= 0 && v <= 1) out.push(t);
225
+ }
226
+ }
227
+ function planParts(p, q, outer, holes) {
228
+ const classify = (m) => {
229
+ if (!inRing(m, outer)) return -2;
230
+ for (let i = 0; i < holes.length; i++) if (holes[i].length >= 3 && inRing(m, holes[i])) return i;
231
+ return -1;
232
+ };
233
+ if (Math.hypot(q[0] - p[0], q[1] - p[1]) < 1e-9) return [{ s0: 0, s1: 1, hole: classify(p) }];
234
+ const ts = [0, 1];
235
+ ringCrossings(p, q, outer, ts);
236
+ for (const h of holes) ringCrossings(p, q, h, ts);
237
+ ts.sort((x, y) => x - y);
238
+ const parts = [];
239
+ for (let i = 0; i + 1 < ts.length; i++) {
240
+ const s0 = ts[i], s1 = ts[i + 1];
241
+ if (s1 - s0 < 1e-9) continue;
242
+ const s = (s0 + s1) / 2;
243
+ const hole = classify([p[0] + (q[0] - p[0]) * s, p[1] + (q[1] - p[1]) * s]);
244
+ const last = parts[parts.length - 1];
245
+ if (last && last.hole === hole) last.s1 = s1;
246
+ else parts.push({ s0, s1, hole });
247
+ }
248
+ return parts;
249
+ }
250
+ var keyOf = (scope, id) => `${scope ?? ""}/${id}`;
251
+ var isMep = (it) => it.cat === "curve" || it.cat === "host";
252
+ function solidBox(s) {
253
+ const ex = support(s, [1, 0, 0]), ey = support(s, [0, 1, 0]), ez = support(s, Z);
254
+ return [s.c[0] - ex, s.c[1] - ey, s.c[2] - ez, s.c[0] + ex, s.c[1] + ey, s.c[2] + ez];
255
+ }
256
+ function splitSystems(s) {
257
+ return (s || "").split(",").map((x) => x.trim()).filter(Boolean);
258
+ }
259
+ function compatible(a, b) {
260
+ const A = splitSystems(a), B = splitSystems(b);
261
+ return A.length === 0 || B.length === 0 || A.some((x) => B.includes(x));
262
+ }
263
+ function pointSegDistance(p, a, b) {
264
+ const d = sub(b, a);
265
+ const l2 = dot(d, d);
266
+ const t = l2 > EPS ? clamp(dot(sub(p, a), d) / l2, 0, 1) : 0;
267
+ return len(sub(p, add(a, mul(d, t))));
268
+ }
269
+ function insideGrown(s, p, grow) {
270
+ return len(sub(p, clampInto(s, p))) <= grow + 1e-6;
271
+ }
272
+ function connected(A, B) {
273
+ if (A.cat === "curve" && B.cat === "curve") {
274
+ if (A.joints.some((j) => B.joints.includes(j))) return true;
275
+ if (!compatible(A.system, B.system)) return false;
276
+ const [a0, a1] = A.ends, [b0, b1] = B.ends;
277
+ const reach = Math.max(A.size, B.size);
278
+ for (const p of [a0, a1]) for (const q of [b0, b1]) if (len(sub(p, q)) <= reach) return true;
279
+ const tap = (A.size + B.size) / 2 + 1e-6;
280
+ const taps = (X, Y) => X.ends.some((p, k) => X.open[k] && pointSegDistance(p, Y.ends[0], Y.ends[1]) <= tap);
281
+ return taps(A, B) || taps(B, A);
282
+ }
283
+ const curve = A.cat === "curve" ? A : B.cat === "curve" ? B : null;
284
+ const host = A.cat === "host" ? A : B.cat === "host" ? B : null;
285
+ if (!curve || !host) return false;
286
+ if (curve.joints.includes(host.key)) return true;
287
+ if (!compatible(curve.system, host.system)) return false;
288
+ return curve.ends.some((p, k) => curve.open[k] && insideGrown(host.solid, p, curve.size / 2));
289
+ }
290
+ function overlapPoint(A, B, grow) {
291
+ let p = null;
292
+ const member = A.ends ? A : B.ends ? B : null;
293
+ const other = member === A ? B : A;
294
+ if (member && member.solid && other.solid) {
295
+ const iv = clipAxis(member.ends[0], member.ends[1], member.solid, other.solid, grow);
296
+ if (iv) p = lerp(member.ends[0], member.ends[1], (iv[0] + iv[1]) / 2);
297
+ }
298
+ if (!p) {
299
+ const a = A.box, b = B.box;
300
+ p = [0, 1, 2].map((k) => (Math.max(a[k], b[k]) + Math.min(a[k + 3], b[k + 3])) / 2);
301
+ }
302
+ const q = clampInto(B.solid, p);
303
+ const r = clampInto(A.solid, q);
304
+ return lerp(q, r, 0.5);
305
+ }
306
+ function slabHit(it, slab, floor) {
307
+ const sl = slab.slab;
308
+ const s = it.solid;
309
+ const [gx, gy] = sl.grad;
310
+ const k = Math.hypot(gx, gy, 1);
311
+ const n = [-gx / k, -gy / k, 1 / k];
312
+ const lo = sl.z0 / k, hi = sl.z1 / k;
313
+ const zc = (lo + hi) / 2, hz = (hi - lo) / 2;
314
+ const zClamp = (p) => clamp(p[2], sl.z0 + gx * p[0] + gy * p[1], sl.z1 + gx * p[0] + gy * p[1]);
315
+ if (it.ends) {
316
+ const [a, b] = it.ends;
317
+ const sz = sectionSupport(s, n);
318
+ const lim = hz + sz;
319
+ let t0 = 0, t1 = 1;
320
+ const va = dot(a, n), vb = dot(b, n);
321
+ const dz = vb - va, p0 = va - zc;
322
+ if (Math.abs(dz) < EPS) {
323
+ if (Math.abs(p0) > lim) return null;
324
+ } else {
325
+ let ta = (-lim - p0) / dz, tb = (lim - p0) / dz;
326
+ if (ta > tb) [ta, tb] = [tb, ta];
327
+ t0 = Math.max(0, ta);
328
+ t1 = Math.min(1, tb);
329
+ if (t0 > t1) return null;
330
+ }
331
+ const za = va + dz * t0, zb = va + dz * t1;
332
+ const depth2 = Math.min(Math.max(za, zb) + sz, hi) - Math.max(Math.min(za, zb) - sz, lo);
333
+ if (depth2 <= floor) return null;
334
+ const pa = lerp(a, b, t0), pb = lerp(a, b, t1);
335
+ const p = [pa[0], pa[1]], q = [pb[0], pb[1]];
336
+ const planR = Math.max(sectionSupport(s, [1, 0, 0]), sectionSupport(s, [0, 1, 0]));
337
+ let best = null, bestDepth = 0;
338
+ for (const part of planParts(p, q, sl.outer, sl.holes)) {
339
+ let d = part.hole === -1 ? depth2 : 0;
340
+ if (part.hole >= 0) {
341
+ const m = (part.s0 + part.s1) / 2;
342
+ d = Math.min(depth2, planR - ringDistance([p[0] + (q[0] - p[0]) * m, p[1] + (q[1] - p[1]) * m], sl.holes[part.hole]));
343
+ }
344
+ if (d > floor && (!best || d > bestDepth || d === bestDepth && part.s1 - part.s0 > best.s1 - best.s0)) {
345
+ best = part;
346
+ bestDepth = d;
347
+ }
348
+ }
349
+ if (!best) return null;
350
+ const at = lerp(pa, pb, (best.s0 + best.s1) / 2);
351
+ at[2] = zClamp(at);
352
+ return { depth: bestDepth, at };
353
+ }
354
+ const c = dot(s.c, n), e = support(s, n);
355
+ const depth = Math.min(c + e, hi) - Math.max(c - e, lo);
356
+ if (depth <= floor) return null;
357
+ const pts = [s.c];
358
+ for (const i of [-1, 1]) for (const j of [-1, 1]) pts.push(add(add(s.c, mul(s.u[0], s.e[0] * i)), mul(s.u[1], s.e[1] * j)));
359
+ for (const pt of pts) {
360
+ const xy = [pt[0], pt[1]];
361
+ if (inRing(xy, sl.outer) && !sl.holes.some((h) => h.length >= 3 && inRing(xy, h))) {
362
+ return { depth, at: [pt[0], pt[1], zClamp([pt[0], pt[1], s.c[2]])] };
363
+ }
364
+ }
365
+ return null;
366
+ }
367
+ function wallCovered(curve, wall, slack) {
368
+ const w = wall.wall;
369
+ if (w.openings.length === 0 || !curve.ends) return false;
370
+ const iv = clipAxis(curve.ends[0], curve.ends[1], curve.solid, wall.solid);
371
+ if (!iv) return false;
372
+ const p = lerp(curve.ends[0], curve.ends[1], (iv[0] + iv[1]) / 2);
373
+ const u = (p[0] - w.a[0]) * w.dir[0] + (p[1] - w.a[1]) * w.dir[1];
374
+ const su = sectionSupport(curve.solid, [w.dir[0], w.dir[1], 0]);
375
+ const sz = sectionSupport(curve.solid, Z);
376
+ return w.openings.some((o) => u - su >= o.u0 - slack && u + su <= o.u1 + slack && p[2] - sz >= o.z0 - slack && p[2] + sz <= o.z1 + slack);
377
+ }
378
+ function buildItems(m) {
379
+ const items = [];
380
+ const hostScopes = /* @__PURE__ */ new Map();
381
+ for (const h of m.hosts) {
382
+ const list = hostScopes.get(h.id);
383
+ if (list) list.push(h.scope ?? "");
384
+ else hostScopes.set(h.id, [h.scope ?? ""]);
385
+ }
386
+ const joint = (ref, scope) => {
387
+ const host = (ref ?? "").split(":")[0].trim();
388
+ if (!host) return null;
389
+ const scopes = hostScopes.get(host);
390
+ const own = scope ?? "";
391
+ if (!scopes || scopes.includes(own)) return keyOf(scope, host);
392
+ return keyOf(scopes.includes("global") ? "global" : scopes[0], host);
393
+ };
394
+ for (const c of m.curves) {
395
+ const ins = Math.max(0, c.insulation ?? 0);
396
+ const w = c.w + 2 * ins;
397
+ const h = (c.shape === "round" ? c.w : c.h > 0 ? c.h : c.w) + 2 * ins;
398
+ const solid = lineSolid(c.a, c.b, c.shape, w, h);
399
+ if (!solid) continue;
400
+ const joints = [joint(c.from, c.scope), joint(c.to, c.scope)].filter((j) => !!j);
401
+ items.push({
402
+ cat: "curve",
403
+ id: c.id,
404
+ table: c.table,
405
+ scope: c.scope,
406
+ key: keyOf(c.scope, c.id),
407
+ system: c.system,
408
+ solid,
409
+ ends: [c.a, c.b],
410
+ open: [!(c.from ?? "").trim(), !(c.to ?? "").trim()],
411
+ size: Math.max(w, h),
412
+ joints,
413
+ penetrates: true,
414
+ box: solidBox(solid)
415
+ });
416
+ }
417
+ for (const h of m.hosts) {
418
+ if (h.fitting) continue;
419
+ const solid = boxSolid(h.center, h.half, h.rotation);
420
+ if (!(solid.e[0] > 0 && solid.e[1] > 0 && solid.e[2] > 0)) continue;
421
+ const key = keyOf(h.scope, h.id);
422
+ items.push({
423
+ cat: "host",
424
+ id: h.id,
425
+ table: h.table,
426
+ scope: h.scope,
427
+ key,
428
+ system: h.system,
429
+ solid,
430
+ size: 2 * Math.max(...solid.e),
431
+ joints: [key],
432
+ penetrates: h.table === "equipment",
433
+ box: solidBox(solid)
434
+ });
435
+ }
436
+ const obstacle = (o, cat, solid, extra = {}) => {
437
+ items.push({
438
+ cat,
439
+ id: o.id,
440
+ table: o.table,
441
+ scope: o.scope,
442
+ key: keyOf(o.scope, o.id),
443
+ system: "",
444
+ solid,
445
+ size: 0,
446
+ joints: [],
447
+ penetrates: false,
448
+ box: solidBox(solid),
449
+ ...extra
450
+ });
451
+ };
452
+ for (const mb of m.members ?? []) {
453
+ const solid = lineSolid(mb.a, mb.b, mb.shape, mb.w, mb.h, mb.top, mb.rotation);
454
+ if (solid) obstacle(mb, "hard", solid);
455
+ }
456
+ for (const bx of m.boxes ?? []) {
457
+ const solid = boxSolid(bx.center, bx.half, bx.rotation);
458
+ if (solid.e[0] > 0 && solid.e[1] > 0 && solid.e[2] > 0) obstacle(bx, "hard", solid);
459
+ }
460
+ for (const w of m.walls ?? []) {
461
+ const dx = w.b[0] - w.a[0], dy = w.b[1] - w.a[1];
462
+ const L = Math.hypot(dx, dy);
463
+ if (!(L > EPS) || !(w.thickness > 0) || !(w.z1 > w.z0)) continue;
464
+ const dir = [dx / L, dy / L];
465
+ const solid = {
466
+ c: [(w.a[0] + w.b[0]) / 2, (w.a[1] + w.b[1]) / 2, (w.z0 + w.z1) / 2],
467
+ u: [[dir[0], dir[1], 0], [-dir[1], dir[0], 0], Z],
468
+ e: [L / 2, w.thickness / 2, (w.z1 - w.z0) / 2],
469
+ round: false
470
+ };
471
+ obstacle(w, w.structural ? "hard" : "soft", solid, { wall: { a: w.a, dir, openings: w.openings ?? [] } });
472
+ }
473
+ for (const s of m.slabs ?? []) {
474
+ if (s.outer.length < 3 || !(s.z1 > s.z0)) continue;
475
+ const grad = s.grad ?? [0, 0];
476
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity, minZ = Infinity, maxZ = -Infinity;
477
+ for (const [x, y] of s.outer) {
478
+ minX = Math.min(minX, x);
479
+ minY = Math.min(minY, y);
480
+ maxX = Math.max(maxX, x);
481
+ maxY = Math.max(maxY, y);
482
+ const rise = grad[0] * x + grad[1] * y;
483
+ minZ = Math.min(minZ, s.z0 + rise);
484
+ maxZ = Math.max(maxZ, s.z1 + rise);
485
+ }
486
+ items.push({
487
+ cat: s.structural ? "hard" : "soft",
488
+ id: s.id,
489
+ table: s.table,
490
+ scope: s.scope,
491
+ key: keyOf(s.scope, s.id),
492
+ system: "",
493
+ slab: { outer: s.outer, holes: s.holes ?? [], z0: s.z0, z1: s.z1, grad },
494
+ size: 0,
495
+ joints: [],
496
+ penetrates: false,
497
+ box: [minX, minY, minZ, maxX, maxY, maxZ]
498
+ });
499
+ }
500
+ return items;
501
+ }
502
+ var SEVERITY_ORDER = { high: 0, medium: 1, low: 2 };
503
+ function detectClashes(m, opts = {}) {
504
+ const tol = Math.max(0, opts.tolerance ?? 0.05);
505
+ const clr = Math.max(0, opts.clearance ?? 0);
506
+ const floor = CONTACT;
507
+ const items = buildItems(m);
508
+ const found = /* @__PURE__ */ new Map();
509
+ const record = (A, B, kind, severity, depth, at) => {
510
+ const minor = kind !== "clearance" && depth <= tol;
511
+ if (minor && !opts.minor) return;
512
+ const key = `${A.key}|${B.key}`;
513
+ const prev = found.get(key);
514
+ if (prev && prev.depth >= depth) return;
515
+ const systems = [.../* @__PURE__ */ new Set([...splitSystems(A.system), ...splitSystems(B.system)])];
516
+ found.set(key, {
517
+ a: A.id,
518
+ aTable: A.table,
519
+ ...A.scope !== void 0 ? { aScope: A.scope } : {},
520
+ b: B.id,
521
+ bTable: B.table,
522
+ ...B.scope !== void 0 ? { bScope: B.scope } : {},
523
+ severity,
524
+ kind,
525
+ at,
526
+ depth,
527
+ systems,
528
+ ...minor ? { minor: true } : {}
529
+ });
530
+ };
531
+ const narrow = (A, B) => {
532
+ if (!A.penetrates && (B.wall || B.slab)) return;
533
+ if (B.slab) {
534
+ const hit = slabHit(A, B, floor);
535
+ if (hit) record(A, B, B.cat === "hard" ? "hard" : "penetration", B.cat === "hard" ? "high" : "low", hit.depth, hit.at);
536
+ return;
537
+ }
538
+ if (isMep(B) && connected(A, B)) return;
539
+ const depth = satDepth(A.solid, B.solid);
540
+ if (depth > floor) {
541
+ if (B.cat === "soft") {
542
+ if (A.ends && B.wall && wallCovered(A, B, floor)) return;
543
+ record(A, B, "penetration", "low", depth, overlapPoint(A, B, 0));
544
+ } else {
545
+ record(A, B, "hard", B.cat === "hard" ? "high" : "medium", depth, overlapPoint(A, B, 0));
546
+ }
547
+ return;
548
+ }
549
+ if (clr > 0 && B.cat !== "soft") {
550
+ const gap = Math.max(0, -depth);
551
+ if (gap < clr) record(A, B, "clearance", "low", gap, overlapPoint(A, B, gap));
552
+ }
553
+ };
554
+ const order = items.map((_, i) => i).sort((i, j) => items[i].box[0] - items[j].box[0]);
555
+ let active = [];
556
+ for (const i of order) {
557
+ const A = items[i];
558
+ const bi = A.box;
559
+ active = active.filter((j) => items[j].box[3] + clr >= bi[0]);
560
+ for (const j of active) {
561
+ const B = items[j];
562
+ const mepA = isMep(A), mepB = isMep(B);
563
+ if (!mepA && !mepB) continue;
564
+ if (opts.mepOnly && (!mepA || !mepB)) continue;
565
+ const bj = B.box;
566
+ if (bj[1] > bi[4] + clr || bi[1] > bj[4] + clr || bj[2] > bi[5] + clr || bi[2] > bj[5] + clr) continue;
567
+ let first = A, second = B;
568
+ if (!mepA || mepB && A.cat === "host" && B.cat === "curve" || mepB && A.cat === B.cat && j < i) {
569
+ first = B;
570
+ second = A;
571
+ }
572
+ narrow(first, second);
573
+ }
574
+ active.push(i);
575
+ }
576
+ const byKey = new Map(items.map((it) => [`${it.scope ?? ""}/${it.id}`, it]));
577
+ const itemOf = (id, scope) => byKey.get(`${scope ?? ""}/${id}`);
578
+ const kept = [];
579
+ for (const c of [...found.values()].sort((x, y) => y.depth - x.depth)) {
580
+ const A = itemOf(c.a, c.aScope);
581
+ const dup = A?.cat === "curve" && kept.some((k) => {
582
+ if (k.b !== c.b || k.bScope !== c.bScope || k.kind !== c.kind || k.a === c.a) return false;
583
+ const K = itemOf(k.a, k.aScope);
584
+ if (!K || K.cat !== "curve" || !connected(A, K)) return false;
585
+ return len(sub(k.at, c.at)) <= Math.max(A.size, K.size, tol) + 1e-6;
586
+ });
587
+ if (!dup) kept.push(c);
588
+ }
589
+ return kept.sort((x, y) => (x.minor ? 1 : 0) - (y.minor ? 1 : 0) || SEVERITY_ORDER[x.severity] - SEVERITY_ORDER[y.severity] || (x.kind === "clearance" ? 1 : 0) - (y.kind === "clearance" ? 1 : 0) || y.depth - x.depth || x.a.localeCompare(y.a) || x.b.localeCompare(y.b));
590
+ }
591
+ function clashCounts(clashes) {
592
+ const out = { high: 0, medium: 0, low: 0 };
593
+ for (const c of clashes) if (!c.minor) out[c.severity]++;
594
+ return out;
595
+ }
596
+
597
+ // src/mep/clash-load.ts
598
+ var DEFAULT_SHAPE = { duct: "rect", pipe: "round", conduit: "round", cable_tray: "rect" };
599
+ var MEMBER_DEFAULTS = { beam: [0.3, 0.5], brace: [0.2, 0.2] };
600
+ var WALL_TABLES = ["wall", "structure_wall", "curtain_wall"];
601
+ var COLUMN_TABLES = ["column", "structure_column"];
602
+ var SLAB_TABLES = ["slab", "structure_slab", "roof"];
603
+ function roofFaces(base, outline, attrs, thickness) {
604
+ const sol = solveRoof(roofInputFor(outline, attrs));
605
+ if (!(sol.maxSlopeDeg > 0) || sol.pieces.length === 0) return [base];
606
+ const vThick = verticalThickness(thickness, sol.maxSlopeDeg);
607
+ return sol.pieces.map((pc) => {
608
+ const pl = sol.planes[pc.plane];
609
+ const z0 = base.z0 + pl.c;
610
+ return { ...base, outer: pc.poly.map((p) => [p.x, p.y]), z0, z1: z0 + vThick, grad: [pl.a, pl.b] };
611
+ });
612
+ }
613
+ function rowsOf(projectDir, d, table) {
614
+ if (!d.files.has(`${table}.csv`)) return [];
615
+ try {
616
+ return effectiveRows(projectDir, table, readCsv(join(d.path, `${table}.csv`)).rows);
617
+ } catch {
618
+ return [];
619
+ }
620
+ }
621
+ var sectionShape = (s) => (s ?? "").trim() === "round" ? "round" : "rect";
622
+ function loadClashModel(dir, level) {
623
+ const layout = discoverLayout(dir);
624
+ const elev = levelElevations(dir);
625
+ const sorted = [...elev.values()].sort((a, b) => a - b);
626
+ const unitM = UNIT_TO_M[projectUnits(dir)];
627
+ const defaultHeight = 3 / unitM;
628
+ const dirs = [{ name: "global", path: layout.globalDir }, ...layout.levelDirs].filter((d) => existsSync(d.path)).map((d) => ({ ...d, base: elev.get(d.name) ?? 0, files: new Set(listFiles(d.path)) }));
629
+ const m = { curves: [], hosts: [], members: [], boxes: [], walls: [], slabs: [] };
630
+ const geoCache = /* @__PURE__ */ new Map();
631
+ const geo = (d, table) => {
632
+ const p = join(d.path, `${table}.geojson`);
633
+ let g = geoCache.get(p);
634
+ if (!g) geoCache.set(p, g = featuresById(p));
635
+ return g;
636
+ };
637
+ const span = (d, row, f) => {
638
+ const baseLevel = row.base_level_id && elev.has(row.base_level_id) ? elev.get(row.base_level_id) : d.base;
639
+ const bottom = baseLevel + num(f.properties?.base_offset ?? row.base_offset);
640
+ const topLevel = elev.get(row.top_level_id ?? "") ?? sorted.find((e) => e > baseLevel + 1e-6);
641
+ let top = topLevel === void 0 ? NaN : topLevel + num(f.properties?.top_offset ?? row.top_offset);
642
+ if (!(top > bottom)) top = bottom + (num(row.height) > 0 ? num(row.height) : defaultHeight);
643
+ return [bottom, top];
644
+ };
645
+ const shafts = [];
646
+ for (const d of dirs) {
647
+ for (const row of rowsOf(dir, d, "opening")) {
648
+ if (!row.top_level_id) continue;
649
+ const f = geo(d, "opening").get(row.id);
650
+ if (!f || f.geometry.type !== "Polygon") continue;
651
+ const top = elev.get(row.top_level_id);
652
+ if (top === void 0) continue;
653
+ const ring = extractPolygonGeometry(f).outer.map((p) => [p.x, p.y]);
654
+ shafts.push({ ring, z0: d.base + num(row.base_offset), z1: top + num(row.top_offset) });
655
+ }
656
+ }
657
+ for (const d of dirs) {
658
+ const mine = !level || d.name === level;
659
+ const scope = d.name;
660
+ if (mine) {
661
+ for (const t of MEP_CURVE_TABLES) {
662
+ for (const row of rowsOf(dir, d, t)) {
663
+ const f = geo(d, t).get(row.id);
664
+ if (!f || f.geometry.type !== "LineString") continue;
665
+ let lg;
666
+ try {
667
+ lg = extractLineGeometry(f);
668
+ } catch {
669
+ continue;
670
+ }
671
+ const z = d.base + num(f.properties?.base_offset);
672
+ const w = num(row.size_x, t === "duct" ? 0.2 / unitM : 0.05 / unitM);
673
+ m.curves.push({
674
+ id: row.id,
675
+ scope,
676
+ table: t,
677
+ a: [lg.start_x, lg.start_y, lg.start_z ?? z],
678
+ b: [lg.end_x, lg.end_y, lg.end_z ?? z],
679
+ shape: (row.shape || "").trim() ? sectionShape(row.shape) : DEFAULT_SHAPE[t],
680
+ w,
681
+ h: num(row.size_y, w),
682
+ insulation: num(row.insulation_thickness),
683
+ system: (row.system_type ?? "").trim(),
684
+ from: row.from ?? "",
685
+ to: row.to ?? ""
686
+ });
687
+ }
688
+ }
689
+ const nodeSize = /* @__PURE__ */ new Map();
690
+ for (const c of m.curves) {
691
+ if (c.scope !== scope) continue;
692
+ for (const ref of [c.from, c.to]) {
693
+ const host = (ref ?? "").split(":")[0].trim();
694
+ if (host) nodeSize.set(host, Math.max(nodeSize.get(host) ?? 0, c.w, c.h));
695
+ }
696
+ }
697
+ for (const t of ["equipment", "terminal", "mep_node"]) {
698
+ for (const row of rowsOf(dir, d, t)) {
699
+ const f = geo(d, t).get(row.id);
700
+ if (!f || f.geometry.type !== "Point") continue;
701
+ const pg = extractPointGeometry(f);
702
+ const z = pg.z ?? d.base + num(f.properties?.base_offset);
703
+ const system = (row.system_type ?? "").trim();
704
+ if (t === "mep_node") {
705
+ const kind = (row.kind ?? "").trim();
706
+ const s = Math.max(num(row.size_w), num(row.size_h), nodeSize.get(row.id) ?? 0, 0.05 / unitM) / 2;
707
+ m.hosts.push({ id: row.id, scope, table: t, center: [pg.x, pg.y, z], half: [s, s, s], rotation: pg.rotation, system, fitting: !kind });
708
+ continue;
709
+ }
710
+ const size = Array.isArray(f.properties?.size) ? f.properties.size : [];
711
+ const w = num(row.size_x, size[0] ?? 0.3 / unitM), dd = num(row.size_y, size[1] ?? w);
712
+ const h = num(row.height, size[2] ?? 0.5 / unitM);
713
+ m.hosts.push({ id: row.id, scope, table: t, center: [pg.x, pg.y, z + h / 2], half: [w / 2, dd / 2, h / 2], rotation: pg.rotation, system });
714
+ }
715
+ }
716
+ } else {
717
+ for (const t of ["equipment", "terminal", "mep_node"]) {
718
+ for (const row of rowsOf(dir, d, t)) m.hosts.push({ id: row.id, scope, table: t, center: [0, 0, 0], half: [0, 0, 0], system: "", fitting: true });
719
+ }
720
+ }
721
+ for (const t of ["beam", "brace"]) {
722
+ for (const row of rowsOf(dir, d, t)) {
723
+ const f = geo(d, t).get(row.id);
724
+ if (!f || f.geometry.type !== "LineString") continue;
725
+ let lg;
726
+ try {
727
+ lg = extractLineGeometry(f);
728
+ } catch {
729
+ continue;
730
+ }
731
+ const z = d.base + num(f.properties?.base_offset);
732
+ const [dw, dh] = MEMBER_DEFAULTS[t];
733
+ const w = num(row.size_x, dw / unitM);
734
+ if ((row.shape ?? "").trim() === "open_web") {
735
+ const d2 = num(row.size_y, 0.356 / unitM), fl = Math.min(num(row.flange, Math.min(0.032 / unitM, d2 * 0.12)), d2 / 3);
736
+ for (const drop of [0, d2 - fl]) {
737
+ m.members.push({
738
+ id: row.id,
739
+ scope,
740
+ table: t,
741
+ a: [lg.start_x, lg.start_y, (lg.start_z ?? z) - drop],
742
+ b: [lg.end_x, lg.end_y, (lg.end_z ?? z) - drop],
743
+ shape: "rect",
744
+ w,
745
+ h: fl,
746
+ top: true
747
+ });
748
+ }
749
+ continue;
750
+ }
751
+ m.members.push({
752
+ id: row.id,
753
+ scope,
754
+ table: t,
755
+ a: [lg.start_x, lg.start_y, lg.start_z ?? z],
756
+ b: [lg.end_x, lg.end_y, lg.end_z ?? z],
757
+ shape: sectionShape(row.shape),
758
+ w,
759
+ h: num(row.size_y, row.shape === "round" ? w : dh / unitM),
760
+ top: true
761
+ });
762
+ }
763
+ }
764
+ for (const t of COLUMN_TABLES) {
765
+ for (const row of rowsOf(dir, d, t)) {
766
+ const f = geo(d, t).get(row.id);
767
+ if (!f || f.geometry.type !== "Point") continue;
768
+ const pg = extractPointGeometry(f);
769
+ const [z0, z1] = span(d, row, f);
770
+ const w = num(row.size_x, 0.4 / unitM);
771
+ m.members.push({
772
+ id: row.id,
773
+ scope,
774
+ table: t,
775
+ a: [pg.x, pg.y, z0],
776
+ b: [pg.x, pg.y, z1],
777
+ shape: sectionShape(row.shape),
778
+ w,
779
+ h: num(row.size_y, w),
780
+ rotation: pg.rotation
781
+ });
782
+ }
783
+ }
784
+ for (const row of rowsOf(dir, d, "foundation")) {
785
+ const f = geo(d, "foundation").get(row.id);
786
+ if (!f) continue;
787
+ const top = d.base + num(f.properties?.base_offset ?? row.base_offset);
788
+ const th = num(row.thickness, 0.4 / unitM);
789
+ const width = num(row.width, 1.5 / unitM);
790
+ if (f.geometry.type === "Point") {
791
+ const pg = extractPointGeometry(f);
792
+ if ((row.kind ?? "") === "pile" && !num(row.length)) {
793
+ m.members.push({ id: row.id, scope, table: "foundation", a: [pg.x, pg.y, top - th], b: [pg.x, pg.y, top], shape: "round", w: width, h: width });
794
+ } else {
795
+ const length = num(row.length, width);
796
+ m.boxes.push({ id: row.id, scope, table: "foundation", center: [pg.x, pg.y, top - th / 2], half: [width / 2, length / 2, th / 2], rotation: pg.rotation });
797
+ }
798
+ } else if (f.geometry.type === "LineString") {
799
+ let lg;
800
+ try {
801
+ lg = extractLineGeometry(f);
802
+ } catch {
803
+ continue;
804
+ }
805
+ m.members.push({ id: row.id, scope, table: "foundation", a: [lg.start_x, lg.start_y, top], b: [lg.end_x, lg.end_y, top], shape: "rect", w: width, h: th, top: true });
806
+ } else {
807
+ const pg = extractPolygonGeometry(f);
808
+ m.slabs.push({
809
+ id: row.id,
810
+ scope,
811
+ table: "foundation",
812
+ outer: pg.outer.map((p) => [p.x, p.y]),
813
+ holes: pg.holes.map((h) => h.map((p) => [p.x, p.y])),
814
+ z0: top - th,
815
+ z1: top,
816
+ structural: true
817
+ });
818
+ }
819
+ }
820
+ const hosted = /* @__PURE__ */ new Map();
821
+ for (const t of ["door", "window", "opening"]) {
822
+ for (const row of rowsOf(dir, d, t)) {
823
+ if (!row.host_id || row.top_level_id) continue;
824
+ const list = hosted.get(row.host_id) ?? [];
825
+ list.push({ ...row, __table: t });
826
+ hosted.set(row.host_id, list);
827
+ }
828
+ }
829
+ for (const t of WALL_TABLES) {
830
+ for (const row of rowsOf(dir, d, t)) {
831
+ const f = geo(d, t).get(row.id);
832
+ if (!f || f.geometry.type !== "LineString") continue;
833
+ let lg;
834
+ try {
835
+ lg = extractLineGeometry(f);
836
+ } catch {
837
+ continue;
838
+ }
839
+ const [z0, z1] = span(d, row, f);
840
+ const a = [lg.start_x, lg.start_y], b = [lg.end_x, lg.end_y];
841
+ const L = Math.hypot(b[0] - a[0], b[1] - a[1]);
842
+ const thickness = t === "curtain_wall" ? num(row.mullion_depth, 0.1 / unitM) : num(row.thickness, 0.2 / unitM);
843
+ const openings = [];
844
+ for (const o of hosted.get(row.id) ?? []) {
845
+ let pos = num(o.position, NaN);
846
+ if (!Number.isFinite(pos) && o.host_x !== void 0 && o.host_x !== "" && L > 0) {
847
+ pos = ((num(o.host_x) - a[0]) * (b[0] - a[0]) + (num(o.host_y) - a[1]) * (b[1] - a[1])) / L;
848
+ }
849
+ if (!Number.isFinite(pos)) continue;
850
+ const width = num(o.width, 0.9 / unitM);
851
+ const isWindow = o.__table === "window";
852
+ const sill = o.base_offset !== void 0 && o.base_offset !== "" ? num(o.base_offset) : isWindow ? 0.9 / unitM : 0;
853
+ const height = num(o.height, (isWindow ? 1.2 : 2.1) / unitM);
854
+ openings.push({ u0: pos - width / 2, u1: pos + width / 2, z0: z0 + sill, z1: z0 + sill + height });
855
+ }
856
+ const wall = { id: row.id, scope, table: t, a, b, thickness, z0, z1, structural: t === "structure_wall", openings };
857
+ m.walls.push(wall);
858
+ }
859
+ }
860
+ const slabHoles = /* @__PURE__ */ new Map();
861
+ for (const row of rowsOf(dir, d, "opening")) {
862
+ if (!row.host_id || row.top_level_id) continue;
863
+ const f = geo(d, "opening").get(row.id);
864
+ if (!f || f.geometry.type !== "Polygon") continue;
865
+ const list = slabHoles.get(row.host_id) ?? [];
866
+ list.push(extractPolygonGeometry(f).outer.map((p) => [p.x, p.y]));
867
+ slabHoles.set(row.host_id, list);
868
+ }
869
+ for (const t of SLAB_TABLES) {
870
+ for (const row of rowsOf(dir, d, t)) {
871
+ const f = geo(d, t).get(row.id);
872
+ if (!f || f.geometry.type !== "Polygon") continue;
873
+ const pg = extractPolygonGeometry(f);
874
+ const off = d.base + num(f.properties?.base_offset ?? row.base_offset);
875
+ const th = num(row.thickness, 0.2 / unitM);
876
+ const [z0, z1] = t === "roof" ? [off, off + th] : [off - th, off];
877
+ const holes = [...pg.holes.map((h) => h.map((p) => [p.x, p.y])), ...slabHoles.get(row.id) ?? []];
878
+ for (const s of shafts) if (s.z0 < z1 - 1e-6 && s.z1 > z0 + 1e-6) holes.push(s.ring);
879
+ const slab = { id: row.id, scope, table: t, outer: pg.outer.map((p) => [p.x, p.y]), holes, z0, z1 };
880
+ if (t === "roof") m.slabs.push(...roofFaces(slab, pg.outer, row, th));
881
+ else m.slabs.push(slab);
882
+ }
883
+ }
884
+ }
885
+ return m;
886
+ }
887
+ function clashReport(dir, opts = {}) {
888
+ const model = loadClashModel(dir, opts.level);
889
+ const tolerance = opts.toleranceM ?? 0.05;
890
+ const all = detectClashes(model, {
891
+ tolerance: metersToProject(dir, tolerance),
892
+ clearance: metersToProject(dir, (opts.clearanceMm ?? 0) / 1e3),
893
+ mepOnly: opts.mepOnly,
894
+ minor: true
895
+ });
896
+ const clashes = all.filter((c) => !c.minor), minor = all.filter((c) => c.minor);
897
+ return {
898
+ units: projectUnits(dir),
899
+ tolerance,
900
+ counts: clashCounts(clashes),
901
+ clashes,
902
+ minorCount: minor.length,
903
+ ...opts.minor ? { minor } : {}
904
+ };
905
+ }
906
+ var SEVERITIES = ["high", "medium", "low"];
907
+ function formatClashReport(r) {
908
+ const unitM = UNIT_TO_M[r.units] ?? 1;
909
+ const mm = (v) => `${Math.round(v * unitM * 1e3)} mm`;
910
+ const fmt = (p) => `(${p.map((v) => v.toFixed(2)).join(", ")})`;
911
+ const row = (c) => {
912
+ const a = `${c.aScope ? `${c.aScope}/` : ""}${c.aTable} ${c.a}`;
913
+ const b = `${c.bScope && c.bScope !== c.aScope ? `${c.bScope}/` : ""}${c.bTable} ${c.b}`;
914
+ const what = c.kind === "clearance" ? `gap ${mm(c.depth)}` : `${c.kind} ${mm(c.depth)}`;
915
+ return ` ${a} x ${b} ${what} at ${fmt(c.at)}${c.systems.length ? ` [${c.systems.join(", ")}]` : ""}`;
916
+ };
917
+ const out = [];
918
+ for (const sev of SEVERITIES) {
919
+ const list = r.clashes.filter((c) => c.severity === sev);
920
+ if (list.length === 0) continue;
921
+ out.push(`${sev.toUpperCase()} (${list.length})`);
922
+ for (const c of list) out.push(row(c));
923
+ out.push("");
924
+ }
925
+ const tol = `${Math.round(r.tolerance * 1e3)} mm`;
926
+ if (r.minor && r.minor.length > 0) {
927
+ out.push(`MINOR, WITHIN TOLERANCE ${tol} (${r.minor.length})`);
928
+ for (const c of r.minor) out.push(row(c));
929
+ out.push("");
930
+ }
931
+ const total = r.clashes.length;
932
+ out.push(total === 0 ? "No clashes." : `${total} clash(es): ${r.counts.high} high, ${r.counts.medium} medium, ${r.counts.low} low.`);
933
+ if (r.minorCount > 0) out.push(`${r.minorCount} minor overlap(s) within the ${tol} tolerance not reported${r.minor ? "" : " (--minor lists them)"}.`);
934
+ return out;
935
+ }
936
+ export {
937
+ clashReport,
938
+ formatClashReport,
939
+ loadClashModel
940
+ };
941
+ //# sourceMappingURL=clash-load-D3LNQR6G.js.map