Wave 416/509: Kernel rig: everyday chamfers of box edges and pocket rims (and 3 more)

4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop.

- 2f88ca2f6 jyviko: Kernel rig: everyday chamfers of box edges and pocket rims
- 51641123c jyviko: Kernel tests: drop the mixed arc-and-line mitre test, the rig's 485 grades it
- e9963439b jyviko: Kernel tests: the round into a hole moves to the rig, with the hole cut the test's way
- 65e46a962 jyviko: Kernel tests: a round as tall as its wall and more builds on the disc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
jyviko
2026-10-30 06:37:24 -04:00
parent f43214a52f
commit e790c6428d
22 changed files with 610 additions and 89 deletions
-46
View File
@@ -1,46 +0,0 @@
//! #324: a round on a block's top edge that runs over a through hole: built as if the top went
//! on, and cut by the hole.
use solidcraft_geom::Vec3;
use crate::{Body, BoolOp, build::box_solid, build::cylinder, ops::boolean};
/// A 40 x 20 x 10 block with a through hole of radius 3 at (20, `y`).
fn block_with_hole(y: f64) -> Body {
let block = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(40.0, 20.0, 10.0)).unwrap();
let hole = cylinder(Vec3::new(20.0, y, -1.0), Vec3::Z, 3.0, 12.0).unwrap();
boolean(&block, &hole, BoolOp::Cut).unwrap().unwrap()
}
/// The round on the top edge at y = 20 covers the top face from y = 20 - r, and the hole's
/// wall reaches y = 17.5: a radius over 2.5 runs into the hole. R4 is built as if the top went
/// on over the hole and cut from the block (the blend-overflow decision, 237f0ae74): the round
/// takes 16 (1 - π/4) of the section along 40, less its part over the hole, where the round's
/// height above its arc, 4 - √(16 - (y - 16)²), stands over the hole's width
/// 2 √(9 - (y - 14.5)²) for y in [16, 17.5] (integrated with y = 17.5 - s², smooth in s).
#[test]
fn a_round_into_a_hole_is_cut_by_it() {
use std::f64::consts::{FRAC_PI_4, PI};
let b = block_with_hole(14.5);
let edge = Vec3::new(10.0, 20.0, 10.0);
let r = crate::fillet(&b, &[edge], 4.0).unwrap();
assert!(r.validity().is_empty(), "{:?}", r.validity());
let (n, top) = (20000, 1.5f64.sqrt());
let over: f64 = (0..n)
.map(|i| {
let s = (i as f64 + 0.5) * top / n as f64;
let y = 17.5 - s * s;
2.0 * (9.0 - (y - 14.5).powi(2)).sqrt() * (4.0 - (16.0 - (y - 16.0).powi(2)).sqrt()) * 2.0 * s
})
.sum::<f64>()
* top
/ n as f64;
let want = 8000.0 - PI * 9.0 * 10.0 - (40.0 * 16.0 * (1.0 - FRAC_PI_4) - over);
let v = crate::measure(&r).unwrap().volume;
assert!((v - want).abs() < 1e-7 * want, "{v} against {want}");
// Clear of the hole (up to 2.5) the round keeps its whole section.
let r = crate::fillet(&b, &[edge], 2.5).unwrap();
let want = 8000.0 - PI * 9.0 * 10.0 - 40.0 * 2.5 * 2.5 * (1.0 - FRAC_PI_4);
let v = r.volume_at(0.005).unwrap();
assert!((v - want).abs() < 0.05, "{v} against {want}");
}
-2
View File
@@ -62,8 +62,6 @@ mod issue_1510_tests;
#[cfg(test)]
mod issue_2005_tests;
#[cfg(test)]
mod issue_324_tests;
#[cfg(test)]
mod issue_616_tests;
#[cfg(test)]
mod issue_674_tests;
+27 -41
View File
@@ -311,10 +311,32 @@ fn loop_fillet_as_tall_as_its_wall_consumes_it() {
let m = measure(&f).unwrap();
assert!(rel(m.volume, want) < 2e-4, "{} vs {want}", m.volume);
assert!(f.validity().is_empty(), "{:?}", f.validity());
// Taller than the wall: still refused, the body unchanged.
// Taller than the wall the round overflows on its tangent side, past the wall's bottom
// edge: it is built on the wall continued down and cut from the disc (the owner's
// blend-overflow ruling, 2026-10-30), keeping its radius. Its section in (ρ, z) is the r
// square at the edge outside the circle about (13 − r, 2 − r), above z = 0: with
// t = z − (2 − r) = r sin θ and ρ(θ) = 13 − r + r cos θ the disc keeps
// π (169·2 − ∫ (169 − ρ²) dz), θ from asin((r − 2) / r) (957.692239 at r = 2.5).
let kept = |r: f64| {
let (n, lo) = (20000, ((r - 2.0) / r).asin());
let taken: f64 = (0..n)
.map(|i| {
let th = lo + (f64::from(i) + 0.5) * (PI / 2.0 - lo) / f64::from(n);
let rho = 13.0 - r + r * th.cos();
(169.0 - rho * rho) * r * th.cos()
})
.sum::<f64>()
* (PI / 2.0 - lo)
/ f64::from(n);
PI * (169.0 * 2.0 - taken)
};
assert!(rel(kept(2.0), PI * 169.0 * 2.0 - spandrel(2.0).0 * 2.0 * PI * (13.0 - spandrel(2.0).1)) < 1e-9);
assert!((kept(2.5) - 957.692239).abs() < 1e-6, "{}", kept(2.5));
for r in [2.0 + 1e-3, 2.5] {
let e = fillet(&disc, &[Vec3::new(0.0, 13.0, 2.0), Vec3::new(0.0, -13.0, 2.0)], r).unwrap_err();
assert!(e.to_string().contains("taller than the walls"), "{r}: {e}");
let f = fillet(&disc, &[Vec3::new(0.0, 13.0, 2.0), Vec3::new(0.0, -13.0, 2.0)], r).unwrap_or_else(|e| panic!("{r}: {e}"));
assert!(f.validity().is_empty(), "{r}: {:?}", f.validity());
let v = measure(&f).unwrap().volume;
assert!(rel(v, kept(r)) < 1e-6, "{r}: {v} vs {}", kept(r));
}
}
@@ -2067,8 +2089,8 @@ fn fillet_mixed_arc_and_line_removed_volume_converges() {
}
let blended = fillet(&body, &[Vec3::new(0.0, 10.0, 15.0), Vec3::new(5.0, 0.0, 15.0)], r).unwrap();
// The removal from the exact volumes (SMLib's, to 1e-8): the reference to a hundred
// thousandth (the blend's surfaces are SMLib's fits; their section error is
// fillet_mixed_arc_and_line_joint_preserves_both_section_radii's).
// thousandth (the blend's surfaces are SMLib's fits; the rig's
// fillets/485-fillet-d-prism-top-outline-arc-and-flat grades the same round).
let done = measure(&blended).unwrap();
let exact = source.volume - done.volume;
assert!(rel(exact, want) < 1e-5, "r={r}: removed {exact}, expected {want}");
@@ -2082,42 +2104,6 @@ fn fillet_mixed_arc_and_line_removed_volume_converges() {
}
}
#[test]
fn fillet_mixed_arc_and_line_joint_preserves_both_section_radii() {
let r = 0.5;
let body = mixed_arc_and_line_prism();
let blended = fillet(&body, &[Vec3::new(0.0, 10.0, 15.0), Vec3::new(5.0, 0.0, 15.0)], r).unwrap();
crate::guard("inspect mixed fillet mitres", || {
let rec = blended.record();
let mut mitres = std::collections::HashSet::new();
for (id, edge) in rec.edges.iter().enumerate() {
let a = Vec3::from(rec.vertices[edge.vertices[0] as usize].point);
let b = Vec3::from(rec.vertices[edge.vertices[1] as usize].point);
// Only the two corner profiles join the top contact to the wall contact.
if (a.z - b.z).abs() < r - 1e-8 || a.z.min(b.z) < 15.0 - r - 1e-8 || a.x * b.x <= 0.0 {
continue;
}
if !mitres.insert(id) {
continue;
}
let curve = solidcraft_geom::brep::eval::CurveEval::new(edge.parameters()).unwrap();
let [lo, hi] = edge.interval;
for i in 0..=257 {
let p = curve.point(lo + (hi - lo) * f64::from(i) / 257.0).unwrap();
// The joint lies on both the cylindrical line blend and the toroidal
// arc blend, not their tangent-plane approximation.
let radius2 = (p.y - r).powi(2) + (p.z - (15.0 - r)).powi(2);
assert!((radius2 - r * r).abs() < 1e-7, "distorted line section at {p:?}: radius squared {radius2}");
let radius2 = (p.x.hypot(p.y) - (10.0 - r)).powi(2) + (p.z - (15.0 - r)).powi(2);
assert!((radius2 - r * r).abs() < 1e-7, "distorted arc section at {p:?}: radius squared {radius2}");
}
}
assert_eq!(mitres.len(), 2, "both arc/line corners must be checked");
Ok(())
})
.unwrap();
}
#[test]
fn fillet_partial_mixed_arc_and_line_perimeter_run() {
let body = partial_mixed_run_prism();
@@ -0,0 +1,13 @@
{
"sources": [
"tangency-labs/solidcraft#324"
],
"what": "324-fillet-over-hole-overlap with the hole cut by a cylinder longer than the block (z -1 to 11), so the hole's wall is trimmed by both the top and the bottom face",
"source": "analytic",
"method": "the same body as 324-fillet-over-hole-overlap: block 40x20x10 minus a through hole of r=3 centred (20,14.5), then R4 on the top long edge at y=20. The round covers y=16..20 and removes 40*(16-4pi) = 137.35; the hole removes 9*pi*10 = 282.74; where both remove the same material (y in 16..17.5) add it back: overlap = integral over y from 16 to 17.5 of [4 - sqrt(16-(y-16)^2)] x 2 sqrt(9-(y-14.5)^2) dy = 0.3758. V = 8000 - 9*pi*10 - 40*(16-4*pi) + overlap = 7580.287.",
"body_count": 1,
"volume_mm3": 7580.287315360674,
"continuity": {
"order": "g1"
}
}
@@ -0,0 +1,44 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"corner": [
0,
0,
0
],
"length": 40,
"width": 20,
"height": 10,
"body_name": "Block"
}
},
{
"command": "solid.cylinder",
"params": {
"base": [
20,
14.5,
-1
],
"radius": 3,
"height": 12,
"operation": "cut"
}
},
{
"command": "solid.fillet",
"params": {
"edges": [
[
10,
20,
10
]
],
"radius": "4 mm"
}
}
]
}
+2
View File
@@ -8,6 +8,8 @@
9-fillet-corner-curvature-with-reduce-fit not supported yet: solid.fillet builds corner g2 with the exact fit only
9-fillet-corner-curvature-with-taper-fit not supported yet: solid.fillet builds corner g2 with the exact fit only
every-block-cylinder-crease-top-edge-after-arc-round-r1 the r1 round's contact seam with the block's side face reads 60 degrees (the cylinder wall's normal) at its end on the crease (8.660, 5, 15.284): G0 where the round is built tangent
every-chamfer-pocket-rim-5-5-refused refused naming 5 mm as the largest distance: the full-width chamfer (legs as deep as the 5 mm walls) builds instead of being refused
every-chamfer-pocket-rim-5-full-depth-refused the full-width chamfer (legs as deep as the 5 mm walls) builds instead of being refused
every-hole-top-rim-chamfer-10-full-depth-refused the full-width chamfer (leg as deep as the 10 mm plate) builds instead of being refused
every-hole-top-rim-r12-past-plate-bottom SMLib status 1001: a convex round past its face on the tangent side is not yet built by subtraction
every-pocket-floor-and-rim-edges-r2 a corner patch where two rim rounds meet at each concave pocket corner (23 faces, not 19) instead of the mitre the rounds make running into each other
@@ -0,0 +1,24 @@
{
"sources": [],
"what": "a box's top front edge chamfered 2",
"source": "analytic",
"method": "box 40x30x20, the edge y=0, z=20 chamfered 2: the right triangle of legs 2 (area 2) along 40: V = 24000 - 80 = 23920. Faces 7; creases (G0).",
"body_count": 1,
"volume_mm3": 23920.0,
"faces": 7,
"bbox": {
"min": [
0,
0,
0
],
"max": [
40,
30,
20
]
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,26 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 40,
"width": 30,
"height": 20,
"body_name": "Part"
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
20,
0,
20
]
],
"distance": 2
}
}
]
}
@@ -0,0 +1,20 @@
{
"sources": [],
"what": "a box's top front edge chamfered by two distances, flipped: 3 down the front and 1 along the top",
"source": "analytic",
"method": "as every-chamfer-box-edge-two-distances-3-1 with `flip`: the front face first, so the triangle (0,20), (1,20), (0,17), area 1.5, V = 23940, its centroid (1/3, 19): centre of mass (20, (360000 - 20)/23940, (240000 - 60 * 19)/23940), graded to 0.0005 mm. Faces 7.",
"body_count": 1,
"volume_mm3": 23940.0,
"faces": 7,
"center_of_mass": [
20.0,
15.036758563074352,
9.977443609022556
],
"tolerance": {
"abs_mm": 0.0005
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,28 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 40,
"width": 30,
"height": 20,
"body_name": "Part"
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
20,
0,
20
]
],
"distance": 3,
"distance2": 1,
"flip": true
}
}
]
}
@@ -0,0 +1,20 @@
{
"sources": [],
"what": "a box's top front edge chamfered by two distances: 3 along the top (the first face, the one facing up) and 1 down the front",
"source": "analytic",
"method": "box 40x30x20, the edge y=0, z=20: the triangle (0,20), (3,20), (0,19) in (y,z), area 1.5, along 40: V = 24000 - 60 = 23940. Its centroid (1, 59/3) fixes which leg went where: centre of mass (20, (360000 - 60)/23940, (240000 - 60 * 59/3)/23940), graded to 0.0005 mm (flipped, it moves 0.0017 mm in y and z). Faces 7.",
"body_count": 1,
"volume_mm3": 23940.0,
"faces": 7,
"center_of_mass": [
20.0,
15.035087719298245,
9.97577276524645
],
"tolerance": {
"abs_mm": 0.0005
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,27 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 40,
"width": 30,
"height": 20,
"body_name": "Part"
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
20,
0,
20
]
],
"distance": 3,
"distance2": 1
}
}
]
}
@@ -0,0 +1,24 @@
{
"sources": [],
"what": "a rectangular pocket's four rim edges chamfered 1",
"source": "analytic",
"method": "plate 60x40x10 with the pocket 30x20x5 (x 15..45, y 10..30, floor z = 5, sharp vertical corners): V0 = 24000 - 3000 = 21000. Each convex rim edge loses the triangle d^2/2 along its length (100 in all); at each pocket corner the two chamfers run on past it and meet in a mitre, the quadrant losing what both remove: points (s, t) past both walls with s + u < d and t + u < d (u the depth), int_0^d (d-u)^2 du = d^3/3. d = 1: removed = 50 d^2 + (4/3) d^3 = 51.3333. V = 20948.6667. Faces 15.",
"body_count": 1,
"volume_mm3": 20948.666666666668,
"faces": 15,
"bbox": {
"min": [
0,
0,
0
],
"max": [
60,
40,
10
]
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,58 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 60,
"width": 40,
"height": 10,
"body_name": "Plate"
}
},
{
"command": "solid.box",
"params": {
"length": 30,
"width": 20,
"height": 6,
"corner": [
15,
10,
5
],
"operation": "cut",
"targets": [
"Plate"
]
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
30,
10,
10
],
[
30,
30,
10
],
[
15,
20,
10
],
[
45,
20,
10
]
],
"distance": 1
}
}
]
}
@@ -0,0 +1,24 @@
{
"sources": [],
"what": "a 5 mm deep pocket's rim edges chamfered 4.9: the legs stop 0.1 short of the floor, so it fits",
"source": "analytic",
"method": "plate 60x40x10 with the pocket 30x20x5 (x 15..45, y 10..30, floor z = 5, sharp vertical corners): V0 = 24000 - 3000 = 21000. Each convex rim edge loses the triangle d^2/2 along its length (100 in all); at each pocket corner the two chamfers run on past it and meet in a mitre, the quadrant losing what both remove: points (s, t) past both walls with s + u < d and t + u < d (u the depth), int_0^d (d-u)^2 du = d^3/3. d = 4.9: removed = 50 d^2 + (4/3) d^3 = 1357.3653. V = 19642.6347. Faces 15.",
"body_count": 1,
"volume_mm3": 19642.634666666665,
"faces": 15,
"bbox": {
"min": [
0,
0,
0
],
"max": [
60,
40,
10
]
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,58 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 60,
"width": 40,
"height": 10,
"body_name": "Plate"
}
},
{
"command": "solid.box",
"params": {
"length": 30,
"width": 20,
"height": 6,
"corner": [
15,
10,
5
],
"operation": "cut",
"targets": [
"Plate"
]
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
30,
10,
10
],
[
30,
30,
10
],
[
15,
20,
10
],
[
45,
20,
10
]
],
"distance": 4.9
}
}
]
}
@@ -0,0 +1,8 @@
{
"sources": [],
"what": "a 5 mm deep pocket's rim edges chamfered 5.5: the legs would run off the walls over the floor: refused, naming the largest distance that fits",
"source": "invariants",
"method": "owner rule: a chamfer whose leg runs off the face beside its edge over another face is refused, naming the largest size that fits, and a full-width chamfer stays refused. The walls are 5 deep, so every distance below 5 fits (every-chamfer-pocket-rim-4-9-fits) and 5 does not; the search names the largest at the request's three significant digits (step 0.001): 4.999.",
"outcome": "refused",
"refusal": "the largest distance that fits is 4.999 mm"
}
@@ -0,0 +1,58 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 60,
"width": 40,
"height": 10,
"body_name": "Plate"
}
},
{
"command": "solid.box",
"params": {
"length": 30,
"width": 20,
"height": 6,
"corner": [
15,
10,
5
],
"operation": "cut",
"targets": [
"Plate"
]
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
30,
10,
10
],
[
30,
30,
10
],
[
15,
20,
10
],
[
45,
20,
10
]
],
"distance": 5.5
}
}
]
}
@@ -0,0 +1,8 @@
{
"sources": [],
"what": "a 5 mm deep pocket's rim edges chamfered 5: the legs would use the whole walls: refused, naming the largest distance that fits",
"source": "invariants",
"method": "owner rule: a chamfer whose leg runs off the face beside its edge over another face is refused, naming the largest size that fits, and a full-width chamfer stays refused. The walls are 5 deep, so every distance below 5 fits (every-chamfer-pocket-rim-4-9-fits) and 5 does not; the search names the largest at the request's three significant digits (step 0.001): 4.999.",
"outcome": "refused",
"refusal": "the largest distance that fits is 4.999 mm"
}
@@ -0,0 +1,58 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 60,
"width": 40,
"height": 10,
"body_name": "Plate"
}
},
{
"command": "solid.box",
"params": {
"length": 30,
"width": 20,
"height": 6,
"corner": [
15,
10,
5
],
"operation": "cut",
"targets": [
"Plate"
]
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
30,
10,
10
],
[
30,
30,
10
],
[
15,
20,
10
],
[
45,
20,
10
]
],
"distance": 5
}
}
]
}
@@ -0,0 +1,24 @@
{
"sources": [],
"what": "a rectangular pocket's rim edges chamfered by two distances: 2 along the top (facing up) and 1 down the walls",
"source": "analytic",
"method": "plate 60x40x10 with the pocket 30x20x5 (x 15..45, y 10..30, floor z = 5, sharp vertical corners): V0 = 24000 - 3000 = 21000. Each rim edge loses the triangle of legs 2 (on the top) and 1 (down the wall), area 1, along 100; at each corner the mitred quadrant loses the points past both walls with s/2 + u < 1 and t/2 + u < 1: int_0^1 (2 (1-u))^2 du = 4/3. Removed = 100 + 16/3 = 105.3333. V = 20894.6667. Faces 15.",
"body_count": 1,
"volume_mm3": 20894.666666666668,
"faces": 15,
"bbox": {
"min": [
0,
0,
0
],
"max": [
60,
40,
10
]
},
"continuity": {
"order": "g0"
}
}
@@ -0,0 +1,59 @@
{
"commands": [
{
"command": "solid.box",
"params": {
"length": 60,
"width": 40,
"height": 10,
"body_name": "Plate"
}
},
{
"command": "solid.box",
"params": {
"length": 30,
"width": 20,
"height": 6,
"corner": [
15,
10,
5
],
"operation": "cut",
"targets": [
"Plate"
]
}
},
{
"command": "solid.chamfer",
"params": {
"edges": [
[
30,
10,
10
],
[
30,
30,
10
],
[
15,
20,
10
],
[
45,
20,
10
]
],
"distance": 2,
"distance2": 1
}
}
]
}