Skip to content

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

Chamfer: one pick follows a straight edge's curved tangent chain at any part size (#2672) (#3295)

rlartotc5b637600c63
diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs
index 5d8b87b00e..cf85cbf822 100644
--- a/crates/kernel/src/blend.rs
+++ b/crates/kernel/src/blend.rs
@@ -2430,7 +2430,20 @@ impl Cutter {
}
pub(crate) fn chamfer_tool(cur: &Body, p: Vec3, s: f64, k: usize) -> Result<Cutter> {
- chamfer_tool_sides(cur, p, s, None, k)
+ let tool = chamfer_tool_sides(cur, p, s, None, k)?;
+ // A straight edge that runs on into a curved one (a slot's side into its end arc) is one
+ // tangent chain: the cutter would chamfer the straight part only, and whether its overshoot
+ // reaches the next edge's material depends on the size of the part (#2672). The blend
+ // follows the whole chain, as it does for a fillet.
+ let all = Body::unique_edges(&cur.solid);
+ let curved_chain = all
+ .get(tool.edge)
+ .and_then(|e| smooth_chain(&cur.solid, e))
+ .is_some_and(|ids| all.iter().any(|e| ids.contains(&e.id()) && !matches!(e.curve(), mt::Curve::Line(_))));
+ if curved_chain {
+ return Err(unsupported("a straight edge continued by a curved one is chamfered with its chain"));
+ }
+ Ok(tool)
}
/// A straight plane/cylinder edge has one constant chamfer section. Sweep its cutter
diff --git a/crates/kernel/tests/chamfer_curved_holder.rs b/crates/kernel/tests/chamfer_curved_holder.rs
index 00e715efcc..b1616a372e 100644
--- a/crates/kernel/tests/chamfer_curved_holder.rs
+++ b/crates/kernel/tests/chamfer_curved_holder.rs
@@ -88,3 +88,35 @@ fn a_chamfer_that_uses_up_the_holder_top_is_refused() {
let body = holder();
assert!(chamfer(&body, &[Vec3::new(10.0, 10.0, 60.0)], 30.0).is_err());
}
+
+/// A plate of side `plate` with a 50 x 10 mm stadium boss, 10 mm tall, joined on top.
+fn plate_with_stadium(plate: f64) -> Body {
+ let base = solidcraft_kernel::box_solid(Vec3::new(-plate / 2.0, -plate / 2.0, 0.0), Vec3::new(plate / 2.0, plate / 2.0, 10.0)).unwrap();
+ let segs = vec![
+ Seg2::Line { a: Vec2::new(-20.0, -5.0), b: Vec2::new(20.0, -5.0) },
+ Seg2::Arc { center: Vec2::new(20.0, 0.0), radius: 5.0, start: -PI / 2.0, sweep: PI },
+ Seg2::Line { a: Vec2::new(20.0, 5.0), b: Vec2::new(-20.0, 5.0) },
+ Seg2::Arc { center: Vec2::new(-20.0, 0.0), radius: 5.0, start: PI / 2.0, sweep: PI },
+ ];
+ let plane = Plane::XY.offset(10.0);
+ let boss = extrude(&plane, &[Region2 { outer: Loop2 { segs }, holes: vec![] }], 0.0, 10.0).unwrap().pop().unwrap();
+ boolean(&base, &boss, BoolOp::Union).unwrap().unwrap()
+}
+
+/// #2672: one pick on a straight edge that runs on into an arc chamfers the whole tangent
+/// chain, whatever the size of the part (it used to stop at the straight edge once the
+/// bounding-box diagonal passed about 200 mm).
+#[test]
+fn one_chamfer_pick_follows_the_tangent_chain_at_any_part_size() {
+ for plate in [140.0, 145.0, 250.0] {
+ let body = plate_with_stadium(plate);
+ let made = chamfer(&body, &[Vec3::new(0.0, 5.0, 20.0)], 1.0).unwrap();
+ assert!(made.validity().is_empty(), "{:?}", made.validity());
+ // Two straight edges (c^2/2 * 40 each) and both end arcs (Pappus, c^2/2 * 2 pi (R - c/3)).
+ let expected = 40.0 + 0.5 * 2.0 * PI * (5.0 - 1.0 / 3.0);
+ let volume = |b: &Body| b.tessellate(1e-4).unwrap().measure().volume;
+ let removed = volume(&body) - volume(&made);
+ assert!((removed - expected).abs() < 0.3, "plate {plate}: removed {removed}, expected {expected}");
+ assert_eq!(made.face_count(), body.face_count() + 4, "plate {plate}: one chamfer face per rim edge");
+ }
+}