Skip to content

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

Wave 420/509: Tests: the knife-edge R2 fillet is checked once, in closed form (and 3 more)

jyviko54c3b1e90e26
diff --git a/crates/engine/src/cmd/features_more_tests.rs b/crates/engine/src/cmd/features_more_tests.rs
index 70af3e8168..21c7d8189d 100644
--- a/crates/engine/src/cmd/features_more_tests.rs
+++ b/crates/engine/src/cmd/features_more_tests.rs
@@ -1725,38 +1725,6 @@ fn fillet_straight_edges_that_end_at_the_arc_wall() {
}
}
-/// The vertical knife edge at the tip (the arc and the back face meeting at no angle) rounds to
-/// the ball 2 from both, about 13 back from the tip: the cusp beyond the ball, on the tip's side
-/// of its contacts, all the way up.
-#[test]
-fn fillet_the_knife_edge_at_the_tip() {
- let cx = 62.166666666666664;
- let (kx, ky) = (cx - (23.0f64 * 23.0 - 19.0 * 19.0).sqrt(), -2.0);
- let (hx, hy) = (0.002, 0.0005);
- let mut area = 0.0;
- let mut x = kx + hx / 2.0;
- while x < cx {
- let lo = -21.0 + (441.0 - (x - cx) * (x - cx)).max(0.0).sqrt();
- for j in 0..((0.0 - lo) / hy).ceil() as usize {
- let (y0, y1) = (lo + j as f64 * hy, (lo + (j + 1) as f64 * hy).min(0.0));
- let y = (y0 + y1) * 0.5;
- let a = (y - ky).atan2(x - kx);
- if (x - kx).hypot(y - ky) > 2.0 && a >= (-21.0 - ky).atan2(cx - kx) {
- area += (y1 - y0) * hx;
- }
- }
- x += hx;
- }
- let mut s = knife_edge_part();
- let before = planned(&s);
- run(&mut s, "solid.fillet", json!({"edges": [[cx, 0.0, 5.0]], "radius": 2}));
- let after = planned(&s);
- assert!(rel(before - after, area * 10.0) < 5e-4, "removed {} vs {}", before - after, area * 10.0);
- let mut s = knife_edge_part();
- run(&mut s, "solid.chamfer", json!({"edges": [[cx, 0.0, 5.0]], "distance": 2}));
- assert!(before - planned(&s) > before - after, "the chamfer takes the ball's bulge off too");
-}
-
/// Rounds of the edges at the arc's top front corner, two or all three together (r 2): they meet
/// in creases (with all three, a piece of sphere fills the corner). Each set takes off its rounds
/// alone, less what each alone takes in a box about the corner, plus what they take there
diff --git a/crates/engine/src/tests/robustness.rs b/crates/engine/src/tests/robustness.rs
index ca302cfc8a..5b431cd769 100644
--- a/crates/engine/src/tests/robustness.rs
+++ b/crates/engine/src/tests/robustness.rs
@@ -57,8 +57,12 @@ fn shell_with_a_hole_through_a_curved_side() {
/// A cut whose end only touches the plate's arc side (#897, robustness seed 14): the end lies
/// tangent to the arc at its apex, the direct boolean fails, and the last-resort nudge used to
/// push the end into the arc, leaving a sliver of it a tenth of a millimetre wide that a shell
-/// then couldn't offset. The nudge the other way parts them: the same faces as a cut clear of
-/// the apex, and seed 14 shells and fillets again.
+/// then couldn't offset. The touching cut must make the same part as a cut 0.1 clear of the
+/// apex (x = −10.1 .. 7.4 instead of −10 .. 7.5), less the hole's last 0.1 mm: the arc (centre
+/// (0, 10), r 10) reaches x = −10 only at y = 10, so both cuts open the same patch of it, and
+/// the slice x = 7.4 .. 7.5 of the r 5 hole lies wholly inside the plate. The touching cut has
+/// π 5² 0.1 less volume and 2π 5 0.1 more area (the longer hole wall; the floor disc is the
+/// same); a sliver left on the arc adds about a square millimetre of faces.
#[test]
fn cut_whose_end_touches_an_arc_side_leaves_no_sliver() {
let plate = |x: f64| {
@@ -72,11 +76,27 @@ fn cut_whose_end_touches_an_arc_side_leaves_no_sliver() {
]))
};
let (touching, clear) = (plate(-10.0), plate(-10.1));
- let faces = |s: &Session| s.model.state().bodies.iter().map(|b| b.body.face_count()).sum::<usize>();
- assert_eq!(faces(&touching), faces(&clear), "a sliver face was left where the cut's end touches the arc");
- let r = fuzz::run(14, 8);
- let kinds: Vec<&str> = r.steps.iter().map(|s| s.kind).collect();
- assert!(r.outcome.kind == "ok" && kinds.contains(&"shell"), "seed 14: {:?} {kinds:?}\n{}", r.outcome, r.script());
+ let area = |s: &Session| s.model.state().bodies.iter().map(|b| solidcraft_kernel::measure(&b.body).map(|m| m.area).unwrap_or(0.0)).sum::<f64>();
+ let dv = total_volume(&clear) - total_volume(&touching);
+ assert!((dv - PI * 25.0 * 0.1).abs() < 1e-4, "volume: clear − touching = {dv}, not π 5² 0.1");
+ let da = area(&touching) - area(&clear);
+ assert!((da - 2.0 * PI * 5.0 * 0.1).abs() < 1e-4, "area: touching − clear = {da}, not 2π 5 0.1: a sliver where the cut's end touches the arc");
+ assert_eq!(touching.model.state().bodies.len(), 1);
+}
+
+/// Robustness seed 14 (#897) as the generator made it: the touching cut above, then a shell
+/// opening the plate's top face (y = 20). Every step builds and the body is a sound solid.
+#[test]
+fn shell_after_a_cut_whose_end_touches_an_arc_side() {
+ script(json!([
+ {"command": "sketch.create", "params": {"plane": "XY"}},
+ {"command": "sketch.line", "params": {"points": [[0, 0], [42.5, 0], [42.5, 20.0], [0, 20.0]]}},
+ {"command": "sketch.arc.three_point", "params": {"end": [0, 0], "start": [0, 20.0], "through": [-10.0, 10.0]}},
+ {"command": "sketch.finish", "params": {}},
+ {"command": "solid.extrude", "params": {"distance": 27.5}},
+ {"command": "solid.cylinder", "params": {"axis": [1.0, 0.0, 0.0], "base": [-10.000000000000002, 12.5, 12.5], "height": 17.5, "operation": "cut", "radius": 5.0}},
+ {"command": "solid.shell", "params": {"faces": [[21.25, 19.999999999999993, 13.749999999999998]], "thickness": 2.0}}
+ ]));
}
/// #827: a hinge barrel joined to a laptop lid through its mounting leaf. The barrel's top lies
@@ -480,18 +500,20 @@ fn planned_volume(s: &Session) -> f64 {
/// #851: the knife edge where the wall runs out has opposite normals on its two faces. It rounds
/// to the ball that fits there and chamfers with the plane through that ball's contacts (the cusp
/// area less the wall's sector and the ball's, or the chord triangle less the wall's segment,
-/// times the 10 mm height).
+/// times the 10 mm height). The ball 2 from both faces sits at (62⅙ − √168, −2); the round takes
+/// 10 (11.5 √168 − 220.5 θ − 2 (π − θ)), θ = acos(19/23), within 5e-4 of it.
#[test]
fn blend_a_knife_edge_where_a_curved_wall_runs_out() {
let knife = json!([[62.1667, 0, 5]]);
- for (command, params, removed) in
- [("solid.fillet", json!({"edges": knife, "radius": 2}), 119.648_812), ("solid.chamfer", json!({"edges": knife, "distance": 2}), 159.236_451)]
- {
+ for (command, params, removed, within) in [
+ ("solid.fillet", json!({"edges": knife, "radius": 2}), 119.648_812, 119.648_812 * 5e-4),
+ ("solid.chamfer", json!({"edges": knife, "distance": 2}), 159.236_451, 0.5),
+ ] {
let mut s = knife_edge_part();
let before = planned_volume(&s);
s.execute(command, &params).unwrap_or_else(|e| panic!("{command}: {e}"));
let after = planned_volume(&s);
- assert!((before - after - removed).abs() < 0.5, "{command}: removed {}, expected {removed}", before - after);
+ assert!((before - after - removed).abs() < within, "{command}: removed {}, expected {removed}", before - after);
for b in &s.model.state().bodies {
assert!(b.body.validity().is_empty(), "{command}: {:?}", b.body.validity());
}
diff --git a/crates/kernel/src/issue_871_tests.rs b/crates/kernel/src/issue_871_tests.rs
index c3555c8e80..8695a15835 100644
--- a/crates/kernel/src/issue_871_tests.rs
+++ b/crates/kernel/src/issue_871_tests.rs
@@ -51,15 +51,16 @@ fn overlapping_rounds_are_refused() {
/// Below half the wall the rounds fit: a closed solid with a round on every edge. Each end face's
/// round section at depth u into the round is the end face's outline moved in by
-/// d = r − √(r² − (r − u)²), each edge parallel to itself: the area less L d (L the outline's
-/// and the window's length together, 2 · 41.5 + 2 · 12.3 = 107.6), plus d² at each of the six
-/// convex corners (two rounds mitred) and less π d² / 4 at each of the six concave ones, the two
-/// shoulders and the window's four corners (two rounds meeting at a concave corner beside an
-/// unpicked sharp edge are swept round it, the owner's ruling of 2026-10-30). Over the round,
-/// ∫ d = r² (1 − π/4) and ∫ d² = r³ (5/3 − π/2), at both ends.
+/// d = r − √(r² − (r − u)²), each edge parallel to itself and every corner mitred (two rounds
+/// meeting at a corner beside an unpicked sharp edge, convex or concave: the owner's ruling of
+/// 2026-10-30): the area less L d (L the outline's and the window's length together,
+/// 2 · 41.5 + 2 · 12.3 = 107.6), plus d² at each of the six convex corners (the two strips
+/// overlap) and less d² at each of the six concave ones (the two shoulders and the window's four
+/// corners: the mitre takes the d × d square beyond both strips). The corner terms cancel, so
+/// both ends remove 2 L ∫ d = 2 L r² (1 − π/4).
#[test]
fn rounds_that_fit_are_closed() {
- use std::f64::consts::{FRAC_PI_2, FRAC_PI_4};
+ use std::f64::consts::FRAC_PI_4;
let p = part();
let r = 0.5;
let b = crate::fillet(&p, &edges(), r).unwrap();
@@ -69,8 +70,7 @@ fn rounds_that_fit_are_closed() {
let part_volume = 14.0 * (21.5 * 10.0 + (top - a) * 10.0 - 5.2 * 7.1);
assert!((crate::measure(&p).unwrap().volume - part_volume).abs() < 1e-9 * part_volume);
let length = 2.0 * (21.5 + 20.0) + 2.0 * (5.2 + 7.1);
- let corners = 6.0 - 6.0 * FRAC_PI_4;
- let removed = 2.0 * (length * r * r * (1.0 - FRAC_PI_4) - corners * r * r * r * (5.0 / 3.0 - FRAC_PI_2));
+ let removed = 2.0 * length * r * r * (1.0 - FRAC_PI_4);
let v = crate::measure(&b).unwrap().volume;
assert!((v - (part_volume - removed)).abs() < 1e-7 * part_volume, "{v} vs {}", part_volume - removed);
}
diff --git a/crates/kernel/src/surface_ruled.rs b/crates/kernel/src/surface_ruled.rs
index 43e9cec935..e6b59fe44a 100644
--- a/crates/kernel/src/surface_ruled.rs
+++ b/crates/kernel/src/surface_ruled.rs
@@ -1518,7 +1518,10 @@ mod tests {
/// Off a doubly curved face (a saddle patch over a cup's rim) its normal turns along a
/// straight edge: the strip is ruled to a far curve of its own, from corner to corner, which
- /// its handles move.
+ /// its handles move. Lifting every handle (the far curve's interior control points) 1 mm in z
+ /// gives the far curve those control points and the same corners, so it rises by
+ /// 1 − R₀ − Rₙ (its end basis functions) inside and not at all at the corners; the strip built
+ /// with them has that curve for its far edge, away from where the default strip's runs.
#[test]
fn a_strip_off_a_curved_face_is_ruled_to_its_far_curve() {
let b = box_solid(Vec3::new(-14.0, -14.0, 0.0), Vec3::new(14.0, 14.0, 20.0)).unwrap();
@@ -1533,9 +1536,29 @@ mod tests {
assert!(s.is_surface() && s.face_count() == 1);
let handles = ruled_far_handles(&cover, &edge, &r).unwrap();
let [Some(h)] = handles.as_slice() else { panic!("one free strip: {handles:?}") };
+ assert!(!h.is_empty(), "the far curve has interior control points to move");
let lifted: Vec<Vec3> = h.iter().map(|p| *p + Vec3::new(0.0, 0.0, 1.0)).collect();
- let moved = ruled_surface_with(&cover, &edge, &r, &[Some(lifted)]).unwrap();
- assert!(measure(&moved).unwrap().bbox.max.z > measure(&s).unwrap().bbox.max.z, "the handles move the far curve");
+ let moved = ruled_surface_with(&cover, &edge, &r, &[Some(lifted.clone())]).unwrap();
+ // The plan takes the handles as they are, and keeps the corners.
+ let (plain, given) = (planned(&cover, &edge, &r, &[]).unwrap(), planned(&cover, &edge, &r, &[Some(lifted.clone())]).unwrap());
+ let (far, far_moved) = (&plain.strips[0].top, &given.strips[0].top);
+ let ctrl = |c: &CurveN<4>| c.ctrl.iter().map(|h| Vec3::new(h[0] / h[3], h[1] / h[3], h[2] / h[3])).collect::<Vec<_>>();
+ let (before, after) = (ctrl(far), ctrl(far_moved));
+ assert_eq!(after.len(), lifted.len() + 2);
+ assert!(after[1..after.len() - 1].iter().zip(&lifted).all(|(a, b)| a.dist(*b) < 1e-12), "{after:?} vs {lifted:?}");
+ assert!(before[0].dist(after[0]) < 1e-12 && before[before.len() - 1].dist(after[after.len() - 1]) < 1e-12);
+ // The built strip's far edge is that curve (its edges' polylines within 1e-4 of their
+ // curves), and its middle is well off the default strip's edges.
+ let tol = 1e-4;
+ for i in 0..=32 {
+ let p = point(far_moved, f64::from(i) / 32.0).unwrap();
+ let (_, d) = moved.nearest_edge(p, tol).unwrap().unwrap();
+ assert!(d < 10.0 * tol, "the far curve at {i}/32, {p:?}, is {d} from the strip's edges");
+ }
+ let (mid, rose) = (point(far_moved, 0.5).unwrap(), point(far_moved, 0.5).unwrap().dist(point(far, 0.5).unwrap()));
+ assert!(rose > 0.1, "the middle rose {rose}");
+ let (_, d) = s.nearest_edge(mid, tol).unwrap().unwrap();
+ assert!(d > 0.5 * rose, "the default strip has an edge {d} from the moved middle (it rose {rose})");
}
/// Each strip is made in place of the edge it stands on; a corner face in place of the two
diff --git a/crates/kernel/src/tests.rs b/crates/kernel/src/tests.rs
index 22e557d730..517d53c444 100644
--- a/crates/kernel/src/tests.rs
+++ b/crates/kernel/src/tests.rs
@@ -1953,23 +1953,16 @@ fn fillet_sharp_arc_and_arc_loop() {
/// with the R25 arc moved in by `da` and the tab's run (its sides, R2 corners and top) by `dt`,
/// each element parallel to itself, by Green's theorem: an arc about c of radius ρ from a to b
/// gives ½ (ρ² (b − a) + ρ (cx (sin b − sin a) − cy (cos b − cos a))), a segment p→q ½ (p × q).
-/// Where only one side of a concave corner at (±4, y) moves the elements meet where they cross
-/// (the round runs into the other wall); where both do, the corner is swept, an arc of radius d
-/// about the corner (the owner's ruling for rounds meeting at a concave corner, 2026-10-30).
+/// At the concave corners (±4, y) the moved elements meet where they cross: where one side moves
+/// the round runs into the other wall, where both do the two rounds are mitred (the owner's
+/// ruling for rounds meeting at a concave corner beside an unpicked sharp edge, 2026-10-30).
fn tabbed_plate_area(da: f64, dt: f64) -> f64 {
- let (y, cy) = ((625.0_f64 - 16.0).sqrt(), 280.0 / 9.0);
- let theta = (4.0_f64 / 25.0).acos();
+ let cy = 280.0 / 9.0;
let (big, rho) = (25.0 - da, 2.0 - dt);
let tab = rho * rho * PI + 2.0 * rho * (2.0 + cy) + 4.0 * (cy + rho);
- if da > 0.0 && dt > 0.0 {
- assert!((da - dt).abs() < 1e-15, "a swept corner of one size");
- let corner = -da * da * theta + da * (4.0 * theta.sin() + y * (1.0 - theta.cos()));
- 0.5 * (big * big * (PI + 2.0 * theta) + 2.0 * corner + tab) + (4.0 - dt) * (cy - y)
- } else {
- let yc = (big * big - (4.0 - dt).powi(2)).sqrt();
- let at = yc.atan2(4.0 - dt);
- 0.5 * (big * big * (PI + 2.0 * at) + tab) + (4.0 - dt) * (cy - yc)
- }
+ let yc = (big * big - (4.0 - dt).powi(2)).sqrt();
+ let at = yc.atan2(4.0 - dt);
+ 0.5 * (big * big * (PI + 2.0 * at) + tab) + (4.0 - dt) * (cy - yc)
}
#[test]