Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Loft: refuse consecutive sections that lie in one plane (#3412)

jb69e44dd4ff9e33
diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rs
index ee30cf0c3b..ced142f4a2 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 1595f050e7..654bdee2c4 100644
--- a/crates/kernel/src/build.rs
+++ b/crates/kernel/src/build.rs
@@ -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);