Wave 503/509: Fillet: a setback too short for its corner is refused naming the least that builds (smlib_blend_fit_size) (and 3 more)
4 commits, squashed; the originals stay reachable from tag archive/merge-main-develop. - 5136898b9 jyviko: Fillet: a setback too short for its corner is refused naming the least that builds (smlib_blend_fit_size) - e6db7be0a jyviko: Kernel tests: three rounds of different radii at a corner meet in SMLib's setback corner - 5d168a5e2 jyviko: Kernel tests: SMLib's own corner between curvature rounds is curvature continuous, as the G2 patch is - 99953687c jyviko: Kernel rig: the boss root's and the hole rim's curvature rounds take the default timeout again (37 s and 34 s on the box under the rig's parallel load, tangency-labs/smlib#96) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ
This commit is contained in:
@@ -224,6 +224,10 @@ pub fn fillet_removing(body: &Body, edges: &[Vec3], radius: f64) -> Result<(Body
|
||||
Ok((closed(body, b)?, gone))
|
||||
}
|
||||
|
||||
/// What a refusal of a setback too short for its corner says before the least that builds (in
|
||||
/// mm): SMLib certifies the corner's fill convex only from that setback on ([`fillet_setback`]).
|
||||
pub const SETBACK_AT_LEAST: &str = "the smallest setback that builds is ";
|
||||
|
||||
/// [`fillet`] with corner setbacks: each `(at, distance)` sets back the corner at the vertex
|
||||
/// nearest `at`, a vertex where every edge is rounded, so its patch starts `distance` along
|
||||
/// each of its edges from the vertex (one distance for all of a corner's edges: SMLib keeps one
|
||||
|
||||
@@ -305,30 +305,6 @@ mod tests {
|
||||
8000.0 - full + (sum - union) * hh * hh
|
||||
}
|
||||
|
||||
/// What the strips leave of the corner block where a patch over the corner of rounds `ra`,
|
||||
/// `rb`, `rc` on a, b, c lies: beyond a's end section (y < rc), b's (x > 20 − rc) and c's end
|
||||
/// (z > 20 − max(ra, rb), where c's rails meet a's and b's), the box's material that no
|
||||
/// strip removes, by columns along z. Outside that block such a body is the strips' (its
|
||||
/// rounds are the strips' cylinders up to those ends), so its patch takes at most this
|
||||
/// beyond them.
|
||||
fn corner_block(ra: f64, rb: f64, rc: f64) -> f64 {
|
||||
let len = |d: f64, r: f64| if d < r { r - (r * r - (r - d) * (r - d)).max(0.0).sqrt() } else { 0.0 };
|
||||
let (n, depth) = (2000, ra.max(rb));
|
||||
let h = rc / n as f64;
|
||||
let mut kept = 0.0;
|
||||
for i in 0..n {
|
||||
let dx = (i as f64 + 0.5) * h;
|
||||
for j in 0..n {
|
||||
let dy = (j as f64 + 0.5) * h;
|
||||
if (rc - dx).powi(2) + (rc - dy).powi(2) > rc * rc && dx < rc && dy < rc {
|
||||
continue;
|
||||
}
|
||||
kept += depth - len(dx, ra).max(len(dy, rb)).min(depth);
|
||||
}
|
||||
}
|
||||
kept * h * h
|
||||
}
|
||||
|
||||
/// Largest angle (degrees) between the two faces' normals along edges between curved faces.
|
||||
fn kink(b: &Body) -> f64 {
|
||||
let rec = Faces::of(b).unwrap();
|
||||
@@ -515,29 +491,41 @@ mod tests {
|
||||
assert!(r.validity().is_empty(), "{:?}", r.validity());
|
||||
assert!((vol(&r) - sphere).abs() < 1e-11 * sphere, "{} vs {sphere}", vol(&r));
|
||||
assert!(kink(&r) < 0.01);
|
||||
// Different radii: a smooth patch over the corner, more than the strips take, and no more
|
||||
// than they leave in the block it lies in: its rounds end at a's section y = rc, b's
|
||||
// x = 20 − rc, and c's rails where they meet a's and b's (z = 20 − ra, z = 20 − rb), the
|
||||
// patch's four corners. (2, 2, 3): 1.168 beyond the strips, of the 11.86 the block keeps;
|
||||
// (2, 3, 4): 3.099 of 32.69.
|
||||
// Different radii: SMLib's setback corner (SmBlendSetback.h). Each round runs whole up to
|
||||
// its section square to its edge at its setback, the owner's rule's (at least 1.5 r, more
|
||||
// where the rails beside it cross later, scaled to the least at which the corner's G1 fill
|
||||
// is certified convex), and the hole between the three sections is filled by the setback
|
||||
// split: one setback patch per round and the triangle between them in three
|
||||
// quadrilaterals, so 6 planes, 3 rounds and 6 patches (15 faces), G1 across every seam.
|
||||
// Outside the box the sections span ([20 - d_b, 20] x [0, d_a] x [20 - d_c, 20], d each
|
||||
// edge's setback) the body is the three strips', so its volume is theirs within that box's.
|
||||
// The rounds a and b of one radius lie mirrored about the plane x + y = 20 with c: one
|
||||
// setback. (2, 2, 3): 3.6155, 3.6155, 4.6485; (2, 3, 4): 4.7745, 5.03975, 6.366 (a, b, c).
|
||||
for (rs, sel) in [((2.0, 2.0, 3.0), fillet(&ab, &[c], 3.0)), ((2.0, 3.0, 4.0), fillet_radii(&bx, &[(a, 2.0), (b, 3.0), (c, 4.0)]))] {
|
||||
let r = sel.unwrap();
|
||||
assert_eq!(r.face_count(), 10);
|
||||
assert_eq!(r.face_count(), 15);
|
||||
assert_eq!(r.unmeshed_faces(), 0);
|
||||
assert!(r.validity().is_empty(), "{:?}", r.validity());
|
||||
let k = kink(&r);
|
||||
assert!(k < 0.05, "kink {k}°");
|
||||
assert!(k < 0.01, "kink {k}°");
|
||||
let (ra, rb, rc) = rs;
|
||||
let ends = [
|
||||
Vec3::new(20.0 - ra, rc, 20.0),
|
||||
Vec3::new(20.0, rc, 20.0 - ra),
|
||||
Vec3::new(20.0 - rc, rb, 20.0),
|
||||
Vec3::new(20.0 - rc, 0.0, 20.0 - rb),
|
||||
];
|
||||
for p in ends {
|
||||
assert!(vertices(&r).iter().any(|q| q.dist(p) < 1e-9), "{rs:?}: no patch corner at {p:?}");
|
||||
let vs = vertices(&r);
|
||||
// An edge's setback: where its round's section meets both faces, at two vertices.
|
||||
let setback = |at: &dyn Fn(f64) -> [Vec3; 2], r: f64| -> Option<f64> {
|
||||
vs.iter()
|
||||
.flat_map(|p| [p.y, 20.0 - p.x, 20.0 - p.z])
|
||||
.find(|d| *d >= 1.5 * r - 1e-9 && *d < 20.0 && at(*d).iter().all(|q| vs.iter().any(|p| p.dist(*q) < 1e-9)))
|
||||
};
|
||||
let da = setback(&|d| [Vec3::new(20.0 - ra, d, 20.0), Vec3::new(20.0, d, 20.0 - ra)], ra);
|
||||
let db = setback(&|d| [Vec3::new(20.0 - d, 0.0, 20.0 - rb), Vec3::new(20.0 - d, rb, 20.0)], rb);
|
||||
let dc = setback(&|d| [Vec3::new(20.0 - rc, 0.0, 20.0 - d), Vec3::new(20.0, rc, 20.0 - d)], rc);
|
||||
eprintln!("{rs:?}: setbacks {da:?} {db:?} {dc:?}");
|
||||
let (Some(da), Some(db), Some(dc)) = (da, db, dc) else { panic!("{rs:?}: a round's setback section is missing: {da:?} {db:?} {dc:?}") };
|
||||
if ra == rb {
|
||||
assert!((da - db).abs() < 1e-9, "{da} vs {db}");
|
||||
}
|
||||
let (v, s) = (vol(&r), strips(ra, rb, rc));
|
||||
assert!(v < s + 0.05 && v > s - corner_block(ra, rb, rc), "{v} vs {s}");
|
||||
assert!((v - s).abs() < db * da * dc, "{v} vs {s}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -418,7 +418,15 @@ mod imp {
|
||||
"not supported yet: the {what} meets a corner of this kind, which SMLib's blends do not handle yet (where its edges \
|
||||
run on tangentially into each other, or meet in a way no blend corner builds)"
|
||||
)),
|
||||
SmError::NoRoom => KernelError::TooLarge(format!("the {what} is larger than the faces beside its edges allow")),
|
||||
// A setback too short for its corner's fill (SMLib certifies it convex only from
|
||||
// its least on) names that least; any other is a blend too large for its room.
|
||||
SmError::NoRoom => match solidcraft_smlib::blend_fit() {
|
||||
Some(solidcraft_smlib::Fit::SetbackAtLeast(least)) => KernelError::Invalid(format!(
|
||||
"the setback is too short for its corner: {}{least:.4} mm (the corner's patch is convex only from there)",
|
||||
crate::SETBACK_AT_LEAST
|
||||
)),
|
||||
_ => KernelError::TooLarge(format!("the {what} is larger than the faces beside its edges allow")),
|
||||
},
|
||||
e => failed(what, "operation", e),
|
||||
})?;
|
||||
// Checked here unless the evaluation's validation mode leaves it to the feature's end
|
||||
|
||||
@@ -344,10 +344,11 @@ fn a_mixed_convexity_corner_is_refused() {
|
||||
}
|
||||
|
||||
/// 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.
|
||||
/// corner: SMLib's own corner between them is its setback corner, whose fill for curvature
|
||||
/// sections meets the rounds and faces curvature-continuously (SmBlendSetback.h: G2 for an order
|
||||
/// 2 section), as the G2 patch filled between the curvature rounds' setback sections does: each
|
||||
/// one closed valid solid, curvature-continuous across every seam round the corner clear of the
|
||||
/// hole's corners.
|
||||
#[test]
|
||||
fn curvature_rounds_meet_at_a_g2_corner() {
|
||||
let (body, edges) = box_corner();
|
||||
@@ -357,9 +358,9 @@ fn curvature_rounds_meet_at_a_g2_corner() {
|
||||
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);
|
||||
let (_, smlib_clear, smlib_n) = 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}");
|
||||
assert!(smlib_n > 0 && smlib_clear <= CURVATURE_SHARE / 5.0, "SMLib's own corner: {smlib_clear} over {smlib_n} stations");
|
||||
// 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}");
|
||||
|
||||
@@ -44,8 +44,10 @@ fn a_setback_off_the_rounded_corner_is_refused() {
|
||||
}
|
||||
|
||||
/// A setback that does not reach past where the corner's rounds meet without one (on faces square
|
||||
/// to each other, the radius) is refused before SMLib runs, naming that least setback; a setback
|
||||
/// just past it builds.
|
||||
/// to each other, the radius) is refused before SMLib runs, naming that least setback. Past it, a
|
||||
/// setback still too short for SMLib's corner fill (certified convex only from a setback on,
|
||||
/// smlib_blend_fit_size's SMLIB_FIT_SETBACK_AT_LEAST) is refused naming the smallest that builds,
|
||||
/// at most twice the one asked for (the certificate scales the setbacks up to 2); that one builds.
|
||||
#[test]
|
||||
fn a_setback_not_past_the_radius_is_refused_naming_the_least() {
|
||||
for s in [2.0, 5.0] {
|
||||
@@ -54,7 +56,16 @@ fn a_setback_not_past_the_radius_is_refused_naming_the_least() {
|
||||
other => panic!("setback {s}: {:?}", other.map(|b| b.face_count())),
|
||||
}
|
||||
}
|
||||
let out = corner_case(Some(5.5)).unwrap();
|
||||
let least = match corner_case(Some(5.5)) {
|
||||
Err(KernelError::Invalid(why)) => {
|
||||
let named = why.split_once(SETBACK_AT_LEAST).and_then(|(_, rest)| rest.split_once(" mm")).and_then(|(n, _)| n.parse::<f64>().ok());
|
||||
named.unwrap_or_else(|| panic!("no least setback named: {why}"))
|
||||
}
|
||||
other => panic!("setback 5.5: {:?}", other.map(|b| b.face_count())),
|
||||
};
|
||||
eprintln!("setback 5.5 refused: the smallest that builds is {least}");
|
||||
assert!(least > 5.5 && least <= 11.0, "{least}");
|
||||
let out = corner_case(Some(least)).unwrap();
|
||||
assert!(out.validity().is_empty(), "{:?}", out.validity());
|
||||
// The least the refusal names, for a form to show before it runs; none at no vertex.
|
||||
let b = box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(60.0, 40.0, 20.0)).unwrap();
|
||||
|
||||
@@ -156,8 +156,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_g2_with_g2_corners,
|
||||
fillet_least_setback, fillet_max, fillet_max_each, fillet_removing, fillet_setback, tangent_chain,
|
||||
ChamferSide, SETBACK_AT_LEAST, 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_removing, 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};
|
||||
|
||||
Reference in New Issue
Block a user