Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Fillets on solidcore: a blend too large names the largest size that fits and its edge, from the kernel; the crossing-rails mixed corner is not supported (solidcore#2256)

brett19881899bee160
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index edc0b12ad2..043a697bf6 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -444,8 +444,12 @@ fn with_largest_fit(
size: &str,
search: impl FnOnce() -> std::result::Result<Option<(f64, kernel::Body)>, kernel::KernelError>,
) -> kernel::KernelError {
+ // The kernel's refusal may name it already, sized exactly where it was found.
+ if kernel::names_largest_fit(&why) {
+ return kernel::KernelError::TooLarge(why);
+ }
match search() {
- Ok(Some((largest, _))) => kernel::KernelError::TooLarge(format!("{why}; the largest {size} that fits is {} mm", show_mm(largest))),
+ Ok(Some((largest, _))) => kernel::KernelError::TooLarge(format!("{why}; {}", kernel::largest_fit_note(size, largest))),
Ok(None) => kernel::KernelError::TooLarge(why),
Err(e) => {
log::debug!("the largest {size} that fits: {e}");
diff --git a/crates/engine/src/tests/blend_fit.rs b/crates/engine/src/tests/blend_fit.rs
index f612fbae49..15b3c39495 100644
--- a/crates/engine/src/tests/blend_fit.rs
+++ b/crates/engine/src/tests/blend_fit.rs
@@ -45,6 +45,24 @@ fn chamfer_that_fits_still_builds() {
}
}
+/// #199's bar, 14 x 6 x 10, its four upright edges rounded: past a full round of its 6 mm ends
+/// the two rounds on each end would cross. Refused, naming 3 mm; on solidcore the kernel's refusal
+/// carries that size and the edge it was found for (`SolidError::FilletRefused`), so the message
+/// names the edge and the feature runs no search.
+#[test]
+fn a_round_past_a_full_round_is_refused_naming_the_largest_that_fits_and_its_edge() {
+ let mut s = Session::default();
+ run(&mut s, "solid.box", json!({"length": 14, "width": 6, "height": 10, "corner": [14, 0, 0]}));
+ let uprights = json!([[14, 0, 5], [28, 0, 5], [14, 6, 5], [28, 6, 5]]);
+ let on_solidcore = solidcraft_kernel::kernel_route::backend() == solidcraft_kernel::kernel_route::Backend::Solidcore;
+ for r in [3.001, 3.5] {
+ let e = s.execute("solid.fillet", &json!({"edges": uprights, "radius": r})).unwrap_err().to_string();
+ assert!(e.contains("the largest radius that fits is 3 mm"), "{r}: {e}");
+ assert!(!on_solidcore || e.contains("beside the edge at ("), "{r}: {e}");
+ }
+ assert!((volume(&mut s) - 840.0).abs() < 1e-6, "the part stays as it was");
+}
+
/// A rib 4 mm wide: blends of its two top edges meet in its top's middle at 2 mm and past that
/// would cross each other. Refused as too large, naming the largest size that fits.
#[test]
diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs
index 3627436f7f..61b2215e1f 100644
--- a/crates/kernel/src/blend.rs
+++ b/crates/kernel/src/blend.rs
@@ -25,6 +25,25 @@ pub(crate) fn too_large(msg: &str) -> KernelError {
KernelError::TooLarge(msg.into())
}
+/// The note on a blend's refusal as too large that names the largest `size` (radius, distance)
+/// that fits: "the largest radius that fits is 3 mm". The kernel's own sized refusals and a fillet
+/// feature's search for the size ([`fillet_max`]) word it alike.
+pub fn largest_fit_note(size: &str, largest: f64) -> String {
+ format!("the largest {size} that fits is {} mm", trimmed_mm(largest))
+}
+
+/// Whether a refusal already names the largest size that fits ([`largest_fit_note`]), so no search
+/// for it is needed.
+pub fn names_largest_fit(why: &str) -> bool {
+ why.contains("that fits is ")
+}
+
+/// `v` to the micrometre, without trailing zeros.
+pub(crate) fn trimmed_mm(v: f64) -> String {
+ let s = format!("{v:.6}");
+ s.trim_end_matches('0').trim_end_matches('.').to_string()
+}
+
fn v3(p: [f64; 3]) -> Vec3 {
Vec3::new(p[0], p[1], p[2])
}
diff --git a/crates/kernel/src/blend_smlib.rs b/crates/kernel/src/blend_smlib.rs
index 77b62d9ccf..d9a0d4c682 100644
--- a/crates/kernel/src/blend_smlib.rs
+++ b/crates/kernel/src/blend_smlib.rs
@@ -445,6 +445,19 @@ mod imp {
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")),
+ SmError::TooLarge { size, kind, at } => {
+ let beside = match at {
+ Some([x, y, z]) => format!("the edge at ({x:.3}, {y:.3}, {z:.3})"),
+ None => "its edges".to_owned(),
+ };
+ let fits = match kind {
+ solidcraft_smlib::FitKind::Scale => {
+ format!("the largest that fits is {} times the distances given", crate::blend::trimmed_mm(size))
+ }
+ kind => crate::blend::largest_fit_note(kind.word(), size),
+ };
+ KernelError::TooLarge(format!("the {what} is larger than the faces beside {beside} allow; {fits}"))
+ }
SmError::Unported(why) => KernelError::Invalid(format!("not supported yet: {why}")),
e => failed(what, "operation", e),
})?;
diff --git a/crates/kernel/src/lib.rs b/crates/kernel/src/lib.rs
index ae969590c3..4f7d6c3201 100644
--- a/crates/kernel/src/lib.rs
+++ b/crates/kernel/src/lib.rs
@@ -157,7 +157,7 @@ pub mod watch;
pub use blend::{
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,
+ fillet_g2_with_g2_corners, fillet_least_setback, fillet_max, fillet_max_each, fillet_removing, fillet_setback, largest_fit_note, names_largest_fit, 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/core/blend.rs b/crates/smlib/src/core/blend.rs
index ebbbf7e68a..0da043b809 100644
--- a/crates/smlib/src/core/blend.rs
+++ b/crates/smlib/src/core/blend.rs
@@ -24,9 +24,10 @@ use std::sync::PoisonError;
use solidcore::EntityRef;
use solidcore::SolidError;
+use solidcore::blend::fillet_corner::p3::MIXED_CORNER_RAILS_CROSS;
use solidcore::blend::fillet_executive::p1::{FilletLaw, FilletLawKind};
-use solidcore::blend::fillet_executive::p3::NoRoomReason;
-use solidcore::blend::fillet_executive::session::FilletSession;
+use solidcore::blend::fillet_executive::p3::{ErrorInfo, FitKind, NoRoomReason};
+use solidcore::blend::fillet_executive::session::{FilletObject, FilletSession};
use solidcore::blend::fillet_geom::p1::{FilletCornerType, FilletErrorType};
use solidcore::blend::fillet_section::section::GN_THUMBWEIGHT_EQUAL_AREA;
use solidcore::blend::fillet_solver::p1::FilletSurfaceGeneratorType;
@@ -52,6 +53,12 @@ use solidcore::topology::{Brep, EdgeId, EdgeuseId, FaceId, FaceuseId, VertexId,
use super::{Body, answer, run};
use crate::{Blend, ChamferSecond, Error, Hole, HoleEdge, MAX_POINTS, Result};
+
+/// Why solidcore refuses the 3x2 mixed-convexity corner whose rails cross
+/// (`fixes.fillet_refuse_mixed_corner_crossing_rails`, [`MIXED_CORNER_RAILS_CROSS`]): it builds no
+/// corner for it yet.
+pub(crate) const MIXED_CORNER_UNSUPPORTED: &str = "a fillet corner where a convex and a concave round leave the vertex along one \
+tangent, so that their contact lines cross before the corner (https://github.com/tangency-labs/solidcore/issues/2256)";
use solidcore::topology::brep::p3::brep_copy;
/// The capi's statuses as SolidCraft errors: an operation's own result.
@@ -66,6 +73,7 @@ pub(super) fn status(e: SolidError) -> Error {
match e {
SolidError::Upstream { code, .. } => Error::Status(code),
SolidError::InvalidInput { .. } => Error::Status(INVALID_INPUT),
+ SolidError::Unsupported { reason, .. } if reason == MIXED_CORNER_RAILS_CROSS => Error::Unported(MIXED_CORNER_UNSUPPORTED),
e if e.is_unported() => Error::Unsupported,
e => Error::Solidcore(e.to_string()),
}
@@ -272,8 +280,41 @@ fn face_set(b: &Brep) -> solidcore::Result<HashSet<FaceId>> {
/// refusing it. Its answer is the fork's only by chance, so it is [`Error::Unsupported`]. With
/// the cliff overflow on, solidcore makes the fork's choice, and its refusals (each with its own
/// reason) are [`Error::NoRoom`] like the fork's.
-fn blend_failure(s: &FilletSession<'_>, e: SolidError, corner: bool) -> Error {
+///
+/// A blend too large that solidcore sizes (the session's fit, as the fork's capi reads it with
+/// `smlib_blend_fit_size`, or [`SolidError::FilletRefused`] carrying it; under
+/// `fixes.fillet_gn_section_generator`) is [`Error::TooLarge`] with that size, its edge's point
+/// filled in by the caller from the edge returned with it ([`sized_on`]); a corner solidcore
+/// refuses as not supported (the mixed corner whose rails cross, solidcore#2256) is
+/// [`Error::Unported`] naming it.
+fn blend_failure(s: &FilletSession<'_>, e: SolidError, corner: bool) -> (Error, Option<EdgeId>) {
let info = s.error_info();
+ let fit = match &e {
+ SolidError::FilletRefused { fit, .. } => Some(*fit),
+ _ if info.code == FilletErrorType::NoRoom as i32 => s.fit_size(),
+ _ => None,
+ };
+ if e.is_unported() || matches!(e, SolidError::Unsupported { reason, .. } if reason == MIXED_CORNER_RAILS_CROSS) {
+ (status(e), None)
+ } else if let Some(fit) = fit
+ && !corner
+ && info.no_room_reason() != Some(NoRoomReason::RailLeavesFace)
+ && fit.size.is_finite()
+ && fit.size > 0.0
+ {
+ let kind = match fit.kind {
+ FitKind::Radius => crate::FitKind::Radius,
+ FitKind::Scale => crate::FitKind::Scale,
+ FitKind::Chord => crate::FitKind::Chord,
+ };
+ (Error::TooLarge { size: fit.size, kind, at: None }, fit.edge)
+ } else {
+ (blend_failure_unsized(info, e, corner), None)
+ }
+}
+
+/// [`blend_failure`] where solidcore gives no size.
+fn blend_failure_unsized(info: &ErrorInfo<FilletObject>, e: SolidError, corner: bool) -> Error {
if e.is_unported() {
status(e)
} else if corner || info.code == FilletErrorType::CornerUnsupported as i32 {
@@ -287,6 +328,32 @@ fn blend_failure(s: &FilletSession<'_>, e: SolidError, corner: bool) -> Error {
}
}
+/// `e` ([`Error::TooLarge`]) with the point at the middle of `edge` of `b`, the edge its size was
+/// found for; an equal chamfer's size (its ball's radius, [`chamfer_radius`]) as its distance.
+/// Where the edge or its point can't be read the size stays as it is, with no point (a chamfer's
+/// size then is not a distance, so it is left a plain refusal).
+fn sized_on(k: &Kernel, b: &mut Brep, edge: Option<EdgeId>, section: Section<'_>, e: Error) -> solidcore::Result<Error> {
+ let Error::TooLarge { size, kind, .. } = e else { return Ok(e) };
+ let Some(edge) = edge else {
+ return Ok(if matches!(section, Section::Chamfer(_)) && kind == crate::FitKind::Radius { Error::NoRoom } else { e });
+ };
+ let at = match b.edge(edge) {
+ Ok(rec) => match rec.curve.as_ref() {
+ Some(c) => answer(c.evaluate_point(k, rec.interval.evaluate(0.5)))?.map(|p| [p.x, p.y, p.z]),
+ None => None,
+ },
+ Err(_) => None,
+ };
+ if matches!(section, Section::Chamfer(_)) && kind == crate::FitKind::Radius {
+ // The ball's radius is linear in the chamfer's distance along an edge.
+ return Ok(match chamfer_radius(k, b, edge, 1.0)? {
+ Some(per_mm) => Error::TooLarge { size: size / per_mm, kind: crate::FitKind::Distance, at },
+ None => Error::NoRoom,
+ });
+ }
+ Ok(Error::TooLarge { size, kind, at })
+}
+
/// `round_edges`' `overflow_first` argument: with it the session stops, nothing built, when blends
/// of several edges overflow their faces across cliffs (`SetOverflowFirst`) or (`classify_only`)
/// always (`SetClassifyOnly`), and `stopped` gets the edges whose blends overflow
@@ -337,6 +404,8 @@ fn blend_edges_stopping(
overflow_first: Option<OverflowFirst<'_>>,
) -> solidcore::Result<std::result::Result<(), std::result::Result<usize, Error>>> {
let before = face_set(b)?;
+ // The edge a sized refusal names ([`blend_failure`]), read after the session lets `b` go.
+ let mut fit_edge = None;
let done = {
let mut s = FilletSession::new(k, b)?;
// `SetFilletParameters(b, es, sections, solvers, values, laws, -1, -1, -1, -1,
@@ -380,11 +449,17 @@ fn blend_edges_stopping(
*m = s.mitred_edges();
}
}
- Ok(Err(Err(blend_failure(&s, e, corner))))
+ let (why, edge) = blend_failure(&s, e, corner);
+ fit_edge = edge;
+ Ok(Err(Err(why)))
}
},
Ok(Err(refusal)) => Ok(Err(refusal)),
- Err(e) => Ok(Err(Err(blend_failure(&s, e, corner)))),
+ Err(e) => {
+ let (why, edge) = blend_failure(&s, e, corner);
+ fit_edge = edge;
+ Ok(Err(Err(why)))
+ }
}
};
let done: solidcore::Result<std::result::Result<(Vec<usize>, Vec<(usize, FaceId)>), std::result::Result<usize, Error>>> = done;
@@ -392,7 +467,10 @@ fn blend_edges_stopping(
Ok(d) => d,
Err(refusal) => {
b.refresh_cached_topology();
- return Ok(Err(refusal));
+ return Ok(Err(match refusal {
+ Err(e @ Error::TooLarge { .. }) => Err(sized_on(k, b, fit_edge, section, e)?),
+ r => r,
+ }));
}
};
let stitched = stitch_and_orient(k, b, &StitchAndOrientOptions::default()).map_err(status);
diff --git a/crates/smlib/src/core/blend_tests.rs b/crates/smlib/src/core/blend_tests.rs
index 460655197f..786e1c91ef 100644
--- a/crates/smlib/src/core/blend_tests.rs
+++ b/crates/smlib/src/core/blend_tests.rs
@@ -254,10 +254,16 @@ fn timed<T: Send + 'static>(name: &str, f: impl FnOnce() -> T + Send + 'static)
type Got = std::result::Result<Measured, Error>;
+/// `e` without the size solidcore names for a blend too large ([`Error::TooLarge`]): the C++
+/// kernel's [`Error::NoRoom`], which the capi here does not size.
+fn without_size(e: Error) -> Error {
+ if matches!(e, Error::TooLarge { .. }) { Error::NoRoom } else { e }
+}
+
/// Checks a kernel's result against the case's closed form; what it measured, or its error.
fn judge(name: &str, who: &str, expect: &Expect, got: Got) -> Got {
match (expect, &got) {
- (Expect::Fails(e), Err(g)) => assert_eq!(g, e, "{name}: {who} failed otherwise"),
+ (Expect::Fails(e), Err(g)) => assert_eq!(&without_size(g.clone()), e, "{name}: {who} failed otherwise"),
(Expect::Fails(e), Ok(m)) => panic!("{name}: {who} gave {m:?}, expected {e:?}"),
(_, Err(g)) => panic!("{name}: {who} failed: {g}"),
(Expect::Volume(v), Ok(m)) => assert!(rel(m.volume, *v) < 1e-9, "{name}: {who} volume {} vs analytic {v}", m.volume),
@@ -325,16 +331,43 @@ fn fork_only_blends_are_not_supported_yet() {
assert_eq!(r.1, Some(Error::NoMatch { point: 0 }));
}
+/// #199's bar, 14 x 6 x 10, its four upright edges rounded: past r 3 (a full round of the 6 mm
+/// ends) the two rounds on each end would cross. solidcore refuses it with the largest radius that
+/// builds and its edge (`SolidError::FilletRefused`, `fixes.fillet_gn_section_generator`): 3, and a
+/// point halfway up an upright edge; an equal chamfer of the 4 mm rib's top edges past 2, as its
+/// distance.
+#[test]
+fn a_blend_too_large_is_refused_with_the_largest_size_that_fits() {
+ let bar = Shape::Box([14.0, 0.0, 0.0], [14.0, 6.0, 10.0]);
+ let uprights = [[14.0, 0.0, 5.0], [28.0, 0.0, 5.0], [14.0, 6.0, 5.0], [28.0, 6.0, 5.0]];
+ for r in [3.001, 3.5] {
+ let e = timed("fit_199", move || blend(&bar.core(), Blend::Round, &uprights, &[r], TOL, &[], &[], Corners::Filled).map(|_| ()).unwrap_err());
+ let Error::TooLarge { size, kind, at: Some(at) } = e else { panic!("{r}: {e:?}") };
+ assert!((size - 3.0).abs() < 1e-9 && kind == crate::FitKind::Radius, "{r}: {size} {kind:?}");
+ assert!(uprights.iter().any(|p| (0..3).all(|i| (p[i] - at[i]).abs() < 1e-9)), "{r}: {at:?}");
+ }
+ let rib = Shape::Box([0.0; 3], [40.0, 4.0, 20.0]);
+ let top = [[20.0, 0.0, 20.0], [20.0, 4.0, 20.0]];
+ let e = timed("fit_1080", move || blend(&rib.core(), Blend::Chamfer, &top, &[3.0], TOL, &[], &[], Corners::Filled).map(|_| ()).unwrap_err());
+ let Error::TooLarge { size, kind, at: Some(_) } = e else { panic!("{e:?}") };
+ assert!((size - 2.0).abs() < 1e-12 && kind == crate::FitKind::Distance, "{size} {kind:?}");
+}
+
/// A cliff overflow the fork refuses too (`fixes.fillet_cliff_overflow`, solidcore#960): the
/// three edges at a 20 mm cube's corner rounded r20, their fillet's boundary on two faces'
-/// surfaces, has no room, as on the fork, not "not supported".
+/// surfaces, has no room, as on the fork, not "not supported": too large, the largest radius that
+/// builds 19.99 (the whole edge less solidcore's fit margin), which builds.
#[test]
fn a_cliff_overflow_the_fork_refuses_has_no_room() {
- let r = timed("cliff_refused", || {
- let corner = [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]];
- blend(&Shape::Box([0.0; 3], [20.0; 3]).core(), Blend::Round, &corner, &[20.0; 3], TOL, &[], &[], Corners::Filled).err()
+ let corner = [[10.0, 0.0, 0.0], [0.0, 10.0, 0.0], [0.0, 0.0, 10.0]];
+ let r = timed("cliff_refused", move || {
+ blend(&Shape::Box([0.0; 3], [20.0; 3]).core(), Blend::Round, &corner, &[20.0; 3], TOL, &[], &[], Corners::Filled).map(|_| ()).unwrap_err()
+ });
+ let Error::TooLarge { size, kind: crate::FitKind::Radius, at: Some(_) } = r else { panic!("{r:?}") };
+ assert!((size - 19.99).abs() < 1e-9, "{size}");
+ timed("cliff_fit", move || {
+ blend(&Shape::Box([0.0; 3], [20.0; 3]).core(), Blend::Round, &corner, &[size; 3], TOL, &[], &[], Corners::Filled).unwrap()
});
- assert_eq!(r, Some(Error::NoRoom));
}
/// The capi's `overflow_goes_first` (fork 241f7ba): R21 on a 20 cube's edge takes all of both faces
@@ -757,7 +790,7 @@ fn rounds_on_the_871_part() {
let fit = blend(&p, Blend::Round, &e, &sizes(0.5), TOL, &[], &[], Corners::Filled).unwrap();
let (v, n) = (volume(&fit, 1e-8).unwrap(), counts(&fit).unwrap());
let refused = blend(&p, Blend::Round, &e, &sizes(1.0), TOL, &[], &[], Corners::Filled).map(|_| ()).unwrap_err();
- assert_eq!(refused, Error::NoRoom);
+ assert_eq!(without_size(refused), Error::NoRoom);
assert_eq!(n[0], 38);
assert!((v - exact).abs() < 1e-3, "{v} vs {exact}");
}
diff --git a/crates/smlib/src/lib.rs b/crates/smlib/src/lib.rs
index daf70944d1..19103d6bbd 100644
--- a/crates/smlib/src/lib.rs
+++ b/crates/smlib/src/lib.rs
@@ -48,6 +48,10 @@ pub enum Error {
/// crossing, a hole's wall offset just reaching a side's, so the result would pinch to
/// nothing along a line. A thinner or a thicker wall builds.
WallsTouch,
+ /// A blend larger than its faces allow, refused with the largest size that builds it
+ /// (solidcore's fit, `SolidError::FilletRefused`): the size, what it sizes, and a point at the
+ /// middle of the edge it was found for, when the refusal names one.
+ TooLarge { size: f64, kind: FitKind, at: Option<[f64; 3]> },
/// SMLib cannot build this exactly yet (a variable radius whose law has a corner).
Unsupported,
/// A blend's edges meet at a vertex of a kind no SMLib blend corner handles yet.
@@ -77,6 +81,31 @@ pub enum Error {
Unported(&'static str),
}
+/// What the largest size that builds a refused blend ([`Error::TooLarge`]) sizes.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum FitKind {
+ /// A round's radius.
+ Radius,
+ /// An equal chamfer's distance.
+ Distance,
+ /// A factor on a chamfer's two distances.
+ Scale,
+ /// A chord round's width.
+ Chord,
+}
+
+impl FitKind {
+ /// The size's name, as a fillet's message names it ("the largest radius that fits").
+ pub fn word(self) -> &'static str {
+ match self {
+ FitKind::Radius => "radius",
+ FitKind::Distance => "distance",
+ FitKind::Scale => "scale",
+ FitKind::Chord => "chord width",
+ }
+ }
+}
+
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@@ -89,6 +118,13 @@ impl std::fmt::Display for Error {
Error::Ambiguous { point } => write!(f, "selection point {} is equally near to two edges or faces", point + 1),
Error::NoRoom => write!(f, "there is no room for it: an offset leaves none inside the body, or a blend is larger than its faces allow"),
Error::WallsTouch => write!(f, "the offset's walls would meet along a line, which leaves no solid there"),
+ Error::TooLarge { size, kind, at } => {
+ write!(f, "the blend is larger than its faces allow")?;
+ if let Some([x, y, z]) = at {
+ write!(f, " at the edge at ({x:.3}, {y:.3}, {z:.3})")?;
+ }
+ write!(f, "; the largest {} that fits is {size}", kind.word())
+ }
Error::Unsupported => write!(f, "not supported yet: SMLib cannot build this exactly"),
Error::CornerUnsupported => write!(f, "not supported yet: a corner of this kind is not supported yet by SMLib's blends"),
Error::CornerRefused { corner } => write!(