SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.
Wave 93/509: docs: SMLib vs truck triage of the sweeps, threads and shell cases (and 3 more)
Brennen Herbruck532027f7a6ab
diff --git a/crates/smlib/src/ffi/ops.rs b/crates/smlib/src/ffi/ops.rsindex 21a033f94f..ca854d9d44 100644--- a/crates/smlib/src/ffi/ops.rs+++ b/crates/smlib/src/ffi/ops.rs@@ -1,6 +1,6 @@//! The operations block of `capi/include/smlib.h` (`smlib_boolean`, `smlib_fillet`,//! `smlib_chamfer`, `smlib_blend`, `smlib_fillet_variable`, `smlib_shell`, `smlib_offset_faces`,-//! `smlib_thicken`, `smlib_brep_solid_count`; the fork's `capi/src/smlib_ops.cpp`), declared by+//! `smlib_thicken`, `smlib_brep_solid_count`, `smlib_imprint`; the fork's `capi/src/smlib_ops.cpp`), declared by//! hand. Part of the FFI boundary, like its parent: called only through//! [`crate::ops`].@@ -16,6 +16,7 @@ pub const ERR_NOT_SOLID: i32 = -1100;pub const ERR_PICK_NONE: i32 = -1101;pub const ERR_PICK_AMBIGUOUS: i32 = -1102;pub const ERR_NO_ROOM: i32 = -1103;+pub const ERR_NO_CUT: i32 = -1104;pub const BOOLEAN_UNION: i32 = 0;pub const BOOLEAN_SUBTRACT: i32 = 1;@@ -46,6 +47,7 @@ type PickFn = unsafe extern "C" fn(*const RawBrep, *const f64, i64, f64, f64, *munsafe extern "C" {fn smlib_boolean(a: *const RawBrep, b: *const RawBrep, op: i32, out: *mut *mut RawBrep) -> i32;fn smlib_brep_solid_count(brep: *const RawBrep, out: *mut i64) -> i32;+ fn smlib_imprint(body: *const RawBrep, tool: *const RawBrep, out: *mut *mut RawBrep) -> i32;fn smlib_fillet(brep: *const RawBrep,points: *const f64,@@ -112,6 +114,11 @@ pub fn boolean(a: &Handle, b: &Handle, op: i32) -> Result<Handle, i32> {new_brep(|out| unsafe { smlib_boolean(a.raw(), b.raw(), op, out) })}+#[cfg(feature = "native")]+pub fn imprint(body: &Handle, tool: &Handle) -> Result<Handle, i32> {+ new_brep(|out| unsafe { smlib_imprint(body.raw(), tool.raw(), out) })+}+#[cfg(feature = "native")]pub fn solid_count(b: &Handle) -> Result<i64, i32> {let mut n = 0i64;@@ -197,6 +204,11 @@ pub fn boolean(_: &Handle, _: &Handle, _: i32) -> Result<Handle, i32> {Err(NOT_BUILT)}+#[cfg(not(feature = "native"))]+pub fn imprint(_: &Handle, _: &Handle) -> Result<Handle, i32> {+ Err(NOT_BUILT)+}+#[cfg(not(feature = "native"))]pub fn solid_count(_: &Handle) -> Result<i64, i32> {Err(NOT_BUILT)diff --git a/crates/smlib/src/import.rs b/crates/smlib/src/import.rsindex bf74a07193..2be8c4ccaf 100644--- a/crates/smlib/src/import.rs+++ b/crates/smlib/src/import.rs@@ -165,6 +165,9 @@ fn laid_out(brep: &b::Brep, trusted: bool, analytic: bool) -> R<Arrays> {}}+ // Each edge's interval as SMLib takes it, and how far it moved (see `turned`).+ let intervals: Vec<([f64; 2], f64)> = brep.edges.iter().map(|e| turned(&e.curve, e.interval)).collect();+// Faces, loops and edgeuses, with the surfaces and, on B-spline faces, the trims.let any_spline_face = brep.faces.iter().any(|f| matches!(f.surface, b::Surface::Spline { .. } | b::Surface::RationalSpline { .. }));for f in &brep.faces {@@ -185,7 +188,8 @@ fn laid_out(brep: &b::Brep, trusted: bool, analytic: bool) -> R<Arrays> {a.i(flat::EDGEUSE_ORIENTATION).push(i64::from(u.forward));if any_spline_face {if spline {- trim(&mut a, &u.pcurve, u.forward)?;+ let shift = intervals.get(u.edge as usize).map_or(0.0, |i| i.1);+ trim(&mut a, &u.pcurve, u.forward, shift)?;} else {a.i(flat::EDGEUSE_NURBS_VERTEX_COUNT).push(0);a.i(flat::EDGEUSE_NURBS_ORDER).push(0);@@ -199,10 +203,10 @@ fn laid_out(brep: &b::Brep, trusted: bool, analytic: bool) -> R<Arrays> {a.i(flat::EDGEUSE_NEXT_RADIAL).extend(next);a.i(flat::EDGEUSE_RADIAL_ENTRY).extend(entry);- for e in &brep.edges {+ for (e, (interval, _)) in brep.edges.iter().zip(&intervals) {curve(&mut a, &e.curve)?;a.i(flat::EDGE_VERTICES).extend([i64::from(e.vertices[0]), i64::from(e.vertices[1])]);- a.r(flat::EDGE_RANGE).extend(e.interval);+ a.r(flat::EDGE_RANGE).extend(*interval);// Each edge's own tolerance, never below the body's.a.r(flat::EDGE_TOLERANCE).push(e.tolerance.max(brep.tolerance));}@@ -445,14 +449,35 @@ fn plane(a: &mut Arrays, origin: [f64; 3], u: [f64; 3], v: [f64; 3], domain: [[fOk(())}-/// A pcurve as the edgeuse's UV trim: reversed when the loop runs against the edge.-fn trim(a: &mut Arrays, c: &b::Curve2, forward: bool) -> R<()> {+/// A circle's or ellipse's interval (radians) as SMLib takes it, within [-2π, 2π]: schema 4+/// lets one run past a full turn (a quarter arc after the seam, [2π, 2.5π]), SMLib's circles+/// take angles up to one turn either way. The same arc a whole turn back, and that shift, by+/// which the edge's pcurves move too (their parameter is the edge's).+fn turned(c: &b::Curve, interval: [f64; 2]) -> ([f64; 2], f64) {+ use std::f64::consts::TAU;+ if !matches!(c, b::Curve::Circle { .. } | b::Curve::Ellipse { .. }) {+ return (interval, 0.0);+ }+ let [lo, hi] = interval;+ let shift = if hi > TAU {+ -TAU * ((hi - TAU) / TAU).ceil()+ } else if lo < -TAU {+ TAU * ((-TAU - lo) / TAU).ceil()+ } else {+ 0.0+ };+ ([lo + shift, hi + shift], shift)+}++/// A pcurve as the edgeuse's UV trim, its parameter moved by `shift` (the edge's, see+/// [`turned`]): reversed when the loop runs against the edge.+fn trim(a: &mut Arrays, c: &b::Curve2, forward: bool, shift: f64) -> R<()> {let (knots, mut pts): (&[f64], Vec<([f64; 2], f64)>) = match c {b::Curve2::Spline { knots, points } => (knots, points.iter().map(|p| (*p, 1.0)).collect()),b::Curve2::RationalSpline { knots, homogeneous } => (knots, homogeneous.iter().map(|h| ([h[0] / h[2], h[1] / h[2]], h[2])).collect()),};let order = knots.len().checked_sub(pts.len()).filter(|o| *o >= 2).ok_or(Unsupported::Invalid("pcurve order"))?;- let mut k = knots.to_vec();+ let mut k: Vec<f64> = knots.iter().map(|t| t + shift).collect();if !forward {pts.reverse();k = k.iter().rev().map(|t| -t).collect();diff --git a/crates/smlib/src/import/tests.rs b/crates/smlib/src/import/tests.rsindex 3495d0886f..769e5365ea 100644--- a/crates/smlib/src/import/tests.rs+++ b/crates/smlib/src/import/tests.rs@@ -220,3 +220,19 @@ fn revolutions_become_the_same_surface_as_a_rational_spline() {}}}++/// A circle or ellipse edge past a full turn (schema 4 allows up to one turn past the seam)+/// goes to SMLib a whole turn back, within [-2π, 2π]; other curves keep their interval.+#[test]+fn arcs_past_a_turn_come_a_turn_back() {+ use std::f64::consts::{FRAC_PI_2, TAU};+ let frame = solidcraft_geom::brep::Frame { origin: [0.0; 3], x_axis: [1.0, 0.0, 0.0], y_axis: [0.0, 1.0, 0.0] };+ let circle = Curve::Circle { frame, radius: 2.0 };+ assert_eq!(turned(&circle, [TAU, TAU + FRAC_PI_2]), ([0.0, FRAC_PI_2], -TAU));+ assert_eq!(turned(&circle, [-TAU - FRAC_PI_2, -TAU]), ([-FRAC_PI_2, 0.0], TAU));+ let (i, s) = turned(&circle, [5.0, 5.0 + TAU]);+ assert!(s == -TAU && i[0] >= -TAU && i[1] <= TAU, "{i:?}");+ assert_eq!(turned(&circle, [0.5, 2.0]), ([0.5, 2.0], 0.0));+ let line = Curve::Line { start: [0.0; 3], end: [1.0, 0.0, 0.0] };+ assert_eq!(turned(&line, [7.0, 9.0]), ([7.0, 9.0], 0.0));+}diff --git a/crates/smlib/src/ops.rs b/crates/smlib/src/ops.rsindex b26ed8faaf..fb945095da 100644--- a/crates/smlib/src/ops.rs+++ b/crates/smlib/src/ops.rs@@ -62,6 +62,18 @@ impl Brep {}}+ /// `self` with each face `tool` meets cut along the intersection, the pieces kept as faces of+ /// one body: `None` when the tool meets no face. Tagged operands give the pieces' history+ /// (each piece is a split of the face it was cut from).+ pub fn imprint(&self, tool: &Brep) -> Result<Option<Brep>> {+ init()?;+ match ffi::ops::imprint(&self.0, &tool.0) {+ Ok(h) => Ok(Some(Brep(h))),+ Err(ffi::ops::ERR_NO_CUT) => Ok(None),+ Err(s) => Err(error(s)),+ }+ }+/// The number of separate solid regions (voids not counted).pub fn solid_count(&self) -> Result<usize> {ffi::ops::solid_count(&self.0).map(|n| usize::try_from(n).unwrap_or(0)).map_err(error)diff --git a/crates/smlib/src/ops_tests.rs b/crates/smlib/src/ops_tests.rsindex d012e38d0b..ea544c726b 100644--- a/crates/smlib/src/ops_tests.rs+++ b/crates/smlib/src/ops_tests.rs@@ -275,3 +275,17 @@ fn a_variable_round_follows_its_law() {assert!(c.fillet_variable([10.0, 20.0, 20.0], 0.1, [0.0, 20.0, 20.0], 1, &[0.0, 0.5, 1.0, 1.0], &[3.0, 1.0]).is_err());assert!(matches!(c.fillet_variable([90.0, 90.0, 90.0], 0.1, [0.0; 3], 1, &knots, &[3.0, 1.0]), Err(Error::NoMatch { .. })));}++#[test]+fn imprint_cuts_faces_where_a_tool_meets_them() {+ // A box half sunk into the cube cuts the four side faces it crosses and the top it lies in.+ let cube = cube(20.0);+ let tool = Brep::make_box([5.0, -1.0, 10.0], [10.0, 22.0, 15.0]).unwrap();+ let cut = cube.imprint(&tool).unwrap().unwrap();+ assert!(cut.counts().unwrap()[0] > 6);+ assert!((cut.volume(1e-7).unwrap() - 8000.0).abs() < 1e-6);+ assert_eq!(cube.counts().unwrap()[0], 6);+ // A tool that misses cuts nothing.+ let far = Brep::make_box([50.0, 0.0, 0.0], [10.0, 10.0, 10.0]).unwrap();+ assert!(cube.imprint(&far).unwrap().is_none());+}diff --git a/crates/step/src/topology.rs b/crates/step/src/topology.rsindex 95c5c7293e..6f336a2a1e 100644--- a/crates/step/src/topology.rs+++ b/crates/step/src/topology.rs@@ -90,6 +90,9 @@ pub struct Solid {pub product: Option<String>,/// In the coordinates of the item's own representation (assembly placements not applied).pub brep: Brep,+ /// The file's face entity (ADVANCED_FACE, FACE_SURFACE) of each of the record's faces, in+ /// the record's face order.+ pub face_origin: Vec<u64>,/// No closed shell: a surface model of open shells only.pub sheet: bool,/// What was repaired or noted on the way (faces whose same_sense disagreed with their@@ -837,8 +840,10 @@ impl<'b, 'a> Builder<'b, 'a> {});}let mut faces = Vec::with_capacity(face_order.len());+ let mut face_origin = Vec::with_capacity(face_order.len());for &f in &face_order {let face = self.faces.get(f as usize).ok_or("face reference")?;+ face_origin.push(face.step);let pc = pcs.get(f as usize).ok_or("face reference")?;let mut loops = Vec::with_capacity(face.loops.len());let mut edge_loop = 0;@@ -881,7 +886,7 @@ impl<'b, 'a> Builder<'b, 'a> {let brep = Brep { version: brep::VERSION, tolerance: self.tol, regions, shells: out_shells, faces, edges, vertices };brep.validate().map_err(|e| format!("the record is invalid: {e}"))?;brep.check_geometry().map_err(|e| format!("the record's geometry disagrees: {e}"))?;- Ok(Solid { item, name, product: None, brep, sheet, notes })+ Ok(Solid { item, name, product: None, brep, face_origin, sheet, notes })}/// Every edge of the shell's faces used at least twice among them.diff --git a/docs/kernel-smlib-sweeps-shell.md b/docs/kernel-smlib-sweeps-shell.mdnew file mode 100644index 0000000000..81474f413b--- /dev/null+++ b/docs/kernel-smlib-sweeps-shell.md@@ -0,0 +1,123 @@+# SMLib vs truck: sweeps, threads, shell and offset++A triage of the regression rig's sweeps, threads and shell cases, and of the ladder's tiers 03+(analytic profiles), 04 (spline profiles), 06 (threads) and 09 (shells and offsets): 169 cases,+each run on both kernels (`solidcraft-cli kernel-cases`, `SOLIDCRAFT_KERNEL` unset and `smlib`)+on `kernel-smlib` at 4b8953726. Each kernel is graded against the case's own answer+([kernel-cases.md](kernel-cases.md)), not against the other kernel. This page lists only the+cases where SMLib does not pass, grouped by what goes wrong, worst first; it is kept by hand as+fixes land.++| | Cases | truck passes | SMLib passes |+|---|---|---|---|+| sweeps | 83 | 55 | 51 |+| threads | 28 | 10 | 11 |+| shell | 18 | 5 | 11 |+| ladder 03, 04, 06, 09 | 40 | 28 | 26 |+| **all** | **169** | **98** | **99** |++SMLib passes 18 cases truck fails (shells of tapered and rounded bodies, offset faces next to+freeform faces, bent and hollow lofts, the 36 twisted blades). Truck passes 17 that SMLib does+not: 11 of them are sweeps SMLib has no path for yet (group G), 6 are below.++A thread off its hole's or shaft's size is refused on this branch (the owner's rule): those+cases pass on both kernels by refusing, and are not listed.++## A. Wrong geometry (worst)++| Case | truck | SMLib | SMLib's result |+|---|---|---|---|+| sweeps/2667-revolve-half-disc-three-quarters | pass | fail | a half disc on the axis turned 270°: SMLib makes a quarter ball turned inside out (V = -226, want 679) |+| sweeps/3528-revolved-dome-cut-by-a-ball-on-its-seam | pass | fail | the ball's cut is lost where it crosses the revolve's seam: V 48118, want 46425 |+| sweeps/2847-loft-rectangles-turning-through-half-a-turn | fail | fail | inside out (V = -127, want 2262); truck's is wrong too (V = 126) |+| sweeps/450-revolve-spherical-shell-sketched-off-the-origin | crash | fail | two shells where one is wanted, which the B-rep record can't close (truck's process dies) |++## B. Crash++| Case | truck | SMLib | SMLib's result |+|---|---|---|---|+| ladder/09-shells-and-offsets/011-part-shell | fail | crash | step 21 (solid.fillet) on the SMLib body: curve blend internal error "Two same vertices cannot construct an edge"; the fillet is the blends work's, not this page's |++## C. Threads: the groove's boolean fails SMLib's check++The groove (SMLib's screw sweep) cuts the body, and the result fails SMLib's own check: vertex+gaps of 1–6e-5 mm against vertex tolerances of 4–20e-6 mm (Test #0/#2 Bad Gap), an edge whose+geometry fails validation (Test #61), or a trim curve that does not lie on its edge when the+result is read back (SMLib export: pcurve). Truck's faceted groove fails SMLib's check on the+same cases with 6 to 752 failed tests.++| Case | truck | SMLib | SMLib's result |+|---|---|---|---|+| ladder/06-threads/001-external-m10-full | fail | fail | Bad Gap (1.89e-5 > 8.6e-6) |+| ladder/06-threads/002-external-m10x1-fine | hang | fail | Test #61 bad edge |+| ladder/06-threads/003-external-m10-partial-length | pass | fail | Bad Gap (1.91e-5 > 8.9e-6) |+| ladder/06-threads/004-external-m10-to-shoulder | fail | fail | Bad Gap ×10 |+| ladder/06-threads/005-internal-m10-through | fail | fail | Bad Gap (3.6e-5 > 1.8e-5) |+| ladder/06-threads/006-external-m10-into-chamfer | fail | fail | Bad Gap |+| ladder/06-threads/007-external-m10-at-filleted-shoulder | fail | fail | Bad Gap |+| ladder/06-threads/010-part-threaded-boss | fail | fail | Bad Gap (2.26e-5 > 2.0e-5) |+| threads/1250-external-m10x1.5-shaft-full-length | fail | fail | Bad Gap ×9 |+| threads/1395-long-external-m6-thread-24-turns | fail | fail | Test #61 bad edge |+| threads/1995-m8x1-thread-in-7mm-hole | fail | fail | Bad Gap (1.5e-5 > 7.5e-6) |+| threads/2038-cut-threaded-stud-from-bored-block | fail | fail | Test #61 bad edge |+| threads/2038-internal-then-external-thread-on-one-body | fail | fail | pcurve off its edge |+| threads/2038-join-two-threaded-bodies | hang | fail | pcurve off its edge |+| threads/2193-modelled-m33x3.5-thread | fail | fail | Bad Gap |+| threads/2209-fine-m44x1-thread-on-shaft | fail | fail | Bad Gap ×7 |+| threads/2209-m44x1.5-thread-on-flange-hub | fail | fail | Bad Gap (6.2e-5 > 2.05e-5) |+| threads/2406-modelled-m8-thread-in-6.8mm-pilot-hole | fail | fail | Bad Gap |+| threads/2526-three-modelled-threads-in-one-body | fail | fail | pcurve off its edge |+| threads/2822-modelled-thread-in-filleted-cube | fail | fail | pcurve off its edge |+| threads/3311-two-tapped-holes-both-modelled-threaded | fail | fail | pcurve off its edge |+| threads/3914-sketch-on-top-face-of-threaded-rounded-block | fail | fail | pcurve off its edge (0.86 mm) |+| threads/3952-modelled-thread-in-blind-hole-of-revolved-ring | fail | fail | pcurve off its edge |+| threads/4149-internal-thread-below-counterbore-filleted-rim | fail | fail | Bad Gap |+| threads/602-fillet-hex-head-beside-modelled-thread | fail | fail | Bad Gap |++## D. Coils and other sweeps in booleans++| Case | truck | SMLib | SMLib's result |+|---|---|---|---|+| sweeps/793-coil-cut-by-a-box-above-a-plane | hang | fail | pcurve off its edge |+| sweeps/793-coil-split-by-a-plane-across-its-axis | fail | fail | pcurve off its edge |+| sweeps/2552-thread-groove-cut-by-a-square-coil-in-a-bore | hang | fail | the boolean's result is not a closed solid |+| sweeps/96-loft-cut-box-sections-pad-first | fail | fail | the boolean's result is not a closed solid |+| sweeps/96-loft-cut-box-sections-top-first | fail | fail | the boolean's result is not a closed solid |+| sweeps/844-join-two-overlapping-swept-arc-walls | fail | fail | boolean status 1006 |+| sweeps/3006-second-sweep-from-a-plane-along-a-closed-path | fail | fail | read back: a face no shell uses |++## E. Shell and offset refused++| Case | truck | SMLib | SMLib's result |+|---|---|---|---|+| ladder/09-shells-and-offsets/006-shell-rounds-r1-thinner-than-t2 | pass | fail | shell status 1001 (rounds of r1 inside a 2 mm wall) |+| shell/1494-shell-box-with-cylinder-on-edge-line | fail | fail | shell status 1001 |+| shell/1525-shell-box-with-rounds-chamfer-and-fillet | fail | fail | shell status 1001 |+| shell/2939-offset-face-sphere | pass | fail | check: edge/surface gap 5.015e-6 > 5e-6 |+| shell/3468-offset-face-boss-wall-next-to-fillet | fail | fail | check: an edge tolerance of 2.0 mm |+| shell/2531-shell-point-pick-after-parameter-edit | fail | fail | V 17952, want 22112 (truck 17376): the shell's face pick after the edit, on both kernels |+| sweeps/2820-pipe-hollow-with-a-wall-along-a-bend | pass | fail | sweep status 1001 |++## F. Same answer on both kernels (engine or case)++| Case | truck | SMLib | Both kernels |+|---|---|---|---|+| sweeps/3345-sweep-profile-mid-line-round-a-rounded-rectangle | fail | fail | the same bbox (±46 × ±36, want ±32 × ±22): the profile's placement, not the kernel |+| sweeps/2516-revolve-about-a-named-construction-axis | fail | fail | unknown sketch line `Axis1` |+| sweeps/3191-revolve-cut-leaves-a-cone | fail | fail | the profile crosses the revolve axis |+| sweeps/4056-surface-loft-rails-…-stern-to-bow | fail | fail | a guide rail misses section 2 |+| sweeps/2570-loft-circle-to-a-non-star-shaped-comb | fail | fail | SMLib: an arc turns more than once; truck: a loop runs clockwise |+| shell/4009-closed-shell-internal-void | fail | fail | `solid.shell` needs 1…1000 faces (a closed shell has none) |+| ladder/06-threads/008-multi-start-thread | unsupported | unsupported | no start count yet |+| ladder/06-threads/009-thread-runout-length | unsupported | unsupported | no runout length yet |++## G. No SMLib path yet ("not supported yet", never truck's in its place)++| What | Cases |+|---|---|+| sweep with a twist or an end scale | sweeps/1269-sweep-twisted-square-ninety-degrees, 2005-closed-sweep-twisted-new-body, 2005-closed-sweep-twisted-cut-inside-a-torus, 2891-twisted-sweep-cut-through-a-tube, 771-sweep-end-scale-cone-frustum |+| sweep along a path with corners | ladder/04/003-pipe-along-bezier, ladder/04/004-sweep-square-along-bezier, sweeps/96-sweep-rectangle-round-a-mitred-corner, 561-extrude-the-end-face-of-a-sweep, 3505-extrude-the-flat-wall-of-a-sweep-with-a-corner |+| loft through sections with holes | sweeps/1184-loft-ring-sections-keep-the-hole, 2435-loft-rectangular-ring-sections, 3111-loft-rectangular-ring-to-circular-ring |+| guide rails | sweeps/201-loft-one-guide-rail-cone-frustum, 771-sweep-one-guide-rail-cone-frustum, 771-sweep-two-guide-rails-cone-frustum |+| sweep along a path of points | sweeps/2862-three-pipes-meeting-at-one-point |+| draft extrusion with a straight foot | shell/391-deboss-text-on-flange-of-filleted-shelled-body |