Repository navigation
feat(exchange): export_step_in for bodies in a unit other than metres - #35
Basnederveen wants to merge 5 commits into
Conversation
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
| export_step_in(brep, "metre", unit) | ||
| } | ||
|
|
||
| pub fn export_step_in( |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Per export.
export_ifc_bodytakes the model unit too and converts to metres through theplaced(input, conversion, scale)call it already makes (it passes1.0today).geometric_toleranceandexchange_error_boundare scaled the same way, solength_unit: "metre"holds for any body. - 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.
There was a problem hiding this comment.
Let’s go with option 1 in this PR.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Let's go with option 1.
There was a problem hiding this comment.
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>
|
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
|
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>
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
|
Option 1 is in 067bd7d, after a merge of 3.0.1 main. Details are in the two threads.
|
What
export_steptakes 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 withmodel_unit = "metre".InvalidGeometrytoo.export_bodiesgets the model unit as a parameter.StepOptionshasmodelUnit(default"metre"), soOpenGeometry.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 throughplaced, with the geometric tolerance, exchange error bound and fitting budget scaled alike, solength_unit: "metre"holds for a millimetre body.export_ifc_bodydelegates with"metre".WorldGraph::export_ifc_body(og_id, model_unit)andOpenGeometry.exportIfcBody(node, { modelUnit })pass it through.Scalelives inexchange/unit.rs, shared by both exports. An unknown model unit isInvalidParameterin the world graph and in JavaScript."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::testshas 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 theSI_UNITprefix), 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 checkwithoutCI=trueon 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 exceptbuild-example, which hits a Windows path error in vite. Details are in the review reply.Files
main/opengeometry/src/exchange/step/mod.rsmain/opengeometry/src/exchange/unit.rsmain/opengeometry/src/exchange/step/tests.rsmain/opengeometry/src/exchange/mod.rsmain/opengeometry/src/exchange/ifc_body/mod.rsmain/opengeometry/src/world_graph/export.rsmain/opengeometry/src/world_graph/export_ifc.rsmain/opengeometry/src/bindings/world_graph/ifc_body.rsmain/opengeometry-three/src/export/export-step.ts,ifc-body.ts,opengeometry.tstests/step_oracle/ifc_body.rs,placed.rs,opengeometry-three/tests/node/export-step.test.mjs,ifc-body.test.mjsREADME.md,docs/opengeometry/api/export.mdx,guides/export-step.mdx,guides/ifc-exchange-body.mdx🤖 Generated with Claude Code