From e44dd4ff9e33a4455388f801dd050c3168a3e09b Mon Sep 17 00:00:00 2001 From: jb69 Date: Tue, 20 Oct 2026 11:43:14 +0000 Subject: [PATCH] Loft: refuse consecutive sections that lie in one plane (#3412) A loft through two sketches on the same plane built a flat body of zero volume and reported success, so the mistake surfaced later, if at all (a measure of 0, or a boolean that did nothing). `loft_wires` now checks each pair of consecutive sections: parallel planes with the second section's centroid in the first's plane are refused with "loft sections i and i+1 lie in the same plane (no volume between them)". The tolerance scales with the section's distance from its plane's origin. Test: two circles on XY; the loft fails with that message and leaves no body. Co-authored-by: Claude Opus 5.5 --- crates/engine/src/cmd/features_more_tests.rs | 15 +++++++++++++++ crates/kernel/src/build.rs | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rs index ee30cf0c3..ced142f4a 100644 --- a/crates/engine/src/cmd/features_more_tests.rs +++ b/crates/engine/src/cmd/features_more_tests.rs @@ -1552,3 +1552,18 @@ fn text_cut_through_a_large_plate_is_one_exact_boolean() { // material in either plate (measured on meshes, which are coarser on the larger one). assert!(small > 10.0 && rel(large, small) < 5e-2, "{small} {large}"); } + +/// A loft between two sections in one plane is refused (it used to build a flat body of zero +/// volume and report success). +#[test] +fn loft_through_coplanar_sections_is_refused() { + let mut s = Session::default(); + for name in ["A", "B"] { + run(&mut s, "sketch.create", json!({"plane": "XY", "name": name})); + run(&mut s, "sketch.circle.center", json!({"center": [0, 0], "radius": 10})); + run(&mut s, "sketch.finish", json!({})); + } + let e = s.execute("solid.loft", &json!({"sections": [{"sketch": "A"}, {"sketch": "B"}]})).unwrap_err().to_string(); + assert!(e.contains("same plane"), "{e}"); + assert!(s.model.state().bodies.is_empty()); +} diff --git a/crates/kernel/src/build.rs b/crates/kernel/src/build.rs index 1595f050e..654bdee2c 100644 --- a/crates/kernel/src/build.rs +++ b/crates/kernel/src/build.rs @@ -1967,6 +1967,18 @@ fn loft_reversed(sections: &[(Plane, Loop2)]) -> Result { // loft touches the body along an edge: an internal panic, or "shell not oriented and // closed"). let centre = |(p, l): &(Plane, Loop2)| p.to_world(l.centroid()); + // Two consecutive sections in one plane span no volume between them: a loft through them + // used to build a flat, zero-volume body and report success. + for (i, w) in sections.windows(2).enumerate() { + let (a, b) = (&w[0], &w[1]); + let n = a.0.normal(); + let size = (centre(a) - a.0.origin).len().max((centre(b) - b.0.origin).len()).max(1.0); + let parallel = n.cross(b.0.normal()).len() < 1e-9; + let in_plane = (centre(b) - centre(a)).dot(n).abs() < 1e-9 * size; + if parallel && in_plane { + return Err(KernelError::Invalid(format!("loft sections {} and {} lie in the same plane (no volume between them)", i + 1, i + 2))); + } + } let (Some(first), Some(last)) = (sections.first(), sections.last()) else { return Err(KernelError::Invalid("no sections".into())) }; let step = centre(last) - centre(first); let big = [step.x, step.y, step.z].into_iter().max_by(|a, b| a.abs().total_cmp(&b.abs())).unwrap_or(0.0);