fix(server,data): one storey-elevation contract across every path (#1841)
Closes the remaining two symptoms of #1841. PR #1848 fixed Symptoms 1 and 2; these were added to the issue by @xyzbety after that PR was already in flight, and #1848 auto-closed the issue without covering them.
Symptom 3 — the server read the wrong attribute
extract_elevation_if_storey read get_float(8) and fell back to get_float(7). Its in-code comment listed the attributes as [5]=Tag, [6]=LongName, [7]=CompositionType, [8]=Elevation — it omits ObjectPlacement and Representation, so it was off by one. The real IfcBuildingStorey order, identical in IFC2X3 and IFC4:
[0] GlobalId [1] OwnerHistory [2] Name [3] Description
[4] ObjectType [5] ObjectPlacement [6] Representation [7] LongName
[8] CompositionType [9] Elevation
Slot 8 is an enum and slot 7 is a string, so neither yields a float: every storey on the server path reported no elevation and the viewer showed 0.
Fixed to read slot 9, plus the ObjectPlacement Z fallback the parser already applies when Elevation is null (common in Revit / ArchiCAD exports, #1289) — walking IfcLocalPlacement -> RelativePlacement -> Location.Coordinates[2], i.e. relative to the parent container, so site-level georeferencing is not folded in.
This class of bug is silent by construction: a wrong index yields "no elevation", never an error. So the indices are now named constants on both sides with the attribute table spelled out, and the TS side asserts them in a test.
Symptom 4 — getStoreyByElevation had four implementations
Three of them disagreed with the fourth:
| implementation | behaviour |
|---|---|
packages/parser/src/spatial-hierarchy-builder.ts | null beyond 1m |
packages/parser/src/data-store-transport.ts | always snapped |
packages/ifcx/src/hierarchy-builder.ts | always snapped |
apps/viewer/src/utils/serverDataModel.ts | always snapped |
The issue reported the viewer one. The other two turned up while checking whether any others had drifted — and the data-store-transport case is the worst of them, because it means the same parse answered differently depending on which side of the worker boundary the store was read from.
All four now call findStoreyByElevation. It lives in @ifc-lite/data, next to the SpatialHierarchy interface it implements — every implementer already depends on that package, which @ifc-lite/parser is not (@ifc-lite/ifcx does not depend on it).
Behaviour follows the tolerance-bounded rule: a Z 40m above the top floor belongs to no storey, and snapping it to the roof silently corrupts storey grouping, floorplan placement, and section cuts.
Verification
- Rust: 80
ifc-lite-servertests pass, incl. 8 new ones pinning the slot, the placement fallback, precedence between them, and thatLongName/CompositionTypenever parse as a float. Clippy clean, module-size ratchet green. - TS: 9 new
@ifc-lite/datatests (tolerance boundary is exclusive, empty set, negative elevations); 73 data / 312 parser / 49 ifcx / 1817 viewer tests pass; viewer typecheck 0 errors;check:api-surfacematches. - Changeset:
@ifc-lite/dataminor.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Ddp5uELykicu1tGSrVmpnK
Summary by CodeRabbit
- Bug Fixes
- Improved building-storey identification from Z elevation values.
- Standardized storey selection logic across parsing, viewer rendering, and worker-loaded data.
- Prevented incorrect storey matches outside the supported 1m tolerance range (including exact boundary behavior).
- Added robust fallback to derive elevation from storey placement when explicit elevation is missing.
- Corrected interpretation of IFC storey attributes, units, negative elevations, and case variations.
- New Features
- Introduced a shared storey-elevation resolver to keep results consistent everywhere.