Commit b8a8206
authored
Route non-rectangular openings through CSG to prevent over-cutting (#575)
* fix(geometry): cut non-box openings with CSG instead of AABB clipping
Fixes #547 "cutting voids sometimes misses the right shape".
`classify_openings` used `vertex_count > 100` as the only signal for
falling back from AABB clipping to CSG. Low-tessellation openings whose
profile is NOT a rectangle — trapezoids, chamfered frames, beveled
rectangles, coarse arcs — have <= 100 vertices and an axis-aligned
extrusion direction, so they slipped into the `Rectangular` path and
got cut as their axis-aligned bounding box. The bounding box reaches
beyond the actual opening (e.g. a trapezoid's wide end extends past its
narrow end), so the wall lost material where the opening did not exist
— visible as oversized voids around some windows and doors.
Add `mesh_fills_axis_aligned_box`: every vertex must sit on one of the
AABB faces. Boxes pass (by definition); cylinders, arches, tilted
boxes, trapezoids don't. `classify_openings` now runs this check on
each representation item's world-space mesh and drops items that fail
into `NonRectangular` (CSG) even when the vertex count is low.
Per-item routing matters because a single `IfcOpeningElement` can
carry several items (a box main opening + a rounded sleeve, for
instance); we classify each item independently rather than
all-or-nothing on the merged mesh.
Ships a regression test with a trapezoidal `IfcArbitraryClosedProfileDef`
opening that checks the wall retains boundary vertices at the
trapezoid's narrow edge — vertices an AABB cut would have removed.
* chore(wasm): rebuild ifc-lite.wasm with non-box opening CSG fix
Regenerate packages/wasm/pkg/ so the viewer picks up the
`classify_openings` fix from the previous commit. Source changes only —
no further code changes.
* fix(geometry): accept tessellated boxes in mesh_fills_axis_aligned_box
Addresses Codex P1 review comment on PR: the per-vertex
"every coordinate at an AABB corner" check rejected axis-aligned box
openings that happened to carry extra collinear vertices on their
faces or edges (e.g. a rectangular IfcArbitraryClosedProfileDef
modelled with polyline midpoints). Those openings got misrouted to
the CSG path, and `apply_void_context` caps CSG at
`MAX_CSG_OPERATIONS = 10` — so models with many such windows left
later openings silently uncut.
Switch the check from "every vertex at an AABB corner" to "every
triangle lies flat on an AABB face". A triangle lies on a face when
all three vertices share the same min or max value on some axis.
Boxes pass by construction; tessellated boxes pass because the extra
vertices still sit on the face plane. Cylinders, arches, trapezoids,
and rotated boxes still fail because their side triangles span the
interior.
Adds a regression test (`many_tessellated_box_openings_are_all_cut`)
that builds a wall with 15 tessellated-rectangle openings and
asserts every opening produced a hole — the test fails on the old
strict check because openings 11..=14 never got cut.
* chore(wasm): rebuild ifc-lite.wasm with tessellated-box classification
Regenerate packages/wasm/pkg/ so the viewer picks up the relaxed
box detector. Source changes only.
* fix(geometry): reject trapezoid extrusions in is_rectangular_box_mesh
The discriminator added in #640 (`is_rectangular_box_mesh`) returns true
for a trapezoid extrusion. After anti-parallel merging, a trapezoid has
exactly 3 face-normal axes (front/back, top/bottom, slanted-sides which
merge into one), but two of those axes are not perpendicular. The AABB
cutter then over-cuts the host wall — exactly the regression #547
describes for low-tessellation non-rectangular openings.
Add a mutual-orthogonality check between the 3 axes (dot tolerance 0.02
matching the existing 0.98 anti-parallel merge tolerance). Trapezoids
and other non-orthogonal 3-axis shapes now route to NonRectangular CSG.
Tests added (in addition to the end-to-end regression in csg_void_test):
- `test_rectangular_box_detector_rejects_trapezoid_extrusion` — direct
unit test on a hand-built trapezoid mesh
- `test_rectangular_box_detector_accepts_rotated_box` — confirms the
orthogonality check doesn't reject 45°-rotated boxes (which still have
3 mutually orthogonal face-normal axes)
Rebuild WASM artifacts (single-thread 1080 KB, threaded 1139 KB; both
under their 1100/1300 KB budgets).
Closes #547.1 parent 85e015e commit b8a8206
5 files changed
Lines changed: 394 additions & 0 deletions
File tree
- .changeset
- packages
- wasm-threaded/pkg
- wasm/pkg
- rust/geometry
- src/router
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Binary file not shown.
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
391 | 406 | | |
392 | 407 | | |
393 | 408 | | |
| |||
2696 | 2711 | | |
2697 | 2712 | | |
2698 | 2713 | | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
| 2731 | + | |
| 2732 | + | |
| 2733 | + | |
| 2734 | + | |
| 2735 | + | |
| 2736 | + | |
| 2737 | + | |
| 2738 | + | |
| 2739 | + | |
| 2740 | + | |
| 2741 | + | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
2699 | 2783 | | |
2700 | 2784 | | |
2701 | 2785 | | |
| |||
0 commit comments