Skip to content

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

Wave 322/509: Blends: a smooth edge and an unfinished tangent chain are refused saying why; SMLib's unsupported corner is named (and 3 more)

jyviko0448d3126f60
diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rs
index d449d3f771..c09cda3f51 100644
--- a/crates/doc/src/eval.rs
+++ b/crates/doc/src/eval.rs
@@ -3552,6 +3552,19 @@ fn off_the_ends(mb: &ModelBody, edge: usize, p: Vec3) -> Vec3 {
/// The edges a tapered fillet tapered (a point on each, with its taper).
type Tapered = Vec<(Vec3, kernel::Taper)>;
+/// A blend's refusal when the feature blended the picked edges' tangent chains too (tangent
+/// propagation, the default), saying so and how to blend the picked edges alone.
+fn with_propagation_hint(e: DocError) -> DocError {
+ const HINT: &str = " (tangent propagation blended the picked edges' tangent chain with them; with it off, tangent_chain: false, only the picked edges are blended)";
+ match e {
+ DocError::Kernel(kernel::KernelError::TooLarge(m)) => DocError::Kernel(kernel::KernelError::TooLarge(m + HINT)),
+ DocError::Kernel(kernel::KernelError::Invalid(m)) => DocError::Kernel(kernel::KernelError::Invalid(m + HINT)),
+ DocError::Kernel(kernel::KernelError::Failed(m)) => DocError::Kernel(kernel::KernelError::Failed(m + HINT)),
+ DocError::Invalid(m) => DocError::Invalid(m + HINT),
+ e => e,
+ }
+}
+
/// Body `mb` with blend `f` applied at `edges` (radius or distance `r`), the radii a fitted fillet
/// used (when it reduced any) and the edges it tapered.
fn blend_body(
@@ -6793,12 +6806,15 @@ fn eval_feature(
let Some(mb) = st.bodies.get(*ti) else { return Err(DocError::Invalid("body".into())) };
let mut w = None;
let edges = blend_edges_on(mb, f, edges, idx, &mut w)?;
+ let picked = edges.len();
let edges = if chain { kernel::tangent_chain(&mb.body, &edges)? } else { edges };
if let Some(w) = w {
notes.push(w);
}
let mut note = None;
- let (nb, used, tapered) = blend_body(vals, f, mb, &edges, r, &mut note)?;
+ let propagated = edges.len() > picked;
+ let (nb, used, tapered) =
+ blend_body(vals, f, mb, &edges, r, &mut note).map_err(|e| if propagated { with_propagation_hint(e) } else { e })?;
if let Some(n) = note {
notes.push(n);
}
@@ -7850,6 +7866,50 @@ mod chain_tests {
}
assert_eq!(tangent_face_chain(b, &[Vec3::new(20.0, 15.0, 20.0); 2]), pts);
}
+
+ fn fillet(at: Vec3, radius: &str, tangent_chain: bool) -> FeatureKind {
+ FeatureKind::Fillet {
+ edges: vec![crate::Position(at)],
+ radius: radius.into(),
+ body: None,
+ style: crate::FilletStyle::Constant,
+ fit: Default::default(),
+ corner: Default::default(),
+ setbacks: Vec::new(),
+ tangent_chain,
+ }
+ }
+
+ /// A 20 box's top edge along y rounded r2, then the top front edge (along x) rounded r3: that
+ /// edge runs on tangentially into the round's end arc, so by default (tangent propagation)
+ /// the arc is rounded with it, which an r3 round on an r2 arc cannot be: refused, saying that
+ /// propagation blended the chain and how to blend the edge alone. With propagation off the
+ /// edge is rounded alone, ending on the r2 round.
+ #[test]
+ fn a_propagated_chain_that_cannot_build_says_how_to_blend_the_edge_alone() {
+ let build = |chain: bool| {
+ let mut doc = Document::new("T");
+ let solid = FeatureKind::Box {
+ corner: crate::point_expr(Vec3::ZERO),
+ length: "20".into(),
+ width: "20".into(),
+ height: "20".into(),
+ operation: Operation::NewBody,
+ };
+ doc.add_feature(solid, None).unwrap();
+ doc.add_feature(fillet(Vec3::new(20.0, 10.0, 20.0), "2", true), None).unwrap();
+ let last = doc.add_feature(fillet(Vec3::new(10.0, 0.0, 20.0), "3", chain), None).unwrap();
+ let mut m = Model::new();
+ m.evaluate(&doc);
+ (m.result(last).and_then(|r| r.error.clone()), m.state().bodies.first().map(|b| b.body.face_count()))
+ };
+ let (on, _) = build(true);
+ let on = on.expect("the propagated chain is refused");
+ assert!(on.contains("with it off, tangent_chain: false, only the picked edges are blended"), "{on}");
+ let (off, faces) = build(false);
+ assert_eq!(off, None);
+ assert_eq!(faces, Some(8));
+ }
}
#[cfg(test)]
diff --git a/crates/kernel/src/blend.rs b/crates/kernel/src/blend.rs
index 9156588098..f48ea25662 100644
--- a/crates/kernel/src/blend.rs
+++ b/crates/kernel/src/blend.rs
@@ -627,20 +627,58 @@ pub fn chamfer_sides(body: &Body, edges: &[Vec3], d1: f64, side: ChamferSide, fl
/// a round cannot pass from one side of the faces to the other, so it ends at that vertex.
/// Picks that find no edge are refused.
pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result<Vec<Vec3>> {
- /// Edges meeting at an angle below this continue one another.
- const TANGENT_DEGREES: f64 = 0.5;
if picks.is_empty() || picks.len() > 1000 || picks.iter().any(|p| !p.is_finite()) {
return Err(KernelError::Invalid("select 1…1000 edges by finite points".into()));
}
let rec = Faces::of(body)?;
let (seeds, hidden) = crate::blend_smlib::picked_edges(body, picks)?;
- let mut chain: Vec<usize> = Vec::new();
+ let mut picked: Vec<usize> = Vec::new();
for e in seeds {
- if !chain.contains(&e) {
- chain.push(e);
+ if !picked.contains(&e) {
+ picked.push(e);
}
}
- let picked = chain.len();
+ let chain = chain_of(&rec, &picked, &hidden);
+ let mut out = picks.to_vec();
+ for e in chain.into_iter().skip(picked.len()) {
+ out.push(edge_middle(&rec, e).ok_or_else(|| KernelError::Failed("a point on a chain edge".into()))?);
+ }
+ Ok(out)
+}
+
+/// Edges meeting at an angle below this continue one another; faces meeting at an angle below
+/// it meet tangentially.
+const TANGENT_DEGREES: f64 = 0.5;
+
+/// The point halfway along edge `e`.
+fn edge_middle(rec: &Faces, e: usize) -> Option<Vec3> {
+ let edge = rec.rec.edges.get(e)?;
+ CurveEval::new(edge.parameters()).ok().and_then(|c| c.point(0.5 * (edge.interval[0] + edge.interval[1])))
+}
+
+/// How far from a face's surface a point may lie for its normal there.
+fn normal_reach(rec: &Faces) -> f64 {
+ rec.rec.tolerance.max(1e-7) * 10.0
+}
+
+/// Whether edge `e`'s two faces meet tangentially (within [`TANGENT_DEGREES`]) at its start: a
+/// smooth edge, with no corner to blend.
+fn smooth_join(rec: &Faces, e: usize) -> bool {
+ let cos = TANGENT_DEGREES.to_radians().cos();
+ let accept = normal_reach(rec);
+ let faces: Vec<u32> = rec.faces_of(e).into_iter().collect();
+ let (Some(&a), Some(&b), Some((p, _))) = (faces.first(), faces.get(1), rec.ends(e)) else { return false };
+ match (rec.normal_at(a as usize, p, accept), rec.normal_at(b as usize, p, accept)) {
+ (Some(na), Some(nb)) => faces.len() == 2 && na.dot(nb) > cos,
+ _ => false,
+ }
+}
+
+/// `seeds` (edges in the record's order, each once), then every other edge that continues one
+/// of them tangentially, as [`tangent_chain`] follows them; `hidden` marks the edges a pick
+/// passes over.
+fn chain_of(rec: &Faces, seeds: &[usize], hidden: &[bool]) -> Vec<usize> {
+ let mut chain = seeds.to_vec();
// The unit direction edge `e` leaves its end `v` in.
let leaving = |e: usize, v: u32| -> Option<Vec3> {
let [a, b] = rec.rec.edges.get(e)?.vertices;
@@ -650,16 +688,7 @@ pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result<Vec<Vec3>> {
if a == v { rec.tangent(e, false) } else { rec.tangent(e, true).map(|t| t * -1.0) }
};
let cos = TANGENT_DEGREES.to_radians().cos();
- let accept = rec.rec.tolerance.max(1e-7) * 10.0;
- // Whether edge `e`'s two faces meet tangentially at its start.
- let smooth = |e: usize| -> bool {
- let faces: Vec<u32> = rec.faces_of(e).into_iter().collect();
- let (Some(&a), Some(&b), Some((p, _))) = (faces.first(), faces.get(1), rec.ends(e)) else { return false };
- match (rec.normal_at(a as usize, p, accept), rec.normal_at(b as usize, p, accept)) {
- (Some(na), Some(nb)) => faces.len() == 2 && na.dot(nb) > cos,
- _ => false,
- }
- };
+ let accept = normal_reach(rec);
// Whether edge `e` is convex at its end `v` (its faces meet at less than 180° inside the
// body): the direction into its second face, square to it, points against its first face's
// outward normal. A face lies to the left of its loop seen from its surface's natural normal.
@@ -686,7 +715,7 @@ pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result<Vec<Vec3>> {
let Some(d) = leaving(e, v) else { continue };
for (f, other) in rec.rec.edges.iter().enumerate() {
let passed_over = hidden.get(f).copied().unwrap_or(false);
- if passed_over || chain.contains(&f) || other.uses.len() < 2 || !other.vertices.contains(&v) || smooth(f) {
+ if passed_over || chain.contains(&f) || other.uses.len() < 2 || !other.vertices.contains(&v) || smooth_join(rec, f) {
continue;
}
let turns_over = matches!((convex(e, v), convex(f, v)), (Some(a), Some(b)) if a != b);
@@ -696,16 +725,47 @@ pub fn tangent_chain(body: &Body, picks: &[Vec3]) -> Result<Vec<Vec3>> {
}
}
}
- let mut out = picks.to_vec();
- for e in chain.into_iter().skip(picked) {
- let edge = rec.rec.edges.get(e).ok_or_else(|| KernelError::Failed("a chain edge".into()))?;
- let mid = CurveEval::new(edge.parameters())
- .ok()
- .and_then(|c| c.point(0.5 * (edge.interval[0] + edge.interval[1])))
- .ok_or_else(|| KernelError::Failed("a point on a chain edge".into()))?;
- out.push(mid);
+ chain
+}
+
+/// Before blending exactly `edges` (the record's edges `picks` took, in order): refuses an edge
+/// whose faces meet tangentially (a smooth edge, nothing to round), and names the first edge a
+/// picked one runs on into tangentially without being blended with it, if any (tangent
+/// propagation off). SMLib blends the picked edges alone where it can end a blend there (a round
+/// ending on the round it runs into); where it can't, [`with_continuation`] says why.
+pub(crate) fn unfinished_chain(body: &Body, picks: &[Vec3], edges: &[usize], hidden: &[bool]) -> Result<Option<Vec3>> {
+ let rec = Faces::of(body)?;
+ let at = |i: usize| picks.get(i).map(|p| format!("({:.3}, {:.3}, {:.3})", p.x, p.y, p.z)).unwrap_or_default();
+ for (i, &e) in edges.iter().enumerate() {
+ if smooth_join(&rec, e) {
+ return Err(KernelError::Invalid(format!("the edge at {} is smooth: its faces meet tangentially, so there is nothing to round", at(i))));
+ }
+ }
+ let mut seeds: Vec<usize> = Vec::new();
+ for &e in edges {
+ if !seeds.contains(&e) {
+ seeds.push(e);
+ }
+ }
+ Ok(chain_of(&rec, &seeds, hidden).get(seeds.len()).and_then(|&next| edge_middle(&rec, next)))
+}
+
+/// A blend's failure where a picked edge continues tangentially into `next`, an edge left out
+/// ([`unfinished_chain`]): SMLib rounds a tangent chain as one sequence and could not end the
+/// blend there, so the reason and the way out are named.
+pub(crate) fn with_continuation(e: KernelError, next: Option<Vec3>) -> KernelError {
+ let Some(p) = next else { return e };
+ let why = format!(
+ " (a picked edge continues tangentially into the edge at ({:.3}, {:.3}, {:.3}), which is not blended with it, and the blend \
+ cannot end there: with tangent propagation on, tangent_chain: true, its tangent chain is blended as one)",
+ p.x, p.y, p.z
+ );
+ match e {
+ KernelError::Invalid(m) => KernelError::Invalid(m + &why),
+ KernelError::Failed(m) => KernelError::Failed(m + &why),
+ KernelError::TooLarge(m) => KernelError::TooLarge(m + &why),
+ e => e,
}
- Ok(out)
}
#[cfg(test)]
diff --git a/crates/kernel/src/blend_corner.rs b/crates/kernel/src/blend_corner.rs
index 05049a7f23..c99932a867 100644
--- a/crates/kernel/src/blend_corner.rs
+++ b/crates/kernel/src/blend_corner.rs
@@ -177,13 +177,15 @@ mod tests {
// using the reported picks, with and without the open cavity visible in the screenshot.
let picks = [Vec3::new(-5.0, 87.2, 12.5), Vec3::new(-4.283446394180081, 86.48344639418008, -1.5001085324947512)];
for base in [b.clone(), crate::shell(&b, &[Vec3::new(15.0, 47.2, 25.0)], 1.0).unwrap()] {
+ // Each fillet with its tangent chain, as the Fillet feature asks for it by default
+ // (tangent propagation).
let mut rounded = base;
for edge in bottom {
- rounded = fillet(&rounded, &[edge], 2.0).unwrap();
+ rounded = fillet(&rounded, &crate::tangent_chain(&rounded, &[edge]).unwrap(), 2.0).unwrap();
}
- let reference = fillet(&rounded, &picks[..1], 2.0).unwrap();
+ let reference = fillet(&rounded, &crate::tangent_chain(&rounded, &picks[..1]).unwrap(), 2.0).unwrap();
for selection in [picks, [picks[1], picks[0]]] {
- let result = fillet(&rounded, &selection, 2.0).unwrap();
+ let result = fillet(&rounded, &crate::tangent_chain(&rounded, &selection).unwrap(), 2.0).unwrap();
assert_eq!(result.face_count(), reference.face_count());
assert_eq!(result.unmeshed_faces(), 0);
assert!(result.validity().is_empty(), "{:?}", result.validity());
diff --git a/crates/kernel/src/blend_smlib.rs b/crates/kernel/src/blend_smlib.rs
index 7d60d42e37..0dfb740660 100644
--- a/crates/kernel/src/blend_smlib.rs
+++ b/crates/kernel/src/blend_smlib.rs
@@ -191,6 +191,7 @@ mod imp {
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,
@@ -198,7 +199,7 @@ mod imp {
Kind::Chamfer => Blend::Chamfer,
};
let tol = pick_tolerance(body);
- run(body, what, &picked.edges, |b| b.blend(kind, &picked.points, sizes, tol))
+ run(body, what, &picked.edges, |b| b.blend(kind, &picked.points, sizes, tol)).map_err(|e| crate::blend::with_continuation(e, next))
}
/// Rounds with corner setbacks: each corner point picks the body's nearest vertex (within
@@ -214,12 +215,14 @@ mod imp {
return Err(KernelError::Invalid(format!("{what}: each corner is a finite point with a positive, finite setback")));
}
let picked = resolve(body, edges)?;
+ let next = crate::blend::unfinished_chain(body, edges, &picked.edges, &picked.hidden)?;
let corners = corner_vertices(body, setbacks.iter().map(|(p, _)| *p))?;
let distances: Vec<f64> = setbacks.iter().map(|(_, d)| *d).collect();
let tol = pick_tolerance(body);
let at: Vec<Vec3> = setbacks.iter().map(|(p, _)| *p).collect();
run_with(body, what, &picked.edges, &at, |b| b.blend_setback(Blend::Round, &picked.points, sizes, &corners, &distances, tol).map(|r| (r, ())))
.map(|(out, (), _)| out)
+ .map_err(|e| crate::blend::with_continuation(e, next))
}
/// [`blend_setback`] with the set-back corners left open (`super::OpenCorners`).
@@ -234,12 +237,14 @@ mod imp {
return Err(KernelError::Invalid(format!("{what}: each corner is a finite point with a positive, finite setback")));
}
let picked = resolve(body, edges)?;
+ let next = crate::blend::unfinished_chain(body, edges, &picked.edges, &picked.hidden)?;
let corners = corner_vertices(body, setbacks.iter().map(|(p, _)| *p))?;
let distances: Vec<f64> = setbacks.iter().map(|(_, d)| *d).collect();
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::Round, &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() };
let renumber = |hole: &solidcraft_smlib::Hole| -> Result<Vec<(usize, bool)>> {
@@ -281,6 +286,7 @@ mod imp {
body.require_brep("chamfer")?;
sizes_ok("chamfer", &vec![d1; edges.len()])?;
let picked = resolve(body, edges)?;
+ let next = crate::blend::unfinished_chain(body, edges, &picked.edges, &picked.hidden)?;
let second = match side {
crate::ChamferSide::Distance(d) => ChamferSecond::Distance(d),
crate::ChamferSide::Angle(a) => ChamferSecond::Angle(a),
@@ -288,6 +294,7 @@ mod imp {
let up = if flip { [0.0, 0.0, -1.0] } else { [0.0, 0.0, 1.0] };
let tol = pick_tolerance(body);
run(body, "chamfer", &picked.edges, |b| b.chamfer_sides(&picked.points, tol, d1, second, up))
+ .map_err(|e| crate::blend::with_continuation(e, next))
}
pub(super) fn variable(body: &Body, edge_at: Vec3, start: Vec3, spline: &RadiusSpline) -> Result<Body> {
@@ -296,11 +303,13 @@ mod imp {
return Err(KernelError::Invalid("the start point must be finite".into()));
}
let picked = resolve(body, &[edge_at])?;
+ let next = crate::blend::unfinished_chain(body, &[edge_at], &picked.edges, &picked.hidden)?;
let [at] = picked.points[..] else { return Err(KernelError::Invalid("one edge".into())) };
let tol = pick_tolerance(body);
run(body, "variable fillet", &picked.edges, |b| {
b.fillet_variable(at, tol, [start.x, start.y, start.z], spline.degree, &spline.knots, &spline.radii)
})
+ .map_err(|e| crate::blend::with_continuation(e, next))
}
/// `op` on `body` in SMLib, tagged as operand 0, checked, decoded, with its history.
@@ -334,6 +343,10 @@ mod imp {
None => failed(what, "operation", SmError::CornerRefused { corner }),
},
SmError::NoEffect => KernelError::Failed(format!("SMLib made no change: the {what} reported success but built no face")),
+ SmError::CornerUnsupported => KernelError::Invalid(format!(
+ "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")),
e => failed(what, "operation", e),
})?;
@@ -594,4 +607,24 @@ mod tests {
assert!(imp::blend(&b, "fillet", Kind::Round, &[Vec3::new(f64::NAN, 20.0, 20.0)], &[1.0]).is_err());
assert!(imp::blend(&b, "fillet", Kind::Round, &[], &[]).is_err());
}
+
+ /// A smooth edge (a round's seam with the face it runs into) has nothing to round, and an
+ /// edge that runs on tangentially into one left out has no end SMLib can blend: both are
+ /// refused before SMLib, saying so. Rounded with its tangent chain the edge builds.
+ #[test]
+ fn smooth_edges_and_unfinished_tangent_chains_are_refused_saying_why() {
+ let b = cube();
+ let rounded = fillet(&b, &[Vec3::new(10.0, 20.0, 20.0)], 3.0).unwrap();
+ // the seam where the r3 round meets the top, 3 in from the old edge
+ let seam = imp::blend(&rounded, "fillet", Kind::Round, &[Vec3::new(10.0, 17.0, 20.0)], &[1.0]).unwrap_err().to_string();
+ assert!(seam.contains("is smooth: its faces meet tangentially, so there is nothing to round"), "{seam}");
+ // the end face's top edge runs on tangentially into the round's end arc
+ let top = Vec3::new(0.0, 8.0, 20.0);
+ let alone = imp::blend(&rounded, "fillet", Kind::Round, &[top], &[1.0]).unwrap_err().to_string();
+ assert!(alone.contains("continues tangentially"), "{alone}");
+ let chain = crate::tangent_chain(&rounded, &[top]).unwrap();
+ assert!(chain.len() > 1, "{chain:?}");
+ let whole = fillet(&rounded, &chain, 1.0).unwrap();
+ assert!(volume(&whole) < volume(&rounded));
+ }
}
diff --git a/crates/kernel/src/curvecorner_tests.rs b/crates/kernel/src/curvecorner_tests.rs
index af199c53c9..db182389f9 100644
--- a/crates/kernel/src/curvecorner_tests.rs
+++ b/crates/kernel/src/curvecorner_tests.rs
@@ -251,16 +251,25 @@ fn the_arc_rounded_after_the_back_edge_matches_both_together() {
one_then_the_other(BACK, arc_top());
}
-/// The edge at `first` rounded (2), then the one at `then` as a fillet of its own, against both
-/// rounded together.
+/// The edge at `first` rounded (2), then the one at `then` as a fillet of its own, each with its
+/// tangent chain as the Fillet feature rounds by default (tangent propagation), against the same
+/// edges of the part rounded together: the picks' chains, and every edge of the part that the
+/// second round's chain carried on into across the first round (the left front upright, after
+/// the front edge's round: the left top edge runs on round that round's end arc and down the
+/// upright, a sphere octant at the corner where the three rounds meet).
fn one_then_the_other(first: Vec3, then: Vec3) {
let body = arc_part();
- let step = crate::fillet(&body, &[first], 2.0).unwrap();
- let after = crate::fillet(&step, &[then], 2.0).unwrap();
+ let chained = |b: &Body, pts: &[Vec3]| crate::tangent_chain(b, pts).unwrap();
+ let step = crate::fillet(&body, &chained(&body, &[first]), 2.0).unwrap_or_else(|e| panic!("{first:?}: {e}"));
+ let second = chained(&step, &[then]);
+ let after = crate::fillet(&step, &second, 2.0).unwrap_or_else(|e| panic!("{first:?} then {then:?}: {e}"));
let v = volume(&after);
- let together = volume(&crate::fillet(&body, &[first, then], 2.0).unwrap());
+ // The part's own edges among the second chain's (points on an edge of the part).
+ let mut picks = vec![first, then];
+ picks.extend(second.iter().skip(1).filter(|p| crate::tangent_chain(&body, &[**p]).is_ok()));
+ let together = volume(&crate::fillet(&body, &chained(&body, &picks), 2.0).unwrap());
// Within the display meshes' accuracy (two different B-reps, meshed apart).
- assert!((v - together).abs() < 5e-3, "{first:?} then {then:?}: {v} vs together {together}");
+ assert!((v - together).abs() < 5e-3, "{first:?} then {then:?}: {v} vs together {together} ({picks:?})");
}
/// Edges rounded together come out the same in any order: a round made first doesn't carry the
diff --git a/crates/smlib/src/ffi/ops.rs b/crates/smlib/src/ffi/ops.rs
index 9f6c2303ef..22ac7ca9fd 100644
--- a/crates/smlib/src/ffi/ops.rs
+++ b/crates/smlib/src/ffi/ops.rs
@@ -20,6 +20,7 @@ pub const ERR_NO_CUT: i32 = -1104;
pub const ERR_UNSUPPORTED: i32 = -1105;
pub const ERR_NO_EFFECT: i32 = -1107;
pub const ERR_WALLS_TOUCH: i32 = -1110;
+pub const ERR_CORNER_UNSUPPORTED: i32 = -1111;
pub const BOOLEAN_UNION: i32 = 0;
pub const BOOLEAN_SUBTRACT: i32 = 1;
diff --git a/crates/smlib/src/lib.rs b/crates/smlib/src/lib.rs
index 6b52b52393..0d60743b64 100644
--- a/crates/smlib/src/lib.rs
+++ b/crates/smlib/src/lib.rs
@@ -58,6 +58,8 @@ pub enum Error {
WallsTouch,
/// 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.
+ CornerUnsupported,
/// SMLib does not set back the corner of corner point `corner`: SMLib sets back a corner
/// only where every edge meeting it is blended and they are all convex or all concave.
CornerRefused { corner: usize },
@@ -92,6 +94,7 @@ impl std::fmt::Display for Error {
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::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!(
f,
"not supported yet: SMLib does not set back corner {}: it sets back a corner only where every edge meeting it is blended, all convex or all concave",
@@ -129,6 +132,7 @@ fn error(s: i32) -> Error {
ffi::ops::ERR_NO_ROOM => Error::NoRoom,
ffi::ops::ERR_WALLS_TOUCH => Error::WallsTouch,
ffi::ops::ERR_UNSUPPORTED => Error::Unsupported,
+ ffi::ops::ERR_CORNER_UNSUPPORTED => Error::CornerUnsupported,
ffi::ops::ERR_NO_EFFECT => Error::NoEffect,
ffi::trim::ERR_NOT_EXACT => Error::NotExact,
ffi::ERR_EXCEPTION => Error::Exception,
diff --git a/crates/smlib/src/ops_tests.rs b/crates/smlib/src/ops_tests.rs
index 8e75bf6c48..85e3ab4b6e 100644
--- a/crates/smlib/src/ops_tests.rs
+++ b/crates/smlib/src/ops_tests.rs
@@ -206,11 +206,15 @@ fn hostile_inputs_are_errors() {
for t in [0.0, f64::NAN, -1e7] {
assert_eq!(c.shell(&[[10.0, 10.0, 20.0]], 0.1, t).unwrap_err(), Error::Argument, "thickness {t}");
}
- // Sizes SMLib cannot build fail as errors, whatever SMLib says.
- match c.fillet(&mid, 0.1, 50.0) {
- Ok(b) => panic!("radius larger than the cube: SMLib built a body of volume {:?}, counts {:?}", b.volume(ACC), b.counts()),
- Err(e) => eprintln!("radius larger than the cube: {e:?}"),
- }
+ // A round larger than the cube overflows its faces' far edges, convex, so it is cut as if the
+ // faces went on: the r50 cylinder about y = z = -30 uses up both faces of the edge and leaves
+ // the part of the cube's 20 x 20 section inside it, from (0, 10) to (10, 0), along x: 20 x
+ // that area, 20 (F(40) - F(30) - 300) with F(u) = (u sqrt(2500 - u^2) + 2500 asin(u / 50)) / 2.
+ let over = c.fillet(&mid, 0.1, 50.0).unwrap();
+ let f = |u: f64| 0.5 * (u * (2500.0 - u * u).sqrt() + 2500.0 * (u / 50.0).asin());
+ let want = 20.0 * (f(40.0) - f(30.0) - 300.0);
+ assert!((volume(&over) - want).abs() < 1e-6 * want, "radius larger than the cube: {} vs {want}", volume(&over));
+ assert_eq!(over.counts().unwrap(), [5, 9, 6], "the two ends, the two far faces and the round");
// A chamfer past the faces runs over their far edges, cliffs: it is cut as if the faces went
// on (the plane y + z = 10 through the setbacks 30 back from the edge y = z = 20), leaving the
// triangle y + z <= 10 of the cube's section along x: 50 x 20.