Skip to content

feat(exchange): export_step_in for bodies in a unit other than metres - #35

Open
Basnederveen wants to merge 5 commits into
OpenGeometry-io:mainfrom
Bas-Automation-Services:feat/step-model-unit
Open

Basnederveen wants to merge 5 commits into
OpenGeometry-io:mainfrom
Bas-Automation-Services:feat/step-model-unit

Conversation

@Basnederveen

@Basnederveen Basnederveen commented Nov 1, 2026 •

Copy link
Copy Markdown

What

export_step takes a body's coordinates as metres and scales them to the file unit. A body built in millimetres had no way to say so: exporting it as millimetres multiplied every coordinate by 1000, so a 100 mm plate came out 100 m wide.

export_step_in(brep, model_unit, unit) takes the unit the body is built in ("metre" or "millimetre") and scales from it to the file unit once. export_step(brep, unit) keeps its behaviour and delegates with model_unit = "metre".

  • Each unit is its length in millimetres, reduced to one factor: metre to millimetre multiplies by 1000 (the same digits as before), millimetre to metre divides by 1000, and equal units are untouched.
  • The file unit check and its message are unchanged; an unknown model unit is InvalidGeometry too.
  • export_bodies gets the model unit as a parameter. StepOptions has modelUnit (default "metre"), so OpenGeometry.exportStep({ nodes, unit: 'millimetre', modelUnit: 'millimetre' }) writes a 100 mm plate unscaled from JavaScript.
  • export_ifc_body_in(brep, model_unit, conversion) does the same for the IFC body. It scales to metres through placed, with the geometric tolerance, exchange error bound and fitting budget scaled alike, so length_unit: "metre" holds for a millimetre body. export_ifc_body delegates with "metre". WorldGraph::export_ifc_body(og_id, model_unit) and OpenGeometry.exportIfcBody(node, { modelUnit }) pass it through.
  • Scale lives in exchange/unit.rs, shared by both exports. An unknown model unit is InvalidParameter in the world graph and in JavaScript.
  • The default is "metre" everywhere, so existing exports are unchanged.

Tests

  • step_oracle::ifc_body: a millimetre model's IFC body is a thousandth of the metre body (points, tolerance and bound), and unknown model units are refused. step_oracle::placed: a millimetre world model exported to millimetres writes the metre-to-metre digits. Node tests check both from JavaScript.
  • exchange::step::tests has five tests, one per behaviour, on a 100 x 50 x 9 mm plate with millimetre accuracy: millimetre to millimetre writes coordinates unchanged (digit for digit the metre export, except the SI_UNIT prefix), millimetre to metre divides by 1000 (the corner is written as 0.1, 0.05, 0.009), a metre body to millimetres still scales by 1000, and unknown file or model units are refused.
  • npm run check without CI=true on Windows x86_64: fmt and clippy are clean. Rust tests give 947 passed, 6 failed, 1 ignored; the 6 are the stored-fixture and digest comparisons that already failed on that machine before this PR. Every npm step passes except build-example, which hits a Windows path error in vite. Details are in the review reply.

Files

  • main/opengeometry/src/exchange/step/mod.rs
  • main/opengeometry/src/exchange/unit.rs
  • main/opengeometry/src/exchange/step/tests.rs
  • main/opengeometry/src/exchange/mod.rs
  • main/opengeometry/src/exchange/ifc_body/mod.rs
  • main/opengeometry/src/world_graph/export.rs
  • main/opengeometry/src/world_graph/export_ifc.rs
  • main/opengeometry/src/bindings/world_graph/ifc_body.rs
  • main/opengeometry-three/src/export/export-step.ts, ifc-body.ts, opengeometry.ts
  • tests: tests/step_oracle/ifc_body.rs, placed.rs, opengeometry-three/tests/node/export-step.test.mjs, ifc-body.test.mjs
  • docs: README.md, docs/opengeometry/api/export.mdx, guides/export-step.mdx, guides/ifc-exchange-body.mdx

🤖 Generated with Claude Code

export_step takes a body's coordinates as metres and scales them to the
file unit. A body built in millimetres had no way to say so: exporting
it as millimetres multiplied every coordinate by 1000 (a 100 mm plate
came out 100 m wide).

export_step_in(brep, model_unit, unit) takes the unit the body is built
in ("metre" or "millimetre") and scales from it to the file unit once.
export_step keeps its behaviour and delegates with model_unit = "metre".
The scale is a fixed table, so metre bodies export the same digits as
before. export_bodies takes the model unit; the world graph passes
"metre".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VFZvqx1RmXzPtbL9VXP4H7

@aka-blackboots aka-blackboots left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are inline, tagged by severity.

The test run in the description used CI=true, which skips the golden and stored STEP comparisons. Please run npm run check from main/ without it and paste the result.

export_step_in(brep, "metre", unit)
}

