From c5b637600c6355dca499ebd80530ac09a729e465 Mon Sep 17 00:00:00 2001 From: rlartot <94693724+rlartot@users.noreply.github.com> Date: Tue, 20 Oct 2026 11:21:32 +0000 Subject: [PATCH] Chamfer: one pick follows a straight edge's curved tangent chain at any part size (#2672) (#3295) * claim: #2672 Co-Authored-By: Claude Sonnet 5.5 * Chamfer: one pick follows a straight edge's curved tangent chain at any size (#2672) chamfer_tool built a single-edge cutter for a straight edge even when the edge runs on tangentially into an arc (a slot side into its end). The cutter's overshoot (max(2*distance, 1% of the part size)) is probed for material beyond the edge ends; on a small part the probe hit the arc's material and the cutter was refused, so the blend followed the whole chain. Past a bounding-box diagonal of about 200 mm the overshoot cleared the arc, the cutter was accepted, and only the straight edge was chamfered, silently. A straight edge whose smooth chain contains a curved edge no longer gets a cutter; it takes the chain-following blend, as at small sizes and as a fillet does. Co-Authored-By: Claude Sonnet 5.5 --------- Co-authored-by: Claude Sonnet 5.5 --- crates/kernel/src/blend.rs | 15 ++++++++- crates/kernel/tests/chamfer_curved_holder.rs | 32 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs index 5d8b87b00..cf85cbf82 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 { - 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 00e715efc..b1616a372 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"); + } +}