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 <noreply@anthropic.com>
This commit is contained in:
jb69
2026-10-20 11:43:14 +00:00
committed by GitHub
parent ebada963a4
commit e44dd4ff9e
2 changed files with 27 additions and 0 deletions
@@ -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());
}
+12
View File
@@ -1967,6 +1967,18 @@ fn loft_reversed(sections: &[(Plane, Loop2)]) -> Result<bool> {
// 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);