@kruschdev/pascal-mep-kernel 0.0.0-stage → 0.1.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.
@@ -0,0 +1,277 @@
1
+ // src/types.ts
2
+ var TRADE_PRIORITY_RANK2 = {
3
+ structural: 1,
4
+ plumbing: 2,
5
+ hvac: 3,
6
+ electrical: 4
7
+ };
8
+ var INCHES_TO_METERS2 = 0.0254;
9
+ var METERS_TO_FEET2 = 3.280839895013123;
10
+ var FEET_TO_METERS2 = 0.3048;
11
+ var SQM_TO_SQFT2 = 10.763910416709722;
12
+ function isVec32(v) {
13
+ return Array.isArray(v) && v.length >= 3 && typeof v[0] === "number" && Number.isFinite(v[0]) && typeof v[1] === "number" && Number.isFinite(v[1]) && typeof v[2] === "number" && Number.isFinite(v[2]);
14
+ }
15
+ function toTupleAabb32(box) {
16
+ return {
17
+ min: [box.minX, box.minY, box.minZ],
18
+ max: [box.maxX, box.maxY, box.maxZ]
19
+ };
20
+ }
21
+ function fromTupleAabb32(box) {
22
+ return {
23
+ minX: box.min[0],
24
+ minY: box.min[1],
25
+ minZ: box.min[2],
26
+ maxX: box.max[0],
27
+ maxY: box.max[1],
28
+ maxZ: box.max[2]
29
+ };
30
+ }
31
+ function expandAabb32(box, margin) {
32
+ const [mx, my, mz] = typeof margin === "number" ? [margin, margin, margin] : margin;
33
+ return {
34
+ minX: box.minX - mx,
35
+ minY: box.minY - my,
36
+ minZ: box.minZ - mz,
37
+ maxX: box.maxX + mx,
38
+ maxY: box.maxY + my,
39
+ maxZ: box.maxZ + mz
40
+ };
41
+ }
42
+ function aabb3Intersects2(a, b) {
43
+ return a.minX <= b.maxX && a.maxX >= b.minX && a.minY <= b.maxY && a.maxY >= b.minY && a.minZ <= b.maxZ && a.maxZ >= b.minZ;
44
+ }
45
+ function segmentIntersectsAabb32(a, b, box, margin = 0, eps = 0.000001) {
46
+ if (!isVec32(a) || !isVec32(b) || !Number.isFinite(eps))
47
+ return false;
48
+ const [mx, my, mz] = typeof margin === "number" ? [margin, margin, margin] : margin;
49
+ const minX = box.minX - mx;
50
+ const maxX = box.maxX + mx;
51
+ const minY = box.minY - my;
52
+ const maxY = box.maxY + my;
53
+ const minZ = box.minZ - mz;
54
+ const maxZ = box.maxZ + mz;
55
+ if (!Number.isFinite(minX) || !Number.isFinite(maxX) || !Number.isFinite(minY) || !Number.isFinite(maxY) || !Number.isFinite(minZ) || !Number.isFinite(maxZ) || minX > maxX || minY > maxY || minZ > maxZ) {
56
+ return false;
57
+ }
58
+ let tMin = 0;
59
+ let tMax = 1;
60
+ const axes = [
61
+ [a[0], b[0] - a[0], minX, maxX],
62
+ [a[1], b[1] - a[1], minY, maxY],
63
+ [a[2], b[2] - a[2], minZ, maxZ]
64
+ ];
65
+ for (const [orig, dir, bMin, bMax] of axes) {
66
+ if (Math.abs(dir) < 0.000000001) {
67
+ if (orig < bMin - eps || orig > bMax + eps)
68
+ return false;
69
+ } else {
70
+ let t1 = (bMin - orig) / dir;
71
+ let t2 = (bMax - orig) / dir;
72
+ if (t1 > t2) {
73
+ const tmp = t1;
74
+ t1 = t2;
75
+ t2 = tmp;
76
+ }
77
+ tMin = Math.max(tMin, t1);
78
+ tMax = Math.min(tMax, t2);
79
+ if (tMin > tMax + eps)
80
+ return false;
81
+ }
82
+ }
83
+ return tMax >= -eps && tMin <= 1 + eps;
84
+ }
85
+ function createOrientedPrismY2(params) {
86
+ const { centerX, centerZ } = params;
87
+ const lxMin = Math.min(params.lxMin, params.lxMax);
88
+ const lxMax = Math.max(params.lxMin, params.lxMax);
89
+ const lzMin = Math.min(params.lzMin, params.lzMax);
90
+ const lzMax = Math.max(params.lzMin, params.lzMax);
91
+ const yMin = Math.min(params.yMin, params.yMax);
92
+ const yMax = Math.max(params.yMin, params.yMax);
93
+ const rawCos = Number.isFinite(params.cos) ? params.cos : 1;
94
+ const rawSin = Number.isFinite(params.sin) ? params.sin : 0;
95
+ const rotLen = Math.hypot(rawCos, rawSin);
96
+ const cos = rotLen > 0.000000001 ? rawCos / rotLen : 1;
97
+ const sin = rotLen > 0.000000001 ? rawSin / rotLen : 0;
98
+ let minX = Number.POSITIVE_INFINITY;
99
+ let maxX = Number.NEGATIVE_INFINITY;
100
+ let minZ = Number.POSITIVE_INFINITY;
101
+ let maxZ = Number.NEGATIVE_INFINITY;
102
+ for (const lx of [lxMin, lxMax]) {
103
+ for (const lz of [lzMin, lzMax]) {
104
+ const wx = centerX + lx * cos - lz * sin;
105
+ const wz = centerZ + lx * sin + lz * cos;
106
+ if (wx < minX)
107
+ minX = wx;
108
+ if (wx > maxX)
109
+ maxX = wx;
110
+ if (wz < minZ)
111
+ minZ = wz;
112
+ if (wz > maxZ)
113
+ maxZ = wz;
114
+ }
115
+ }
116
+ return {
117
+ centerX,
118
+ centerZ,
119
+ cos,
120
+ sin,
121
+ lxMin,
122
+ lxMax,
123
+ lzMin,
124
+ lzMax,
125
+ yMin,
126
+ yMax,
127
+ aabb: { minX, minY: yMin, minZ, maxX, maxY: yMax, maxZ }
128
+ };
129
+ }
130
+ function segmentIntersectsOrientedPrismY2(a, b, prism, padM = 0, eps = 0.000001) {
131
+ const [px, py, pz] = typeof padM === "number" ? [padM, padM, padM] : padM;
132
+ const posPx = Math.max(0, px);
133
+ const posPz = Math.max(0, pz);
134
+ const absCos = Math.abs(prism.cos);
135
+ const absSin = Math.abs(prism.sin);
136
+ const worldPadX = posPx * absCos + posPz * absSin;
137
+ const worldPadZ = posPx * absSin + posPz * absCos;
138
+ if (!segmentIntersectsAabb32(a, b, prism.aabb, [worldPadX, Math.max(0, py), worldPadZ], eps)) {
139
+ return false;
140
+ }
141
+ const adx = a[0] - prism.centerX;
142
+ const adz = a[2] - prism.centerZ;
143
+ const bdx = b[0] - prism.centerX;
144
+ const bdz = b[2] - prism.centerZ;
145
+ const la = [adx * prism.cos + adz * prism.sin, a[1], -adx * prism.sin + adz * prism.cos];
146
+ const lb = [bdx * prism.cos + bdz * prism.sin, b[1], -bdx * prism.sin + bdz * prism.cos];
147
+ const localBox = {
148
+ minX: prism.lxMin,
149
+ maxX: prism.lxMax,
150
+ minY: prism.yMin,
151
+ maxY: prism.yMax,
152
+ minZ: prism.lzMin,
153
+ maxZ: prism.lzMax
154
+ };
155
+ return segmentIntersectsAabb32(la, lb, localBox, [px, py, pz], eps);
156
+ }
157
+ function orientedPrismIntersectsAabb32(prism, box) {
158
+ if (prism.yMax <= box.minY || prism.yMin >= box.maxY)
159
+ return false;
160
+ if (!aabb3Intersects2(prism.aabb, box))
161
+ return false;
162
+ const bCx = (box.minX + box.maxX) / 2;
163
+ const bCz = (box.minZ + box.maxZ) / 2;
164
+ const bHx = (box.maxX - box.minX) / 2;
165
+ const bHz = (box.maxZ - box.minZ) / 2;
166
+ const pLcX = (prism.lxMin + prism.lxMax) / 2;
167
+ const pLcZ = (prism.lzMin + prism.lzMax) / 2;
168
+ const pHx = (prism.lxMax - prism.lxMin) / 2;
169
+ const pHz = (prism.lzMax - prism.lzMin) / 2;
170
+ const pCx = prism.centerX + pLcX * prism.cos - pLcZ * prism.sin;
171
+ const pCz = prism.centerZ + pLcX * prism.sin + pLcZ * prism.cos;
172
+ const dx = bCx - pCx;
173
+ const dz = bCz - pCz;
174
+ const axes = [
175
+ [1, 0],
176
+ [0, 1],
177
+ [prism.cos, prism.sin],
178
+ [-prism.sin, prism.cos]
179
+ ];
180
+ for (const [ax, az] of axes) {
181
+ const dist = Math.abs(dx * ax + dz * az);
182
+ const rBox = bHx * Math.abs(ax) + bHz * Math.abs(az);
183
+ const rPrism = pHx * Math.abs(prism.cos * ax + prism.sin * az) + pHz * Math.abs(-prism.sin * ax + prism.cos * az);
184
+ if (dist >= rBox + rPrism - 0.000001)
185
+ return false;
186
+ }
187
+ return true;
188
+ }
189
+ function extractNodeYawRad2(rotation) {
190
+ if (typeof rotation === "number" && Number.isFinite(rotation))
191
+ return rotation;
192
+ if (Array.isArray(rotation)) {
193
+ const y = rotation[1];
194
+ if (typeof y === "number" && Number.isFinite(y))
195
+ return y;
196
+ }
197
+ return 0;
198
+ }
199
+ function polylineLengthM2(path) {
200
+ let total = 0;
201
+ for (let i = 1;i < path.length; i++) {
202
+ const a = path[i - 1];
203
+ const b = path[i];
204
+ total += Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
205
+ }
206
+ return total;
207
+ }
208
+ function polylineHorizontalLengthM2(path) {
209
+ let total = 0;
210
+ for (let i = 1;i < path.length; i++) {
211
+ const a = path[i - 1];
212
+ const b = path[i];
213
+ total += Math.hypot(b[0] - a[0], b[2] - a[2]);
214
+ }
215
+ return total;
216
+ }
217
+ var MIN_PATH_SEGMENT_LEN_M = 0.0001;
218
+ function countPathBendDegrees2(path) {
219
+ let total = 0;
220
+ let prevDir = null;
221
+ for (let i = 1;i < path.length; i++) {
222
+ const a = path[i - 1];
223
+ const b = path[i];
224
+ const dx = b[0] - a[0];
225
+ const dy = b[1] - a[1];
226
+ const dz = b[2] - a[2];
227
+ const len = Math.hypot(dx, dy, dz);
228
+ if (len < MIN_PATH_SEGMENT_LEN_M)
229
+ continue;
230
+ const dir = [dx / len, dy / len, dz / len];
231
+ if (prevDir) {
232
+ const dot = Math.max(-1, Math.min(1, prevDir[0] * dir[0] + prevDir[1] * dir[1] + prevDir[2] * dir[2]));
233
+ const deg = Math.acos(dot) * 180 / Math.PI;
234
+ if (deg > 2)
235
+ total += deg;
236
+ }
237
+ prevDir = dir;
238
+ }
239
+ return total;
240
+ }
241
+ function countPathElbows2(path) {
242
+ let elbows90 = 0;
243
+ let elbows45 = 0;
244
+ let prevDir = null;
245
+ for (let i = 1;i < path.length; i++) {
246
+ const a = path[i - 1];
247
+ const b = path[i];
248
+ const dx = b[0] - a[0];
249
+ const dy = b[1] - a[1];
250
+ const dz = b[2] - a[2];
251
+ const len = Math.hypot(dx, dy, dz);
252
+ if (len < MIN_PATH_SEGMENT_LEN_M)
253
+ continue;
254
+ const dir = [dx / len, dy / len, dz / len];
255
+ if (prevDir) {
256
+ const dot = Math.max(-1, Math.min(1, prevDir[0] * dir[0] + prevDir[1] * dir[1] + prevDir[2] * dir[2]));
257
+ const deg = Math.acos(dot) * 180 / Math.PI;
258
+ if (deg >= 67.5)
259
+ elbows90++;
260
+ else if (deg >= 22.5)
261
+ elbows45++;
262
+ }
263
+ prevDir = dir;
264
+ }
265
+ return { elbows90, elbows45 };
266
+ }
267
+ function round22(n) {
268
+ return Math.round(n * 100) / 100;
269
+ }
270
+ function round32(n) {
271
+ return Math.round(n * 1000) / 1000;
272
+ }
273
+ function round42(n) {
274
+ return Math.round(n * 1e4) / 1e4;
275
+ }
276
+
277
+ export { TRADE_PRIORITY_RANK2, INCHES_TO_METERS2, METERS_TO_FEET2, FEET_TO_METERS2, SQM_TO_SQFT2, isVec32, toTupleAabb32, fromTupleAabb32, expandAabb32, aabb3Intersects2, segmentIntersectsAabb32, createOrientedPrismY2, segmentIntersectsOrientedPrismY2, orientedPrismIntersectsAabb32, extractNodeYawRad2, polylineLengthM2, polylineHorizontalLengthM2, countPathBendDegrees2, countPathElbows2, round22, round32, round42 };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `@kruschdev/pascal-mep-kernel` — Shared zero-dependency 3-layer spatial anatomy,
3
+ * legal-cavity MEP routing graph, and single-source declarative code constraint engine
4
+ * for Pascal Editor plugins.
5
+ */
6
+ export * from './types';
7
+ export * from './anatomy/index';
8
+ export * from './router/index';
9
+ export * from './rules/index';
package/dist/index.js ADDED
@@ -0,0 +1,186 @@
1
+ import {
2
+ TRADE_PRIORITY_RANK2,
3
+ INCHES_TO_METERS2,
4
+ METERS_TO_FEET2,
5
+ FEET_TO_METERS2,
6
+ SQM_TO_SQFT2,
7
+ isVec32,
8
+ toTupleAabb32,
9
+ fromTupleAabb32,
10
+ expandAabb32,
11
+ aabb3Intersects2,
12
+ segmentIntersectsAabb32,
13
+ createOrientedPrismY2,
14
+ segmentIntersectsOrientedPrismY2,
15
+ orientedPrismIntersectsAabb32,
16
+ extractNodeYawRad2,
17
+ polylineLengthM2,
18
+ polylineHorizontalLengthM2,
19
+ countPathBendDegrees2,
20
+ countPathElbows2,
21
+ round22,
22
+ round32,
23
+ round42
24
+ } from "./chunk-yd3hcm7n.js";
25
+ import {
26
+ resolveNodeLevelId2,
27
+ belongsToLevel2,
28
+ resolveLevelBuildingId2,
29
+ areLevelsInSameBuilding2,
30
+ levelSortOrder2,
31
+ compareLevelsVertically2,
32
+ isBasementLevel2,
33
+ levelHasWalls2,
34
+ resolveWallHeightM2,
35
+ resolveLevelHeightM2,
36
+ getLowerWalledLevelIds2,
37
+ resolveLowerWalledLevelsSummary2,
38
+ isGroundOrLowestWalledLevel2,
39
+ isHighestWalledLevelInBuilding2,
40
+ findImmediateLowerWalledLevel2,
41
+ classifyOpeningKind2,
42
+ extractCanonicalWallOpenings2,
43
+ extractCanonicalWalls2,
44
+ extractLevelOpeningPrisms2,
45
+ countPathOpeningPrismHits2,
46
+ findNearestWallToPoint2,
47
+ distancePointToSegment2D2,
48
+ pointInPolygon2D2,
49
+ polygonArea2D2,
50
+ polygonAreaAndCentroid2,
51
+ polygonBounds2D2,
52
+ clipSegmentToPolygon2D2,
53
+ extractBoundedWallFaces2,
54
+ isPointEnclosedByWalls2,
55
+ extractBaseRoomPolygons2,
56
+ computeLevelBounds2,
57
+ clusterLevelFootprints2,
58
+ isOutdoorOrUnwalledSlab2,
59
+ compileLevelFootprint2,
60
+ PLUMBING_PIPE_HALF_OD_M2,
61
+ ELECTRICAL_CONDUIT_HALF_OD_M2,
62
+ parseNominalInches2,
63
+ resolveMepRunExtents2,
64
+ extractBeamPrism2,
65
+ extractColumnPrism2,
66
+ getHvacEquipmentPrism2,
67
+ getHvacEquipmentAabb2,
68
+ getHvacPlenumPrism2,
69
+ getHvacPlenumAabb2,
70
+ getPlumbingFixturePrism2,
71
+ getPlumbingFixtureAabb2,
72
+ getPlumbingEquipmentPrism2,
73
+ getPlumbingEquipmentAabb2,
74
+ getElectricalDedicatedSpacePrisms2,
75
+ extractEquipmentPrisms2,
76
+ extractTradeOccupancyObstacles2,
77
+ TradeOccupancyGrid2,
78
+ shouldAdoptWallLessRoofLevel2,
79
+ shouldAdoptRoofSegmentOntoLevel2,
80
+ evaluateRoofSegmentSurfaceY2,
81
+ extractCanonicalRoofSegments2,
82
+ compileLevelRoofShell2,
83
+ compileBuildingAnatomy2
84
+ } from "./chunk-kmtew7g8.js";
85
+ import {
86
+ compileLegalCavityGraph2,
87
+ findLegalWallRiserPier2,
88
+ routeInLegalCavities2
89
+ } from "./chunk-q8cxxynd.js";
90
+ import {
91
+ effectivePlacementThreshold2,
92
+ evaluatePlacementCandidate2,
93
+ filterLegalCandidates2,
94
+ evaluateDeclarativeRules2,
95
+ validateRuleTable2
96
+ } from "./chunk-92mknkfa.js";
97
+ export {
98
+ ELECTRICAL_CONDUIT_HALF_OD_M2 as ELECTRICAL_CONDUIT_HALF_OD_M,
99
+ FEET_TO_METERS2 as FEET_TO_METERS,
100
+ INCHES_TO_METERS2 as INCHES_TO_METERS,
101
+ METERS_TO_FEET2 as METERS_TO_FEET,
102
+ PLUMBING_PIPE_HALF_OD_M2 as PLUMBING_PIPE_HALF_OD_M,
103
+ SQM_TO_SQFT2 as SQM_TO_SQFT,
104
+ TRADE_PRIORITY_RANK2 as TRADE_PRIORITY_RANK,
105
+ TradeOccupancyGrid2 as TradeOccupancyGrid,
106
+ aabb3Intersects2 as aabb3Intersects,
107
+ areLevelsInSameBuilding2 as areLevelsInSameBuilding,
108
+ belongsToLevel2 as belongsToLevel,
109
+ classifyOpeningKind2 as classifyOpeningKind,
110
+ clipSegmentToPolygon2D2 as clipSegmentToPolygon2D,
111
+ clusterLevelFootprints2 as clusterLevelFootprints,
112
+ compareLevelsVertically2 as compareLevelsVertically,
113
+ compileBuildingAnatomy2 as compileBuildingAnatomy,
114
+ compileLegalCavityGraph2 as compileLegalCavityGraph,
115
+ compileLevelFootprint2 as compileLevelFootprint,
116
+ compileLevelRoofShell2 as compileLevelRoofShell,
117
+ computeLevelBounds2 as computeLevelBounds,
118
+ countPathBendDegrees2 as countPathBendDegrees,
119
+ countPathElbows2 as countPathElbows,
120
+ countPathOpeningPrismHits2 as countPathOpeningPrismHits,
121
+ createOrientedPrismY2 as createOrientedPrismY,
122
+ distancePointToSegment2D2 as distancePointToSegment2D,
123
+ effectivePlacementThreshold2 as effectivePlacementThreshold,
124
+ evaluateDeclarativeRules2 as evaluateDeclarativeRules,
125
+ evaluatePlacementCandidate2 as evaluatePlacementCandidate,
126
+ evaluateRoofSegmentSurfaceY2 as evaluateRoofSegmentSurfaceY,
127
+ expandAabb32 as expandAabb3,
128
+ extractBaseRoomPolygons2 as extractBaseRoomPolygons,
129
+ extractBeamPrism2 as extractBeamPrism,
130
+ extractBoundedWallFaces2 as extractBoundedWallFaces,
131
+ extractCanonicalRoofSegments2 as extractCanonicalRoofSegments,
132
+ extractCanonicalWallOpenings2 as extractCanonicalWallOpenings,
133
+ extractCanonicalWalls2 as extractCanonicalWalls,
134
+ extractColumnPrism2 as extractColumnPrism,
135
+ extractEquipmentPrisms2 as extractEquipmentPrisms,
136
+ extractLevelOpeningPrisms2 as extractLevelOpeningPrisms,
137
+ extractNodeYawRad2 as extractNodeYawRad,
138
+ extractTradeOccupancyObstacles2 as extractTradeOccupancyObstacles,
139
+ filterLegalCandidates2 as filterLegalCandidates,
140
+ findImmediateLowerWalledLevel2 as findImmediateLowerWalledLevel,
141
+ findLegalWallRiserPier2 as findLegalWallRiserPier,
142
+ findNearestWallToPoint2 as findNearestWallToPoint,
143
+ fromTupleAabb32 as fromTupleAabb3,
144
+ getElectricalDedicatedSpacePrisms2 as getElectricalDedicatedSpacePrisms,
145
+ getHvacEquipmentAabb2 as getHvacEquipmentAabb,
146
+ getHvacEquipmentPrism2 as getHvacEquipmentPrism,
147
+ getHvacPlenumAabb2 as getHvacPlenumAabb,
148
+ getHvacPlenumPrism2 as getHvacPlenumPrism,
149
+ getLowerWalledLevelIds2 as getLowerWalledLevelIds,
150
+ getPlumbingEquipmentAabb2 as getPlumbingEquipmentAabb,
151
+ getPlumbingEquipmentPrism2 as getPlumbingEquipmentPrism,
152
+ getPlumbingFixtureAabb2 as getPlumbingFixtureAabb,
153
+ getPlumbingFixturePrism2 as getPlumbingFixturePrism,
154
+ isBasementLevel2 as isBasementLevel,
155
+ isGroundOrLowestWalledLevel2 as isGroundOrLowestWalledLevel,
156
+ isHighestWalledLevelInBuilding2 as isHighestWalledLevelInBuilding,
157
+ isOutdoorOrUnwalledSlab2 as isOutdoorOrUnwalledSlab,
158
+ isPointEnclosedByWalls2 as isPointEnclosedByWalls,
159
+ isVec32 as isVec3,
160
+ levelHasWalls2 as levelHasWalls,
161
+ levelSortOrder2 as levelSortOrder,
162
+ orientedPrismIntersectsAabb32 as orientedPrismIntersectsAabb3,
163
+ parseNominalInches2 as parseNominalInches,
164
+ pointInPolygon2D2 as pointInPolygon2D,
165
+ polygonArea2D2 as polygonArea2D,
166
+ polygonAreaAndCentroid2 as polygonAreaAndCentroid,
167
+ polygonBounds2D2 as polygonBounds2D,
168
+ polylineHorizontalLengthM2 as polylineHorizontalLengthM,
169
+ polylineLengthM2 as polylineLengthM,
170
+ resolveLevelBuildingId2 as resolveLevelBuildingId,
171
+ resolveLevelHeightM2 as resolveLevelHeightM,
172
+ resolveLowerWalledLevelsSummary2 as resolveLowerWalledLevelsSummary,
173
+ resolveMepRunExtents2 as resolveMepRunExtents,
174
+ resolveNodeLevelId2 as resolveNodeLevelId,
175
+ resolveWallHeightM2 as resolveWallHeightM,
176
+ round22 as round2,
177
+ round32 as round3,
178
+ round42 as round4,
179
+ routeInLegalCavities2 as routeInLegalCavities,
180
+ segmentIntersectsAabb32 as segmentIntersectsAabb3,
181
+ segmentIntersectsOrientedPrismY2 as segmentIntersectsOrientedPrismY,
182
+ shouldAdoptRoofSegmentOntoLevel2 as shouldAdoptRoofSegmentOntoLevel,
183
+ shouldAdoptWallLessRoofLevel2 as shouldAdoptWallLessRoofLevel,
184
+ toTupleAabb32 as toTupleAabb3,
185
+ validateRuleTable2 as validateRuleTable
186
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Layer 2 — Legal Cavity Graph Compiler (`@kruschdev/pascal-mep-kernel/router`).
3
+ *
4
+ * Compiles a building level's `BuildingAnatomy` into a 3D legal-space-first routing graph
5
+ * (`LegalCavityGraph`) where physical violations are impossible by construction (`INV-MEP-01`, `INV-MEP-06`):
6
+ *
7
+ * 1. Solid Wall Stud-Bay Layer (`under-sill`, `mid-wall`, `top-plate`):
8
+ * - Splits walls at junctions/intersections (`0.25 m` snap) and opening jamb boundaries
9
+ * (`startU - 0.08`, `endU + 0.08` clamped within `[0.03, wall.lengthM - 0.03]`).
10
+ * - Emits solid king-stud riser piers (`WallRiserPier`) where vertical travel
11
+ * `[0.02 .. levelH - 0.04]` has zero intersection with any 3D opening keepout prism.
12
+ * - Emits horizontal & vertical wall edges ONLY when zero 3D opening prisms are intersected
13
+ * and roof clearance holds. Shares vertices at corners/junctions on the same band.
14
+ * 2. Conditioned Overhead Plenum & Attic Layer (`overhead-plenum`, `attic`):
15
+ * - Builds an interior-only 2D grid + room-centroid + pier-projection graph strictly inside
16
+ * `footprint` (`precedence: 'room-first'`) and strictly beneath `roofShell.roofEnvelopeY`.
17
+ * - Connects orthogonal neighbors (plus attic diagonals) ONLY when both `footprint.isSegmentInside`
18
+ * and `roofShell.isPathClearOfRoof` pass, eliminating courtyard bridging and roof pokes.
19
+ * 3. Under-Slab / Crawlspace Trench Layer (`under-slab` / `crawlspace`):
20
+ * - Emits interior-footprint vertices and orthogonal edges at `subFloorElevationM` (default `-0.35 m`),
21
+ * connected downward from solid wall riser piers.
22
+ *
23
+ * Pure framework-free TypeScript (`INV-MEP-01`): zero React, Three.js, `@pascal-app/*`, Next, Zod, or `node:*`.
24
+ */
25
+ import type { BuildingAnatomy } from '../anatomy';
26
+ import type { CompileCavityGraphOptions, LegalCavityGraph, WallRiserPier } from './types';
27
+ /**
28
+ * Compile a 3D legal-space-first routing graph (`LegalCavityGraph`) for a building level.
29
+ * Every emitted vertex and edge is legal by construction against opening keepout prisms,
30
+ * concave interior footprint boundaries, and the 7-type roof shell (`INV-MEP-01`, `INV-MEP-06`).
31
+ */
32
+ export declare function compileLegalCavityGraph(anatomy: BuildingAnatomy, levelId: string | null, opts?: CompileCavityGraphOptions): LegalCavityGraph;
33
+ /**
34
+ * Find the closest legal solid king-stud riser pier on `wallId` to `desiredT` whose
35
+ * safe vertical span covers `[fromY, toY]` without intersecting any door/window prism.
36
+ */
37
+ export declare function findLegalWallRiserPier(graph: LegalCavityGraph, wallId: string, desiredT: number, fromY: number, toY: number): WallRiserPier | null;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Layer 2 — Legal-Space-First Routing Graph (`@kruschdev/pascal-mep-kernel/router`).
3
+ *
4
+ * Compiles building anatomy into legal navigable cavities (wall stud bays minus 3D
5
+ * door/window prisms, enclosed overhead plenums clamped below roof surfaces, and
6
+ * under-slab/crawlspace trenches) and solves constrained shortest paths with strict
7
+ * cross-trade occupancy reservation (`INV-MEP-06`, `INV-MEP-07`).
8
+ */
9
+ export type { CavityBand, RoutingPhysicsMode, CavityVertex, CavityEdge, WallRiserPier, CompileCavityGraphOptions, LegalCavityGraph, CavityRouteRequest, CavityRouteResult, } from './types';
10
+ export { compileLegalCavityGraph, findLegalWallRiserPier } from './cavity-graph';
11
+ export { type RouteInLegalCavitiesParams, routeInLegalCavities } from './shortest-path';
@@ -0,0 +1,12 @@
1
+ import {
2
+ compileLegalCavityGraph2,
3
+ findLegalWallRiserPier2,
4
+ routeInLegalCavities2
5
+ } from "../chunk-q8cxxynd.js";
6
+ import"../chunk-kmtew7g8.js";
7
+ import"../chunk-yd3hcm7n.js";
8
+ export {
9
+ compileLegalCavityGraph2 as compileLegalCavityGraph,
10
+ findLegalWallRiserPier2 as findLegalWallRiserPier,
11
+ routeInLegalCavities2 as routeInLegalCavities
12
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Layer 2 — Constrained Shortest-Path Solver Over Legal Building Cavities (`@kruschdev/pascal-mep-kernel/router`).
3
+ *
4
+ * Implements `routeInLegalCavities` (`INV-MEP-01`, `INV-MEP-06`, `INV-MEP-07`):
5
+ * 1. Zero-mutation dynamic endpoint port splicing (`from` / `to` -> allowed `LegalCavityGraph` vertices)
6
+ * plus legal direct same-cavity shortcuts.
7
+ * 2. Two-pass constrained A* with a deterministic binary min-heap and direction-bucket bend tracking:
8
+ * - Pass 1 (Hard-Free): strictly rejects obstacle clashes, opening-prism hits, roof violations,
9
+ * outdoor-void excursions, physics-mode violations, and `maxBendDegrees` overruns.
10
+ * - Pass 2 (Degraded Diagnostic Fallback): invoked ONLY if Pass 1 finds no path (e.g., an
11
+ * irreducible blocker around an endpoint), allowing penalized transitions (`+5000` per clash)
12
+ * so the solver never returns empty/NaN and always reports exact `clashObstacleIds` & `ok: false`.
13
+ * 3. Physics-mode post-shaping & strict enforcement:
14
+ * - `'orthogonal'`: collinear compaction, orthogonal/wall-aligned legs, optional `lateralStaggerM`.
15
+ * - `'euclidean-cavity'`: line-of-sight string-pulling inside unobstructed open cavities.
16
+ * - `'gravity-slope'`: strict monotonic downward fall (`y(i) = y(i-1) - horizDist * (minSlopeInPerFt / 12)`),
17
+ * zero uphill segments (`dy <= 0.002`), and exact `slopeInPerFt`.
18
+ * - `'non-descending-vent'`: IPC 905.5 horizontal floor (`>= minHorizontalElevationM`) and
19
+ * IPC 905.2 inverted-U prevention (`<= tieInY`, non-descending).
20
+ * 4. Optional `INV-MEP-07` run reservation on `TradeOccupancyGrid` when `reserveOnCommit === true`.
21
+ *
22
+ * Pure framework-free TypeScript (`INV-MEP-01`): zero React, Three.js, `@pascal-app/*`, Next, Zod, or `node:*`.
23
+ */
24
+ import { type BuildingAnatomy, type TradeOccupancyGrid } from '../anatomy';
25
+ import type { CavityRouteRequest, CavityRouteResult, LegalCavityGraph } from './types';
26
+ export type RouteInLegalCavitiesParams = {
27
+ readonly anatomy: BuildingAnatomy;
28
+ readonly graph: LegalCavityGraph;
29
+ readonly occupancy: TradeOccupancyGrid;
30
+ readonly request: CavityRouteRequest;
31
+ };
32
+ /**
33
+ * Route an MEP run inside the pre-compiled `LegalCavityGraph` with dynamic zero-mutation endpoint
34
+ * splicing, two-pass constrained A* (hard-free -> degraded diagnostic fallback), physics-mode
35
+ * post-shaping, full spatial audit, and optional `TradeOccupancyGrid` reservation (`INV-MEP-07`).
36
+ */
37
+ export declare function routeInLegalCavities(params: RouteInLegalCavitiesParams): CavityRouteResult;
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Layer 2 — Legal-Space-First Routing Graph Types (`@kruschdev/pascal-mep-kernel/router`).
3
+ * Shared contract between `cavity-graph.ts` (cavity compiler) and `shortest-path.ts` (constrained solver).
4
+ */
5
+ import type { TradeId, Vec3 } from '../types';
6
+ export type CavityBand = 'under-sill' | 'mid-wall' | 'top-plate' | 'overhead-plenum' | 'attic' | 'under-slab' | 'crawlspace';
7
+ export type RoutingPhysicsMode = 'orthogonal' | 'euclidean-cavity' | 'gravity-slope' | 'non-descending-vent';
8
+ export type CavityVertex = {
9
+ readonly id: number;
10
+ readonly pos: Vec3;
11
+ readonly band: CavityBand;
12
+ readonly wallId?: string;
13
+ readonly wallT?: number;
14
+ readonly isRiserPier?: boolean;
15
+ readonly maxClearY?: number;
16
+ };
17
+ export type CavityEdge = {
18
+ readonly to: number;
19
+ readonly lengthM: number;
20
+ readonly horizontalLengthM: number;
21
+ readonly band: CavityBand;
22
+ readonly isWallEdge: boolean;
23
+ readonly isVerticalTransition: boolean;
24
+ readonly wallId?: string;
25
+ readonly baseCostWeight: number;
26
+ };
27
+ export type WallRiserPier = {
28
+ readonly wallId: string;
29
+ readonly t: number;
30
+ readonly x: number;
31
+ readonly z: number;
32
+ readonly minSafeY: number;
33
+ readonly maxSafeY: number;
34
+ };
35
+ export type CompileCavityGraphOptions = {
36
+ /** Clearance below roof surface in meters. Default: `0.14`. */
37
+ readonly roofClearanceM?: number;
38
+ /** Vertical half-extent of the routed run (e.g. half duct height or pipe radius). Default: `0.02`. */
39
+ readonly halfY?: number;
40
+ /** Horizontal half-extent of the routed run. Default: `0.02`. */
41
+ readonly halfXZ?: number;
42
+ /** Overhead plenum grid spacing inside enclosed footprint (meters). Default: `1.5`. */
43
+ readonly plenumGridStepM?: number;
44
+ /** Include under-slab / crawlspace trench layer (ground story). Default: `true`. */
45
+ readonly includeSubFloorLayer?: boolean;
46
+ /** Band label assigned to the compiled sub-floor layer (`'under-slab'` or `'crawlspace'`). Default: `'under-slab'`. */
47
+ readonly subFloorBand?: 'under-slab' | 'crawlspace';
48
+ /** Sub-floor trench elevation (meters, negative below finished floor). Default: `-0.35`. */
49
+ readonly subFloorElevationM?: number;
50
+ /** Overhead attic elevation (meters above floor). Auto-derived from wallH & roof if omitted. */
51
+ readonly atticElevationM?: number;
52
+ /** Flat-roof / lower-story ceiling soffit margin below `levelH`. Default: `0.16` if `levelH >= 2.6` else `0.08`. */
53
+ readonly flatSoffitMarginM?: number;
54
+ /** Outdoor room polygons excluded from interior plenum cavities. */
55
+ readonly outdoorPolygons?: readonly (readonly (readonly [number, number])[])[];
56
+ /** Explicit interior room polygons. */
57
+ readonly interiorPolygons?: readonly (readonly (readonly [number, number])[])[];
58
+ };
59
+ export type LegalCavityGraph = {
60
+ readonly levelId: string | null;
61
+ readonly levelHeightM: number;
62
+ readonly vertices: readonly CavityVertex[];
63
+ readonly adjacency: readonly (readonly CavityEdge[])[];
64
+ readonly wallRiserPiers: ReadonlyMap<string, readonly WallRiserPier[]>;
65
+ readonly bandsPresent: ReadonlySet<CavityBand>;
66
+ readonly ceilingPlenumY: number;
67
+ readonly atticY: number | null;
68
+ readonly subFloorY: number | null;
69
+ readonly compiledHalfXZ?: number;
70
+ readonly compiledHalfY?: number;
71
+ readonly compiledRoofClearanceM?: number;
72
+ readonly minBaseWeight?: number;
73
+ };
74
+ export type CavityRouteRequest = {
75
+ readonly trade: TradeId;
76
+ readonly from: Vec3;
77
+ readonly to: Vec3;
78
+ readonly halfXZ: number;
79
+ readonly halfY: number;
80
+ readonly clearanceM: number;
81
+ readonly allowedBands: readonly CavityBand[];
82
+ readonly mode: RoutingPhysicsMode;
83
+ readonly maxBendDegrees?: number;
84
+ readonly minSlopeInPerFt?: number;
85
+ readonly minHorizontalElevationM?: number;
86
+ readonly roofClearanceM?: number;
87
+ readonly preferWallFollowing?: boolean;
88
+ readonly lateralStaggerM?: number;
89
+ readonly reserveOnCommit?: boolean;
90
+ readonly runId?: string;
91
+ readonly ignoreObstacleNodeIds?: ReadonlySet<string>;
92
+ };
93
+ export type CavityRouteResult = {
94
+ readonly ok: boolean;
95
+ readonly path: readonly Vec3[];
96
+ readonly lengthM: number;
97
+ readonly horizontalLengthM: number;
98
+ readonly bendDegrees: number;
99
+ readonly elbowCount: number;
100
+ readonly bandsUsed: readonly CavityBand[];
101
+ readonly avoidedObstacleIds: readonly string[];
102
+ readonly clashObstacleIds: readonly string[];
103
+ readonly openingHits: number;
104
+ readonly roofViolation: boolean;
105
+ readonly outdoorVoidViolation: boolean;
106
+ readonly slopeInPerFt?: number;
107
+ readonly reservationId?: string;
108
+ };