SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 191/509: engine: no boolean retries to report; overlaps are SMLib's exact intersection (and 3 more)
jyviko816e43c5d0ce
diff --git a/apps/solidcraft-cli/src/fuzz.rs b/apps/solidcraft-cli/src/fuzz.rsindex 5a25b9d0fd..7b1fa61a37 100644--- a/apps/solidcraft-cli/src/fuzz.rs+++ b/apps/solidcraft-cli/src/fuzz.rs@@ -40,8 +40,6 @@ pub fn one(args: &[String]) -> Result<(), String> {"steps": run.steps.iter().map(|s| s.kind).collect::<Vec<_>>(),"unsupported": run.unsupported,"rejected": run.rejected,- "boolean_fallbacks": run.boolean_fallbacks,- "boolean_reports_truncated": run.boolean_reports_truncated,"panics": PANICS.swap(0, std::sync::atomic::Ordering::SeqCst),});if run.outcome.is_bug() {@@ -191,23 +189,9 @@ fn summarise(results: &[Value], took: Duration) -> String {let mut boolean: BTreeMap<String, usize> = BTreeMap::new();let mut at_step: BTreeMap<String, usize> = BTreeMap::new();let mut unsupported: BTreeMap<String, usize> = BTreeMap::new();- let mut fallbacks: BTreeMap<String, [u64; 2]> = BTreeMap::new();- let mut truncated = [0usize; 2];let mut steps = 0;let (mut dp, mut bp) = (0, 0);for v in results {- for (i, group) in ["design", "boolean"].into_iter().enumerate() {- if v[group]["boolean_reports_truncated"].as_bool().unwrap_or(false) {- truncated[i] += 1;- }- if let Some(counts) = v[group]["boolean_fallbacks"].as_object() {- for (strategy, count) in counts {- if let Some(total) = fallbacks.entry(strategy.clone()).or_default().get_mut(i) {- *total = total.saturating_add(count.as_u64().unwrap_or(0));- }- }- }- }dp += usize::from(v["design"]["panics"].as_u64().unwrap_or(0) > 0);bp += usize::from(v["boolean_panics"].as_u64().unwrap_or(0) > 0);let k = if v.get("timeout").is_some() {@@ -246,11 +230,6 @@ fn summarise(results: &[Value], took: Duration) -> String {for (k, c) in &boolean {s += &format!("- {k}: {}\n", pct(*c));}- s += "\nSuccessful Boolean retries (events, including nested operations):\n";- for (strategy, [designs, checks]) in &fallbacks {- s += &format!("- {strategy}: designs {designs}, boolean checks {checks}\n");- }- s += &format!("- Capped reports: designs {}, boolean checks {}\n", truncated[0], truncated[1]);s}@@ -259,15 +238,13 @@ mod tests {use super::*;#[test]- fn report_counts_retry_events_separately_and_marks_incomplete_logs() {+ fn report_counts_outcomes_and_timeouts() {let results = [- json!({"design":{"outcome":{"kind":"ok"},"boolean_fallbacks":{"shifted_operands":2}},"boolean":{"outcome":"ok","boolean_fallbacks":{"shifted_operands":3},"boolean_reports_truncated":true}}),- json!({"design":{"outcome":{"kind":"ok"},"boolean_fallbacks":{"shifted_operands":1}},"boolean":{"outcome":"ok"}}),+ json!({"design":{"outcome":{"kind":"ok"}},"boolean":{"outcome":"ok"}}),+ json!({"design":{"outcome":{"kind":"ok"}},"boolean":{"outcome":"ok"}}),json!({"timeout":90}),];let text = summarise(&results, Duration::ZERO);- assert!(text.contains("shifted_operands: designs 3, boolean checks 3"), "{text}");- assert!(text.contains("Capped reports: designs 0, boolean checks 1"), "{text}");assert!(text.contains("timeout: 1 (33.3 %)"), "{text}");}}diff --git a/apps/solidcraft-cli/tests/corpus/issue-616-lid-ribs.expected.json b/apps/solidcraft-cli/tests/corpus/issue-616-lid-ribs.expected.jsonindex 081a3baab8..cac060415e 100644--- a/apps/solidcraft-cli/tests/corpus/issue-616-lid-ribs.expected.json+++ b/apps/solidcraft-cli/tests/corpus/issue-616-lid-ribs.expected.json@@ -131,7 +131,7 @@"rolled_back": false,"suppressed": false,"type": "BoxFeature",- "warning": "Boolean retry: exact planar fallback (no displacement)"+ "warning": null},{"error": null,diff --git a/crates/doc/src/eval.rs b/crates/doc/src/eval.rsindex 576c7175cf..b744d8aa55 100644--- a/crates/doc/src/eval.rs+++ b/crates/doc/src/eval.rs@@ -3991,15 +3991,15 @@ fn sheet_hole_cut(// Many plain drills along one axis (a hole on each of a pattern's points): all in one pass.let prisms: Option<Vec<more::PrimitivePrism>> = tools.iter().map(|(_, prism)| *prism).collect();if let Some(prisms) = prisms {- match more::sheet_drill_cuts(f, st, &prisms, &mut parted) {- Ok(Some(done)) => {+ match more::sheet_drill_cuts(f, st, &prisms, &mut parted)? {+ Some(done) => {if let Some(note) = parted {append_warning(warning, note);}return Ok(done);}- // Not all of them that way, or refused at once: one by one, from the model as it was.- Ok(None) | Err(_) => {+ // Not all of them that way: one by one, from the model as it was.+ None => {(st.sheets, st.bodies) = saved.clone();parted = None;}@@ -4007,22 +4007,15 @@ fn sheet_hole_cut(}for (tool, prism) in tools {let tool = &tool.body;+ // Square across the panels it meets, a flat cut-out; along them into a rim, a bore.let done = match prism {- Some(prism) => match more::sheet_primitive_cut(f, st, tool, *prism, Operation::Cut, true, &mut parted) {- Ok(done) => done,- // Drilled along a panel (into a rim) the hole is no flat cut-out: a bore of- // that panel, when it stays inside it.- Err(e) => match more::sheet_bore_cut(f, st, *prism)? {- Some(done) => done,- None => return Err(e),- },+ Some(prism) => match more::sheet_drill(f, st, *prism)? {+ Some(more::Drill::Across) => more::sheet_primitive_cut(f, st, tool, *prism, Operation::Cut, true, &mut parted)?,+ Some(more::Drill::Along) => more::sheet_bore_cut(f, st, *prism)?.unwrap_or_default(),+ None => Vec::new(),},None => Vec::new(),};- let done = match (done.is_empty(), prism) {- (true, Some(prism)) => more::sheet_bore_cut(f, st, *prism)?.unwrap_or_default(),- _ => done,- };if done.is_empty() {let mut meets = false;for sheet in &st.sheets {diff --git a/crates/doc/src/eval_more.rs b/crates/doc/src/eval_more.rsindex 5b9e09b9fb..0c1efc7f4c 100644--- a/crates/doc/src/eval_more.rs+++ b/crates/doc/src/eval_more.rs@@ -1065,11 +1065,39 @@ pub(super) fn sheet_primitive_cut(sheet_prism_cut(f, st, &plane, std::slice::from_ref(®ion), operation, &tools, &[], None, false, &[], warning)}+/// How a hole's straight drill machines the sheets it meets, from the panels it passes through.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(super) enum Drill {+ /// Square across every panel it meets: a cut-out or pocket of the flat pattern+ /// ([`sheet_primitive_cut`]).+ Across,+ /// Along every panel it meets, into a rim: a bore of each ([`sheet_bore_cut`]).+ Along,+}++/// Which [`Drill`] a hole's straight drill is for the sheets `f` machines; None when it meets+/// none of them. A box is a prism across its sheet. A drill square to some panels it meets and+/// along others, or at an angle to one, has no exact place in the flat pattern and is refused.+pub(super) fn sheet_drill(f: &Feature, st: &ModelState, prism: PrimitivePrism) -> Result<Option<Drill>> {+ let PrimitivePrism::Cylinder { base, axis, radius, height } = prism else { return Ok(Some(Drill::Across)) };+ let mut squares = Vec::new();+ for sh in st.sheets.iter().filter(|sh| sheet_eligible(f, st, &[], sh)) {+ squares.extend(sh.drilled_panels(base, axis, radius, height)?.into_iter().map(|(_, square)| square));+ }+ if squares.is_empty() {+ Ok(None)+ } else if squares.iter().all(|s| *s >= 1.0 - 1e-6) {+ Ok(Some(Drill::Across))+ } else if squares.iter().all(|s| *s <= 1e-6) {+ Ok(Some(Drill::Along))+ } else {+ Err(DocError::Invalid("this hole crosses a sheet panel at an angle; drill it square to the panel, or along it into a rim".into()))+ }+}+/// A hole's straight drill along a panel of a sheet (into its rim), kept as a bore of each/// panel it meets (see [`crate::sheet::SheetBore`]), so the sheet still unfolds. Returns the-/// sheet bodies it machined; None, with the model as it was, when the drill is not a plain-/// cylinder or a sheet it meets can't keep it that way (it runs into a bend, or crosses a-/// panel at an angle).+/// sheet bodies it machined; None when the drill is not a plain cylinder or meets no sheet.pub(super) fn sheet_bore_cut(f: &Feature, st: &mut ModelState, prism: PrimitivePrism) -> Result<Option<Vec<String>>> {let PrimitivePrism::Cylinder { base, axis, radius, height } = prism else { return Ok(None) };let mut plans = Vec::new();@@ -1081,8 +1109,6 @@ pub(super) fn sheet_bore_cut(f: &Feature, st: &mut ModelState, prism: PrimitivePmatch sh.add_bore(base, axis, radius, height) {Ok(true) => {}Ok(false) => continue,- // Refused here, the hole keeps the message of the machining it was first tried as.- Err(DocError::Invalid(_)) => return Ok(None),Err(e) => return Err(e),}let body = sh.solid()?;@@ -1112,8 +1138,8 @@ const MAX_DRILLS_AT_ONCE: usize = 1000;/// of them, rather than one per drill, each on a sheet machined by the ones before./// The drills are the cut-outs and pockets [`sheet_primitive_cut`] makes of them one at a time./// None when they can't all be taken this way (they are not all cylinders along one axis that-/// every sheet they may machine takes square, or a sheet keeps one some other way): the caller-/// then puts the model back and drills them one by one.+/// every sheet they may machine takes square, or a depth of them meets no sheet): the caller then+/// puts the model back and drills them one by one.pub(super) fn sheet_drill_cuts(f: &Feature,st: &mut ModelState,@@ -1884,7 +1910,7 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Flet rule = |target: &str| -> Result<Option<crate::plastic::PlasticValues>> {doc.plastic_rule_for(target).map(|r| doc.plastic_values(vals, &r)).transpose()};- // Tools start a little inside the material so they overlap it instead of touching a face.+ // Each tool stands on the face as drawn: SMLib joins and cuts touching faces exactly.match &f.kind {FeatureKind::Boss {position,@@ -1916,16 +1942,14 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Fif r_top <= 0.0 {return Err(DocError::Invalid("the draft closes the boss before its top".into()));}- let delta = (h * 0.05).clamp(1e-3, 0.5);let (x, _, z) = local_frame(direction.0, None)?;- // The post: a (tapered) cylinder from a little inside the face.- let base = Plane::new(position.0 - z * delta, x, z.cross(x)).ok_or_else(|| DocError::Invalid("boss frame".into()))?;- let r_in = r0 + delta * dr.tan();- let disc = Region2 { outer: Loop2::circle(Vec2::ZERO, r_in), holes: Vec::new() };+ // The post: a (tapered) cylinder standing on the face.+ let base = Plane::new(position.0, x, z.cross(x)).ok_or_else(|| DocError::Invalid("boss frame".into()))?;+ let disc = Region2 { outer: Loop2::circle(Vec2::ZERO, r0), holes: Vec::new() };let post = if dr.abs() > 1e-12 {- vec![kernel::extrude_tapered(&base, &disc, h + delta, 1.0, -dr)?]+ vec![kernel::extrude_tapered(&base, &disc, h, 1.0, -dr)?]} else {- kernel::extrude(&base, &[disc], 0.0, h + delta)?+ kernel::extrude(&base, &[disc], 0.0, h)?};let mut tools: Vec<Traced> = post.into_iter().map(|b| crate::lineage::part_tool(b, "post")).collect();if let Some(n) = ribs {@@ -1964,7 +1988,7 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &F]),holes: Vec::new(),};- tools.extend(kernel::extrude(&rp, &[rect], -delta, hr)?.into_iter().map(|b| crate::lineage::part_tool(b, &format!("rib{k}"))));+ tools.extend(kernel::extrude(&rp, &[rect], 0.0, hr)?.into_iter().map(|b| crate::lineage::part_tool(b, &format!("rib{k}"))));}}apply_traced(doc, st, f, tools, Operation::Join, std::slice::from_ref(&target))?;@@ -1989,7 +2013,7 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Freturn Err(DocError::Invalid("the boss hole must fit inside the boss".into()));}let hp = Plane::new(position.0, x, z.cross(x)).ok_or_else(|| DocError::Invalid("hole frame".into()))?;- let tool = kernel::extrude(&hp, &[Region2 { outer: Loop2::circle(Vec2::ZERO, rh), holes: Vec::new() }], h - depth, h + delta)?;+ let tool = kernel::extrude(&hp, &[Region2 { outer: Loop2::circle(Vec2::ZERO, rh), holes: Vec::new() }], h - depth, h)?;let tool = tool.into_iter().map(|b| crate::lineage::part_tool(b, "hole")).collect();apply_traced(doc, st, f, tool, Operation::Cut, std::slice::from_ref(&target))?;}@@ -2049,12 +2073,10 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &F*slot = ModelBody::traced_new(target.clone(), Traced::step(b, &[&mb.traced()]), slot.feature);return Ok(());}- // A groove: the band along the chosen edge, inside the rim face, and its gap. The- // cutter reaches past the edge into the free side (the cavity, or outside).- let bw = w + g;- let (plane, band) = kernel::rim_band(&mb.body, face.0, bw, bw, *outside)?;- let delta = (h * 0.05).clamp(1e-3, 0.5);- let tool = kernel::extrude(&plane, &[band], -(h + g), delta)?.into_iter().map(|b| crate::lineage::part_tool(b, "groove")).collect();+ // A groove: the band along the chosen edge, inside the rim face, its gap included,+ // cut down from the face.+ let (plane, band) = kernel::rim_band(&mb.body, face.0, w + g, 0.0, *outside)?;+ let tool = kernel::extrude(&plane, &[band], -(h + g), 0.0)?.into_iter().map(|b| crate::lineage::part_tool(b, "groove")).collect();apply_traced(doc, st, f, tool, Operation::Cut, std::slice::from_ref(&target))}FeatureKind::SnapFit { position, direction, hook, length, thickness, width, catch_depth, catch_length, base_height, new_body, body } => {@@ -2067,11 +2089,9 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Freturn Err(DocError::Invalid("the snap fit's catch must be shorter than its arm".into()));}let (x, y, z) = local_frame(direction.0, Some(hook.0))?;- let delta = (l * 0.05).clamp(1e-3, 0.5);// Side profile (x = toward the catch, y = up the arm), extruded across the width.- // The base reaches `base_height` below the face; a joined arm bites `delta` into- // the wall, a separate body sits flush on it.- let y0 = if *new_body { -bh } else { -delta - bh };+ // The base reaches `base_height` below the face, joined or a separate body.+ let y0 = -bh;let pts = [Vec2::new(-t, y0), Vec2::new(0.0, y0), Vec2::new(0.0, l - cl), Vec2::new(cd, l - cl), Vec2::new(0.0, l), Vec2::new(-t, l)];let o = position.0 - y * (w / 2.0);let pl = Plane::new(o, x, z).ok_or_else(|| DocError::Invalid("snap fit frame".into()))?;@@ -2110,10 +2130,8 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &Fif closes {return Err(DocError::Invalid("the draft closes the rest before its top".into()));}- let delta = (h * 0.05).clamp(1e-3, 0.5);- let (x, y, z) = local_frame(direction.0, along.map(Vec3::from))?;- // Sized at the face: the tool starts a little inside, grown by the draft over that.- let e = delta * dr.tan();+ let (x, y, _) = local_frame(direction.0, along.map(Vec3::from))?;+ // Sized at the face, where the tool starts.let shape = |grow: f64| match l {Some(l) => Loop2::polygon(&[Vec2::new(-l / 2.0 - grow, -w / 2.0 - grow),@@ -2124,15 +2142,15 @@ pub(super) fn plastic_eval(doc: &Document, vals: &BTreeMap<String, Value>, f: &FNone => Loop2::circle(Vec2::ZERO, w / 2.0 + grow),};let holes = match t {- Some(t) => vec![shape(-t - e).reversed()],+ Some(t) => vec![shape(-t).reversed()],None => Vec::new(),};- let region = Region2 { outer: shape(e), holes };- let base = Plane::new(position.0 - z * delta, x, y).ok_or_else(|| DocError::Invalid("rest frame".into()))?;+ let region = Region2 { outer: shape(0.0), holes };+ let base = Plane::new(position.0, x, y).ok_or_else(|| DocError::Invalid("rest frame".into()))?;let tool = if dr.abs() > 1e-12 {- vec![kernel::extrude_tapered(&base, ®ion, h + delta, 1.0, -dr)?]+ vec![kernel::extrude_tapered(&base, ®ion, h, 1.0, -dr)?]} else {- kernel::extrude(&base, &[region], 0.0, h + delta)?+ kernel::extrude(&base, &[region], 0.0, h)?};let tool = tool.into_iter().map(|b| crate::lineage::part_tool(b, "rest")).collect();apply_traced(doc, st, f, tool, Operation::Join, std::slice::from_ref(&target))diff --git a/crates/doc/src/sheet.rs b/crates/doc/src/sheet.rsindex eb46165315..652beba1d7 100644--- a/crates/doc/src/sheet.rs+++ b/crates/doc/src/sheet.rs@@ -1691,18 +1691,14 @@ impl SheetBody {Ok(body)}- /// Record a round bore drilled along the sheet (a hole into a rim): the world cylinder from- /// `base` along `axis`, one record per panel whose material it meets. Ok(false) when it- /// meets no material; an error when it meets a bend, or crosses a panel other than along- /// its plane (that machining has no exact place in the flat pattern).- pub(crate) fn add_bore(&mut self, base: Vec3, axis: Vec3, radius: f64, height: f64) -> Result<bool> {+ /// The panels a straight drill (the world cylinder from `base` along `axis`) meets, each with+ /// how square the drill is to it: |panel normal · axis|, 1 across the panel and 0 along it.+ /// A drill that meets a bend is refused (a bend's material has no flat place for a hole).+ pub(crate) fn drilled_panels(&self, base: Vec3, axis: Vec3, radius: f64, height: f64) -> Result<Vec<(Option<usize>, f64)>> {let axis = axis.normalized().ok_or_else(|| DocError::Invalid("bore axis".into()))?;if ![base.x, base.y, base.z, radius, height].iter().all(|v| v.is_finite()) || !(radius > 0.0) || height == 0.0 {return Err(DocError::Invalid("invalid sheet bore".into()));}- if self.bores.len() >= MAX_BORES {- return Err(flat_budget_error());- }let mut work = FlatWork::new();let drill = kernel::cylinder(base, axis, radius, height)?;let mut found = Vec::new();@@ -1726,11 +1722,29 @@ impl SheetBody {));};let w = self.world(if self.flat { None } else { pi });- if apply_vector(&w, Vec3::Z).dot(axis).abs() > 1e-6 {+ found.push((pi, apply_vector(&w, Vec3::Z).dot(axis).abs()));+ }+ Ok(found)+ }++ /// Record a round bore drilled along the sheet (a hole into a rim): the world cylinder from+ /// `base` along `axis`, one record per panel whose material it meets. Ok(false) when it+ /// meets no material; an error when it meets a bend, or crosses a panel other than along+ /// its plane (that machining has no exact place in the flat pattern).+ pub(crate) fn add_bore(&mut self, base: Vec3, axis: Vec3, radius: f64, height: f64) -> Result<bool> {+ if self.bores.len() >= MAX_BORES {+ return Err(flat_budget_error());+ }+ let panels = self.drilled_panels(base, axis, radius, height)?;+ let axis = axis.normalized().ok_or_else(|| DocError::Invalid("bore axis".into()))?;+ let mut found = Vec::new();+ for (pi, square) in panels {+ if square > 1e-6 {return Err(DocError::Invalid("this hole crosses a sheet panel at an angle; drill it square to the panel, or along it into a rim".into(),));}+ let w = self.world(if self.flat { None } else { pi });let inv = mat_inverse(&w).ok_or_else(|| DocError::Invalid("invalid sheet panel frame".into()))?;let bore = SheetBore { panel: pi, base: apply_point(&inv, base), axis: apply_vector(&inv, axis), radius, height };if !found.contains(&bore) {diff --git a/crates/engine/src/cmd/clearance.rs b/crates/engine/src/cmd/clearance.rsindex aec14f2422..b0e636f8ea 100644--- a/crates/engine/src/cmd/clearance.rs+++ b/crates/engine/src/cmd/clearance.rs@@ -47,9 +47,6 @@ enum SkipWithin {/// Most pairs [`PairCache`] keeps; it starts over when full.const MAX_CACHED: usize = 2 * MAX_PAIRS;-/// The kernel's tries at intersecting a pin with its hole on one cylinder (each about a second-/// on real parts; a plain pin on its axis needs one or two).-const PIN_ATTEMPTS: usize = 4;/// Pairs measured before, by the two bodies' geometry where they stood/// ([`solidcraft_doc::ModelBody::geometry_key`]) and the settings that shape the result@@ -357,78 +354,19 @@ fn measure_pair(let touching = mesh.is_some_and(|m| m.distance <= slack);if touching || holds(ba, bb) || holds(bb, ba) {// A pair whose shared part can't be worked out is reported, not passed as clear.- let region = shared_region(a, b);- let (ca, cb) = (clipped(ka, region), clipped(kb, region));- // A pin of one in a hole of the other of its own size. On its very axis the boolean takes- // the two walls as one and answers plain ones at once, but with blends next to them it- // tries for minutes and gives up; a hair off the axis it cannot intersect them at all- // (and may pass the pin as clear). So a pin on its axis gets a few tries of the boolean- // first, and what the walls share is otherwise worked out apart, with a few tries of the- // boolean left for when that declines. The body left whole is cut down to where the- // other's piece is first, so that both meet only the faces there.- let candidate = solidcraft_kernel::coaxial_candidate(ca.as_ref().unwrap_or(ka), cb.as_ref().unwrap_or(kb));- let pin = candidate.is_some();- let (ca, cb) = match (ca, cb) {- (Some(x), None) if pin => {- let y = narrowed(kb, &x);- (Some(x), y)- }- (None, Some(y)) if pin => (narrowed(ka, &y), Some(y)),- other => other,- };- // A body left whole is the copy that keeps its meshes: meeting several others at one- // size, it is meshed once for the booleans of all of them.- let (pa, pb) = (ca.as_ref().unwrap_or(ka), cb.as_ref().unwrap_or(kb));- let intersect = || {- solidcraft_kernel::capture_boolean_diagnostics(|| {- let run = || solidcraft_kernel::boolean(pa, pb, solidcraft_kernel::BoolOp::Intersect);- if pin { solidcraft_kernel::with_attempt_budget(PIN_ATTEMPTS, run) } else { run() }- })- };- let first = (candidate != Some(false)).then(intersect);- let answered = first.as_ref().is_some_and(|(r, report)| r.is_ok() && report.unverified().is_none());- let coaxial = if pin && !answered { solidcraft_kernel::coaxial_overlap(pa, pb) } else { None };- if let Some(o) = coaxial {- if o.volume > 0.0 {- out.overlap = Some((o.volume, o.area, o.bbox, o.centroid));+ match solidcraft_kernel::boolean(ka, kb, solidcraft_kernel::BoolOp::Intersect) {+ Err(e) => {+ out.unchecked = Some(e.to_string());+ return out;}- } else {- let (shared, report) = first.unwrap_or_else(intersect);- let failed =- |why: String| if pin { format!("a pin on one cylinder with its hole, whose walls could not be intersected ({why})") } else { why };- let shared = match shared {+ Ok(Some(o)) => match measure_near_origin(&o, shared_region(a, b).center()) {+ Ok(m) => out.overlap = Some((m.volume, m.area, m.bbox, m.centroid)),Err(e) => {- out.unchecked = Some(failed(e.to_string()));+ out.unchecked = Some(e.to_string());return out;}- Ok(shared) => shared,- };- if let Some(reason) = report.unverified() {- out.unchecked = Some(failed(reason));- return out;- }- if let Some(o) = shared {- match measure_near_origin(&o, region.center()) {- Ok(m) if !plausible(m.volume, m.centroid, m.bbox) => {- out.unchecked = Some(format!(- "the shared part came out malformed ({:.4} mm³ with its centre outside its own box), so it is not measured",- m.volume- ));- return out;- }- Ok(m) => {- if let Some(reason) = union_disagrees(pa, pb, m.volume, region.center()) {- out.unchecked = Some(reason);- return out;- }- out.overlap = Some((m.volume, m.area, m.bbox, m.centroid));- }- Err(e) => {- out.unchecked = Some(e.to_string());- return out;- }- }- }+ },+ Ok(None) => {}}if out.overlap.is_some_and(|o| o.0 >= min_volume) {return out;@@ -456,8 +394,7 @@ fn measure_pair(out}-/// The box where two bodies may share volume: where their boxes meet, grown by a margin so that-/// a cut there stays clear of both bodies' faces.+/// The box where two bodies may share volume: where their boxes meet, grown by a margin.fn shared_region(a: &DistanceShape, b: &DistanceShape) -> Aabb3 {let (x, y) = (a.bounds(), b.bounds());let min = x.min.max(y.min);@@ -470,109 +407,16 @@ fn shared_region(a: &DistanceShape, b: &DistanceShape) -> Aabb3 {Aabb3 { min: min - g, max: max + g }}-/// `body` cut down to `region` when the body is much larger than it. The boolean works to a-/// tolerance that grows with the bodies' size: a 0.01 mm overlap against a plate 1.7 m long-/// comes out a quarter too small, and thinner ones not at all. Cut to the region first, the-/// body is small and its faces there are the same faces. `None`: use the whole body.-fn clipped(body: &solidcraft_kernel::Body, region: Aabb3) -> Option<solidcraft_kernel::Body> {- if region.is_empty() || body.size() <= 4.0 * region.diagonal() {- return None;- }- let cut = solidcraft_kernel::box_solid(region.min, region.max).ok()?;- let (r, report) = solidcraft_kernel::capture_boolean_diagnostics(|| solidcraft_kernel::boolean(body, &cut, solidcraft_kernel::BoolOp::Intersect));- match r {- Ok(Some(c)) if report.unverified().is_none() => Some(c),- _ => None,- }-}--/// `body` cut down to where it may meet `piece` (their boxes' common part, grown as-/// [`shared_region`] grows it), when that leaves part of it out. `None`: use the whole body.-fn narrowed(body: &solidcraft_kernel::Body, piece: &solidcraft_kernel::Body) -> Option<solidcraft_kernel::Body> {- let bounds = |b: &solidcraft_kernel::Body| b.mesh(&solidcraft_kernel::MeshTolerance::chord((b.size() * 1e-3).max(1e-4))).ok().map(|m| m.bounds());- let (x, y) = (bounds(body)?, bounds(piece)?);- let (min, max) = (x.min.max(y.min), x.max.min(y.max));- if x.is_empty() || y.is_empty() || !(min.x <= max.x && min.y <= max.y && min.z <= max.z) {- return None;- }- let grow = 1.0 + 0.05 * min.dist(max);- let g = solidcraft_geom::Vec3::new(grow, grow, grow);- let region = Aabb3 { min: min - g, max: max + g };- if region.min.x <= x.min.x- && region.min.y <= x.min.y- && region.min.z <= x.min.z- && x.max.x <= region.max.x- && x.max.y <= region.max.y- && x.max.z <= region.max.z- {- return None;- }- let cut = solidcraft_kernel::box_solid(region.min, region.max).ok()?;- let (r, report) = solidcraft_kernel::capture_boolean_diagnostics(|| solidcraft_kernel::boolean(body, &cut, solidcraft_kernel::BoolOp::Intersect));- match r {- Ok(Some(c)) if report.unverified().is_none() => Some(c),- _ => None,- }-}-/// [`solidcraft_kernel::measure`] of `body` moved by `-at` and back: far from the origin, the/// centre of a thin part loses its precision (its moments are large numbers that nearly cancel).fn measure_near_origin(body: &solidcraft_kernel::Body, at: solidcraft_geom::Vec3) -> solidcraft_kernel::Result<solidcraft_kernel::BodyMeasure> {- let Ok(moved) = solidcraft_kernel::transform(body, -at, solidcraft_geom::Vec3::ZERO, solidcraft_geom::Vec3::Z, 0.0) else {- return solidcraft_kernel::measure(body);- };+ let moved = solidcraft_kernel::transform(body, -at, solidcraft_geom::Vec3::ZERO, solidcraft_geom::Vec3::Z, 0.0)?;let mut m = solidcraft_kernel::measure(&moved)?;m.centroid += at;m.bbox = Aabb3 { min: m.bbox.min + at, max: m.bbox.max + at };Ok(m)}-/// Does the shared volume of `a` and `b` disagree with the one their union implies,-/// vol(a) + vol(b) − vol(a ∪ b)? The intersection can come out well formed and still wrong (a-/// mirrored pair read three times its volume). `None` when they agree, or when the union gives no-/// answer to compare with.-fn union_disagrees(a: &solidcraft_kernel::Body, b: &solidcraft_kernel::Body, shared: f64, at: solidcraft_geom::Vec3) -> Option<String> {- let (union, report) = solidcraft_kernel::capture_boolean_diagnostics(|| solidcraft_kernel::boolean(a, b, solidcraft_kernel::BoolOp::Union));- let union = union.ok().flatten().filter(|_| report.unverified().is_none())?;- let volume = |x: &solidcraft_kernel::Body| measure_near_origin(x, at).ok().map(|m| m.volume).filter(|v| v.is_finite());- contradicted(shared, volume(a)?, volume(b)?, volume(&union)?)-}--/// How far vol(a) + vol(b) − vol(a ∪ b) can stray from the shared volume by measuring alone,-/// as a share of vol(a) + vol(b) + vol(a ∪ b). [`solidcraft_kernel::measure`] facets a curved-/// face with chords of up to 3e-4 of its radius where the radius sets them, which leaves the-/// volume it encloses short by up to (4/3) × 3e-4 = 4e-4. That shortfall is the same for a face-/// measured on its own body and in the union, and cancels in the difference, except where the-/// chord changes with the body measured (it also follows the body's size). Measured, that-/// change stays near 2e-5 of the three volumes: 2.1e-5 for a 40 mm roller pressed 0.2 mm into a-/// 2 m plate (`a_roller_pressed_into_a_large_plate_is_reported`), 2e-5 and 1e-6 in the examples-/// of `the_union_check_allows_for_the_bodies_measuring_error`. This allows five times that.-const VOLUME_NOISE: f64 = 1e-4;--/// [`union_disagrees`] on measured volumes: `shared` against vol(a) + vol(b) − vol(a ∪ b).-/// That difference of large numbers carries the measuring error of all three, so a small overlap-/// on large bodies can come out near zero or below it: then the union cannot tell, and a shared-/// part small next to both bodies stands. A shared part the union clearly contradicts (412 mm³-/// where the bodies of a few thousand and their union imply 141) does not.-fn contradicted(shared: f64, va: f64, vb: f64, vu: f64) -> Option<String> {- let implied = va + vb - vu;- let noise = VOLUME_NOISE * (va + vb + vu) + 1e-6;- let allowed = 0.01 * shared.max(implied.abs()) + noise;- let unresolved = implied <= noise && shared <= 0.1 * va.min(vb);- ((implied - shared).abs() > allowed && !unresolved)- .then(|| format!("the shared part measures {shared:.4} mm³ but the bodies and their union imply {implied:.4} mm³, so neither is reported"))-}--/// Is a measured shared part well formed? A part whose shell came out inside out or open can-/// carry a volume with its centre outside its own box, or more volume than its box holds.-fn plausible(volume: f64, centre: solidcraft_geom::Vec3, bbox: Aabb3) -> bool {- let slack = 1e-6 * bbox.diagonal().max(1.0);- let (lo, hi) = (bbox.min, bbox.max);- let inside = [(centre.x, lo.x, hi.x), (centre.y, lo.y, hi.y), (centre.z, lo.z, hi.z)].iter().all(|&(c, l, h)| c >= l - slack && c <= h + slack);- let s = bbox.size();- volume.is_finite() && volume >= 0.0 && inside && volume <= s.x * s.y * s.z + slack-}-/// Each subject's `count` nearest bodies, nearest first: pairs are measured in the order of their/// boxes' gaps (a lower bound of their distance), in rounds, until the boxes of the next ones/// are farther apart than the last neighbour kept. `known` holds distances already measured.diff --git a/crates/engine/src/cmd/clearance_tests.rs b/crates/engine/src/cmd/clearance_tests.rsindex 026b094f37..9a2207d30f 100644--- a/crates/engine/src/cmd/clearance_tests.rs+++ b/crates/engine/src/cmd/clearance_tests.rs@@ -217,18 +217,6 @@ fn a_thin_overlap_with_a_large_plate_is_measured_in_full() {}}-/// A shared part whose centre lies outside its own box, or which holds more than its box, is-/// malformed: the pair is reported unchecked rather than with that volume.-#[test]-fn a_malformed_shared_part_is_not_measured() {- use solidcraft_geom::{Aabb3, Vec3};- let bbox = Aabb3 { min: Vec3::new(0.0, 0.0, 0.0), max: Vec3::new(10.0, 10.0, 1.0) };- assert!(super::plausible(50.0, Vec3::new(5.0, 5.0, 0.5), bbox));- assert!(!super::plausible(50.0, Vec3::new(5.0, 5.0, 3.0), bbox));- assert!(!super::plausible(1239.0, Vec3::new(5.0, 5.0, 0.5), bbox));- assert!(!super::plausible(f64::NAN, Vec3::new(5.0, 5.0, 0.5), bbox));-}-/// Two plates 0.2 mm apart, the upper one set 10 mm in from the lower one's corner, and two set/// side by side with a 0.2 mm gap: 0.2, not 0 (a point past a corner, on the line of one of its/// edges, was taken for a point of the face). Gaps under twice the meshes' chord went wrong.@@ -348,13 +336,8 @@ fn a_body_that_changed_shape_is_measured_again() {/// A flanged bushing and a headed pin seated in it line to line, on its very axis, the head on/// the flange. Plain, they touch and share nothing; sunk 0.2 into the flange, the head shares the/// ring under it. With a fillet under the head against the bore's sharp edge, the fillet's ring-/// is in the flange (about 0.49 mm³), next to walls that lie on one another: the boolean tried-/// for minutes there and gave up; now it is reported as such within seconds.-///-/// The clock is not read: what is under test is the result, and the boolean that gives up is-/// reported as such instead of hanging the test. The wall that lies on the other one is what-/// makes the pair unchecked, and that is what the assertions below check (#2999 dropped the clock-/// from the sibling tests the same way).+/// is in the flange (about 0.49 mm³), next to walls that lie on one another: an overlap. The clock+/// is not read: what is under test is the result (#2999 dropped it from the sibling tests).#[test]fn a_pin_seated_line_to_line_in_its_bushing_is_measured() {let ring = std::f64::consts::PI * (7.0f64.powi(2) - 4.0f64.powi(2)) * 0.2;@@ -371,11 +354,11 @@ fn a_pin_seated_line_to_line_in_its_bushing_is_measured() {run(&mut s, "solid.fillet", json!({"edges": [[107, 0, z + 1.5]], "radius": 0.5, "body": "Pin"}));}let r = run(&mut s, "inspect.clearance", json!({"bodies": ["Pin"], "against": ["Bush"], "min_volume": 0.01, "clearance": 1e-6}));+ assert_eq!(r["unchecked"], json!([]), "sunk {sunk}: {r}");if fillet {- assert!(r["unchecked"][0]["reason"].as_str().is_some_and(|w| w.contains("pin on one cylinder")), "{r}");+ assert!(f(&r["overlaps"][0]["volume_mm3"]) > 0.01, "{r}");continue;}- assert_eq!(r["unchecked"], json!([]), "sunk {sunk}: {r}");if sunk == 0.0 {assert_eq!(r["overlaps"].as_array().map(Vec::len), Some(0), "{r}");assert_eq!(f(&r["near"][0]["distance_mm"]), 0.0, "{r}");@@ -386,9 +369,9 @@ fn a_pin_seated_line_to_line_in_its_bushing_is_measured() {}}-/// A chamfered pin through a hole of its own radius, its axis a hair off the hole's: the boolean-/// cannot intersect walls all but tangent along two lines and once passed the pair as clear.-/// The crescent the pin shares with the plate is reported, against the lens of two circles.+/// A chamfered pin through a hole of its own radius, its axis a hair off the hole's, the walls+/// all but tangent along two lines: the crescent the pin shares with the plate is reported,+/// against the lens of two circles.#[test]fn a_pin_a_hair_off_its_hole_shares_its_crescent() {let crescent = |r: f64, e: f64| std::f64::consts::PI * r * r - (2.0 * r * r * (e / (2.0 * r)).acos() - e / 2.0 * (4.0 * r * r - e * e).sqrt());@@ -406,38 +389,6 @@ fn a_pin_a_hair_off_its_hole_shares_its_crescent() {}}-/// The shared volume is checked against the bodies and their union: two 10 mm cubes sharing a-/// 3 mm corner cube agree at 27 mm³, and a shared part read as three times that (as a mirrored-/// pair once was) does not.-#[test]-fn a_shared_volume_the_union_contradicts_is_caught() {- use solidcraft_geom::Vec3;- let a = solidcraft_kernel::box_solid(Vec3::new(0.0, 0.0, 0.0), Vec3::new(10.0, 10.0, 10.0)).unwrap_or_else(|e| panic!("{e}"));- let b = solidcraft_kernel::box_solid(Vec3::new(7.0, 7.0, 7.0), Vec3::new(17.0, 17.0, 17.0)).unwrap_or_else(|e| panic!("{e}"));- let at = Vec3::new(8.5, 8.5, 8.5);- assert_eq!(super::union_disagrees(&a, &b, 27.0, at), None);- assert!(super::union_disagrees(&a, &b, 81.0, at).is_some());-}--/// The check works on measured volumes, and vol(a) + vol(b) − vol(a ∪ b) carries the error of-/// all three: a small overlap on large bodies can come out near zero, or below it. A union that-/// cannot resolve the shared part leaves it standing; one that clearly contradicts it does not.-#[test]-fn the_union_check_allows_for_the_bodies_measuring_error() {- use super::contradicted;- // 0.96 mm³ shared where the union of 40 000 and 300 mm³ implies -0.75: noise, not a contradiction.- assert_eq!(contradicted(0.96, 40_000.0, 300.0, 40_300.75), None);- // 5.92 mm³ of a small body in a large sheet, with the union 0.4 mm³ off the bodies' sum.- assert_eq!(contradicted(5.92, 250_000.0, 80.0, 250_074.48), None);- // Past the noise, but the union implies nothing at all while the shared part is small next- // to both bodies: the union cannot tell, and the shared part stands.- assert_eq!(contradicted(6.0, 400.0, 200.0, 600.5), None);- // 412 mm³ shared where bodies of a few thousand and their union imply 141: caught.- assert!(contradicted(411.98, 3_200.0, 3_150.0, 6_350.0 - 141.18).is_some());- // A large shared part the union says is not there at all: caught too.- assert!(contradicted(900.0, 3_200.0, 3_150.0, 6_350.0).is_some());-}-/// A small box pressed 0.6 mm into a 2000 × 1000 × 1 mm plate shares 3 × 3 × 0.6 = 5.4 mm³: an/// overlap, not an unchecked pair.#[test]diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rsindex c99a4f294b..78724b5a7a 100644--- a/crates/engine/src/cmd/features.rs+++ b/crates/engine/src/cmd/features.rs@@ -762,7 +762,7 @@ fn add_feature_in(s: &mut Session, p: &Value, kind: FeatureKind, world: bool) ->st.bodies.iter().filter(|b| b.feature != id && old.get(b.name.as_str()).is_some_and(|o| !o.same(&b.body))).map(|b| b.name.as_str()).collect();let removed: Vec<&str> = before.bodies.iter().map(|b| b.name.as_str()).filter(|n| !now.contains(n)).collect();let fname = s.doc.feature(id).map(|f| f.name.clone()).unwrap_or_default();- // A warning (a Boolean that needed a retry, a reference found again elsewhere) is part of+ // A warning (a reference found again elsewhere, a reduced radius) is part of// the reply: a script or an agent sees it without asking the timeline (#616).let warning = r.as_ref().and_then(|r| r.warning.clone());let owned = |names: Vec<&str>| names.into_iter().map(str::to_string).collect();diff --git a/crates/engine/src/cmd/interference.rs b/crates/engine/src/cmd/interference.rsindex 43781bb663..8cdff49920 100644--- a/crates/engine/src/cmd/interference.rs+++ b/crates/engine/src/cmd/interference.rs@@ -56,8 +56,6 @@ enum Outcome {/// One pair's answer and where its time went.struct Done {outcome: Outcome,- /// Unverified boolean results are listed as unchecked and still reported as a hit.- note: Option<String>,ms: f64,kernel: KernelTimes,}@@ -171,9 +169,6 @@ pub(super) fn interference(s: &mut Session, p: &Value) -> Result<Value> {json!({"a": a, "b": b, "ms": round_ms(d.ms), "boolean_ms": round_ms(d.kernel.boolean_ms),"tessellate_ms": round_ms(d.kernel.tessellate_ms)}),));- if let Some(reason) = d.note {- unchecked.push(json!({"a": a, "b": b, "reason": reason}));- }match d.outcome {Outcome::Hit(v) => hits.push(v),Outcome::Clear => {}@@ -263,92 +258,31 @@ fn any_inside(points: &[Vec3], outer: &Mesh) -> bool {}}-/// The exact check of one pair: a pin a hair off the axis of its hole by the walls' crescent,-/// otherwise the intersection measured.+/// The exact check of one pair: the bodies' intersection, measured.fn check(job: &Job) -> Done {let started = web_time::Instant::now();- let ((outcome, note), kernel) = solidcraft_kernel::profile::capture(|| check_pair(&job.a, &job.b, &job.names));- Done { outcome, note, ms: started.elapsed().as_secs_f64() * 1000.0, kernel }+ let (outcome, kernel) = solidcraft_kernel::profile::capture(|| check_pair(&job.a, &job.b, &job.names));+ Done { outcome, ms: started.elapsed().as_secs_f64() * 1000.0, kernel }}-fn check_pair(a: &Body, b: &Body, (na, nb): &(String, String)) -> (Outcome, Option<String>) {+fn check_pair(a: &Body, b: &Body, (na, nb): &(String, String)) -> Outcome {let threshold = 1e-9 * a.size().max(1.0).powi(3);- // A pin a hair off the axis of its hole: the crescent the walls share, which the boolean- // can't intersect.- if let Some(o) = solidcraft_kernel::coaxial_overlap(a, b) {- if o.volume > threshold {- let hit = json!({"a": na, "b": nb, "volume_mm3": o.volume, "area_mm2": o.area, "center": o.centroid,- "bbox": {"min": o.bbox.min, "max": o.bbox.max}, "near_coaxial": {"offset_mm": o.offset, "length_mm": o.length}});- return (Outcome::Hit(hit), None);- }- return (Outcome::Clear, None);- }// A pair whose shared part can't be worked out is reported, not passed as clear.- let (shared, report) = solidcraft_kernel::capture_boolean_diagnostics(|| solidcraft_kernel::boolean(a, b, solidcraft_kernel::BoolOp::Intersect));- let shared = match shared {- Ok(o) => o,- Err(e) => return (Outcome::Unchecked(e.to_string()), None),+ let shared = match solidcraft_kernel::boolean(a, b, solidcraft_kernel::BoolOp::Intersect) {+ Ok(Some(o)) => o,+ Ok(None) => return Outcome::Clear,+ Err(e) => return Outcome::Unchecked(e.to_string()),};- let mut note = report.unverified();- let pieces = match shared {- Some(o) => vec![o],- // A body in several pieces, one of them wholly inside the other body: the whole bodies'- // boolean can come out empty, so the pieces are intersected one by one.- None if a.shell_count() > 1 || b.shell_count() > 1 => match by_pieces(a, b) {- Ok((pieces, unverified)) => {- note = note.or(unverified);- pieces- }- Err(e) => return (Outcome::Unchecked(e), note),- },- None => return (Outcome::Clear, note),+ let m = match solidcraft_kernel::measure_mass(&shared) {+ Ok(m) => m,+ Err(e) => return Outcome::Unchecked(e.to_string()),};- // The shared parts measured together: volumes and areas add, the centre is the volumes'.- let mut measured = Vec::new();- for o in &pieces {- match solidcraft_kernel::measure_mass(o) {- Ok(m) => measured.push(m),- Err(e) => return (Outcome::Unchecked(e.to_string()), note),- }- }- let volume: f64 = measured.iter().map(|m| m.volume).sum();- if volume > threshold {- let area: f64 = measured.iter().map(|m| m.area).sum();- let bbox = measured.iter().fold(Aabb3::EMPTY, |b, m| b.union(&m.bbox));- let center = match measured.as_slice() {- [m] => m.centroid,- _ => measured.iter().fold(Vec3::ZERO, |c, m| c + m.centroid * m.volume) / volume,- };- let hit = json!({"a": na, "b": nb, "volume_mm3": volume, "area_mm2": area, "center": center, "bbox": {"min": bbox.min, "max": bbox.max}});- return (Outcome::Hit(hit), note);- }- (Outcome::Clear, note)-}--/// Most pairs of pieces [`by_pieces`] intersects.-const MAX_PIECE_PAIRS: usize = 256;--/// The shared parts of two bodies, a piece of each at a time, and why any of them is unverified.-fn by_pieces(a: &Body, b: &Body) -> std::result::Result<(Vec<Body>, Option<String>), String> {- let (la, lb) = (a.lumps().map_err(|e| e.to_string())?, b.lumps().map_err(|e| e.to_string())?);- if la.len() < 2 && lb.len() < 2 {- return Ok((Vec::new(), None));- }- if la.len().saturating_mul(lb.len()) > MAX_PIECE_PAIRS {- return Err(format!("not checked: {} by {} pieces are more than {MAX_PIECE_PAIRS} pairs of pieces", la.len(), lb.len()));- }- let (mut out, mut note) = (Vec::new(), None);- for x in &la {- for y in &lb {- let (r, report) =- solidcraft_kernel::capture_boolean_diagnostics(|| solidcraft_kernel::boolean(x, y, solidcraft_kernel::BoolOp::Intersect));- note = note.or(report.unverified());- if let Some(o) = r.map_err(|e| e.to_string())? {- out.push(o);- }- }+ if m.volume > threshold {+ let hit = json!({"a": na, "b": nb, "volume_mm3": m.volume, "area_mm2": m.area, "center": m.centroid,+ "bbox": {"min": m.bbox.min, "max": m.bbox.max}});+ return Outcome::Hit(hit);}- Ok((out, note))+ Outcome::Clear}/// Each job's answer (in pair order, with the pair's names; `None`: not finished within@@ -391,7 +325,6 @@ fn run_ordered(jobs: Vec<Job>, budget: std::time::Duration) -> (Vec<Option<Done>let Some(job) = jobs.get(k) else { break };let done = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| check(job))).unwrap_or_else(|_| Done {outcome: Outcome::Unchecked("internal error while checking this pair".into()),- note: None,ms: 0.0,kernel: KernelTimes::default(),});diff --git a/crates/engine/src/cmd/joints.rs b/crates/engine/src/cmd/joints.rsindex c74f5767de..8da2287daa 100644--- a/crates/engine/src/cmd/joints.rs+++ b/crates/engine/src/cmd/joints.rs@@ -94,7 +94,7 @@ pub static COMMANDS: &[CommandSpec] = &[),CommandSpec::new("joint.solve", "Solve Joints", solve_cmd).icon("compute").params("re-place the occurrences from the joints → conflicts, errors, dof"),CommandSpec::new("inspect.interference", "Interference", super::interference::interference).at("SOLID", "INSPECT").icon("interference").noundo().params(- "bodies?: [names] (default: all, in world placement); budget_s?: seconds (default 240, at most 86400: pairs not finished by then are listed in unchecked as \"not checked: the time budget … ran out\" and the call returns) → interferences: pairs that overlap with the overlap volume, area, bounding box and centre (a pin a hair off the axis of a hole of its size also has near_coaxial: {offset_mm, length_mm}, its volume the crescent the walls share); unchecked: [{a, b, reason}], the pairs that could not be checked, with the reason, and each mesh body (STL, 3MF or OBJ import: not intersected) as {a: name, b: null, reason: \"mesh body: not checked\"}, so count: 0 is not read as no overlap (checked counts the solid bodies). Bodies are pruned by bounding box first, then by their display meshes (pairs whose meshes stay apart by more than their chord tolerances, neither inside the other, are clear without a boolean), so any number of bodies is fine; the pairs left are intersected exactly, in parallel on desktop, the slowest first; at most 20000 pairs whose boxes overlap are intersected per call (truncated: true and skipped_pairs: n say when more were left out). Also: pairs_candidate (boxes overlap), pairs_cleared (by the meshes), pairs_intersected, pairs_not_checked, budget_exceeded, threads (worker threads; 0: on the calling thread), boolean_ms and tessellate_ms (kernel time summed over the pairs), slowest: [{a, b, ms, boolean_ms, tessellate_ms}] and ms",+ "bodies?: [names] (default: all, in world placement); budget_s?: seconds (default 240, at most 86400: pairs not finished by then are listed in unchecked as \"not checked: the time budget … ran out\" and the call returns) → interferences: pairs that overlap with the overlap volume, area, bounding box and centre; unchecked: [{a, b, reason}], the pairs that could not be checked, with the reason, and each mesh body (STL, 3MF or OBJ import: not intersected) as {a: name, b: null, reason: \"mesh body: not checked\"}, so count: 0 is not read as no overlap (checked counts the solid bodies). Bodies are pruned by bounding box first, then by their display meshes (pairs whose meshes stay apart by more than their chord tolerances, neither inside the other, are clear without a boolean), so any number of bodies is fine; the pairs left are intersected exactly, in parallel on desktop, the slowest first; at most 20000 pairs whose boxes overlap are intersected per call (truncated: true and skipped_pairs: n say when more were left out). Also: pairs_candidate (boxes overlap), pairs_cleared (by the meshes), pairs_intersected, pairs_not_checked, budget_exceeded, threads (worker threads; 0: on the calling thread), boolean_ms and tessellate_ms (kernel time summed over the pairs), slowest: [{a, b, ms, boolean_ms, tessellate_ms}] and ms",),];diff --git a/crates/engine/src/cmd/joints_tests.rs b/crates/engine/src/cmd/joints_tests.rsindex c9d22a9313..b8ca196fac 100644--- a/crates/engine/src/cmd/joints_tests.rs+++ b/crates/engine/src/cmd/joints_tests.rs@@ -1826,10 +1826,9 @@ mod motion_analysis;mod motion_sweep;/// A pin through a hole of its own radius whose axis is a hair off the hole's (parts placed from-/// rounded coordinates): the walls are all but tangent along two lines, which the boolean can't-/// intersect. Each offset gets a checked answer: clear on the axis and within the kernel's-/// same-surface tolerance, and otherwise the crescent the pin shares with the plate, against-/// the textbook lens of two circles. The pin is chamfered, so it is not a plain prism.+/// rounded coordinates): the walls are all but tangent along two lines. Each offset gets a+/// checked answer: clear on the axis and within the kernel's same-surface tolerance, and+/// otherwise the crescent the pin shares with the plate, against the textbook lens of two circles. The pin is chamfered, so it is not a plain prism.#[test]fn interference_of_a_pin_a_hair_off_its_hole() {let crescent = |r: f64, e: f64| std::f64::consts::PI * r * r - (2.0 * r * r * (e / (2.0 * r)).acos() - e / 2.0 * (4.0 * r * r - e * e).sqrt());@@ -1849,7 +1848,6 @@ fn interference_of_a_pin_a_hair_off_its_hole() {let want = 5.0 * crescent(3.0, offset);let got = i["interferences"][0]["volume_mm3"].as_f64().unwrap_or(0.0);assert!((got - want).abs() < 1e-6 * want, "{offset}: {got} against {want}: {i}");- assert!((i["interferences"][0]["near_coaxial"]["offset_mm"].as_f64().unwrap_or(0.0) - offset).abs() < 1e-9, "{i}");}}@@ -1870,7 +1868,6 @@ fn interference_of_a_headed_pin_a_hair_off_a_bush_of_its_heads_radius() {let want = 5.0 * crescent(3.0, offset);let got = i["interferences"][0]["volume_mm3"].as_f64().unwrap_or(0.0);assert!((got - want).abs() < 1e-6 * want, "{got} against {want}: {i}");- assert!(i["interferences"][0]["near_coaxial"].is_object(), "{i}");}/// A headed pin made before the plate it sits in, a hair off the plate's hole: the crescentdiff --git a/crates/engine/src/fuzz.rs b/crates/engine/src/fuzz.rsindex 2219c5ed6a..a84b9650b8 100644--- a/crates/engine/src/fuzz.rs+++ b/crates/engine/src/fuzz.rs@@ -64,8 +64,6 @@ pub struct Run {pub unsupported: Vec<(String, String)>,/// Steps whose generated parameters a command refused.pub rejected: usize,- pub boolean_fallbacks: std::collections::BTreeMap<solidcraft_kernel::BooleanStrategy, usize>,- pub boolean_reports_truncated: bool,}impl Run {@@ -84,9 +82,8 @@ fn classify(e: &EngineError) -> Outcome {match e {EngineError::Internal(..) => Outcome::new("panic", msg),EngineError::BadParams { .. } | EngineError::Disabled(..) | EngineError::UnknownCommand(_) => Outcome::new("rejected", msg),- // A failed boolean is a failure even when it says "not supported" (the planar fallback on- // curved bodies): those are the cases to fix. Features the kernel doesn't do yet (a- // fillet between curved faces) are limitations.+ // A failed boolean is a failure even when it says "not supported": those are the cases+ // to fix. Features the kernel doesn't do yet are limitations.// Picks the generator got wrong (a centroid off its face).EngineError::Other(_) if msg.starts_with("invalid input") => Outcome::new("rejected", msg),EngineError::Other(_) if msg.contains("boolean") => Outcome::new("failed", msg),@@ -340,8 +337,6 @@ fn run_session(seed: u64, max_steps: usize, on_step: &mut dyn FnMut(&Step)) -> (outcome: Outcome::ok(),unsupported: Vec::new(),rejected: 0,- boolean_fallbacks: Default::default(),- boolean_reports_truncated: false,};let mut last_feature: Option<String> = None;let n = 2 + r.below(max_steps.max(2) - 1);@@ -367,12 +362,6 @@ fn run_session(seed: u64, max_steps: usize, on_step: &mut dyn FnMut(&Step)) -> (continue;}let kind = st.kind;- for result in s.model.results.iter().skip(before).filter(|result| result.error.is_none()) {- run.boolean_reports_truncated |= result.boolean_diagnostics.truncated;- for event in &result.boolean_diagnostics.events {- *run.boolean_fallbacks.entry(event.strategy).or_default() += 1;- }- }run.steps.push(st);if out.kind != "ok" {run.outcome = out;@@ -388,19 +377,14 @@ fn run_session(seed: u64, max_steps: usize, on_step: &mut dyn FnMut(&Step)) -> (/// Run fixed steps (a recorded or minimised design): the index and outcome of the first step/// that isn't ok (or the last step's, ok).pub fn replay(steps: &[Step]) -> (usize, Outcome) {- let (index, outcome, _) = replay_session(steps);- (index, outcome)-}--fn replay_session(steps: &[Step]) -> (usize, Outcome, Session) {let mut s = Session::default();for (i, st) in steps.iter().enumerate() {let out = apply(&mut s, st);if out.kind != "ok" {- return (i, out, s);+ return (i, out);}}- (steps.len().saturating_sub(1), Outcome::ok(), s)+ (steps.len().saturating_sub(1), Outcome::ok())}/// The start of a message, to tell failures apart (numbers vary between versions of a case).@@ -431,16 +415,8 @@ pub fn minimise(run: &Run) -> Run {}}}- let (_, outcome, session) = replay_session(&steps);- let mut boolean_fallbacks = std::collections::BTreeMap::new();- let mut boolean_reports_truncated = false;- for result in &session.model.results {- boolean_reports_truncated |= result.boolean_diagnostics.truncated;- for event in &result.boolean_diagnostics.events {- *boolean_fallbacks.entry(event.strategy).or_default() += 1;- }- }- Run { seed: run.seed, steps, outcome, unsupported: Vec::new(), rejected: 0, boolean_fallbacks, boolean_reports_truncated }+ let (_, outcome) = replay(&steps);+ Run { seed: run.seed, steps, outcome, unsupported: Vec::new(), rejected: 0 }}#[cfg(test)]diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rsindex 85605a03a0..42e186e631 100644--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@ -323,6 +323,7 @@ fn join_of_a_lobed_disc_pattern_is_not_refused() {assert!(rel(got, want) < 1e-3, "{got} vs {want}");}+mod barrel_join;mod blend_fit;mod component_frames;mod curved_seam_round;diff --git a/crates/engine/src/tests/barrel_join.rs b/crates/engine/src/tests/barrel_join.rsnew file mode 100644index 0000000000..a81aa61485--- /dev/null+++ b/crates/engine/src/tests/barrel_join.rs@@ -0,0 +1,31 @@+use super::*;++/// A barrel joined under a plate's back edge, its ends flush with the sides of the leaf it hangs+/// from (#827 without its fillets): the join is exact, so the command's reply carries no warning,+/// and the barrel's ends stay in the leaf's sides.+#[test]+fn a_barrel_joined_between_the_sides_of_a_leaf_is_exact() {+ let mut session = Session::default();+ run(&mut session, "solid.box", json!({"length": 40, "width": 20, "height": 6, "corner": [0, 0, 5], "body_name": "Plate"}));+ run(&mut session, "solid.box", json!({"length": 14, "width": 10, "height": 6, "corner": [10, 10, 0], "operation": "join", "targets": ["Plate"]}));+ let reply = run(+ &mut session,+ "solid.cylinder",+ json!({"radius": 5, "height": 14, "axis": "X", "base": [10, 20, 0], "operation": "join", "targets": ["Plate"]}),+ );+ assert!(reply["warning"].is_null(), "{reply}");+ let state = session.model.state();+ let plate = &state.body("Plate").unwrap().body;+ assert_eq!(plate.shell_count(), 1);+ assert!(plate.validity().is_empty(), "{:?}", plate.validity());+ // Every edge ends on a level along x of the plate, the leaf or the barrel.+ for edge in plate.edges(1e-3).unwrap() {+ for p in [edge.points.first(), edge.points.last()].into_iter().flatten() {+ assert!([0., 10., 24., 40.].iter().any(|x| (p.x - x).abs() < 1e-9), "an edge ends at {p:?}");+ }+ }+ // A quarter of the barrel lies in the leaf.+ let expected = 5500. + 0.75 * PI * 25. * 14.;+ let actual = plate.mesh(&solidcraft_kernel::MeshTolerance::chord(1e-4)).unwrap().measure().volume;+ assert!(rel(actual, expected) < 1e-5, "{actual} vs {expected}");+}diff --git a/crates/geom/src/brep/eval.rs b/crates/geom/src/brep/eval.rsindex 3cb10ff592..420579fac5 100644--- a/crates/geom/src/brep/eval.rs+++ b/crates/geom/src/brep/eval.rs@@ -14,7 +14,6 @@ use crate::Vec3;use crate::bspline::MAX_SPLINE_DEGREE;use crate::tess::uv::{self, Domain};use crate::tess::{EvalCurve, EvalSurface, MAX_EVAL_KNOTS, MAX_EVAL_POINTS};-use std::cell::Cell;use std::f64::consts::{FRAC_PI_2, TAU};/// Newton steps of one intersection point.@@ -286,9 +285,6 @@ pub enum CurveEval {pub struct Intersection {surfaces: [SurfaceEval; 2],leader: CurveEval,- tolerance: f64,- /// Both surfaces' parameters of the last point found: the next point starts from them.- hint: Cell<Option<[[f64; 2]; 2]>>,}impl CurveEval {@@ -300,7 +296,7 @@ impl CurveEval {Curve::Polyline { points } => CurveEval::Polyline(points.iter().copied().map(v3).collect()),Curve::Spline { knots, points } => spline(knots, points.iter().map(|p| [p[0], p[1], p[2], 1.0]).collect())?,Curve::RationalSpline { knots, homogeneous } => spline(knots, homogeneous.clone())?,- Curve::SurfaceIntersection { surfaces, leader, tolerance } => {+ Curve::SurfaceIntersection { surfaces, leader, .. } => {let leader = CurveEval::new(leader)?;if !matches!(leader, CurveEval::Polyline(_) | CurveEval::Spline(_)) {return Err(Error::Invalid("intersection leader".into()));@@ -308,8 +304,6 @@ impl CurveEval {CurveEval::Intersection(Box::new(Intersection {surfaces: [SurfaceEval::new(&surfaces[0])?, SurfaceEval::new(&surfaces[1])?],leader,- tolerance: *tolerance,- hint: Cell::new(None),}))}})@@ -380,29 +374,21 @@ fn spline(knots: &[f64], ctrl: Vec<[f64; 4]>) -> Result<CurveEval, Error> {}impl Intersection {- /// The point in the leader's normal plane at `t`: from the last point's parameters when that- /// lands within the trace tolerance of the leader (as truck takes a hinted point), else from- /// the leader's point alone.+ /// The point in the leader's normal plane at `t`, found from the leader's point: a function+ /// of `t` alone, whatever was evaluated before (and so the same on every thread).fn point(&self, t: f64) -> Option<Vec3> {let (lead, along) = self.leader.leader(t)?;if !(along.len2() > 0.0) {return None;}- let near = self.tolerance.max(1e-6);- let hinted = self.hint.get().and_then(|h| self.solve(lead, along, Some(h))).filter(|(x, _)| x.dist(lead) <= near);- let (x, uv) = match hinted {- Some(found) => found,- None => self.solve(lead, along, None)?,- };- self.hint.set(Some(uv));- Some(x)+ self.solve(lead, along)}/// Newton on the planes: each surface's tangent plane at the foot of the current point, and/// the leader's normal plane, until the point stops moving.- fn solve(&self, lead: Vec3, along: Vec3, hint: Option<[[f64; 2]; 2]>) -> Option<(Vec3, [[f64; 2]; 2])> {+ fn solve(&self, lead: Vec3, along: Vec3) -> Option<Vec3> {let mut x = lead;- let mut uv = hint;+ let mut uv: Option<[[f64; 2]; 2]> = None;for _ in 0..MAX_NEWTON {let mut planes = [(Vec3::ZERO, 0.0); 2];let mut feet = [[0.0; 2]; 2];@@ -419,7 +405,7 @@ impl Intersection {let step = y.dist(x);x = y;if step <= 1e-12 * (1.0 + x.len()) {- return Some((x, feet));+ return Some(x);}}None