From 5f2de93fc6cbd142a9cef09ef990edfab972ad2f Mon Sep 17 00:00:00 2001 From: jyviko <2501648+jyviko@users.noreply.github.com> Date: Sun, 1 Nov 2026 22:45:59 -0500 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01DtL5M41G8Nua7HvuFPZkmJ --- apps/solidcraft-cli/tests/model_cache.rs | 7 +- .../pending/fillet-setback-at-least.json | 23 +++++++ crates/engine/src/tests.rs | 17 ++--- crates/kernel/src/blend.rs | 4 ++ crates/kernel/src/blend_corner.rs | 68 ++++++++----------- crates/kernel/src/blend_smlib.rs | 10 ++- crates/kernel/src/corner_g2_tests.rs | 13 ++-- crates/kernel/src/fillet_setback_tests.rs | 17 ++++- crates/kernel/src/lib.rs | 4 +- crates/smlib/src/ffi/ops.rs | 21 +++++- crates/smlib/src/lib.rs | 2 +- crates/smlib/src/ops.rs | 29 ++++++++ crates/ui-egui/src/dialogs.rs | 14 ++-- crates/ui-egui/src/dialogs_dense.rs | 20 ++++++ tests/KNOWN_FAILING_TESTS | 1 - .../expected.json | 3 +- .../expected.json | 3 +- 17 files changed, 182 insertions(+), 74 deletions(-) create mode 100644 assets/locales/pending/fillet-setback-at-least.json diff --git a/apps/solidcraft-cli/tests/model_cache.rs b/apps/solidcraft-cli/tests/model_cache.rs index c5586052a..5d9ec3ed5 100644 --- a/apps/solidcraft-cli/tests/model_cache.rs +++ b/apps/solidcraft-cli/tests/model_cache.rs @@ -317,7 +317,8 @@ fn a_model_saved_under_another_check_mode_is_evaluated_again() { /// later round at the corner where they meet blends them again with it whether the design was /// opened from its model or evaluated anew. Two edges of a 20 mm box rounded r2 (a mitre at the /// corner (20, 0, 20)), saved; opened, the upright edge there rounded r3: the corner all three -/// rounded at once make, 10 faces and 7928.743041 mm³, the same body as the design evaluated anew. +/// rounded at once make (SMLib's setback corner, kernel `three_rounds_at_a_corner`), 15 faces and +/// 7928.142563938 mm³, the same body as the design evaluated anew. #[test] fn a_later_round_after_opening_blends_the_saved_rounds_again() { let mut built = Session::default(); @@ -334,8 +335,8 @@ fn a_later_round_after_opening_blends_the_saved_rounds_again() { let st = s.model.state(); let b = &st.body("Box").unwrap().body; let v = solidcraft_engine::kernel::measure(b).unwrap().volume; - assert_eq!(b.face_count(), 10); - assert!((v - 7928.743041).abs() < 1e-6, "{v}"); + assert_eq!(b.face_count(), 15); + assert!((v - 7928.142563938).abs() < 1e-6, "{v}"); } assert_eq!(model("later round", &cached), model("later round", &rebuilt)); let _ = std::fs::remove_file(&path); diff --git a/assets/locales/pending/fillet-setback-at-least.json b/assets/locales/pending/fillet-setback-at-least.json new file mode 100644 index 000000000..9c2ac2a48 --- /dev/null +++ b/assets/locales/pending/fillet-setback-at-least.json @@ -0,0 +1,23 @@ +{ + "en": { + "ui.fillet_error_setback_short": "The setback is too short for this corner's patch: it builds from {least} on. Try a longer Setback." + }, + "ar": { + "ui.fillet_error_setback_short": "مسافة الإرجاع قصيرة جدًا على رقعة هذه الزاوية: تُبنى ابتداءً من {least}. جرّب مسافة إرجاع أطول." + }, + "de": { + "ui.fillet_error_setback_short": "Der Rücksprung ist für das Eckstück zu kurz: Es lässt sich ab {least} bauen. Versuchen Sie einen längeren Rücksprung." + }, + "he": { + "ui.fillet_error_setback_short": "הנסיגה קצרה מדי עבור הטלאי של פינה זו: הוא נבנה החל מ-{least}. נסו נסיגה ארוכה יותר." + }, + "ja": { + "ui.fillet_error_setback_short": "このコーナーのパッチにはセットバックが短すぎます。{least} 以上で作れます。より長いセットバックを試してください。" + }, + "ko": { + "ui.fillet_error_setback_short": "이 코너의 패치에 비해 셋백이 너무 짧습니다. {least}부터 만들 수 있습니다. 더 긴 셋백을 시도해 보세요." + }, + "zh": { + "ui.fillet_error_setback_short": "对于此角点的面片,后退距离太短:从 {least} 起可以构建。请尝试更长的后退距离。" + } +} diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 598d39e50..4c8c5fd00 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -91,10 +91,10 @@ fn fillet_as_wide_as_a_face_rounds_it_off() { /// The owner's ruling of 2026-10-30: two edges of a 20 mm box rounded r2 in one fillet (they /// meet in a mitre at the corner (20, 0, 20), the upright edge there sharp), then the upright edge -/// r3 in a second fillet, whose tangent chain takes the mitre's seam with it. The corner is one -/// smooth patch, the body rounding all three at once makes (kernel `fillet_radii` of the box with -/// each edge's radius: 10 faces, 7928.743041 mm³); the r2 rounds keep their names, and the r3 -/// round and the corner patch are the second fillet's. +/// r3 in a second fillet, whose tangent chain takes the mitre's seam with it. The corner is the +/// body rounding all three at once makes (kernel `fillet_radii` of the box with each edge's +/// radius, `three_rounds_at_a_corner`: SMLib's setback corner, 15 faces, 7928.142563938 mm³); the +/// r2 rounds keep their names, and the r3 round and the corner's patches are the second fillet's. #[test] fn a_later_round_at_a_mitred_corner_is_blended_with_the_rounds_there() { let mut s = Session::default(); @@ -116,16 +116,17 @@ fn a_later_round_at_a_mitred_corner_is_blended_with_the_rounds_there() { let second = run(&mut s, "solid.fillet", json!({"edges": [[20, 0, 10]], "radius": 3}))["feature"].as_u64().unwrap(); assert!(s.model.results.iter().all(|r| r.error.is_none()), "{:?}", s.model.results); let v = volume(&mut s); - assert!((v - 7928.743041).abs() < 1e-5, "{v}"); + assert!((v - 7928.142563938).abs() < 1e-6, "{v}"); let faces = run(&mut s, "model.faces", json!({"body": "Box"}))["faces"].as_array().cloned().unwrap_or_default(); - assert_eq!(faces.len(), 10); + assert_eq!(faces.len(), 15); let after: Vec = rounds.iter().map(|p| named(&mut s, *p)).collect(); assert_eq!(after, before); - // The r3 round (halfway up, at 45°) and the corner patch: the two faces the second fillet made. + // The r3 round (halfway up, at 45°) and the corner's patches: the faces the second fillet made. let k3 = 3.0 - 4.5_f64.sqrt(); assert!(named(&mut s, solidcraft_geom::Vec3::new(20.0 - k3, k3, 10.0)).starts_with(&format!("F{second}:blend:"))); let made = faces.iter().filter(|f| f["name"].as_str().is_some_and(|n| n.starts_with(&format!("F{second}:")))).count(); - assert_eq!(made, 2, "{faces:?}"); + // the r3 round and the corner's six patches (a setback patch per round, three in the triangle) + assert_eq!(made, 7, "{faces:?}"); } #[test] diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs index 9dc8e3960..3627436f7 100644 --- a/crates/kernel/src/blend.rs +++ b/crates/kernel/src/blend.rs @@ -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 diff --git a/crates/kernel/src/blend_corner.rs b/crates/kernel/src/blend_corner.rs index a6fbaf575..544e2a2ef 100644 --- a/crates/kernel/src/blend_corner.rs +++ b/crates/kernel/src/blend_corner.rs @@ -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 { + 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}"); } } diff --git a/crates/kernel/src/blend_smlib.rs b/crates/kernel/src/blend_smlib.rs index 88e209246..032aea79a 100644 --- a/crates/kernel/src/blend_smlib.rs +++ b/crates/kernel/src/blend_smlib.rs @@ -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 diff --git a/crates/kernel/src/corner_g2_tests.rs b/crates/kernel/src/corner_g2_tests.rs index 88125bc27..325741826 100644 --- a/crates/kernel/src/corner_g2_tests.rs +++ b/crates/kernel/src/corner_g2_tests.rs @@ -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}"); diff --git a/crates/kernel/src/fillet_setback_tests.rs b/crates/kernel/src/fillet_setback_tests.rs index 5c9166099..04a92776e 100644 --- a/crates/kernel/src/fillet_setback_tests.rs +++ b/crates/kernel/src/fillet_setback_tests.rs @@ -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::().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(); diff --git a/crates/kernel/src/lib.rs b/crates/kernel/src/lib.rs index 461fed2fa..72ee89ccf 100644 --- a/crates/kernel/src/lib.rs +++ b/crates/kernel/src/lib.rs @@ -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}; diff --git a/crates/smlib/src/ffi/ops.rs b/crates/smlib/src/ffi/ops.rs index 9d2ba3bfd..6cdc07c44 100644 --- a/crates/smlib/src/ffi/ops.rs +++ b/crates/smlib/src/ffi/ops.rs @@ -1,5 +1,5 @@ //! The operations block of `capi/include/smlib.h` (`smlib_boolean`, `smlib_boolean_union_all`, `smlib_boolean2d`, `smlib_fillet`, -//! `smlib_chamfer`, `smlib_blend`, `smlib_blend_dropping`, `smlib_blend_setback`, `smlib_blend_setback_open`, `smlib_fillet_variable`, `smlib_chamfer_sides`, `smlib_shell`, `smlib_offset_faces`, +//! `smlib_chamfer`, `smlib_blend`, `smlib_blend_dropping`, `smlib_blend_setback`, `smlib_blend_setback_open`, `smlib_blend_fit_size`, `smlib_fillet_variable`, `smlib_chamfer_sides`, `smlib_shell`, `smlib_offset_faces`, //! `smlib_thicken`, `smlib_draft`, `smlib_merge_faces`, `smlib_brep_solid_count`, `smlib_imprint`; the fork's `capi/src/smlib_ops.cpp`), declared by //! hand. Part of the FFI boundary, like its parent: called only through //! [`crate::ops`]. @@ -31,6 +31,11 @@ pub const BLEND_CURVATURE: i32 = 1; pub const BLEND_CHORD: i32 = 2; pub const BLEND_CHAMFER: i32 = 3; +pub const FIT_SIZE: i32 = 0; +pub const FIT_SETBACK: i32 = 1; +pub const FIT_SCALE: i32 = 2; +pub const FIT_SETBACK_AT_LEAST: i32 = 3; + /// Which selection operation: the C functions share one signature. #[derive(Clone, Copy)] pub enum Pick { @@ -95,6 +100,7 @@ unsafe extern "C" { out: *mut *mut RawBrep, out_failed_point: *mut i64, ) -> i32; + fn smlib_blend_fit_size(out_size: *mut f64, out_what: *mut i32) -> i32; fn smlib_blend_dropping( brep: *const RawBrep, kind: i32, @@ -251,6 +257,19 @@ pub fn pick_op(kind: Pick, b: &Handle, points: &[[f64; 3]], tolerance: f64, size }) } +/// `smlib_blend_fit_size`: the size that builds, and what it sizes (`FIT_*`), for the last blend +/// call SMLib refused as too large or a setback as too short; `None` where it names none. +#[cfg(feature = "native")] +pub fn blend_fit_size() -> Option<(f64, i32)> { + let (mut size, mut what) = (0.0f64, -1i32); + (unsafe { smlib_blend_fit_size(&mut size, &mut what) } == OK).then_some((size, what)) +} + +#[cfg(not(feature = "native"))] +pub fn blend_fit_size() -> Option<(f64, i32)> { + None +} + #[cfg(feature = "native")] pub fn thicken(b: &Handle, thickness: f64, symmetric: bool) -> Result { new_brep(|out| unsafe { smlib_thicken(b.raw(), thickness, i32::from(symmetric), out) }) diff --git a/crates/smlib/src/lib.rs b/crates/smlib/src/lib.rs index 3682e6a8a..8a63fb7b8 100644 --- a/crates/smlib/src/lib.rs +++ b/crates/smlib/src/lib.rs @@ -32,7 +32,7 @@ pub mod trim; pub use check::{CheckLevel, CheckReport}; pub use measure::{MEASURE_ACCURACY, MassProperties, PointClass}; -pub use ops::{Blend, BooleanOp, ChamferSecond, Hole, HoleEdge, MAX_POINTS, MAX_UNION_BREPS}; +pub use ops::{Blend, BooleanOp, ChamferSecond, Fit, Hole, HoleEdge, MAX_POINTS, MAX_UNION_BREPS, blend_fit}; /// Why an SMLib call failed. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/smlib/src/ops.rs b/crates/smlib/src/ops.rs index 44d5f422d..83f41e12d 100644 --- a/crates/smlib/src/ops.rs +++ b/crates/smlib/src/ops.rs @@ -8,6 +8,35 @@ use crate::{Brep, Error, Result, error, ffi, init}; +/// What size builds a blend SMLib refused ([`blend_fit`]): from the refusal's own cause, never by +/// building again. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum Fit { + /// The largest size (a round's radius, a chamfer's distance, a chord's width) that builds. + Size(f64), + /// The largest setback of a set-back corner that fits (the one asked for is too long). + Setback(f64), + /// The factor (< 1) a two-distance chamfer's distances are both scaled by to build. + Scale(f64), + /// The smallest setback that builds the corner (the one asked for is too short: its fill is + /// certified convex only from there). + SetbackAtLeast(f64), +} + +/// The size that builds the last blend this process's SMLib refused as too large +/// ([`Error::NoRoom`]) or whose setback it refused as too short; `None` where it names no single +/// size. Read it right after the refused call: SMLib keeps only the last one. +pub fn blend_fit() -> Option { + let (size, what) = ffi::ops::blend_fit_size()?; + match what { + ffi::ops::FIT_SIZE => Some(Fit::Size(size)), + ffi::ops::FIT_SETBACK => Some(Fit::Setback(size)), + ffi::ops::FIT_SCALE => Some(Fit::Scale(size)), + ffi::ops::FIT_SETBACK_AT_LEAST => Some(Fit::SetbackAtLeast(size)), + _ => None, + } +} + /// How [`Brep::boolean`] combines two bodies. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum BooleanOp { diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 533ae07b3..e6cdb875b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2665,7 +2665,7 @@ fn error_rows(app: &mut SolveApp, ctx: &egui::Context, d: &mut Dialog, ui: &mut #[derive(Debug, PartialEq)] pub(crate) enum FilletRefusal { /// In these plain words. - Plain(&'static str), + Plain(String), /// Not again: the Setback field already flags the value and names the least it takes. InField, } @@ -2680,6 +2680,12 @@ pub(crate) fn fillet_plain_error(error: &str, setback_in_field: bool) -> Option< if setback_in_field && error.contains("the setback must be more than") { return Some(FilletRefusal::InField); } + // A setback too short for its corner's patch: the least that builds, as the kernel names it + if let Some((_, rest)) = error.split_once(solidcraft_engine::kernel::SETBACK_AT_LEAST) + && let Some(least) = rest.split_once(" mm").map(|(n, _)| n.trim()).filter(|n| n.parse::().is_ok()) + { + return Some(FilletRefusal::Plain(crate::i18n::format("ui.fillet_error_setback_short", &[("least", &format!("{least} mm"))]))); + } let too_large = error.contains("larger than the faces beside its edges allow"); let corner = error.contains("setback") || error.contains("G2 corner") || error.contains("corner patch"); let kernel = error.contains("SMLib") @@ -2688,11 +2694,11 @@ pub(crate) fn fillet_plain_error(error: &str, setback_in_field: bool) -> Option< || error.contains("kernel internal error") || error.contains("the rounds would leave openings"); if too_large { - Some(FilletRefusal::Plain(tr("ui.fillet_error_too_large"))) + Some(FilletRefusal::Plain(tr("ui.fillet_error_too_large").to_string())) } else if corner && kernel { - Some(FilletRefusal::Plain(tr("ui.fillet_error_corner"))) + Some(FilletRefusal::Plain(tr("ui.fillet_error_corner").to_string())) } else if kernel { - Some(FilletRefusal::Plain(tr("ui.fillet_error_failed"))) + Some(FilletRefusal::Plain(tr("ui.fillet_error_failed").to_string())) } else { None } diff --git a/crates/ui-egui/src/dialogs_dense.rs b/crates/ui-egui/src/dialogs_dense.rs index 3814f8c02..f9f8400bd 100644 --- a/crates/ui-egui/src/dialogs_dense.rs +++ b/crates/ui-egui/src/dialogs_dense.rs @@ -1416,6 +1416,26 @@ mod tests { /// A smooth-patch fillet reopens with its corner and setback, and OK writes them as saved; a /// setback list the dialog cannot show as one distance is kept as it is. + /// A setback too short for SMLib's corner fill (past the least the field flags) is refused by + /// the kernel naming the smallest that builds; the dialog says it in plain words, that length + /// in them. + #[test] + fn a_setback_too_short_for_the_corner_says_the_least_that_builds() { + let refused = format!( + "invalid parameters for `solid.fillet`: the setback is too short for its corner: {}5.9620 mm (the corner's patch is convex only from there)", + solidcraft_engine::kernel::SETBACK_AT_LEAST + ); + match crate::dialogs::fillet_plain_error(&refused, true) { + Some(crate::dialogs::FilletRefusal::Plain(plain)) => assert!(plain.contains("5.9620 mm"), "{plain}"), + other => panic!("{other:?}"), + } + // A blend too large for its faces keeps its own words. + assert_eq!( + crate::dialogs::fillet_plain_error("the fillet is larger than the faces beside its edges allow", true), + Some(crate::dialogs::FilletRefusal::Plain(crate::i18n::tr("ui.fillet_error_too_large").to_string())) + ); + } + #[test] fn a_saved_smooth_patch_reopens_with_its_setback() { for (setbacks, field) in [ diff --git a/tests/KNOWN_FAILING_TESTS b/tests/KNOWN_FAILING_TESTS index e9003bc98..49db644ff 100644 --- a/tests/KNOWN_FAILING_TESTS +++ b/tests/KNOWN_FAILING_TESTS @@ -15,7 +15,6 @@ solidcraft-engine::tests::shell_tangent_chain_that_opens_every_face_explains_how solidcraft-kernel::blend::corner_tests::a_round_ending_in_an_earlier_round_matches_both_together SMLib fillet status 1001 on the round that ends in the earlier one solidcraft-kernel::blend::corner_tests::corner_blends_hold_at_any_scale at 0.01x a picked edge runs on tangentially into an unblended edge and SMLib's result is not a closed solid (the smooth-vertex End, tangency-labs/smlib#81) solidcraft-kernel::blend_corner::tests::issue2422_vertical_after_separate_bottom_rounds SMLib's check refuses the fillet: edge and vertex tolerance 0.97 against the body's 0.01 (#2422) -solidcraft-kernel::blend_corner::tests::three_rounds_at_a_corner the corner's variable-radius transition between rounds of different radii (its elliptic law, a rail edge the corner interpolates) meets its neighbours at 0.144 degrees once its sections are the balls' touch circles (0 with the great circles); the corner step replaces that transition solidcraft-kernel::corner_g2::tests::a_long_setback_keeps_the_g2_patch_inside_the_box at set backs 11 to 15 the G2 corner patch bulges 2.6e-6 to 1.33e-3 past the box (the explicit corner is in progress) solidcraft-kernel::corner_g2::tests::the_box_corner_g2_patch_is_a_closed_solid_curvature_continuous_to_its_neighbours the fitted G2 corner patch bulges 1.7e-5 past the box, which SMLib's exact tight box now sees (the explicit G2 corner builds it inside) solidcraft-kernel::tests::fillet_tabbed_plate_outer_loop_and_partial_selection_after_hole the partial selection runs on tangentially into an unblended edge and SMLib's result is not a closed solid (the smooth-vertex End, tangency-labs/smlib#81) diff --git a/tests/kernel-cases/fillets/cov-fillet-section-curvature-boss-root-r2/expected.json b/tests/kernel-cases/fillets/cov-fillet-section-curvature-boss-root-r2/expected.json index 06733808a..f752858e7 100644 --- a/tests/kernel-cases/fillets/cov-fillet-section-curvature-boss-root-r2/expected.json +++ b/tests/kernel-cases/fillets/cov-fillet-section-curvature-boss-root-r2/expected.json @@ -11,6 +11,5 @@ }, "tolerance": { "rel": 1e-07 - }, - "timeout_s": 1800 + } } diff --git a/tests/kernel-cases/fillets/every-hole-top-rim-r1-curvature/expected.json b/tests/kernel-cases/fillets/every-hole-top-rim-r1-curvature/expected.json index a05967899..8f1712ccb 100644 --- a/tests/kernel-cases/fillets/every-hole-top-rim-r1-curvature/expected.json +++ b/tests/kernel-cases/fillets/every-hole-top-rim-r1-curvature/expected.json @@ -20,6 +20,5 @@ }, "continuity": { "order": "g2" - }, - "timeout_s": 600 + } }