From 34c5bc74a5d4b16c123bcb75cbe43e0a209f1302 Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Mon, 26 Oct 2026 13:37:34 -0400 Subject: [PATCH] Wave 270/509: kernel-cases: a continuity check, and ladder 07/015 graded by it (and 3 more) 4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - d8282b336 jyviko: doc, engine: corner: g2 sets each corner back for its G2 patch - 8fbb575a5 jyviko: kernel-cases: a continuity check, and ladder 07/015 graded by it - 808913777 jyviko: kernel: G2 corners at concave corners, mixed ones refused - ba38fbd2a jyviko: kernel-cases: ladder 07/019, a concave corner's G2 patch Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- apps/solidcraft-cli/src/kernel_cases.rs | 72 +++++++++++++++++++ crates/doc/src/document.rs | 4 +- crates/doc/src/eval.rs | 17 ++--- crates/engine/src/cmd/features.rs | 32 ++++++--- crates/kernel/src/blend.rs | 5 +- crates/kernel/src/corner_g2_tests.rs | 41 +++++++++++ tests/kernel-cases/README.md | 1 + .../015-corner-g2-patch/expected.json | 26 ++++++- .../019-concave-corner-g2-patch/expected.json | 30 ++++++++ .../019-concave-corner-g2-patch/recipe.json | 53 ++++++++++++++ tests/kernel-cases/ladder/golden.json | 24 ++++++- tests/kernel-cases/ladder/ladder.json | 1 + tools/kernel-ladder/cases.py | 21 +++++- 13 files changed, 299 insertions(+), 28 deletions(-) create mode 100644 tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/expected.json create mode 100644 tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/recipe.json diff --git a/apps/solidcraft-cli/src/kernel_cases.rs b/apps/solidcraft-cli/src/kernel_cases.rs index d75f83ae0..272c3c99b 100644 --- a/apps/solidcraft-cli/src/kernel_cases.rs +++ b/apps/solidcraft-cli/src/kernel_cases.rs @@ -114,6 +114,60 @@ fn open_edges(positions: &[solidcraft_engine::geom::Vec3], triangles: &[[u32; 3] } /// An error that means "this kernel can't do it yet", not a wrong answer. +/// Stations along each seam the `continuity` check samples. +const SEAM_SAMPLES: usize = 65; +/// A seam is tangent (G1), and two seams meeting at a vertex turn there, past this angle (°). +const SEAM_ANGLE_DEG: f64 = 1.0; + +/// The `continuity` check's measure of `body`: over the tangent seams lying wholly within +/// `within` of `near`, the worst curvature jump (1/mm) at every station and at the stations at +/// least `clear` (mm, along the seam) from each vertex where two of those seams turn (a corner of +/// the patch's boundary, where its neighbours' own G1 seams end and no surface is G2 to both), +/// with how many seams and stations clear there were. An error where the seams can't be measured. +fn curvature_jumps(body: &solidcraft_engine::kernel::Body, near: [f64; 3], within: f64, clear: f64) -> Result { + use solidcraft_engine::geom::Vec3; + let tol = solidcraft_engine::kernel::ContinuityTolerances { gap_mm: 1e-3, angle_deg: SEAM_ANGLE_DEG, curvature_per_mm: 0.0 }; + let report = solidcraft_engine::kernel::seam_diagnostics(body, &[], SEAM_SAMPLES, tol).map_err(|e| e.to_string())?; + let at = Vec3::new(near[0], near[1], near[2]); + let seams: Vec<_> = report + .seams + .iter() + .filter(|s| s.normal_angle_deg.value <= SEAM_ANGLE_DEG && s.points.len() >= 2 && s.points.iter().all(|p| p.dist(at) <= within)) + .collect(); + // Each seam's end directions, pointing into it. + let ends = |s: &solidcraft_engine::kernel::SeamReport| -> Option<[(Vec3, Vec3); 2]> { + let (p0, p1) = (*s.points.first()?, *s.points.last()?); + let (q0, q1) = (*s.points.get(1)?, *s.points.get(s.points.len() - 2)?); + Some([(p0, (q0 - p0).normalized()?), (p1, (q1 - p1).normalized()?)]) + }; + let all_ends: Vec<(Vec3, Vec3)> = seams.iter().filter_map(|s| ends(s)).flatten().collect(); + let weld = 1e-6 * within.max(1.0); + let cos = SEAM_ANGLE_DEG.to_radians().cos(); + // A vertex turns where another seam leaves it other than straight on. + let turns = |p: Vec3, d: Vec3| all_ends.iter().any(|(q, e)| q.dist(p) <= weld && (*e - d).len() > 1e-9 && -e.dot(d) < cos); + let (mut worst, mut worst_clear, mut stations) = (0.0f64, 0.0f64, 0usize); + for s in &seams { + let Some(e) = ends(s) else { continue }; + let turning: Vec = e.iter().filter(|(p, d)| turns(*p, *d)).map(|(p, _)| *p).collect(); + // Arc length along the seam to each station, from its start. + let mut along = vec![0.0f64; s.points.len()]; + for k in 1..s.points.len() { + along[k] = along[k - 1] + s.points[k].dist(s.points[k - 1]); + } + let length = along.last().copied().unwrap_or(0.0); + for (k, st) in s.stations.iter().enumerate() { + worst = worst.max(st.curvature_jump_per_mm); + let a = along.get(k).copied().unwrap_or(0.0); + let from_turn = turning.iter().map(|p| if p.dist(s.points[0]) <= weld { a } else { length - a }).fold(f64::INFINITY, f64::min); + if from_turn >= clear { + worst_clear = worst_clear.max(st.curvature_jump_per_mm); + stations += 1; + } + } + } + Ok(json!({"seams": seams.len(), "stations_clear": stations, "worst_per_mm": worst, "worst_clear_per_mm": worst_clear})) +} + fn unsupported(e: &str) -> bool { e.contains("not supported yet") } @@ -256,6 +310,24 @@ fn check_case(dir: &str, dumps: Option<&std::path::Path>) -> Value { open == 0 && over == 0, ); } + // Curvature continuity across the seams round a point: the worst jump clear of the + // seams' turns must be within the case's bound. + if let Some(cont) = want.get("continuity").filter(|c| !c.is_null()) { + let (near, within, clear, bound) = + (v3(&cont["near"]), cont["within_mm"].as_f64(), cont["clear_mm"].as_f64(), cont["curvature_jump_per_mm"].as_f64()); + match (near, within, clear, bound) { + (Some(near), Some(within), Some(clear), Some(bound)) => match curvature_jumps(&b.body, near, within, clear) { + Ok(got) => { + let ok = got["seams"].as_u64().unwrap_or(0) > 0 + && got["stations_clear"].as_u64().unwrap_or(0) > 0 + && got["worst_clear_per_mm"].as_f64().is_some_and(|w| w <= bound); + c.push("curvature_jump", got, json!({"worst_clear_per_mm": format!("<= {bound}")}), ok); + } + Err(e) => c.push("curvature_jump", json!(format!("{}: {e}", b.name)), json!("measurable"), false), + }, + _ => c.push("curvature_jump", json!("continuity needs near, within_mm, clear_mm and curvature_jump_per_mm"), json!("a bound"), false), + } + } if want_valid { // Closed shells, and every validity check this build has. if want_shells.is_none() { diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index da54060a2..ce847c458 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -1845,7 +1845,9 @@ pub enum FilletCorner { /// A piece of the rolling ball's sphere: tangent (G1) to each blend. #[default] Rolling, - /// A G2 patch repeating each blend's surface up to the second order (see `corner_g2`). + /// The corner set back (its distance from the fillet's `setbacks`, else 1.5 × the radius) + /// and filled with a patch meeting the rounds and the faces round it to the second order + /// (`solidcraft_kernel::fillet_g2_corners`). G2, } diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs index 29caa08e7..47267b8f7 100644 --- a/crates/doc/src/eval.rs +++ b/crates/doc/src/eval.rs @@ -3494,13 +3494,16 @@ fn blend_body( let (mut used, mut tapered) = (None, Vec::new()); // The blended body, and the lineage of what the last blend started from. let (nb, from) = match &f.kind { - FeatureKind::Fillet { corner: crate::FilletCorner::G2, .. } => (kernel::fillet_g2_corners(&mb.body, edges, r)?, input), - FeatureKind::Fillet { setbacks, .. } if !setbacks.is_empty() => { + FeatureKind::Fillet { corner, setbacks, .. } if matches!(corner, crate::FilletCorner::G2) || !setbacks.is_empty() => { + // Each setback: its corner's vertex and its distance. let mut corners = Vec::with_capacity(setbacks.len()); for c in setbacks { corners.push((c.vertex.0, val(vals, &c.distance, Kind::Length)?)); } - (kernel::fillet_setback(&mb.body, edges, r, &corners)?, input) + match corner { + crate::FilletCorner::G2 => (kernel::fillet_g2_corners(&mb.body, edges, r, &corners)?, input), + crate::FilletCorner::Rolling => (kernel::fillet_setback(&mb.body, edges, r, &corners)?, input), + } } FeatureKind::Fillet { style: crate::FilletStyle::Curvature, .. } => (kernel::fillet_g2(&mb.body, edges, r)?, input), FeatureKind::Fillet { style: crate::FilletStyle::Chord, .. } => (kernel::fillet_chord(&mb.body, edges, r)?, input), @@ -6656,13 +6659,11 @@ fn eval_feature(doc: &Document, vals: &BTreeMap, f: &Feature, st: // Each edge is found on its own body (picked over several bodies, the edges of each // are blended on it), all against the bodies as they were before this feature. // Corner setbacks likewise: SMLib sets back the corners of constant-radius rounds. - if let FeatureKind::Fillet { setbacks, corner, style, fit, .. } = &f.kind + if let FeatureKind::Fillet { setbacks, style, fit, .. } = &f.kind && !setbacks.is_empty() - && (!corner.is_rolling() || !matches!(style, crate::FilletStyle::Constant) || !matches!(fit, crate::FilletFit::Exact)) + && (!matches!(style, crate::FilletStyle::Constant) || !matches!(fit, crate::FilletFit::Exact)) { - return Err(DocError::Invalid( - "corner setbacks are built for a constant-radius fillet (type: constant, fit: exact, corner: rolling) only".into(), - )); + return Err(DocError::Invalid("corner setbacks are built for a constant-radius fillet (type: constant, fit: exact) only".into())); } let on = blend_bodies(st, f, body, &crate::plain(edges))?; let mut groups: Vec<(usize, Vec)> = Vec::new(); diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index c4de9df76..61179189f 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -49,7 +49,7 @@ pub static COMMANDS: &[CommandSpec] = &[ .at("SOLID", "MODIFY") .icon("fillet") .key("F") - .params("edges: [[x,y,z] point on edge | {body, index}] ; radius: expr; tangent_chain?: bool (default true: each picked edge's tangent chain is rounded with it; false: exactly the picked edges); body?; type?: constant|curvature (alias g2: curvature-continuous quintic between planar faces along straight edges, one planar end face at each end (including sloped ends); radius sets the equivalent circular setback, not constant curvature; exact fit only)|chord (radius is the width across)|variable (radius at the end nearest start, radius2 at the other; one end may be 0, where the round closes to the corner)|spline (the radius along the edge is a clamped B-spline from the end nearest start: radius is its first control radius, radii the rest, knots its knot vector from 0 to 1; one end may be 0); radius2?; start?: [x,y,z]; radii?: [expr, …]; knots?: [number, …]; mid?: [[position 0…1 from start, radius expr], …] (variable radii between the ends); smooth?: bool (smooth instead of straight between the radii); corner?: rolling|g2 (rolling, the default: the corners where three blended edges meet are pieces of the rolling ball's sphere, tangent to each blend; g2: a patch repeating each blend's surface up to the second order, constant-radius exact fillets only, refused where it cannot be built); setbacks?: [{vertex: [x,y,z], distance: expr}, …] (corner setbacks: the corner at the vertex nearest `vertex`, where every edge meeting it is rounded, starts its patch `distance` along each of those edges from the vertex, past where the rounds would meet (past the radius at a square corner), so the rounds blend through a larger patch; one distance for all of a corner's edges; constant-radius exact fillets with rolling corners only); fit?: exact|reduce|taper (exact, the default: a radius too large for the geometry around the edges is refused; reduce: where it doesn't fit it is reduced to the largest that does, one radius for edges sharing a face; the smallest used is returned as `radius_applied`, each edge's as `radii_applied: [{edge: [x,y,z], radius}]`, and noted in the feature's warning; taper: along each straight edge between planar faces where it doesn't fit, the radius follows the room there as a smooth spline, down to 0 where a face closes to a point, noted in the feature's warning)"), + .params("edges: [[x,y,z] point on edge | {body, index}] ; radius: expr; tangent_chain?: bool (default true: each picked edge's tangent chain is rounded with it; false: exactly the picked edges); body?; type?: constant|curvature (alias g2: curvature-continuous quintic between planar faces along straight edges, one planar end face at each end (including sloped ends); radius sets the equivalent circular setback, not constant curvature; exact fit only)|chord (radius is the width across)|variable (radius at the end nearest start, radius2 at the other; one end may be 0, where the round closes to the corner)|spline (the radius along the edge is a clamped B-spline from the end nearest start: radius is its first control radius, radii the rest, knots its knot vector from 0 to 1; one end may be 0); radius2?; start?: [x,y,z]; radii?: [expr, …]; knots?: [number, …]; mid?: [[position 0…1 from start, radius expr], …] (variable radii between the ends); smooth?: bool (smooth instead of straight between the radii); corner?: rolling|g2 (rolling, the default: the corners where three blended edges meet are pieces of the rolling ball's sphere, tangent to each blend; g2: each corner where three or more rounded edges meet, and every edge there is rounded, is set back (1.5 × the radius along each edge unless `setbacks` names it) and filled with a patch meeting the rounds and the faces round it to the second order (curvature-continuous seams, clear of the points where a round's section ends on a face), constant-radius exact fillets only, refused where it cannot be built); setbacks?: [{vertex: [x,y,z], distance: expr}, …] (corner setbacks: the corner at the vertex nearest `vertex`, where every edge meeting it is rounded, starts its patch `distance` along each of those edges from the vertex, past where the rounds would meet (past the radius at a square corner), so the rounds blend through a larger patch; one distance for all of a corner's edges; constant-radius exact fillets only; with `corner: g2`, the G2 patch's corners); fit?: exact|reduce|taper (exact, the default: a radius too large for the geometry around the edges is refused; reduce: where it doesn't fit it is reduced to the largest that does, one radius for edges sharing a face; the smallest used is returned as `radius_applied`, each edge's as `radii_applied: [{edge: [x,y,z], radius}]`, and noted in the feature's warning; taper: along each straight edge between planar faces where it doesn't fit, the radius follows the room there as a smooth spline, down to 0 where a face closes to a point, noted in the feature's warning)"), CommandSpec::new("solid.chamfer", "Chamfer", chamfer).at("SOLID", "MODIFY").icon("chamfer").params("edges: [[x,y,z] | {body, index}] ; distance: expr; tangent_chain?: bool (default true: each picked edge's tangent chain is cut with it; false: exactly the picked edges); distance2?: expr (along the second face) | angle?: expr (from the first face); flip?: bool (which face is first: by default the one facing up most); body?"), CommandSpec::new("solid.combine", "Combine", combine).at("SOLID", "MODIFY").icon("combine").params("target: body; tools: [body]; operation?: join|cut|intersect; touching?: separate|one_body (what a join makes of pieces that share no face: separate, the default, makes each piece that touches another only along an edge or at a point a body of its own and keeps pieces that touch nothing in one body; one_body keeps every piece in one body); keep_tools?: bool; new_component?: bool (the result goes into a new component; component_name?)"), CommandSpec::new("solid.pattern.rectangular", "Rectangular Pattern", pattern_rect) @@ -1676,8 +1676,8 @@ fn fillet(s: &mut Session, p: &Value) -> Result { check_expr(s, &distance, Kind::Length, cmd, "setback distance")?; setbacks.push(solidcraft_doc::CornerSetback { vertex: Position(vertex), distance }); } - if !setbacks.is_empty() && (!style.is_constant() || !fit.is_exact() || !corner.is_rolling()) { - return Err(bad(cmd, "`setbacks` are built for a constant-radius fillet (`type: constant`, `fit: exact`, `corner: rolling`) only")); + if !setbacks.is_empty() && (!style.is_constant() || !fit.is_exact()) { + return Err(bad(cmd, "`setbacks` are built for a constant-radius fillet (`type: constant`, `fit: exact`) only")); } } let mut out = add_feature( @@ -3192,8 +3192,8 @@ mod thin_extrude_tests; #[path = "extrude_convention_tests.rs"] mod extrude_convention_tests; /// `solid.fillet corner?: rolling|g2`: the default keeps the rolling ball's sphere corner, `g2` -/// is accepted and refuses (item 10's patch is built but not sewn in yet, see `corner_g2`), and an -/// unknown word is refused. +/// sets the corner back and fills it with the G2 patch (`solidcraft_kernel::fillet_g2_corners`), +/// with `setbacks` naming its distance, and an unknown word is refused. #[cfg(test)] #[allow(clippy::unwrap_used)] mod corner_tests { @@ -3218,7 +3218,7 @@ mod corner_tests { } #[test] - fn the_default_corner_is_the_rolling_ball_and_g2_refuses_clearly() { + fn the_default_corner_is_the_rolling_ball_and_g2_sets_it_back_for_its_patch() { let (default, reply) = cornered(None); assert_eq!(reply["warning"], json!(null), "{reply}"); let (rolling, _) = cornered(Some("rolling")); @@ -3227,13 +3227,23 @@ mod corner_tests { // `corner: rolling` is the default: the same body, to the last bit of its area. assert_eq!(solidcraft_kernel::measure(&ball).unwrap().area, solidcraft_kernel::measure(&same).unwrap().area); assert!(solidcraft_kernel::measure(&ball).unwrap().volume > 7000.0); - // `corner: g2`: accepted, and refused with a clear message until the patch sews in. + // `corner: g2`: the corner set back (1.5 r by default, or as `setbacks` says) and filled + // with the G2 patch: one closed solid of the box's faces, the rounds and the patch, a + // little fuller than the ball's corner (its patch spans the setback, not the ball). + let ball_volume = solidcraft_kernel::measure(&ball).unwrap().volume; + for setbacks in [json!([]), json!([{"vertex": [0, 0, 0], "distance": 7}])] { + let mut s = Session::default(); + run(&mut s, "solid.box", &json!({"length": 20, "width": 20, "height": 20, "body_name": "B"})); + run(&mut s, "solid.fillet", &json!({"edges": [[10, 0, 0], [0, 10, 0], [0, 0, 10]], "radius": 4, "corner": "g2", "setbacks": setbacks})); + let body = s.world_state().unwrap().body("B").unwrap().body.clone(); + assert!(body.validity().is_empty(), "{:?}", body.validity()); + let m = solidcraft_kernel::measure(&body).unwrap(); + eprintln!("corner g2, setbacks {setbacks}: {} faces, volume {:.4} (ball {:.4})", m.faces, m.volume, ball_volume); + assert_eq!(m.faces, 10); + assert!((m.volume - ball_volume).abs() < 1e-3 * ball_volume, "{} vs {}", m.volume, ball_volume); + } let mut s = Session::default(); run(&mut s, "solid.box", &json!({"length": 20, "width": 20, "height": 20, "body_name": "B"})); - let err = - s.execute("solid.fillet", &json!({"edges": [[10, 0, 0], [0, 10, 0], [0, 0, 10]], "radius": 4, "corner": "g2"})).unwrap_err().to_string(); - eprintln!("corner g2: {err}"); - assert!(err.contains("not supported yet:") && err.contains("G2 corner"), "{err}"); // An unknown word, and a style the G2 corner has no patch for, are refused as parameters. assert!(s.execute("solid.fillet", &json!({"edges": [[10, 0, 0]], "radius": 4, "corner": "round"})).is_err()); assert!(s.execute("solid.fillet", &json!({"edges": [[10, 0, 0]], "radius": 4, "corner": "g2", "type": "chord"})).is_err()); diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs index f1cc3c452..bfbde93e9 100644 --- a/crates/kernel/src/blend.rs +++ b/crates/kernel/src/blend.rs @@ -233,8 +233,9 @@ pub fn fillet_setback(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec /// its vertex and the distance its patch starts along each edge there (the others take /// [`crate::DEFAULT_SETBACK_FACTOR`] times the radius), SMLib leaves it open, and a patch that /// meets the rounds and the faces round it to the second order fills it. The faces are sewn -/// into one solid. Without such a corner this is [`fillet`]. Refused: a corner where an edge is -/// not rounded (SMLib sets back only corners where all are), a setback that does not reach past +/// into one solid, convex corners and concave ones alike. Without such a corner this is +/// [`fillet`]. Refused: a corner where an edge is not rounded, or whose edges are not all of one +/// convexity (SMLib sets back only corners where all are rounded, alike), a setback that does not reach past /// where the rounds would meet, a hole that is no height field over its plane or a patch that /// does not meet its neighbours within the tolerances. pub fn fillet_g2_corners(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec3, f64)]) -> Result { diff --git a/crates/kernel/src/corner_g2_tests.rs b/crates/kernel/src/corner_g2_tests.rs index 9fd4dcf96..9306c0bf3 100644 --- a/crates/kernel/src/corner_g2_tests.rs +++ b/crates/kernel/src/corner_g2_tests.rs @@ -164,3 +164,44 @@ fn what_the_g2_corner_cannot_build_is_refused() { let plain = fillet(&body, &edges[..2], 5.0).unwrap(); assert_eq!(measure(&two).unwrap().faces, measure(&plain).unwrap().faces); } + +/// The 60 x 40 x 20 box with a 20 x 20 x 10 notch cut from its top corner (60, 40, 20): its +/// inner corner (40, 20, 10) where three concave edges meet, and the notch's outer corner +/// (60, 20, 10) where the concave edge along x meets two convex ones. +fn notched() -> Body { + let a = box_solid(Vec3::ZERO, Vec3::new(60.0, 40.0, 20.0)).unwrap(); + let b = box_solid(Vec3::new(40.0, 20.0, 10.0), Vec3::new(70.0, 50.0, 30.0)).unwrap(); + boolean(&a, &b, BoolOp::Cut).unwrap().unwrap() +} + +/// The notch's inner corner, three concave r5 rounds (ladder 07/019): set back 7.5 and filled, +/// one closed valid solid with the faces the ball corner has, the patch's seams G2 clear of the +/// hole's corners where the ball's jump 1/r. +#[test] +fn a_concave_corner_takes_the_g2_patch_too() { + let body = notched(); + let edges = [Vec3::new(50.0, 20.0, 10.0), Vec3::new(40.0, 30.0, 10.0), Vec3::new(40.0, 20.0, 15.0)]; + let ball = fillet(&body, &edges, 5.0).unwrap(); + let g2 = fillet_g2_corners(&body, &edges, 5.0, &[]).unwrap(); + assert!(g2.validity().is_empty(), "{:?}", g2.validity()); + let v = crate::validity::validity(&g2); + assert!(v.ok(), "{v:?}"); + let (m, mb) = (measure(&g2).unwrap(), measure(&ball).unwrap()); + let (_, clear, n) = corner_seams(&g2, 0.15); + let (_, ball_clear, _) = corner_seams(&ball, 0.15); + eprintln!("concave G2 corner: {} faces (ball {}), volume {:.4} (ball {:.4}), jump clear of the corners {clear:.3e} ({n} stations), ball's {ball_clear:.3e}", m.faces, mb.faces, m.volume, mb.volume); + assert_eq!(m.faces, mb.faces); + assert!(clear <= CURVATURE_SHARE / 5.0 && ball_clear > 0.19, "{clear} {ball_clear}"); +} + +/// The notch's outer corner, two convex rounds and a concave one: SMLib sets back only a corner +/// of one convexity, so the G2 corner is refused as not supported (the rolling ball builds). +#[test] +fn a_mixed_convexity_corner_is_refused() { + let body = notched(); + let edges = [Vec3::new(50.0, 20.0, 10.0), Vec3::new(60.0, 30.0, 10.0), Vec3::new(60.0, 20.0, 15.0)]; + assert!(fillet(&body, &edges, 5.0).is_ok()); + let err = fillet_g2_corners(&body, &edges, 5.0, &[]).unwrap_err().to_string(); + eprintln!("mixed corner: {err}"); + assert!(err.contains("not supported yet"), "{err}"); +} diff --git a/tests/kernel-cases/README.md b/tests/kernel-cases/README.md index 04b6cee87..5de1011e4 100644 --- a/tests/kernel-cases/README.md +++ b/tests/kernel-cases/README.md @@ -88,6 +88,7 @@ the frozen truck-geometry PRs, a `kernel-paused` PR), for the report's coverage | `body_count`, `faces`, `edges`, `vertices` | Exact counts, where the geometry fixes them. Faces and edges count whole analytic surfaces and curves once (a full cylinder side is one face). | | `volume_mm3`, `area_mm2`, `center_of_mass`, `bbox` | As in `tests/oracle`: totals over every body, relative tolerance 1e-3 for volume and area, 1e-3 of the box diagonal for positions. | | `faces`, `edges`, `vertices`, `shells`, `body_count` as `[min, max]` | An inclusive range, where the geometry only bounds a count (a modelled thread's faces). | +| `continuity` | `{near, within_mm, clear_mm, curvature_jump_per_mm}`: over every tangent seam lying wholly within `within_mm` of `near` (a corner's patch and its neighbours), the curvature jump across it (the faces' normal curvatures square to the seam, from their exact surfaces, at 65 stations a seam) is at most `curvature_jump_per_mm` at every station at least `clear_mm` along the seam from a vertex where two of those seams turn (where a neighbour's own G1 seam ends, which no surface is G2 to both sides of). A rolling ball's corner jumps 1 / r everywhere. | | `watertight` | `true`: each body's display mesh (chord tolerance `tolerance.mesh_mm`, default 0.01 mm) has no open and no over-shared edges, with vertices closer than `tolerance.weld_mm` (default 1e-4 mm) taken as one. | | `timeout_s` | A longer timeout for this case than the run's (at most 1800 s), for cases that are slow by nature. A case that only needs it on a loaded machine shouldn't set it. | | `tolerance` | Optional overrides: `rel`, `abs_mm`, `mesh_mm`, `weld_mm`. | diff --git a/tests/kernel-cases/ladder/07-fillets/015-corner-g2-patch/expected.json b/tests/kernel-cases/ladder/07-fillets/015-corner-g2-patch/expected.json index a5246f697..da5c27f96 100644 --- a/tests/kernel-cases/ladder/07-fillets/015-corner-g2-patch/expected.json +++ b/tests/kernel-cases/ladder/07-fillets/015-corner-g2-patch/expected.json @@ -2,7 +2,29 @@ "sources": [], "what": "three r5 rounds at a corner with the g2 corner patch", "source": "invariants", - "method": "the g2 patch replaces the sphere octant; no closed-form volume; one valid body, the same faces as 009", + "method": "the corner set back 1.5 r = 7.5 and filled with one patch G2 to the three rounds and the three faces; no closed-form volume; one valid body, the same faces as 009, within the box; across the patch's seams the curvature jump is at most 1e-3 per mm (the ball's corner, 009, jumps 1/r = 0.2) clear of the six points where a round's section ends on a face, where the round's own G1 seam with the face ends (the patch passes from one curvature to the other within 15% of each side: 1.2 mm covers it)", "body_count": 1, - "faces": 10 + "faces": 10, + "bbox": { + "min": [ + 0, + 0, + 0 + ], + "max": [ + 60, + 40, + 20 + ] + }, + "continuity": { + "near": [ + 60, + 40, + 20 + ], + "within_mm": 15, + "clear_mm": 1.2, + "curvature_jump_per_mm": 0.001 + } } diff --git a/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/expected.json b/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/expected.json new file mode 100644 index 000000000..0ede2bac0 --- /dev/null +++ b/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/expected.json @@ -0,0 +1,30 @@ +{ + "sources": [], + "what": "three concave r5 rounds at the inner corner of a 20x20x10 notch, with the g2 corner patch", + "source": "invariants", + "method": "the notch's inner corner (40,20,10), three concave edges, set back 1.5 r = 7.5 and filled with one patch G2 to the three rounds and the three faces; one valid body with the faces of the ball corner (13); across the patch's seams the curvature jump is at most 1e-3 per mm (the ball's corner jumps 1/r = 0.2) clear of the six points where a round's section ends on a face (within 11 mm of the corner: the hole reaches 7.5 sqrt 2; the vertical round, 2.5 mm long past its setback, meets its faces 11.2 mm out, with the G1 jump every round has)", + "body_count": 1, + "faces": 13, + "bbox": { + "min": [ + 0, + 0, + 0 + ], + "max": [ + 60, + 40, + 20 + ] + }, + "continuity": { + "near": [ + 40, + 20, + 10 + ], + "within_mm": 11, + "clear_mm": 1.2, + "curvature_jump_per_mm": 0.001 + } +} diff --git a/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/recipe.json b/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/recipe.json new file mode 100644 index 000000000..0a9853272 --- /dev/null +++ b/tests/kernel-cases/ladder/07-fillets/019-concave-corner-g2-patch/recipe.json @@ -0,0 +1,53 @@ +{ + "base": "../../01-primitives/001-box", + "commands": [ + { + "command": "solid.box", + "params": { + "corner": [ + 40, + 20, + 10 + ], + "length": 30, + "width": 30, + "height": 20, + "body_name": "Notch" + } + }, + { + "command": "solid.combine", + "params": { + "target": "Part", + "tools": [ + "Notch" + ], + "operation": "cut" + } + }, + { + "command": "solid.fillet", + "params": { + "edges": [ + [ + 50, + 20, + 10 + ], + [ + 40, + 30, + 10 + ], + [ + 40, + 20, + 15 + ] + ], + "radius": 5, + "corner": "g2" + } + } + ] +} diff --git a/tests/kernel-cases/ladder/golden.json b/tests/kernel-cases/ladder/golden.json index 7f35e0b01..53aa862d7 100644 --- a/tests/kernel-cases/ladder/golden.json +++ b/tests/kernel-cases/ladder/golden.json @@ -1189,8 +1189,28 @@ "status": "pass" }, "ladder/07-fillets/015-corner-g2-patch": { - "seconds": 0.00302384, - "status": "unsupported" + "measured": { + "area_mm2": 8520.38925544218, + "body_count": 1, + "edges": 24, + "faces": 10, + "vertices": 16, + "volume_mm3": 47370.10741440046 + }, + "seconds": 2.184099933, + "status": "pass" + }, + "ladder/07-fillets/019-concave-corner-g2-patch": { + "measured": { + "area_mm2": 8702.800595617835, + "body_count": 1, + "edges": 33, + "faces": 13, + "vertices": 22, + "volume_mm3": 44254.3419135911 + }, + "seconds": 2.217877403, + "status": "pass" }, "ladder/07-fillets/016-corner-three-sequential-r5-r3-r7": { "seconds": 0.045599545, diff --git a/tests/kernel-cases/ladder/ladder.json b/tests/kernel-cases/ladder/ladder.json index 22df15ac6..ae3c21f85 100644 --- a/tests/kernel-cases/ladder/ladder.json +++ b/tests/kernel-cases/ladder/ladder.json @@ -124,6 +124,7 @@ { "cases": [ "ladder/07-fillets/015-corner-g2-patch", + "ladder/07-fillets/019-concave-corner-g2-patch", "ladder/07-fillets/006-variable-r5-to-zero", "ladder/07-fillets/001-single-edge-r5", "ladder/07-fillets/007-variable-r5-to-1e-3", diff --git a/tools/kernel-ladder/cases.py b/tools/kernel-ladder/cases.py index 515083702..562a4e09a 100644 --- a/tools/kernel-ladder/cases.py +++ b/tools/kernel-ladder/cases.py @@ -863,8 +863,25 @@ case(T7, "014-curved-edge-r2", "an r2 round on the top edge of a cylinder r10 h2 {"body_count": 1, "volume_mm3": PI * 100 * 20 - SPANDREL * 4 * 2 * PI * (10 - XBAR * 2), "faces": 4}, "a torus round: Pappus on the removed section (1-pi/4) r^2 at radius 10 - r(10-3pi)/(12-3pi)") case(T7, "015-corner-g2-patch", "three r5 rounds at a corner with the g2 corner patch", - [F(corner, 5, corner="g2")], {"body_count": 1, "faces": 10}, - "the g2 patch replaces the sphere octant; no closed-form volume; one valid body, the same faces as 009", base=B1, source="invariants") + [F(corner, 5, corner="g2")], + {"body_count": 1, "faces": 10, "bbox": {"min": [0, 0, 0], "max": [60, 40, 20]}, + "continuity": {"near": [60, 40, 20], "within_mm": 15, "clear_mm": 1.2, "curvature_jump_per_mm": 0.001}}, + "the corner set back 1.5 r = 7.5 and filled with one patch G2 to the three rounds and the three faces; no closed-form volume; " + "one valid body, the same faces as 009, within the box; across the patch's seams the curvature jump is at most 1e-3 per mm " + "(the ball's corner, 009, jumps 1/r = 0.2) clear of the six points where a round's section ends on a face, where the round's " + "own G1 seam with the face ends (the patch passes from one curvature to the other within 15% of each side: 1.2 mm covers it)", + base=B1, source="invariants") +notch = [[50, 20, 10], [40, 30, 10], [40, 20, 15]] +case(T7, "019-concave-corner-g2-patch", "three concave r5 rounds at the inner corner of a 20x20x10 notch, with the g2 corner patch", + [box([40, 20, 10], 30, 30, 20, body_name="Notch"), C("solid.combine", target="Part", tools=["Notch"], operation="cut"), + F(notch, 5, corner="g2")], + {"body_count": 1, "faces": 13, "bbox": {"min": [0, 0, 0], "max": [60, 40, 20]}, + "continuity": {"near": [40, 20, 10], "within_mm": 11, "clear_mm": 1.2, "curvature_jump_per_mm": 0.001}}, + "the notch's inner corner (40,20,10), three concave edges, set back 1.5 r = 7.5 and filled with one patch G2 to the three " + "rounds and the three faces; one valid body with the faces of the ball corner (13); across the patch's seams the curvature " + "jump is at most 1e-3 per mm (the ball's corner jumps 1/r = 0.2) clear of the six points where a round's section ends on a face (within 11 mm of the corner: the hole reaches 7.5 sqrt 2; " + "the vertical round, 2.5 mm long past its setback, meets its faces 11.2 mm out, with the G1 jump every round has)", + base=B1, source="invariants") V7 = V5 - 2 * SPANDREL * 25 * 20 - SPANDREL * 9 * 60 + SPANDREL * 1 * 2 * PI * (8 + XBAR * 1) case(T7, "017-part-rounds", "the running part: r5 on the front vertical edges, r3 on the back wall's top front edge, r1 where the boss meets the top", [F([[0, 0, 10], [60, 0, 10]], 5), F([[30, 30, 35]], 3), F([[23, 15, 20]], 1)],