Wave 435/509: Fillets: a curvature-continuous fillet's corners are G2 patches

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

- ccc690c53 jyviko: Fillets: a curvature-continuous fillet's corners are G2 patches

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:38:21 -04:00
parent 4a0519e464
commit e58e85e3d6
13 changed files with 661 additions and 16 deletions
+16 -2
View File
@@ -337,6 +337,20 @@ fn setback_minimum(faces: &Faces, vertex: u32, radius: f64) -> Option<f64> {
/// 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<Body> {
g2_corners(body, edges, radius, setbacks, false)
}
/// [`fillet_g2`] (curvature-continuous sections) whose corners where three or more rounded edges
/// meet are G2 patches, as [`fillet_g2_corners`] builds them: SMLib's own patch at such a corner
/// is only tangent to the rounds (its curvature jumps across their seams), which no
/// curvature-continuous fillet may leave. Without such a corner this is [`fillet_g2`]. Refused
/// as [`fillet_g2_corners`] is.
pub fn fillet_g2_with_g2_corners(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec3, f64)]) -> Result<Body> {
g2_corners(body, edges, radius, setbacks, true)
}
/// [`fillet_g2_corners`] (circular sections) or [`fillet_g2_with_g2_corners`] (`curvature`).
fn g2_corners(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec3, f64)], curvature: bool) -> Result<Body> {
let _span = solidcraft_profile::span("kernel", "fillet_g2_corners");
body.require_brep("fillet")?;
if !(radius.is_finite() && radius > 0.0) {
@@ -372,7 +386,7 @@ pub fn fillet_g2_corners(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(
corners.push(p);
}
if corners.is_empty() {
return fillet(body, edges, radius);
return if curvature { fillet_g2(body, edges, radius) } else { fillet(body, edges, radius) };
}
// Each corner's setback: the one given at its vertex, else the default.
let reach = body.size() * 0.05 + 1e-3;
@@ -397,7 +411,7 @@ pub fn fillet_g2_corners(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(
}
let set_back: Vec<(Vec3, f64)> = corners.iter().copied().zip(distance).collect();
setbacks_reach(body, edges, radius, &set_back)?;
let open = crate::blend_smlib::fillet_setback_open(body, edges, radius, &set_back)?;
let open = crate::blend_smlib::fillet_setback_open(body, edges, radius, &set_back, curvature)?;
let mut patches = Vec::with_capacity(open.holes.len());
for hole in &open.holes {
let (patch, _) = crate::corner_g2::corner_patch(&open.sheet, hole, radius)?;
+17 -10
View File
@@ -55,8 +55,10 @@ pub(crate) struct OpenCorners {
/// [`fillet_setback`] with each set-back corner left open: SMLib builds the rounds up to the
/// corners' setback sections and the curves on the faces between them, and leaves out the patch
/// that would fill each corner, for the caller to fill.
pub(crate) fn fillet_setback_open(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec3, f64)]) -> Result<OpenCorners> {
imp::blend_setback_open(body, edges, &vec![radius; edges.len()], setbacks)
/// `curvature`: the rounds' sections are curvature-continuous ([`fillet_g2`]), else circular.
pub(crate) fn fillet_setback_open(body: &Body, edges: &[Vec3], radius: f64, setbacks: &[(Vec3, f64)], curvature: bool) -> Result<OpenCorners> {
let kind = if curvature { Kind::Curvature } else { Kind::Round };
imp::blend_setback_open(body, kind, edges, &vec![radius; edges.len()], setbacks)
}
/// Curvature-continuous rounds with the setback of a round of `radius` ([`crate::fillet_g2`]).
@@ -187,17 +189,22 @@ mod imp {
Ok(())
}
/// SMLib's blend of each kind.
fn blend_kind(kind: Kind) -> Blend {
match kind {
Kind::Round => Blend::Round,
Kind::Curvature => Blend::Curvature,
Kind::Chord => Blend::Chord,
Kind::Chamfer => Blend::Chamfer,
}
}
pub(super) fn blend(body: &Body, what: &str, kind: Kind, edges: &[Vec3], sizes: &[f64]) -> Result<Body> {
body.require_brep(what)?;
sizes_ok(what, sizes)?;
let picked = resolve(body, edges)?;
let next = crate::blend::unfinished_chain(body, edges, &picked.edges, &picked.hidden)?;
let kind = match kind {
Kind::Round => Blend::Round,
Kind::Curvature => Blend::Curvature,
Kind::Chord => Blend::Chord,
Kind::Chamfer => Blend::Chamfer,
};
let kind = blend_kind(kind);
let tol = pick_tolerance(body);
run(body, what, &picked.edges, |b| b.blend(kind, &picked.points, sizes, tol)).map_err(|e| crate::blend::with_continuation(e, next))
}
@@ -226,7 +233,7 @@ mod imp {
}
/// [`blend_setback`] with the set-back corners left open (`super::OpenCorners`).
pub(super) fn blend_setback_open(body: &Body, edges: &[Vec3], sizes: &[f64], setbacks: &[(Vec3, f64)]) -> Result<super::OpenCorners> {
pub(super) fn blend_setback_open(body: &Body, kind: Kind, edges: &[Vec3], sizes: &[f64], setbacks: &[(Vec3, f64)]) -> Result<super::OpenCorners> {
let what = "fillet with open setback corners";
body.require_brep(what)?;
sizes_ok(what, sizes)?;
@@ -243,7 +250,7 @@ mod imp {
let at: Vec<Vec3> = setbacks.iter().map(|(p, _)| *p).collect();
let tol = pick_tolerance(body);
let (sheet, holes, order) =
run_with(body, what, &picked.edges, &at, |b| b.blend_setback_open(Blend::Round, &picked.points, sizes, &corners, &distances, tol))
run_with(body, what, &picked.edges, &at, |b| b.blend_setback_open(blend_kind(kind), &picked.points, sizes, &corners, &distances, tol))
.map_err(|e| crate::blend::with_continuation(e, next))?;
// SMLib's indices in the sheet's own orders.
let place = |list: &[usize], i: usize| if list.is_empty() { Some(i) } else { list.get(i).copied() };
+22
View File
@@ -211,3 +211,25 @@ fn a_mixed_convexity_corner_is_refused() {
// The refusal names the corner and why: its rounds are not all of one convexity.
assert!(err.contains("not supported yet") && err.contains("(60.000, 20.000, 10.000)") && err.contains("all convex or all concave"), "{err}");
}
/// Curvature-continuous rounds (`fillet_g2`, equivalent radius 5) of the three edges at the box
/// corner: SMLib's own corner patch between them is only tangent to the rounds, its curvature
/// jumping across their seams (it showed as a dome on the corner), so the corner is the G2 patch
/// instead, filled between the curvature rounds' setback sections: one closed valid solid, the
/// patch curvature-continuous to every round and face round it clear of the hole's corners.
#[test]
fn curvature_rounds_meet_at_a_g2_corner() {
let (body, edges) = box_corner();
let smlib_corner = fillet_g2(&body, &edges, 5.0).unwrap();
let g2 = fillet_g2_with_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 (_, clear, n) = corner_seams(&g2, 0.15);
let (_, smlib_clear, _) = corner_seams(&smlib_corner, 0.15);
assert!(n > 0 && clear <= CURVATURE_SHARE / 5.0, "{clear} over {n} stations");
assert!(smlib_clear > 10.0 * CURVATURE_SHARE / 5.0, "SMLib's own corner patch: {smlib_clear}");
// Both differ only within the setback cube (side 1.5 r = 7.5) at the corner.
let (a, b) = (measure(&g2).unwrap().volume, measure(&smlib_corner).unwrap().volume);
assert!((a - b).abs() < 7.5f64.powi(3), "{a} vs {b}");
}
+2 -2
View File
@@ -154,8 +154,8 @@ mod validity;
pub mod watch;
pub use blend::{
ChamferSide, blend_edges, chamfer, chamfer_max, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_least_setback,
fillet_max, fillet_max_each, fillet_setback, tangent_chain,
ChamferSide, blend_edges, chamfer, chamfer_max, chamfer_sides, fillet, fillet_each, fillet_g2, fillet_g2_corners, fillet_g2_with_g2_corners,
fillet_least_setback, fillet_max, fillet_max_each, fillet_setback, tangent_chain,
};
pub use blend_corner::fillet_radii;
pub use blend_variable::{RadiusSpline, Taper, fillet_chord, fillet_tapered, fillet_variable, fillet_variable_points, fillet_variable_spline, taper};