fix(create,export): refuse non-finite coordinates across every builder and at the serializer
Closes #5217
As requested, this is split into two commits so a bisect can separate them: the builder guards first, then the serializer.
Root cause
A non-finite Position reached serializeStepValue, which turns every non-finite number into $. $ is the ISO 10303-21 token for an omitted whole attribute. As a member of IfcCartesianPoint.Coordinates (a mandatory LIST [1:3] OF IfcLengthMeasure), (($,0,0)) is a malformed file, not a degraded value.
The two authoring paths agreed with each other on the gap. In-store door/window/column/slab/roof/plate/space and their IfcCreator.addIfc* twins skipped the finiteness check that wall/beam/member apply. Because both paths skipped the same builders, nothing looked inconsistent to a reviewer, while the reachable surface was doubled.
Fix
Commit 1 (builders).
- In-store: Petru's
assertFinitePoint3onPositionin the seven in-store builders, cherry-picked with authorship kept. The guard is conditional for the polygon variants of slab/roof/plate/space, wherePositionis optional. IfcCreator: the guard is at the one place everyIfcCartesianPointis written (addCartesianPoint/addCartesianPoint2D), not as seven per-method lines. The issue listed seven methods, but the class is wider.addIfcStair,addIfcRamp,addIfcGableRoof,addIfcFooting,addIfcPile,addIfcFurnishingElement,addIfcBuildingElementProxy, hosted door and window fills, and openings all place a caller-supplied point with no check too. The chokepoint covers all of them with one line. It also keepsifc-creator.tswithin its module-size budget: the seven extra lines took it to 2850 against a budget of 2843, which failedcheck-module-size. On that path a non-finite value used to be written as the tokenNaN..
Commit 2 (serializer). You asked me to confirm that $ is never legitimately produced from a non-finite number before writing the throw. Petru's branch had held back on this because IfcMapConversion.Scale (real-slot-non-numeric.test.ts) relies on non-finite → $. Checking every serializeStepValue caller confirms your reading: the two cases differ by position, not by value.
Scaleis a whole optional attribute.$is correct there and still produced.- A non-finite list member has no legal reading anywhere, so
serializeStepValuenow throws for it.serializeAttributeSlotadds the entity type and attribute index to the error. - The only callers are the export's slot serializers (
attribute-real-slots.ts,step-attribute-serializers.ts). The viewer'sraw-step-format.tsand collab'smutation-bridge.tsmention the function only in comments.
The serializer guard is the backstop for every StoreEditor.addEntity caller: the builders, and also scripts, MCP and flow nodes (store-adapter.ts's bare params as … casts). It also covers inputs no builder guard names, such as a polygon OuterCurve vertex. null inside a list is unchanged. That's an explicit caller value, not a converted one, and it's outside this issue.
Evidence
RED→GREEN, each run against the unfixed file:
packages/create/src/in-store/position-finite-validation.test.ts(Petru's): 70 RED → GREEN. Mutation table on the issue.ifc-creator.test.ts: withifc-creator.tsatmain, all 14 non-finite-Position cases fail (the 7 named plus the 7 other builders I added). All pass with the fix.packages/export/src/nonfinite-list-member.test.ts(new): with the serializer at the builder-commit state, 2 of 5 fail. The failures are a list member refused, and an overlayIfcCartesianPoint([NaN,0,0])export that now fails withIfcCartesianPoint attribute 0: Cannot write NaN as a STEP list member…instead of writing(($,0,0)). A whole-attribute NaN still gives$, and finite lists are unchanged.real-slot-non-numeric.test.ts(theScale→$pin) still passes.
Full suites:
packages/create: 646/646.packages/export: 1396 passed. The only failure iscolumns-to-parquet.test.ts, which timed out at 27s under local load. It's unrelated and passes on CI.
Typecheck (pnpm turbo run typecheck --filter=@ifc-lite/export --filter=@ifc-lite/create) and check-module-size are both OK.
Hard-boundary note: packages/create/** is also being edited by another session for LandXML export. This diff touches only ifc-creator.ts (two guard lines and a 6-line compaction of addLocalPlacement), the seven in-store builders, and tests.
Credit: the in-store builder guards and their test file come from Petru Conduraru's branch fix-5217-nonfinite-position.
Perf: not a perf-sensitive path.
🤖 Generated with Claude Code