Skip to content

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

Hole: on a cone or torus face, drill along the face's normal, not a facet's (#10698) (#10885)

semmelrinde9b431fea162b
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index 9ee632930a..eba1de3491 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -3986,6 +3986,18 @@ fn faces_through(st: &ModelState, p: Vec3, reach: f64) -> Vec<(f64, Vec3, Option
((v - axis * v.dot(axis)).normalized(), None)
}
Some(kernel::FaceSurface::Sphere { center, .. }) => ((p - center).normalized(), None),
+ // Square to the line through the apex, not the nearest facet's normal (#10698).
+ Some(kernel::FaceSurface::Cone { apex, axis, half_angle }) => {
+ let v = p - apex;
+ let out = (v - axis * v.dot(axis)).normalized();
+ (out.and_then(|u| (u * half_angle.cos() - axis * half_angle.sin()).normalized()), None)
+ }
+ // Away from the nearest point of the ring the tube goes round.
+ Some(kernel::FaceSurface::Torus { center, axis, major, .. }) => {
+ let v = p - center;
+ let ring = (v - axis * v.dot(axis)).normalized().map(|u| center + u * major);
+ (ring.and_then(|q| (p - q).normalized()), None)
+ }
_ => (None, None),
};
let n = match exact {
diff --git a/crates/engine/src/hole_matrix_tests.rs b/crates/engine/src/hole_matrix_tests.rs
index 5898647ee4..8c30b0ada3 100644
--- a/crates/engine/src/hole_matrix_tests.rs
+++ b/crates/engine/src/hole_matrix_tests.rs
@@ -856,3 +856,17 @@ fn recessed_drill_point_through_and_exact_shoulder_keep_the_existing_exit() {
}
}
}
+
+/// A hole on the side of a cone, given no direction, drills along the cone's normal there, not
+/// the nearest mesh facet's, which leaned it up to 2.6° sideways (#10698).
+#[test]
+fn a_hole_on_a_cones_side_drills_along_its_normal() {
+ let mut s = Session::default();
+ run(&mut s, "solid.cone", json!({"radius": 15, "height": 20, "body_name": "Cone"})).unwrap();
+ // The side is r = 15 (1 - z / 20): at (7.5, 0, 10) the outward normal is (0.8, 0, 0.6).
+ run(&mut s, "solid.hole", json!({"position": [7.5, 0, 10], "diameter": 4, "depth": 4, "name": "H"})).unwrap();
+ let f = s.doc.find_feature("H").unwrap();
+ let solidcraft_doc::FeatureKind::Hole { direction, .. } = &f.kind else { panic!("not a hole") };
+ let d = direction.0;
+ assert!((d.x + 0.8).abs() < 1e-6 && d.y.abs() < 1e-6 && (d.z + 0.6).abs() < 1e-6, "{d:?}");
+}