@kruschdev/pascal-mep-kernel 0.0.0-stage → 0.1.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 +29 -2
- package/dist/anatomy/footprint.d.ts +164 -0
- package/dist/anatomy/index.d.ts +31 -0
- package/dist/anatomy/index.js +121 -0
- package/dist/anatomy/levels.d.ts +121 -0
- package/dist/anatomy/occupancy.d.ts +194 -0
- package/dist/anatomy/openings.d.ts +125 -0
- package/dist/anatomy/roof.d.ts +102 -0
- package/dist/chunk-0w98adg9.js +2486 -0
- package/dist/chunk-2e23cyn0.js +3567 -0
- package/dist/chunk-jfzqztgh.js +260 -0
- package/dist/chunk-sab5aaa6.js +615 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +186 -0
- package/dist/router/cavity-graph.d.ts +37 -0
- package/dist/router/index.d.ts +11 -0
- package/dist/router/index.js +12 -0
- package/dist/router/shortest-path.d.ts +37 -0
- package/dist/router/types.d.ts +108 -0
- package/dist/rules/evaluator.d.ts +60 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.js +15 -0
- package/dist/rules/schema.d.ts +227 -0
- package/dist/types.d.ts +137 -0
- package/dist/types.js +48 -0
- package/package.json +73 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Ruschman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@kruschdev/pascal-mep-kernel`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Shared zero-dependency, framework-free TypeScript kernel for Pascal Editor MEP and Structural plugins (`@kruschdev/pascal-plugin-structural`, `@kruschdev/pascal-plugin-plumbing`, `@kruschdev/pascal-plugin-hvac`, and `@kruschdev/pascal-plugin-electrical`).
|
|
4
|
+
|
|
5
|
+
## Architecture (3 Layers)
|
|
6
|
+
|
|
7
|
+
1. **Layer 1: Shared Cross-Trade Spatial Anatomy (`@kruschdev/pascal-mep-kernel/anatomy`)**
|
|
8
|
+
- `WeakMap`-memoized `compileBuildingAnatomy(nodes)` so all four trades observe the exact same building geometry:
|
|
9
|
+
- Story and level hierarchy (`resolveNodeLevelId`, `belongsToLevel`, `compareLevelsVertically`, `resolveLevelHeightM`, `isGroundOrLowestWalledLevel`, `isHighestWalledLevelInBuilding`, `findImmediateLowerWalledLevel`) ranking explicit `level` ordinal before `baseElevation`.
|
|
10
|
+
- 7-type canonical roof shell (`flat`, `shed`, `gable`, `hip`, `dutch`, `mansard`, `conical`) with multi-hop parent `roof` transform accumulation, per-segment spatial adoption, and upper-wing seating.
|
|
11
|
+
- Unified wall and opening extraction (both native `door`/`window` nodes and wall-attached `item` openings) with unclamped `rawSillYM` (supporting floor-to-ceiling storefront glass), framed `framedSillYM`, and exact 3D `OrientedPrismY` keepout prisms.
|
|
12
|
+
- Concave building footprint enclosure (`pointInPolygon2D`, planar half-edge bounded faces, 16-ray fallback, NFD-normalized room polygons, footprint clustering).
|
|
13
|
+
- Cross-trade spatial occupancy grid (`TradeOccupancyGrid`, exact rotated OBB beam/column clash detection, `resolveMepRunExtents`, and strict trade-priority ordering `structural < plumbing < hvac < electrical`).
|
|
14
|
+
|
|
15
|
+
2. **Layer 2: Legal-Space-First Routing Graph (`@kruschdev/pascal-mep-kernel/router`)**
|
|
16
|
+
- `compileLegalCavityGraph` builds navigable cavities by construction: solid wall stud bays minus 3D door/window/header keepout prisms, enclosed overhead plenums and attics clamped beneath roof surfaces, and under-slab/crawlspace trenches.
|
|
17
|
+
- `routeInLegalCavities` solves constrained shortest paths (`orthogonal`, `euclidean-cavity`, `gravity-slope`, and `non-descending-vent`) with `TradeOccupancyGrid` reservation.
|
|
18
|
+
|
|
19
|
+
3. **Layer 3: Single-Source Declarative Code Rule Engine (`@kruschdev/pascal-mep-kernel/rules`)**
|
|
20
|
+
- Typed `DeclarativeRule` schema and dual-projection evaluator (`filterLegalCandidates` for placement/routing generators and `evaluateDeclarativeRules` for live compliance auditors) guaranteeing placement thresholds are never looser than audit thresholds (`effectivePlacementThreshold` + `validateRuleTable`).
|
|
21
|
+
|
|
22
|
+
## Verification
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
bun run check # tsc --noEmit && bun test && bun run check:purity && bun run build
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical 2D Polygon Geometry, Wall-Graph Concave Footprint Enclosure,
|
|
3
|
+
* Room Extraction, Footprint Clustering & Outdoor Void Detection (`INV-MEP-01`, `INV-MEP-06`).
|
|
4
|
+
*
|
|
5
|
+
* Unifies:
|
|
6
|
+
* - Single `pointInPolygon2D`, `polygonArea2D`, `polygonAreaAndCentroid`, `polygonBounds2D`,
|
|
7
|
+
* `distancePointToSegment2D`, and `clipSegmentToPolygon2D` across all 4 trades.
|
|
8
|
+
* - Planar half-edge bounded wall faces (`extractBoundedWallFaces`) + 16-ray analytic wall
|
|
9
|
+
* enclosure fallback (`isPointEnclosedByWalls`) for concave L/U/T/H footprints.
|
|
10
|
+
* - `LevelFootprintModel` supporting both `'wall-first'` (Electrical) and `'room-first'` (HVAC)
|
|
11
|
+
* precedence policies with `isPointInside`, `isSegmentInside`, `pathCrossesOutdoorVoid`, and `clampPointInset`.
|
|
12
|
+
*
|
|
13
|
+
* Pure framework-free TypeScript: zero React, Three.js, `@pascal-app/*`, Next, Zod, or `node:*`.
|
|
14
|
+
*/
|
|
15
|
+
import { type SceneNodeLike, type Vec2, type Vec3, type XzBounds2D } from '../types';
|
|
16
|
+
import { type CanonicalWall } from './openings';
|
|
17
|
+
export type BaseRoomPolygon = {
|
|
18
|
+
readonly id: string;
|
|
19
|
+
readonly name: string;
|
|
20
|
+
readonly rawCategory: string;
|
|
21
|
+
/** NFD-normalized, diacritic-stripped, lowercased `name + rawCategory` for multilingual matching. */
|
|
22
|
+
readonly normalizedText: string;
|
|
23
|
+
readonly polygon: readonly Vec2[];
|
|
24
|
+
readonly areaSqM: number;
|
|
25
|
+
readonly areaSqFt: number;
|
|
26
|
+
readonly centroid: Vec2;
|
|
27
|
+
readonly bounds: XzBounds2D;
|
|
28
|
+
};
|
|
29
|
+
export type FootprintCluster = {
|
|
30
|
+
readonly minX: number;
|
|
31
|
+
readonly maxX: number;
|
|
32
|
+
readonly minZ: number;
|
|
33
|
+
readonly maxZ: number;
|
|
34
|
+
readonly widthM: number;
|
|
35
|
+
readonly depthM: number;
|
|
36
|
+
readonly areaSqM: number;
|
|
37
|
+
readonly centerX: number;
|
|
38
|
+
readonly centerZ: number;
|
|
39
|
+
readonly avgWallHeightM: number;
|
|
40
|
+
readonly baseElevationM: number;
|
|
41
|
+
readonly slabIds: string[];
|
|
42
|
+
readonly wallIds: string[];
|
|
43
|
+
};
|
|
44
|
+
export type LevelBounds = {
|
|
45
|
+
readonly minX: number;
|
|
46
|
+
readonly maxX: number;
|
|
47
|
+
readonly minZ: number;
|
|
48
|
+
readonly maxZ: number;
|
|
49
|
+
readonly widthM: number;
|
|
50
|
+
readonly depthM: number;
|
|
51
|
+
readonly heightM: number;
|
|
52
|
+
readonly centerX: number;
|
|
53
|
+
readonly centerZ: number;
|
|
54
|
+
};
|
|
55
|
+
export type BoundedWallFacesResult = {
|
|
56
|
+
readonly faces: Vec2[][];
|
|
57
|
+
readonly complete: boolean;
|
|
58
|
+
readonly aabb: XzBounds2D | null;
|
|
59
|
+
};
|
|
60
|
+
export type FootprintPrecedence = 'wall-first' | 'room-first';
|
|
61
|
+
export type FootprintPointOptions = {
|
|
62
|
+
/** `'wall-first'` (Electrical default) vs `'room-first'` (HVAC). */
|
|
63
|
+
readonly precedence?: FootprintPrecedence;
|
|
64
|
+
/** Wall proximity tolerance in meters (`0.025` bonus over `thickness/2` in wall-first; `0.45` total in room-first). */
|
|
65
|
+
readonly wallToleranceM?: number;
|
|
66
|
+
/** Override outdoor/exterior exclusion polygons. */
|
|
67
|
+
readonly outdoorPolygons?: readonly (readonly Vec2[])[];
|
|
68
|
+
/** Override interior room polygons. */
|
|
69
|
+
readonly interiorPolygons?: readonly (readonly Vec2[])[];
|
|
70
|
+
};
|
|
71
|
+
export type FootprintSegmentOptions = FootprintPointOptions & {
|
|
72
|
+
/** Margin (meters) from an already-exterior endpoint to ignore when checking outdoor void crossing. */
|
|
73
|
+
readonly skipExteriorEndpointMarginM?: number;
|
|
74
|
+
/** Sampling step along XZ segment in meters. */
|
|
75
|
+
readonly stepM?: number;
|
|
76
|
+
};
|
|
77
|
+
export type LevelFootprintModel = {
|
|
78
|
+
readonly levelId: string | null;
|
|
79
|
+
readonly boundedFaces: readonly (readonly Vec2[])[];
|
|
80
|
+
readonly boundedFacesComplete: boolean;
|
|
81
|
+
readonly roomPolygons: readonly BaseRoomPolygon[];
|
|
82
|
+
readonly clusters: readonly FootprintCluster[];
|
|
83
|
+
readonly bounds: XzBounds2D | null;
|
|
84
|
+
readonly isPointInside: (px: number, pz: number, opts?: FootprintPointOptions) => boolean;
|
|
85
|
+
readonly isSegmentInside: (a: Vec3, b: Vec3, opts?: FootprintSegmentOptions) => boolean;
|
|
86
|
+
readonly pathCrossesOutdoorVoid: (path: readonly Vec3[], opts?: FootprintSegmentOptions) => boolean;
|
|
87
|
+
readonly clampPointInset: (px: number, pz: number, insetM?: number, opts?: FootprintPointOptions) => Vec2;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Shortest 2D Euclidean distance from point `(px, pz)` to line segment `[(ax, az), (bx, bz)]`.
|
|
91
|
+
*/
|
|
92
|
+
export declare function distancePointToSegment2D(px: number, pz: number, ax: number, az: number, bx: number, bz: number): number;
|
|
93
|
+
/**
|
|
94
|
+
* Ray-casting 2D point-in-polygon test in XZ plane.
|
|
95
|
+
* Safe for degenerate polygons (`polygon.length < 3` returns `false`), with optional
|
|
96
|
+
* boundary inclusion tolerance `edgeTol` (meters).
|
|
97
|
+
*/
|
|
98
|
+
export declare function pointInPolygon2D(px: number, pz: number, polygon: ReadonlyArray<Vec2>, edgeTol?: number): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Unsigned area (square meters) of a simple 2D polygon via the shoelace formula.
|
|
101
|
+
*/
|
|
102
|
+
export declare function polygonArea2D(polygon: ReadonlyArray<Vec2>): number;
|
|
103
|
+
/**
|
|
104
|
+
* Exact shoelace area (`areaSqM`) and geometric centroid (`centroid`) of a simple 2D polygon.
|
|
105
|
+
* Falls back cleanly to vertex average for zero-area or degenerate polygons.
|
|
106
|
+
*/
|
|
107
|
+
export declare function polygonAreaAndCentroid(polygon: ReadonlyArray<Vec2>): {
|
|
108
|
+
readonly areaSqM: number;
|
|
109
|
+
readonly centroid: Vec2;
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Compute tight 2D XZ bounding box of a polygon, or `null` when empty / non-finite.
|
|
113
|
+
*/
|
|
114
|
+
export declare function polygonBounds2D(polygon: ReadonlyArray<Vec2>): XzBounds2D | null;
|
|
115
|
+
/**
|
|
116
|
+
* Exact 2D segment vs. simple (convex or concave) polygon clipping in XZ.
|
|
117
|
+
* Returns sorted, merged `[t0, t1]` parameter intervals (`0 <= t0 < t1 <= 1`) lying inside `polygon`.
|
|
118
|
+
*/
|
|
119
|
+
export declare function clipSegmentToPolygon2D(a: Vec2, b: Vec2, polygon: readonly Vec2[]): Array<[number, number]>;
|
|
120
|
+
/**
|
|
121
|
+
* Extract all bounded interior face polygons (positive signed area in XZ) from a planar wall
|
|
122
|
+
* network using junction splitting + half-edge angle sorting.
|
|
123
|
+
* Handles concave L/U/T/H footprints and multi-room layouts without requiring `zone` nodes.
|
|
124
|
+
*/
|
|
125
|
+
export declare function extractBoundedWallFaces(walls: readonly CanonicalWall[]): BoundedWallFacesResult;
|
|
126
|
+
/**
|
|
127
|
+
* 16-ray analytic wall enclosure test: returns `true` when `(px, pz)` lies strictly inside
|
|
128
|
+
* a closed walled envelope (immune to interior partition walls, concave L/U shapes, and rotations).
|
|
129
|
+
*/
|
|
130
|
+
export declare function isPointEnclosedByWalls(px: number, pz: number, walls: readonly CanonicalWall[]): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Extract base room/zone polygons on a level with NFD-normalized text, shoelace area/centroid,
|
|
133
|
+
* and tight XZ bounds.
|
|
134
|
+
*/
|
|
135
|
+
export declare function extractBaseRoomPolygons(nodes: Readonly<Record<string, SceneNodeLike>>, levelId?: string | null, opts?: {
|
|
136
|
+
readonly includeHidden?: boolean;
|
|
137
|
+
readonly includeUnparented?: boolean;
|
|
138
|
+
}): BaseRoomPolygon[];
|
|
139
|
+
/**
|
|
140
|
+
* Compute world/level-local XZ bounds and resolved story height of a level from its visible walls and slabs.
|
|
141
|
+
* Returns `null` when no valid walls or slabs exist on the level.
|
|
142
|
+
*/
|
|
143
|
+
export declare function computeLevelBounds(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null): LevelBounds | null;
|
|
144
|
+
/**
|
|
145
|
+
* Partition slabs and walls on a level into connected building footprint clusters.
|
|
146
|
+
* Guarantees detached rooms/buildings on the same level never bridge empty yard.
|
|
147
|
+
*/
|
|
148
|
+
export declare function clusterLevelFootprints(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null, gapToleranceM?: number): FootprintCluster[];
|
|
149
|
+
/**
|
|
150
|
+
* Determine whether a slab is an outdoor/unwalled surface (pool, patio, deck, yard pad,
|
|
151
|
+
* exterior step) that must be excluded from interior floor-joist synthesis.
|
|
152
|
+
*/
|
|
153
|
+
export declare function isOutdoorOrUnwalledSlab(slab: SceneNodeLike, walls: readonly CanonicalWall[], outdoorZonePolys?: ReadonlyArray<ReadonlyArray<Vec2>>, baseWallElev?: number): boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Compile a unified `LevelFootprintModel` for a level combining planar wall-graph faces,
|
|
156
|
+
* 16-ray wall enclosure fallback, NFD-normalized room polygons, and connected footprint clusters.
|
|
157
|
+
*
|
|
158
|
+
* Supports both:
|
|
159
|
+
* - `'wall-first'` precedence (Electrical): points concealed inside wall thickness are interior
|
|
160
|
+
* even adjacent to outdoor zones; falls back cleanly to tight wall AABB on incomplete wall loops.
|
|
161
|
+
* - `'room-first'` precedence (HVAC): explicit exterior room zones (pools/courtyards) override
|
|
162
|
+
* wall proximity; supports strict (`wallToleranceM: 0`) exterior-face probing.
|
|
163
|
+
*/
|
|
164
|
+
export declare function compileLevelFootprint(nodes: Readonly<Record<string, SceneNodeLike>>, levelId?: string | null, walls?: readonly CanonicalWall[]): LevelFootprintModel;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Layer 1 — Shared Cross-Trade Spatial Anatomy Kernel (`@kruschdev/pascal-mep-kernel/anatomy`).
|
|
3
|
+
*
|
|
4
|
+
* `compileBuildingAnatomy(nodes)` is WeakMap-memoized by `nodes` object reference (`INV-MEP-09`),
|
|
5
|
+
* guaranteeing all 4 trades (Structural, Plumbing, HVAC, Electrical) observe the exact same
|
|
6
|
+
* level hierarchy, 7-type roof shell, 3D door/window opening prisms, concave building footprint,
|
|
7
|
+
* and cross-trade spatial occupancy grid.
|
|
8
|
+
*/
|
|
9
|
+
import type { OrientedPrismY, SceneNodeLike } from '../types';
|
|
10
|
+
import { type BaseRoomPolygon, type BoundedWallFacesResult, type FootprintCluster, type FootprintPointOptions, type FootprintPrecedence, type FootprintSegmentOptions, type LevelBounds, type LevelFootprintModel, clipSegmentToPolygon2D, clusterLevelFootprints, compileLevelFootprint, computeLevelBounds, distancePointToSegment2D, extractBaseRoomPolygons, extractBoundedWallFaces, isOutdoorOrUnwalledSlab, isPointEnclosedByWalls, pointInPolygon2D, polygonArea2D, polygonAreaAndCentroid, polygonBounds2D } from './footprint';
|
|
11
|
+
import { type BelongsToLevelOptions, type LowerWalledLevelsSummary, type ResolveLevelHeightOptions, type ResolveLevelOptions, areLevelsInSameBuilding, belongsToLevel, compareLevelsVertically, findImmediateLowerWalledLevel, getLowerWalledLevelIds, isBasementLevel, isGroundOrLowestWalledLevel, isHighestWalledLevelInBuilding, levelHasWalls, levelSortOrder, resolveLevelBuildingId, resolveLevelHeightM, resolveLowerWalledLevelsSummary, resolveNodeLevelId, resolveWallHeightM } from './levels';
|
|
12
|
+
import { type DetectPathClashesParams, ELECTRICAL_CONDUIT_HALF_OD_M, type ElectricalDedicatedSpacePrisms, type EquipmentPrismObstacle, type ExtractTradeOccupancyOptions, type MepRunExtents, type OccupancyKind, type OccupancyObstacle, PLUMBING_PIPE_HALF_OD_M, type PathClashRecord, type ReserveBoxParams, type ReserveRunParams, type SegmentClashParams, TradeOccupancyGrid, extractBeamPrism, extractColumnPrism, extractEquipmentPrisms, extractTradeOccupancyObstacles, getElectricalDedicatedSpacePrisms, getHvacEquipmentAabb, getHvacEquipmentPrism, getHvacPlenumAabb, getHvacPlenumPrism, getPlumbingEquipmentAabb, getPlumbingEquipmentPrism, getPlumbingFixtureAabb, getPlumbingFixturePrism, parseNominalInches, resolveMepRunExtents } from './occupancy';
|
|
13
|
+
import { type CanonicalWall, type CanonicalWallOpening, type ClassifyOpeningOptions, type ExtractCanonicalWallsOptions, type ExtractWallOpeningsOptions, type NearestWallProjection, type TaggedOpeningPrism, classifyOpeningKind, countPathOpeningPrismHits, extractCanonicalWallOpenings, extractCanonicalWalls, extractLevelOpeningPrisms, findNearestWallToPoint } from './openings';
|
|
14
|
+
import { type CanonicalRoofSegment, type CompileRoofShellOptions, type LevelRoofShell, type RoofSegmentKind, compileLevelRoofShell, evaluateRoofSegmentSurfaceY, extractCanonicalRoofSegments, shouldAdoptRoofSegmentOntoLevel, shouldAdoptWallLessRoofLevel } from './roof';
|
|
15
|
+
export type { BelongsToLevelOptions, LowerWalledLevelsSummary, ResolveLevelHeightOptions, ResolveLevelOptions, RoofSegmentKind, CanonicalRoofSegment, CompileRoofShellOptions, LevelRoofShell, CanonicalWallOpening, CanonicalWall, TaggedOpeningPrism, NearestWallProjection, ClassifyOpeningOptions, ExtractWallOpeningsOptions, ExtractCanonicalWallsOptions, BaseRoomPolygon, FootprintCluster, LevelBounds, BoundedWallFacesResult, FootprintPrecedence, FootprintPointOptions, FootprintSegmentOptions, LevelFootprintModel, MepRunExtents, OccupancyKind, OccupancyObstacle, PathClashRecord, ExtractTradeOccupancyOptions, ElectricalDedicatedSpacePrisms, EquipmentPrismObstacle, ReserveRunParams, ReserveBoxParams, SegmentClashParams, DetectPathClashesParams, };
|
|
16
|
+
export { resolveNodeLevelId, belongsToLevel, resolveLevelBuildingId, areLevelsInSameBuilding, levelSortOrder, compareLevelsVertically, isBasementLevel, levelHasWalls, resolveWallHeightM, resolveLevelHeightM, getLowerWalledLevelIds, resolveLowerWalledLevelsSummary, isGroundOrLowestWalledLevel, isHighestWalledLevelInBuilding, findImmediateLowerWalledLevel, shouldAdoptWallLessRoofLevel, shouldAdoptRoofSegmentOntoLevel, evaluateRoofSegmentSurfaceY, extractCanonicalRoofSegments, compileLevelRoofShell, classifyOpeningKind, extractCanonicalWallOpenings, extractCanonicalWalls, extractLevelOpeningPrisms, countPathOpeningPrismHits, findNearestWallToPoint, pointInPolygon2D, polygonArea2D, polygonAreaAndCentroid, polygonBounds2D, distancePointToSegment2D, clipSegmentToPolygon2D, extractBoundedWallFaces, isPointEnclosedByWalls, extractBaseRoomPolygons, clusterLevelFootprints, computeLevelBounds, isOutdoorOrUnwalledSlab, compileLevelFootprint, PLUMBING_PIPE_HALF_OD_M, ELECTRICAL_CONDUIT_HALF_OD_M, parseNominalInches, resolveMepRunExtents, extractBeamPrism, extractColumnPrism, getHvacEquipmentPrism, getHvacEquipmentAabb, getHvacPlenumPrism, getHvacPlenumAabb, getPlumbingFixturePrism, getPlumbingFixtureAabb, getPlumbingEquipmentPrism, getPlumbingEquipmentAabb, getElectricalDedicatedSpacePrisms, extractEquipmentPrisms, extractTradeOccupancyObstacles, TradeOccupancyGrid, };
|
|
17
|
+
export type BuildingAnatomy = {
|
|
18
|
+
readonly nodes: Readonly<Record<string, SceneNodeLike>>;
|
|
19
|
+
readonly levelIds: readonly string[];
|
|
20
|
+
readonly getLevelHeightM: (levelId: string | null, opts?: ResolveLevelHeightOptions) => number;
|
|
21
|
+
readonly getWalls: (levelId: string | null, opts?: ExtractCanonicalWallsOptions) => readonly CanonicalWall[];
|
|
22
|
+
readonly getOpeningPrisms: (levelId: string | null) => readonly TaggedOpeningPrism[];
|
|
23
|
+
readonly getRoofShell: (levelId: string | null, opts?: CompileRoofShellOptions) => LevelRoofShell;
|
|
24
|
+
readonly getFootprint: (levelId: string | null) => LevelFootprintModel;
|
|
25
|
+
readonly createOccupancyGrid: (levelId: string | null, opts: ExtractTradeOccupancyOptions) => TradeOccupancyGrid;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Compile (or retrieve WeakMap-cached) authoritative `BuildingAnatomy` for a Pascal scene graph.
|
|
29
|
+
*/
|
|
30
|
+
export declare function compileBuildingAnatomy(nodes: Readonly<Record<string, SceneNodeLike>>): BuildingAnatomy;
|
|
31
|
+
export type { OrientedPrismY };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveNodeLevelId2,
|
|
3
|
+
belongsToLevel2,
|
|
4
|
+
resolveLevelBuildingId2,
|
|
5
|
+
areLevelsInSameBuilding2,
|
|
6
|
+
levelSortOrder2,
|
|
7
|
+
compareLevelsVertically2,
|
|
8
|
+
isBasementLevel2,
|
|
9
|
+
levelHasWalls2,
|
|
10
|
+
resolveWallHeightM2,
|
|
11
|
+
resolveLevelHeightM2,
|
|
12
|
+
getLowerWalledLevelIds2,
|
|
13
|
+
resolveLowerWalledLevelsSummary2,
|
|
14
|
+
isGroundOrLowestWalledLevel2,
|
|
15
|
+
isHighestWalledLevelInBuilding2,
|
|
16
|
+
findImmediateLowerWalledLevel2,
|
|
17
|
+
classifyOpeningKind2,
|
|
18
|
+
extractCanonicalWallOpenings2,
|
|
19
|
+
extractCanonicalWalls2,
|
|
20
|
+
extractLevelOpeningPrisms2,
|
|
21
|
+
countPathOpeningPrismHits2,
|
|
22
|
+
findNearestWallToPoint2,
|
|
23
|
+
distancePointToSegment2D2,
|
|
24
|
+
pointInPolygon2D2,
|
|
25
|
+
polygonArea2D2,
|
|
26
|
+
polygonAreaAndCentroid2,
|
|
27
|
+
polygonBounds2D2,
|
|
28
|
+
clipSegmentToPolygon2D2,
|
|
29
|
+
extractBoundedWallFaces2,
|
|
30
|
+
isPointEnclosedByWalls2,
|
|
31
|
+
extractBaseRoomPolygons2,
|
|
32
|
+
computeLevelBounds2,
|
|
33
|
+
clusterLevelFootprints2,
|
|
34
|
+
isOutdoorOrUnwalledSlab2,
|
|
35
|
+
compileLevelFootprint2,
|
|
36
|
+
PLUMBING_PIPE_HALF_OD_M2,
|
|
37
|
+
ELECTRICAL_CONDUIT_HALF_OD_M2,
|
|
38
|
+
parseNominalInches2,
|
|
39
|
+
resolveMepRunExtents2,
|
|
40
|
+
extractBeamPrism2,
|
|
41
|
+
extractColumnPrism2,
|
|
42
|
+
getHvacEquipmentPrism2,
|
|
43
|
+
getHvacEquipmentAabb2,
|
|
44
|
+
getHvacPlenumPrism2,
|
|
45
|
+
getHvacPlenumAabb2,
|
|
46
|
+
getPlumbingFixturePrism2,
|
|
47
|
+
getPlumbingFixtureAabb2,
|
|
48
|
+
getPlumbingEquipmentPrism2,
|
|
49
|
+
getPlumbingEquipmentAabb2,
|
|
50
|
+
getElectricalDedicatedSpacePrisms2,
|
|
51
|
+
extractEquipmentPrisms2,
|
|
52
|
+
extractTradeOccupancyObstacles2,
|
|
53
|
+
TradeOccupancyGrid2,
|
|
54
|
+
shouldAdoptWallLessRoofLevel2,
|
|
55
|
+
shouldAdoptRoofSegmentOntoLevel2,
|
|
56
|
+
evaluateRoofSegmentSurfaceY2,
|
|
57
|
+
extractCanonicalRoofSegments2,
|
|
58
|
+
compileLevelRoofShell2,
|
|
59
|
+
compileBuildingAnatomy2
|
|
60
|
+
} from "../chunk-2e23cyn0.js";
|
|
61
|
+
import"../chunk-jfzqztgh.js";
|
|
62
|
+
export {
|
|
63
|
+
ELECTRICAL_CONDUIT_HALF_OD_M2 as ELECTRICAL_CONDUIT_HALF_OD_M,
|
|
64
|
+
PLUMBING_PIPE_HALF_OD_M2 as PLUMBING_PIPE_HALF_OD_M,
|
|
65
|
+
TradeOccupancyGrid2 as TradeOccupancyGrid,
|
|
66
|
+
areLevelsInSameBuilding2 as areLevelsInSameBuilding,
|
|
67
|
+
belongsToLevel2 as belongsToLevel,
|
|
68
|
+
classifyOpeningKind2 as classifyOpeningKind,
|
|
69
|
+
clipSegmentToPolygon2D2 as clipSegmentToPolygon2D,
|
|
70
|
+
clusterLevelFootprints2 as clusterLevelFootprints,
|
|
71
|
+
compareLevelsVertically2 as compareLevelsVertically,
|
|
72
|
+
compileBuildingAnatomy2 as compileBuildingAnatomy,
|
|
73
|
+
compileLevelFootprint2 as compileLevelFootprint,
|
|
74
|
+
compileLevelRoofShell2 as compileLevelRoofShell,
|
|
75
|
+
computeLevelBounds2 as computeLevelBounds,
|
|
76
|
+
countPathOpeningPrismHits2 as countPathOpeningPrismHits,
|
|
77
|
+
distancePointToSegment2D2 as distancePointToSegment2D,
|
|
78
|
+
evaluateRoofSegmentSurfaceY2 as evaluateRoofSegmentSurfaceY,
|
|
79
|
+
extractBaseRoomPolygons2 as extractBaseRoomPolygons,
|
|
80
|
+
extractBeamPrism2 as extractBeamPrism,
|
|
81
|
+
extractBoundedWallFaces2 as extractBoundedWallFaces,
|
|
82
|
+
extractCanonicalRoofSegments2 as extractCanonicalRoofSegments,
|
|
83
|
+
extractCanonicalWallOpenings2 as extractCanonicalWallOpenings,
|
|
84
|
+
extractCanonicalWalls2 as extractCanonicalWalls,
|
|
85
|
+
extractColumnPrism2 as extractColumnPrism,
|
|
86
|
+
extractEquipmentPrisms2 as extractEquipmentPrisms,
|
|
87
|
+
extractLevelOpeningPrisms2 as extractLevelOpeningPrisms,
|
|
88
|
+
extractTradeOccupancyObstacles2 as extractTradeOccupancyObstacles,
|
|
89
|
+
findImmediateLowerWalledLevel2 as findImmediateLowerWalledLevel,
|
|
90
|
+
findNearestWallToPoint2 as findNearestWallToPoint,
|
|
91
|
+
getElectricalDedicatedSpacePrisms2 as getElectricalDedicatedSpacePrisms,
|
|
92
|
+
getHvacEquipmentAabb2 as getHvacEquipmentAabb,
|
|
93
|
+
getHvacEquipmentPrism2 as getHvacEquipmentPrism,
|
|
94
|
+
getHvacPlenumAabb2 as getHvacPlenumAabb,
|
|
95
|
+
getHvacPlenumPrism2 as getHvacPlenumPrism,
|
|
96
|
+
getLowerWalledLevelIds2 as getLowerWalledLevelIds,
|
|
97
|
+
getPlumbingEquipmentAabb2 as getPlumbingEquipmentAabb,
|
|
98
|
+
getPlumbingEquipmentPrism2 as getPlumbingEquipmentPrism,
|
|
99
|
+
getPlumbingFixtureAabb2 as getPlumbingFixtureAabb,
|
|
100
|
+
getPlumbingFixturePrism2 as getPlumbingFixturePrism,
|
|
101
|
+
isBasementLevel2 as isBasementLevel,
|
|
102
|
+
isGroundOrLowestWalledLevel2 as isGroundOrLowestWalledLevel,
|
|
103
|
+
isHighestWalledLevelInBuilding2 as isHighestWalledLevelInBuilding,
|
|
104
|
+
isOutdoorOrUnwalledSlab2 as isOutdoorOrUnwalledSlab,
|
|
105
|
+
isPointEnclosedByWalls2 as isPointEnclosedByWalls,
|
|
106
|
+
levelHasWalls2 as levelHasWalls,
|
|
107
|
+
levelSortOrder2 as levelSortOrder,
|
|
108
|
+
parseNominalInches2 as parseNominalInches,
|
|
109
|
+
pointInPolygon2D2 as pointInPolygon2D,
|
|
110
|
+
polygonArea2D2 as polygonArea2D,
|
|
111
|
+
polygonAreaAndCentroid2 as polygonAreaAndCentroid,
|
|
112
|
+
polygonBounds2D2 as polygonBounds2D,
|
|
113
|
+
resolveLevelBuildingId2 as resolveLevelBuildingId,
|
|
114
|
+
resolveLevelHeightM2 as resolveLevelHeightM,
|
|
115
|
+
resolveLowerWalledLevelsSummary2 as resolveLowerWalledLevelsSummary,
|
|
116
|
+
resolveMepRunExtents2 as resolveMepRunExtents,
|
|
117
|
+
resolveNodeLevelId2 as resolveNodeLevelId,
|
|
118
|
+
resolveWallHeightM2 as resolveWallHeightM,
|
|
119
|
+
shouldAdoptRoofSegmentOntoLevel2 as shouldAdoptRoofSegmentOntoLevel,
|
|
120
|
+
shouldAdoptWallLessRoofLevel2 as shouldAdoptWallLessRoofLevel
|
|
121
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single authoritative Level / Story Hierarchy & Height Resolution (`INV-MEP-04`).
|
|
3
|
+
*
|
|
4
|
+
* Permanently eliminates the `baseElevation: 0` trap by always ranking explicit `level`
|
|
5
|
+
* storey ordinal BEFORE `elevation` / `baseElevation` / `index`.
|
|
6
|
+
*/
|
|
7
|
+
import type { SceneNodeLike } from '../types';
|
|
8
|
+
export type ResolveLevelOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* When `true` (default), returns a dangling `parentId` string when `nodes[parentId]` is absent
|
|
11
|
+
* (supports synthetic unit-test scenes without explicit `level` nodes).
|
|
12
|
+
* Pass `false` to require an actual `type === 'level'` node in `nodes`.
|
|
13
|
+
*/
|
|
14
|
+
readonly allowDanglingParentId?: boolean;
|
|
15
|
+
};
|
|
16
|
+
export type BelongsToLevelOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* When `true`, nodes with `parentId == null` are accepted into any requested `levelId`
|
|
19
|
+
* (preserves flat-scene compatibility in legacy Electrical tests). Default: `false`.
|
|
20
|
+
*/
|
|
21
|
+
readonly includeUnparented?: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ResolveLevelHeightOptions = {
|
|
24
|
+
/** Optional minimum floor clamp in meters (e.g., `2.2` for HVAC ceiling sanity). */
|
|
25
|
+
readonly minClampM?: number;
|
|
26
|
+
/** Fallback height when neither walls nor level define one. Default: `2.7`. */
|
|
27
|
+
readonly defaultHeightM?: number;
|
|
28
|
+
/** Whether to include `visible === false` walls when computing max wall height. Default: `false`. */
|
|
29
|
+
readonly includeHiddenWalls?: boolean;
|
|
30
|
+
/** Whether unparented walls count toward `levelId`. Default: `false`. */
|
|
31
|
+
readonly includeUnparentedWalls?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type LowerWalledLevelsSummary = {
|
|
34
|
+
readonly cumulativeBelowHeightM: number;
|
|
35
|
+
readonly lowerLevelIds: readonly string[];
|
|
36
|
+
readonly groundLevelId: string | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Walk `parentId` chain with cycle protection to find the enclosing `level` node ID.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveNodeLevelId(nodes: Readonly<Record<string, SceneNodeLike>>, node: SceneNodeLike, options?: ResolveLevelOptions): string | null;
|
|
42
|
+
/**
|
|
43
|
+
* Determine whether `node` belongs to `levelId`.
|
|
44
|
+
* When `levelId` is `null` or `undefined`, returns `true` (unscoped scene).
|
|
45
|
+
*/
|
|
46
|
+
export declare function belongsToLevel(nodes: Readonly<Record<string, SceneNodeLike>>, node: SceneNodeLike, levelId: string | null | undefined, options?: BelongsToLevelOptions): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Resolve the owning `building` node ID for a level (normalizing empty string `""` to `null`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveLevelBuildingId(nodes: Readonly<Record<string, SceneNodeLike>>, level: SceneNodeLike | undefined): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Whether two level nodes belong to the same building scope.
|
|
53
|
+
* When `strictNullBuilding` is `false` (default), a `null`-parented level matches a
|
|
54
|
+
* building-parented level (matching `elc`/`hvac`/`str`); when `true`, both must match exactly.
|
|
55
|
+
*/
|
|
56
|
+
export declare function areLevelsInSameBuilding(nodes: Readonly<Record<string, SceneNodeLike>>, a: SceneNodeLike, b: SceneNodeLike, strictNullBuilding?: boolean): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Canonical vertical story sort ordinal (`INV-MEP-04`).
|
|
59
|
+
*
|
|
60
|
+
* Always prioritizes explicit `level` storey ordinal BEFORE `elevation` / `baseElevation` / `index`,
|
|
61
|
+
* because Pascal levels default to `baseElevation: 0` on every story.
|
|
62
|
+
*/
|
|
63
|
+
export declare function levelSortOrder(level: SceneNodeLike | undefined): number;
|
|
64
|
+
/**
|
|
65
|
+
* Strict vertical comparator between two level nodes (`< 0` means `a` is below `b`).
|
|
66
|
+
* Ranks `level` ordinal first, breaking ties with `elevation`, then `baseElevation`, then `index`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function compareLevelsVertically(a: SceneNodeLike | undefined, b: SceneNodeLike | undefined): number;
|
|
69
|
+
/** True when a level represents a below-grade basement story (`level < 0` or elevation `< -0.5 m`). */
|
|
70
|
+
export declare function isBasementLevel(level: SceneNodeLike | undefined): boolean;
|
|
71
|
+
/** True when `levelId` has at least one wall node (excluding `visible === false` unless `includeHidden`). */
|
|
72
|
+
export declare function levelHasWalls(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string, includeHidden?: boolean): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Resolve a single wall's physical height in meters (`wall.height` -> parent `level.height` -> `fallbackM`).
|
|
75
|
+
*
|
|
76
|
+
* Defaults `fallbackM` to `2.55 m` (standard stud-framing rough wall height), intentionally distinct
|
|
77
|
+
* from `resolveLevelHeightM`'s `2.7 m` full story floor-to-ceiling default.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveWallHeightM(nodes: Readonly<Record<string, SceneNodeLike>>, wall: SceneNodeLike, fallbackM?: number): number;
|
|
80
|
+
/**
|
|
81
|
+
* Single authoritative level height resolver across all 4 trades.
|
|
82
|
+
* Prefers max explicit wall height in `(1.5, 12]` on the level, then `level.height` in `(1.5, 12]`,
|
|
83
|
+
* then `defaultHeightM` (`2.7 m`), optionally clamped at `minClampM`.
|
|
84
|
+
*/
|
|
85
|
+
export declare function resolveLevelHeightM(nodes: Readonly<Record<string, SceneNodeLike>>, levelId?: string | null | undefined, options?: ResolveLevelHeightOptions): number;
|
|
86
|
+
/**
|
|
87
|
+
* Return all walled sibling levels strictly below `levelId` in the same building,
|
|
88
|
+
* sorted bottom-to-top.
|
|
89
|
+
*/
|
|
90
|
+
export declare function getLowerWalledLevelIds(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null | undefined, options?: {
|
|
91
|
+
readonly excludeBasements?: boolean;
|
|
92
|
+
readonly includeHiddenWalls?: boolean;
|
|
93
|
+
readonly strictNullBuilding?: boolean;
|
|
94
|
+
}): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Return summary of walled levels below `levelId` plus cumulative stacked height
|
|
97
|
+
* (used by HVAC to seat upper-story condensers on grade and route multi-story linesets).
|
|
98
|
+
*/
|
|
99
|
+
export declare function resolveLowerWalledLevelsSummary(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null | undefined, options?: {
|
|
100
|
+
readonly excludeBasements?: boolean;
|
|
101
|
+
readonly includeHiddenWalls?: boolean;
|
|
102
|
+
}): LowerWalledLevelsSummary;
|
|
103
|
+
/**
|
|
104
|
+
* True when `levelId` is the ground / lowest walled story in its building.
|
|
105
|
+
*/
|
|
106
|
+
export declare function isGroundOrLowestWalledLevel(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null | undefined, options?: {
|
|
107
|
+
readonly excludeBasements?: boolean;
|
|
108
|
+
readonly includeHiddenWalls?: boolean;
|
|
109
|
+
}): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* True when `levelId` has NO walled sibling level strictly above it in the same building.
|
|
112
|
+
*/
|
|
113
|
+
export declare function isHighestWalledLevelInBuilding(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null | undefined, options?: {
|
|
114
|
+
readonly includeHiddenWalls?: boolean;
|
|
115
|
+
}): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Return the highest walled sibling level strictly below `levelId` (the immediate lower story).
|
|
118
|
+
*/
|
|
119
|
+
export declare function findImmediateLowerWalledLevel(nodes: Readonly<Record<string, SceneNodeLike>>, levelId: string | null | undefined, options?: {
|
|
120
|
+
readonly includeHiddenWalls?: boolean;
|
|
121
|
+
}): SceneNodeLike | null;
|