diff --git a/crates/goldens/expected/known_failing.json b/crates/goldens/expected/known_failing.json index f0e2d105cf..94e044e800 100644 --- a/crates/goldens/expected/known_failing.json +++ b/crates/goldens/expected/known_failing.json @@ -1,5 +1,9 @@ { "blend.fillet_executive_p3": { "real-box-high-corner-setback-eight": "tangency-labs/solidcore#2933: the N x N corner patch meets the three rounds up to 4.35 degrees off tangent; edge tolerance 5.17e-5" + }, + "primitive.primitive_creation_p2": { + "gen0092": "tangency-labs/solidcore#2794: a circle of radius 1e-3 swept along two 1e-2 legs at a right angle returns success, but the body fails check_brep level 2 (vertex 1.8284271e-3 off its faces); a refusal or the valid body of volume 6.2832e-8 is right; fix in #2840", + "gen0189": "tangency-labs/solidcore#2794: the same input as gen0092 (circle of radius 1e-3 swept along two 1e-2 legs at a right angle) returns success with an invalid body (vertex 1.8284271e-3 off its faces); fix in #2840" } } diff --git a/crates/goldens/expected/primitive.primitive_creation_p2.jsonl b/crates/goldens/expected/primitive.primitive_creation_p2.jsonl index e1502d09b7..09ddbcde25 100644 --- a/crates/goldens/expected/primitive.primitive_creation_p2.jsonl +++ b/crates/goldens/expected/primitive.primitive_creation_p2.jsonl @@ -95,7 +95,6 @@ {"case":"gen0089","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,1.0,1.0]}} {"case":"gen0090","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0091","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} -{"case":"gen0092","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0]}} {"case":"gen0093","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0094","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0095","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} @@ -192,7 +191,6 @@ {"case":"gen0186","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0187","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0188","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1007.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} -{"case":"gen0189","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0]}} {"case":"gen0190","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0191","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} {"case":"gen0192","deferred":null,"error":null,"ints":{},"topology":null,"values":{"record":[1001.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]}} diff --git a/crates/solidcore/tests/issue_2794_planar_path_mitred_elbow.rs b/crates/solidcore/tests/issue_2794_planar_path_mitred_elbow.rs new file mode 100644 index 0000000000..d001d25dec --- /dev/null +++ b/crates/solidcore/tests/issue_2794_planar_path_mitred_elbow.rs @@ -0,0 +1,72 @@ +//! #2794: a circle swept along two perpendicular lines (the shape of difftest +//! `primitive.primitive_creation_p2` `gen0092`/`gen0189`, 100 times larger: those have radius 1e-3, +//! legs 1e-2, and their body is not valid, see `plan/findings/`). The elbow's net is its +//! definition exactly and the mitre's union succeeds (the fitted net failed it with status 1001). +//! The result is checked directly: a valid closed body of the closed-form volume. +#![allow(clippy::unwrap_used, clippy::indexing_slicing)] +use solidcore::curve::curve::Curve; +use solidcore::geom::attribute::{AttributeStore, ObjectKey}; +use solidcore::geom::axis2_placement::Axis2Placement; +use solidcore::mass::integrator::properties::{brep_volume, PropertyAttributes}; +use solidcore::math::Vec3; +use solidcore::nurbs::b_spline_curve::p1::{BSplineCurve, NurbCircleParam}; +use solidcore::primitive::primitive_creation::{model::PrimitiveModel, p1::PrimitiveCreation}; +use solidcore::topology::brep::validation::{check_brep, CheckLevel}; +use solidcore::Kernel; + +fn elbow(k: &mut Kernel, radius: f64, leg: f64, tol: f64) -> solidcore::Brep { + let profile = Curve::from( + BSplineCurve::create_circle_segment( + 3, + &Axis2Placement::new(Vec3::ZERO, Vec3::X, Vec3::Y), + radius, + 0., + 360., + NurbCircleParam::Quadratic, + ) + .unwrap(), + ); + let up = Vec3::new(0., 0., leg); + let path = |a, b| Curve::from(BSplineCurve::create_line_segment(3, a, b).unwrap()); + let paths = [path(Vec3::ZERO, up), path(up, Vec3::new(leg, 0., leg))]; + let (_, mut b) = PrimitiveModel::build_new(k, |_, model| { + let id = PrimitiveCreation::create_sweep_along_planar_path( + model, + PrimitiveModel::MAIN, + &[profile], + &paths, + tol, + true, + true, + true, + )?; + model.take_brep(id) + }) + .unwrap(); + b.refresh_cached_topology(); + b +} + +#[test] +fn elbow_of_two_lines_is_a_valid_body_of_the_closed_form_volume() { + let (radius, leg) = (1e-1, 1.); + let mut k = Kernel::default(); + let mut b = elbow(&mut k, radius, leg, 1e-7); + let check = check_brep(&mut k, &mut b, CheckLevel::Level2).unwrap(); + assert!(check.is_valid(), "{:?}", check.lines()); + let store = AttributeStore::default(); + let v = brep_volume( + &k, + &mut b, + 1e-12, + &PropertyAttributes { + store: &store, + key_of: &|_| ObjectKey(0), + }, + ) + .unwrap(); + // the mitre plane passes through the bend's centre point, so the volume is the straight + // pipe of the summed leg lengths + let exact = std::f64::consts::PI * radius * radius * 2. * leg; + assert!((v - exact).abs() < exact * 1e-4, "{v} != {exact}"); +} diff --git a/plan/findings/primitive.primitive_creation_p2--exact-net-elbow-unites-into-an-invalid-body-below-radius-0-1.md b/plan/findings/primitive.primitive_creation_p2--exact-net-elbow-unites-into-an-invalid-body-below-radius-0-1.md new file mode 100644 index 0000000000..8eae2e719b --- /dev/null +++ b/plan/findings/primitive.primitive_creation_p2--exact-net-elbow-unites-into-an-invalid-body-below-radius-0-1.md @@ -0,0 +1,43 @@ +# primitive.primitive_creation_p2: the exact net lets a small elbow's union succeed with an invalid body (2026-11-05) + +Cases `gen0092` (seed 11582637188108233846) and `gen0189` (seed 11582637188108233943), the same +input: op 9, `CreateSweepAlongPlanarPath` of a circle of radius 1e-3 (centre at the origin, +normal +Z) along two lines (0,0,0)-(0,0,1e-2) and (0,0,1e-2)-(1e-2,0,1e-2), tolerance 1e-7, +both caps, profile moved to the path. Part of #2794. + +Measured on main with #2740 (main's difftest sweep, `difftest-sweep-reports`): + +| field | C++ | Rust | +|---|---|---| +| `values.record[0]` (status) | 1001 | 0 | +| `values.record[2]` (`DoingBoolean` left set) | 1 | 0 | +| `values.record[10]` (a B-rep returned) | 0 | 1 | + +Before #2740 both cases passed with both sides failing alike: the C++ and the pre-#2740 Rust return 1001 from +the union of the two mitred pieces (`boolean::merge::p3`, `SM_ERR`), leaving the flag set. #2740 +builds a path sweep's net from its definition (`PathMotion::create_exact`) instead of fitting it. +Reproduced the old result by making `create_curve_sweep` keep the fitted net (the `.filter` on the +exact net false): `Upstream { operation: "boolean::merge::p3", code: 1001 }`, the C++'s status. + +**Solidcore's success is not a correct body.** `check_brep` (level 2) on the result: + +| radius | leg | tolerance | failed checks | +|---|---|---|---| +| 1e-1 | 1 | 1e-7, 1e-3 | 0 | +| 1e-1 | 1e-1 | 1e-7 | 0 | +| 1e-2 | 1e-1 | 1e-5, 1e-3 | 14 (edge/edge gaps of 9.4e-3, `SmBrep::Test #61`, `#82`) | +| 1e-3 | 1 | 1e-7 | 2 | +| 1e-3 | 1e-2 | 1e-7 | 2: `SmVertex::Test #1 Bad Vertex Gap`, offset 1.8284271e-3 = r(2 sqrt 2 - 1), tolerance 2e-5 | +| 1e-3 | 1e-2 | 1e-3 | 5 | + +The leg does not matter, the radius does: from radius 0.1 the elbow is a valid body of volume +pi r^2 (leg1 + leg2) (test `issue_2794_planar_path_mitred_elbow`); at 1e-2 and below the union +succeeds and leaves vertices off their faces by the order of the radius. So the exact net removes +the failure that made the C++ and the old path refuse, and shows the defect behind it: the mitre +at a profile this small (50 times the kernel's 2e-5 and less). Not traced; the fixed 0.1 +reference offsets in the mitre trim (`planar_path.rs`, `before[0] + (-before[1] * 0.1)`, upstream's) +are not the cause alone, since a leg of 1 fails the same. + +Solidcore returns an invalid body where the C++ refused. +Both cases are listed in `crates/goldens/expected/known_failing.json` (no golden line) until the small-profile mitre is fixed (the correct answer for +radius 1e-3 is the valid body of volume pi r^2 2 leg = 6.2832e-8, or a refusal).