pub fn export_step_in(

@aka-blackboots aka-blackboots Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: the unit exists only for STEP.

After this change a body can be in millimetres, but only export_step_in knows that. The IFC body export still writes length_unit: "metre" (exchange/ifc_body/mod.rs), and the world graph assumes metres too. So the same millimetre body comes out right in STEP and 1000× too large in IFC.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Today only STEP knows that a body is in millimetres. Before I widen this PR, I'd like your call on where the unit should live:

  1. Per export. export_ifc_body takes the model unit too and converts to metres through the placed(input, conversion, scale) call it already makes (it passes 1.0 today). geometric_tolerance and exchange_error_bound are scaled the same way, so length_unit: "metre" holds for any body.
  2. On the world graph. The world graph gets one length unit that every export reads. That matches your point that the world graph assumes metres too, but it is a bigger change.

Which do you prefer? I can do it in this PR or in a follow-up.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s go with option 1 in this PR.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 067bd7d. export_ifc_body_in(brep, model_unit, conversion) takes the unit the body is built in and scales to metres through the placed call. export_ifc_body delegates with "metre", the same way export_step delegates to export_step_in. geometric_tolerance, exchange_error_bound and the fitting budget are scaled too, so length_unit: "metre" holds for a millimetre body. WorldGraph::export_ifc_body(og_id, model_unit) and OpenGeometry.exportIfcBody(node, { modelUnit }) pass it through, and an unknown unit is InvalidParameter. Scale moved from exchange/step/unit.rs to exchange/unit.rs so both exports use it. Metre bodies are unchanged: the 2.0.18 IFC oracle tests pass.

One difference from STEP: placed takes a single f64 scale, so a millimetre body's IFC coordinates are multiplied by 0.001, and a 9 mm edge comes out as 0.009000000000000001 m, not 0.009. Making placed divide exactly would change it for every caller, so I left it as is. Tell me if you want that in this PR.

.collect::<Vec<_>>();
export_bodies(
&inputs,
"metre",

@aka-blackboots aka-blackboots Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: JavaScript users can't reach this yet.

The only STEP export in the wasm bindings goes through WorldGraph::export_step, and it passes "metre" here. So the npm package behaves exactly as before, and the 100 mm plate from the description still can't be exported unscaled from JS.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. With option 1 from the other thread, StepOptions gets a modelUnit (default "metre", validated like unit) and passes it through here instead of the literal. JS can then call exportStep(nodes, { unit: "millimetre", modelUnit: "millimetre" }). With option 2, this option isn't needed. I'll wait for your answer there before building either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go with option 1.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 067bd7d. StepOptions has modelUnit (default "metre", InvalidParameter unless metre or millimetre), and it is passed here instead of the literal. From JS, exportStep({ nodes, unit: 'millimetre', modelUnit: 'millimetre' }) writes the 100 mm plate as 100. A node test checks that this text is the metre-to-metre export with only the SI_UNIT changed, and step_oracle::placed checks the same in Rust.

…aviour

Each length unit is now its size in millimetres, reduced to a single
factor: metre to millimetre still multiplies by 1000 (same digits as
before), millimetre to metre divides by 1000 instead of multiplying by
1e-3, and equal units leave coordinates untouched. A 9 mm thickness is
written as 0.009 rather than 0.009000000000000001.

The millimetre tests build their plate with an accuracy scaled to
millimetres and check the written SI_UNIT and corner points. The one
combined test is split into five, one per behaviour.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Basnederveen

Copy link
Copy Markdown
Author

Thanks for the review. The fixes are in 4efe153 and I've replied inline. The two High items need your decision on where the model unit should live; the options are in the thread on exchange/step/mod.rs.

npm run check without CI=true (Windows x86_64):

  • opengeometry Rust: fmt and clippy are clean. cargo test --offline --all-targets --no-fail-fast gives 893 passed, 6 failed, 1 ignored. All 6 failures fail the same way on the commit before 4efe153 on this machine. They are stored-fixture and digest comparisons that this PR doesn't touch:

    • booleans: wc_subtract::the_wc_pan_shell_minus_its_six_arc_bowl_opening_is_the_recorded_prismatic_result
    • cases: tessellation::primitive_tessellation_matches_stored_fixtures, matrix::boolean_support_matrix_matches_stored_outcomes_and_handlers, batch::batch_subtraction_matches_stored_brep_and_handlers
    • golden: every_golden_scene_matches_the_recorded_golden_for_this_target
    • step_oracle: ifc_body::ifc_bodies_of_the_matrix_results_match_the_2_0_18_digests

    The other 44 step_oracle tests pass, including the bit-for-bit membership checks.

  • These pass: test-support fmt, clippy and test; test:wasm, build, worker-bundle, lint:check, typecheck, check:source, check:cycles, check:duplicates, test:bindings, test:node and test:performance.

  • build-example fails in vite on Windows, unrelated to this PR: [vite:build-html] The "fileName" or "name" properties of emitted chunks and assets must be strings that are neither absolute nor relative paths, received "../../../../../../../Repositories/.../analytic-boolean-operations.html".

verify.mjs itself doesn't run on Windows. It names its log files after the step (.check/rust:opengeometry:fmt.log), and Windows file names can't contain :. It also spawns npm without a shell, which gives spawn npm ENOENT. I patched both locally to get the results above; neither patch is in this PR. I can open a separate PR for them if you'd like.

Basnederveen and others added 2 commits November 17, 2026 06:44
export_ifc_body_in(brep, model_unit, conversion) scales a body built in
millimetres to metres through placed(), with the geometric tolerance,
exchange error bound and fitting budget scaled alike; export_ifc_body
delegates with "metre". The Scale helper moves from exchange/step to
exchange so both exports share it.

StepOptions gets modelUnit (default "metre") and WorldGraph::export_ifc_body
takes the model unit, so OpenGeometry.exportStep({ modelUnit }) and
OpenGeometry.exportIfcBody(node, { modelUnit }) reach it from JavaScript.
Metre bodies export exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mintlify

mintlify Bot commented Nov 17, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 067bd7d.

Approve preview

@Basnederveen

Copy link
Copy Markdown
Author

Option 1 is in 067bd7d, after a merge of 3.0.1 main. Details are in the two threads.

npm run check without CI=true (Windows x86_64):

  • opengeometry Rust: fmt and clippy are clean. Tests give 947 passed, 6 failed, 1 ignored. The 6 failures are the same six stored-fixture and digest comparisons as last time, which this PR doesn't touch.
  • Every other step passes except build-example (the vite path error on Windows) and typecheck, which only fails on the local shell patch that verify.mjs needs to run on Windows. Without that patch, npm run typecheck passes.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants