Skip to content

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

Wave 75/509: kernel-cases: tessellation cases from mesh-hole reports grade watertightness (and 3 more)

bherbruck924ed1b57de8
diff --git a/apps/solidcraft-cli/src/kernel_cases.rs b/apps/solidcraft-cli/src/kernel_cases.rs
index 149a86ebe9..6d01d51db2 100644
--- a/apps/solidcraft-cli/src/kernel_cases.rs
+++ b/apps/solidcraft-cli/src/kernel_cases.rs
@@ -56,6 +56,63 @@ fn scratch(area: &str, name: &str) -> Result<String, String> {
Ok(d.to_string_lossy().to_string())
}
+/// Chord tolerance of the mesh a `watertight` case is checked on (mm).
+const MESH_TOL: f64 = 0.01;
+
+/// A mesh's edges used by one triangle only (open) and by more than two (over-shared). Vertices
+/// closer than `weld` (mm) are one vertex: a mesh repeats a vertex for each face, and faces
+/// meeting at an edge may place it a rounding error apart.
+fn open_edges(positions: &[solidcraft_engine::geom::Vec3], triangles: &[[u32; 3]], weld: f64) -> (usize, usize) {
+ use std::collections::HashMap;
+ let weld = if weld.is_finite() && weld > 0.0 { weld } else { 1e-4 };
+ let cell = |p: &solidcraft_engine::geom::Vec3| [p.x, p.y, p.z].map(|x| (x / weld).floor() as i64);
+ // Union-find over positions, joining each vertex with any within `weld` in the 27 cells round it.
+ let mut parent: Vec<usize> = (0..positions.len()).collect();
+ fn find(parent: &mut [usize], mut i: usize) -> usize {
+ while let Some(&p) = parent.get(i) {
+ if p == i {
+ break;
+ }
+ let gp = parent.get(p).copied().unwrap_or(p);
+ if let Some(slot) = parent.get_mut(i) {
+ *slot = gp;
+ }
+ i = p;
+ }
+ i
+ }
+ let mut grid: HashMap<[i64; 3], Vec<usize>> = HashMap::new();
+ for (i, p) in positions.iter().enumerate() {
+ let c = cell(p);
+ for dx in -1..=1 {
+ for dy in -1..=1 {
+ for dz in -1..=1 {
+ let Some(near) = grid.get(&[c[0] + dx, c[1] + dy, c[2] + dz]) else { continue };
+ for &j in near {
+ if positions.get(j).is_some_and(|q| q.dist(*p) <= weld) {
+ let (a, b) = (find(&mut parent, i), find(&mut parent, j));
+ if let Some(slot) = parent.get_mut(a) {
+ *slot = b;
+ }
+ }
+ }
+ }
+ }
+ }
+ grid.entry(c).or_default().push(i);
+ }
+ let mut uses: HashMap<(usize, usize), usize> = HashMap::new();
+ for t in triangles {
+ for (a, b) in [(t[0], t[1]), (t[1], t[2]), (t[2], t[0])] {
+ let (a, b) = (find(&mut parent, a as usize), find(&mut parent, b as usize));
+ if a != b {
+ *uses.entry((a.min(b), a.max(b))).or_default() += 1;
+ }
+ }
+ }
+ (uses.values().filter(|&&n| n == 1).count(), uses.values().filter(|&&n| n > 2).count())
+}
+
/// An error that means "this kernel can't do it yet", not a wrong answer.
fn unsupported(e: &str) -> bool {
e.contains("not supported yet")
@@ -170,6 +227,22 @@ fn check_case(dir: &str) -> Value {
"faces": m.merged.faces, "edges": m.merged.edges, "vertices": m.merged.vertices,
}));
shells += m.shells as u64;
+ if want["watertight"].as_bool() == Some(true) {
+ let tol = want["tolerance"]["mesh_mm"].as_f64().unwrap_or(MESH_TOL);
+ let (open, over) = match b.body.tessellate(tol) {
+ Ok(mesh) => open_edges(&mesh.positions, &mesh.triangles, want["tolerance"]["weld_mm"].as_f64().unwrap_or(1e-4)),
+ Err(e) => {
+ c.push("watertight", json!(format!("{}: {e}", b.name)), json!("no open edges"), false);
+ continue;
+ }
+ };
+ c.push(
+ "watertight",
+ json!(format!("{}: {open} open, {over} over-shared mesh edges", b.name)),
+ json!("no open edges"),
+ open == 0 && over == 0,
+ );
+ }
if want_valid {
// Closed shells, and every validity check this build has.
if want_shells.is_none() {
@@ -201,9 +274,14 @@ fn check_case(dir: &str) -> Value {
let diag = |b: ([f64; 3], [f64; 3])| ((b.1[0] - b.0[0]).powi(2) + (b.1[1] - b.0[1]).powi(2) + (b.1[2] - b.0[2]).powi(2)).sqrt();
let want_bbox = v3(&want["bbox"]["min"]).zip(v3(&want["bbox"]["max"]));
let abs = want["tolerance"]["abs_mm"].as_f64().unwrap_or_else(|| ABS_FRAC * want_bbox.map(diag).unwrap_or_else(|| diag(got.bbox)).max(1.0));
+ // A count is exact, or an inclusive range `[min, max]` where the geometry only bounds it.
let count = |c: &mut Checks, k: &str, g: u64| {
if has(k) {
- c.push(k, json!(g), want[k].clone(), want[k].as_u64() == Some(g));
+ let ok = match want[k].as_array() {
+ Some(r) => r.first().and_then(Value::as_u64).is_some_and(|lo| g >= lo) && r.get(1).and_then(Value::as_u64).is_some_and(|hi| g <= hi),
+ None => want[k].as_u64() == Some(g),
+ };
+ c.push(k, json!(g), want[k].clone(), ok);
}
};
count(&mut c, "body_count", got.body_count as u64);
diff --git a/tests/kernel-cases/README.md b/tests/kernel-cases/README.md
index 3cb355a206..ca7e73ead4 100644
--- a/tests/kernel-cases/README.md
+++ b/tests/kernel-cases/README.md
@@ -86,7 +86,10 @@ the frozen truck-geometry PRs, a `kernel-paused` PR), for the report's coverage
| `shells` | The total number of shells, where it isn't one per body: a body with a sealed void (2), several lumps kept in one body. |
| `body_count`, `faces`, `edges`, `vertices` | Exact counts, where the geometry fixes them. Faces and edges count whole analytic surfaces and curves once (a full cylinder side is one face). |
| `volume_mm3`, `area_mm2`, `center_of_mass`, `bbox` | As in `tests/oracle`: totals over every body, relative tolerance 1e-3 for volume and area, 1e-3 of the box diagonal for positions. |
-| `tolerance` | Optional overrides: `rel`, `abs_mm`. |
+| `faces`, `edges`, `vertices`, `shells`, `body_count` as `[min, max]` | An inclusive range, where the geometry only bounds a count (a modelled thread's faces). |
+| `watertight` | `true`: each body's display mesh (chord tolerance `tolerance.mesh_mm`, default 0.01 mm) has no open and no over-shared edges, with vertices closer than `tolerance.weld_mm` (default 1e-4 mm) taken as one. |
+| `timeout_s` | A longer timeout for this case than the run's (at most 1800 s), for cases that are slow by nature. A case that only needs it on a loaded machine shouldn't set it. |
+| `tolerance` | Optional overrides: `rel`, `abs_mm`, `mesh_mm`, `weld_mm`. |
| `missing` | A capability SolidCraft has no command or parameter for yet (`"solid.thread has no start count"`): the case is reported **not supported yet** without running, so the gap stays visible. |
## The complexity ladder
diff --git a/tests/kernel-cases/tessellation/1666-loft-18-gon-ruled-sides/expected.json b/tests/kernel-cases/tessellation/1666-loft-18-gon-ruled-sides/expected.json
index 103a3a2f20..b49cbba182 100644
--- a/tests/kernel-cases/tessellation/1666-loft-18-gon-ruled-sides/expected.json
+++ b/tests/kernel-cases/tessellation/1666-loft-18-gon-ruled-sides/expected.json
@@ -1,8 +1,12 @@
{
- "sources": ["tangency-labs/solidcraft#1666", "tangency-labs/solidcraft#1670"],
- "what": "a loft between two 18-vertex polylines whose side faces are twisted ruled (bilinear) patches: each used to be exported as two flat triangles with crossing diagonals",
- "source": "analytic",
- "method": "A ruled loft joining vertex i of the bottom polygon (z=0) to vertex i of the top polygon (z=90.5) has, at height t*90.5, the polygon with vertices (1-t)p_i + t q_i. Its shoelace area is quadratic in t, so Simpson's rule is exact: V = h/6 (A0 + 4 A(1/2) + A1) with h=90.5, A0=247.28368 (shoelace of the bottom polygon), A1=156 (the top polygon is the 52 x 3 rectangle), A(1/2)=area of the polygon of midpoints. That gives 17993.405 (a 2000-slice numerical integral of the same area agrees to 1e-8).",
- "body_count": 1,
- "volume_mm3": 17993.405
+ "sources": [
+ "tangency-labs/solidcraft#1666",
+ "tangency-labs/solidcraft#1670"
+ ],
+ "what": "a loft between two 18-vertex polylines whose side faces are twisted ruled (bilinear) patches: each used to be exported as two flat triangles with crossing diagonals",
+ "source": "analytic",
+ "method": "A ruled loft joining vertex i of the bottom polygon (z=0) to vertex i of the top polygon (z=90.5) has, at height t*90.5, the polygon with vertices (1-t)p_i + t q_i. Its shoelace area is quadratic in t, so Simpson's rule is exact: V = h/6 (A0 + 4 A(1/2) + A1) with h=90.5, A0=247.28368 (shoelace of the bottom polygon), A1=156 (the top polygon is the 52 x 3 rectangle), A(1/2)=area of the polygon of midpoints. That gives 17993.405 (a 2000-slice numerical integral of the same area agrees to 1e-8). Watertight: each body's mesh has no open or over-shared edge (the reports were holes in the exported mesh).",
+ "body_count": 1,
+ "volume_mm3": 17993.405,
+ "watertight": true
}
diff --git a/tests/kernel-cases/tessellation/1666-loft-twisted-square/expected.json b/tests/kernel-cases/tessellation/1666-loft-twisted-square/expected.json
index 86748d55cd..6d85c7d779 100644
--- a/tests/kernel-cases/tessellation/1666-loft-twisted-square/expected.json
+++ b/tests/kernel-cases/tessellation/1666-loft-twisted-square/expected.json
@@ -1,9 +1,13 @@
{
- "sources": ["tangency-labs/solidcraft#1666", "tangency-labs/solidcraft#1670"],
- "what": "a loft from a 20x20 square to the same square turned 45 degrees, 30 mm higher: its four side faces are strongly twisted ruled patches, the case a two-triangle mesh gets visibly wrong",
- "source": "analytic",
- "method": "At height 30t the section is the polygon of (1-t)p_i + t q_i (p_i the square's corners at angles 45+90k deg, q_i those at 90+90k deg, both radius 10 sqrt 2). Its shoelace area is quadratic in t, so Simpson is exact: A0=A1=400, A(1/2)= 2 r^2 (1 - ... ) computed from the midpoint polygon (a square of circumradius r cos(22.5 deg): area 2 r^2 cos^2(22.5 deg) = 400 cos^2(22.5 deg)=341.42). V = 30/6 (400 + 4*341.4214 + 400) = 5*(2165.6854)=10828.427. Faces: 4 sides and 2 caps.",
- "body_count": 1,
- "volume_mm3": 10828.427,
- "faces": 6
+ "sources": [
+ "tangency-labs/solidcraft#1666",
+ "tangency-labs/solidcraft#1670"
+ ],
+ "what": "a loft from a 20x20 square to the same square turned 45 degrees, 30 mm higher: its four side faces are strongly twisted ruled patches, the case a two-triangle mesh gets visibly wrong",
+ "source": "analytic",
+ "method": "At height 30t the section is the polygon of (1-t)p_i + t q_i (p_i the square's corners at angles 45+90k deg, q_i those at 90+90k deg, both radius 10 sqrt 2). Its shoelace area is quadratic in t, so Simpson is exact: A0=A1=400, A(1/2)= 2 r^2 (1 - ... ) computed from the midpoint polygon (a square of circumradius r cos(22.5 deg): area 2 r^2 cos^2(22.5 deg) = 400 cos^2(22.5 deg)=341.42). V = 30/6 (400 + 4*341.4214 + 400) = 5*(2165.6854)=10828.427. Faces: 4 sides and 2 caps. Watertight: each body's mesh has no open or over-shared edge (the reports were holes in the exported mesh).",
+ "body_count": 1,
+ "volume_mm3": 10828.427,
+ "faces": 6,
+ "watertight": true
}
diff --git a/tests/kernel-cases/tessellation/1753-bowl-rim-cut-by-cylinder/expected.json b/tests/kernel-cases/tessellation/1753-bowl-rim-cut-by-cylinder/expected.json
index a4f3f5c2f0..5a272eb65d 100644
--- a/tests/kernel-cases/tessellation/1753-bowl-rim-cut-by-cylinder/expected.json
+++ b/tests/kernel-cases/tessellation/1753-bowl-rim-cut-by-cylinder/expected.json
@@ -1,10 +1,11 @@
{
- "sources": [
- "tangency-labs/solidcraft#1753"
- ],
- "what": "a revolved bowl whose rim is cut by a large cylinder (R320, axis across the bowl): the cut edge is an intersection curve between the cylinder and the cone walls, whose two faces used to put different vertices on it, so the STL/3MF export had a 0.001 mm crack",
- "source": "analytic",
- "method": "Section (r,z): (0,0),(40,0),(70,40),(64,40),(34,6),(0,6), revolved 360 deg about Z: Pappus/shoelace V = (pi/3)|sum (x_i y_{i+1}-x_{i+1} y_i)(x_i+x_{i+1})| = 125085.653 uncut. The cutter is the cylinder r=320 with axis along X, lowest line at z=36 (centre z=356): it removes everything above z_c(y) = 356 - sqrt(320^2 - y^2), which cuts the rim (z=40) only for |y| small (z_c(70)=43.75 > 40). The column of material at (x,y), r=sqrt(x^2+y^2), runs from z_low(r) (0 for r<=40, (r-40)*4/3 beyond) to min(z_up(r), z_c(y)) with z_up = 6 for r<=34, 6+(r-34)*34/30 for r<=64, 40 beyond. Integrating in polar coordinates (2800x2880 midpoint cells, converged to 1e-7) gives V = 121495.05. The export mesh being closed (every edge used by two triangles) is not graded by the rig.",
- "body_count": 1,
- "volume_mm3": 121495.05
-}
\ No newline at end of file
+ "sources": [
+ "tangency-labs/solidcraft#1753"
+ ],
+ "what": "a revolved bowl whose rim is cut by a large cylinder (R320, axis across the bowl): the cut edge is an intersection curve between the cylinder and the cone walls, whose two faces used to put different vertices on it, so the STL/3MF export had a 0.001 mm crack",
+ "source": "analytic",
+ "method": "Section (r,z): (0,0),(40,0),(70,40),(64,40),(34,6),(0,6), revolved 360 deg about Z: Pappus/shoelace V = (pi/3)|sum (x_i y_{i+1}-x_{i+1} y_i)(x_i+x_{i+1})| = 125085.653 uncut. The cutter is the cylinder r=320 with axis along X, lowest line at z=36 (centre z=356): it removes everything above z_c(y) = 356 - sqrt(320^2 - y^2), which cuts the rim (z=40) only for |y| small (z_c(70)=43.75 > 40). The column of material at (x,y), r=sqrt(x^2+y^2), runs from z_low(r) (0 for r<=40, (r-40)*4/3 beyond) to min(z_up(r), z_c(y)) with z_up = 6 for r<=34, 6+(r-34)*34/30 for r<=64, 40 beyond. Integrating in polar coordinates (2800x2880 midpoint cells, converged to 1e-7) gives V = 121495.05. The export mesh being closed (every edge used by two triangles) is not graded by the rig. Watertight: each body's mesh has no open or over-shared edge (the reports were holes in the exported mesh).",
+ "body_count": 1,
+ "volume_mm3": 121495.05,
+ "watertight": true
+}
diff --git a/tests/kernel-cases/tessellation/784-stl-open-edges-filleted-and-drilled/expected.json b/tests/kernel-cases/tessellation/784-stl-open-edges-filleted-and-drilled/expected.json
index 00a847dc34..568c0be4b4 100644
--- a/tests/kernel-cases/tessellation/784-stl-open-edges-filleted-and-drilled/expected.json
+++ b/tests/kernel-cases/tessellation/784-stl-open-edges-filleted-and-drilled/expected.json
@@ -1,13 +1,14 @@
{
- "sources": [
- "tangency-labs/solidcraft#784",
- "tangency-labs/solidcraft#811"
- ],
- "what": "two bodies whose STL export used to have open edges where faces were meshed apart: a 40x30x20 box with all twelve edges rounded 2 mm, and a cylinder R15 x 20 with a coaxial 6 mm bore",
- "source": "analytic",
- "method": "Rounded box: Steiner formula for the box 36x26x16 grown by a ball of r=2 (equal rounds on all twelve edges meet in spherical corners): V = xyz + 2r(xy+yz+zx) + pi r^2 (x+y+z) + 4/3 pi r^3 = 23701.687, A = 2(xy+yz+zx) + 2 pi r (x+y+z) + 4 pi r^2 = 4886.442; 26 faces (6 planes, 12 cylinders, 8 sphere corners). Drilled cylinder: V = pi (15^2-3^2) 20 = 13571.680, A = 2 pi (15^2-3^2) + 2 pi 15 20 + 2 pi 3 20 = 1152 pi = 3619.115; 4 faces. Totals over both bodies. A watertight STL (every edge shared by two triangles) is not graded by the rig.",
- "body_count": 2,
- "volume_mm3": 37273.367,
- "area_mm2": 8505.557,
- "faces": 30
-}
\ No newline at end of file
+ "sources": [
+ "tangency-labs/solidcraft#784",
+ "tangency-labs/solidcraft#811"
+ ],
+ "what": "two bodies whose STL export used to have open edges where faces were meshed apart: a 40x30x20 box with all twelve edges rounded 2 mm, and a cylinder R15 x 20 with a coaxial 6 mm bore",
+ "source": "analytic",
+ "method": "Rounded box: Steiner formula for the box 36x26x16 grown by a ball of r=2 (equal rounds on all twelve edges meet in spherical corners): V = xyz + 2r(xy+yz+zx) + pi r^2 (x+y+z) + 4/3 pi r^3 = 23701.687, A = 2(xy+yz+zx) + 2 pi r (x+y+z) + 4 pi r^2 = 4886.442; 26 faces (6 planes, 12 cylinders, 8 sphere corners). Drilled cylinder: V = pi (15^2-3^2) 20 = 13571.680, A = 2 pi (15^2-3^2) + 2 pi 15 20 + 2 pi 3 20 = 1152 pi = 3619.115; 4 faces. Totals over both bodies. A watertight STL (every edge shared by two triangles) is not graded by the rig. Watertight: each body's mesh has no open or over-shared edge (the reports were holes in the exported mesh).",
+ "body_count": 2,
+ "volume_mm3": 37273.367,
+ "area_mm2": 8505.557,
+ "faces": 30,
+ "watertight": true
+}
diff --git a/tests/kernel-cases/threads/2822-modelled-thread-in-filleted-cube/expected.json b/tests/kernel-cases/threads/2822-modelled-thread-in-filleted-cube/expected.json
index fd7ce87291..f493c0a438 100644
--- a/tests/kernel-cases/threads/2822-modelled-thread-in-filleted-cube/expected.json
+++ b/tests/kernel-cases/threads/2822-modelled-thread-in-filleted-cube/expected.json
@@ -27,5 +27,6 @@
20,
10
]
- }
+ },
+ "timeout_s": 600
}
diff --git a/tests/kernel-cases/threads/3952-modelled-thread-in-blind-hole-of-revolved-ring/expected.json b/tests/kernel-cases/threads/3952-modelled-thread-in-blind-hole-of-revolved-ring/expected.json
index fc806d35fd..a23718cc9e 100644
--- a/tests/kernel-cases/threads/3952-modelled-thread-in-blind-hole-of-revolved-ring/expected.json
+++ b/tests/kernel-cases/threads/3952-modelled-thread-in-blind-hole-of-revolved-ring/expected.json
@@ -19,5 +19,6 @@
30,
30
]
- }
+ },
+ "timeout_s": 600
}
diff --git a/tests/kernel-cases/threads/4149-internal-thread-below-counterbore-filleted-rim/expected.json b/tests/kernel-cases/threads/4149-internal-thread-below-counterbore-filleted-rim/expected.json
index 02d00be605..c7ede9a0fb 100644
--- a/tests/kernel-cases/threads/4149-internal-thread-below-counterbore-filleted-rim/expected.json
+++ b/tests/kernel-cases/threads/4149-internal-thread-below-counterbore-filleted-rim/expected.json
@@ -22,5 +22,6 @@
20,
30
]
- }
+ },
+ "timeout_s": 600
}
diff --git a/xtask/src/kernel_cases.rs b/xtask/src/kernel_cases.rs
index daaf5bd9df..edb87615f4 100644
--- a/xtask/src/kernel_cases.rs
+++ b/xtask/src/kernel_cases.rs
@@ -100,14 +100,16 @@ fn run_case(o: &Options, kernel: &str, case: &Path) -> Value {
Ok(c) => c,
Err(e) => return base("fail", format!("solidcraft-cli: {e}")),
};
+ // A case may need longer than the run's timeout (`timeout_s`, at most 30 min).
+ let timeout = read(&case.join("expected.json"))["timeout_s"].as_u64().map_or(o.timeout, |s| Duration::from_secs(s.min(1800)).max(o.timeout));
let start = Instant::now();
loop {
match child.try_wait() {
Ok(Some(_)) => break,
- Ok(None) if start.elapsed() > o.timeout => {
+ Ok(None) if start.elapsed() > timeout => {
let _ = child.kill();
let _ = child.wait();
- return base("hang", format!("no result after {} s", o.timeout.as_secs()));
+ return base("hang", format!("no result after {} s", timeout.as_secs()));
}
Ok(None) => std::thread::sleep(Duration::from_millis(50)),
Err(e) => return base("fail", format!("wait: {e}")),