Skip to content

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

Hole: a countersink cuts nothing outside its diameter above the face (#5041) (#8261)

semmelrinde861fb8ad56ff
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index f0159c7370..d6bcc46624 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -5053,12 +5053,22 @@ fn hole_tools_and_prisms(
if !(rc > r && half > 1e-3 && half < std::f64::consts::FRAC_PI_2) {
return Err(DocError::Invalid("the countersink must be wider than the hole".into()));
}
- // Cone from above the face to just inside the hole radius, then the hole.
- let r_top = rc + top * half.tan();
+ // One revolved tool: the cone from just above the face to just inside the hole
+ // radius, and above it a cylinder of the countersink's own diameter up to the run-on
+ // height. A cone started at the run-on height is wider than the countersink above
+ // the face and notches a wall or step next to the hole (#5041). The cone is the
+ // profile's first segment, so its face keeps the name `csink:side:0`.
+ let lift = top / 20.0;
+ let r_rim = rc + lift * half.tan();
let r_end = r * 0.9;
- let len = (r_top - r_end) / half.tan();
- let top_plane = plane.offset(top);
- tools.push((crate::lineage::part_tool(kernel::extrude_tapered(&top_plane, &disc(r_top), len, -1.0, -half)?, "csink"), None));
+ let low = lift - (r_rim - r_end) / half.tan();
+ let up = -dir;
+ let rp = Plane::new(*position, up.any_perp(), up).ok_or_else(|| DocError::Invalid("hole axis".into()))?;
+ let pts = [Vec2::new(r_rim, lift), Vec2::new(r_end, low), Vec2::new(0.0, low), Vec2::new(0.0, top), Vec2::new(r_rim, top)];
+ let region = Region2 { outer: solidcraft_geom::Loop2::polygon(&pts), holes: vec![] };
+ for tool in kernel::revolve(&rp, &[region], Vec2::ZERO, Vec2::Y, std::f64::consts::TAU)? {
+ tools.push((crate::lineage::part_tool(tool, "csink"), None));
+ }
tools.extend(bore(tip_angle.as_ref())?);
}
}
diff --git a/crates/engine/src/hole_matrix_tests.rs b/crates/engine/src/hole_matrix_tests.rs
index 8c30b0ada3..e53b6f90a6 100644
--- a/crates/engine/src/hole_matrix_tests.rs
+++ b/crates/engine/src/hole_matrix_tests.rs
@@ -802,6 +802,28 @@ fn hole_matrix() {
);
}
+/// #5041: a countersink cuts nothing outside its diameter above the face, so a wall standing
+/// just past its rim keeps its face.
+#[test]
+fn a_countersink_next_to_a_wall_leaves_the_wall_whole() {
+ let mut s = Session::default();
+ run(&mut s, "solid.box", json!({"length": 40, "width": 40, "height": 8, "corner": [0, 0, 0], "name": "Plate"})).unwrap();
+ run(&mut s, "solid.box", json!({"length": 40, "width": 10, "height": 30, "corner": [0, 30, 8], "operation": "join", "name": "Wall"})).unwrap();
+ let (before, _) = measure(&mut s).unwrap();
+ // A Ø13.7 countersink whose rim ends 0.15 mm short of the wall.
+ let p = json!({"position": [20, 23, 8], "direction": [0, 0, -1], "diameter": 6.4, "depth": 8, "type": "countersink", "cs_diameter": 13.7, "cs_angle": 90});
+ run(&mut s, "solid.hole", p).unwrap();
+ assert!(solid_at(&s, Vec3::new(20.0, 30.05, 8.3)), "the wall above the plate is notched");
+ assert!(solid_at(&s, Vec3::new(20.0, 30.05, 8.02)));
+ assert!(!solid_at(&s, Vec3::new(20.0, 29.0, 7.9)), "the countersink reaches its rim");
+ // Exactly the countersink and the clearance hole are taken: the frustum from Ø13.7 to the
+ // hole, and the rest of the hole down through the plate.
+ let r = 3.2;
+ let (cs, h) = csink(13.7 / 2.0, r);
+ let (after, _) = measure(&mut s).unwrap();
+ assert!(close(before - after, cs + cyl(r, 8.0 - h), cs), "{} taken, want {}", before - after, cs + cyl(r, 8.0 - h));
+}
+
#[test]
fn recessed_drill_point_geometry_roundtrip_preview_and_undo() {
for kind in ["counterbore", "countersink"] {