Skip to content

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

Wave 429/509: Continuity rig: an opened tube end capped G1 and G2, as cases (and 3 more)

jyviko9be549e6a1f3
diff --git a/crates/kernel/src/fill_general_tests.rs b/crates/kernel/src/fill_general_tests.rs
index 61273fc281..ca5903732e 100644
--- a/crates/kernel/src/fill_general_tests.rs
+++ b/crates/kernel/src/fill_general_tests.rs
@@ -212,15 +212,6 @@ fn report(name: &str, r: &PatchReport) {
);
}
-/// A cylinder about z of radius 10 and 30 high with its top face taken off; points around the rim.
-fn open_tube() -> (Body, Vec<Vec3>) {
- let solid = cylinder(Vec3::ZERO, Vec3::Z, 10.0, 30.0).unwrap();
- let open = copy_faces(&solid, &[&around(10.0, 15.0)[..], &[Vec3::ZERO]].concat()).unwrap();
- assert!(open.is_surface());
- let rim = (0..8).map(|k| Vec2::from_angle(k as f64 * 0.785).extend(0.0) * 10.0 + Vec3::Z * 30.0).collect();
- (open, rim)
-}
-
/// `body` without its planar faces but those at height `z0` or `z1` (the ends of a cylinder):
/// a cut solid's walls (and ends) as a surface, the faces the cut made taken away.
fn curved_and_ends(body: &Body, ends: &[f64]) -> Body {
@@ -258,49 +249,10 @@ fn free_edge_points(body: &Body) -> Vec<Vec3> {
points
}
-/// Points round the circle of radius `r` about z at height `z`, every 30°.
-fn around(r: f64, z: f64) -> Vec<Vec3> {
- (0..12).map(|k| Vec2::from_angle(0.1 + k as f64 * std::f64::consts::TAU / 12.0).extend(0.0) * r + Vec3::Z * z).collect()
-}
-
fn radial(p: Vec3) -> Vec3 {
Vec3::new(p.x, p.y, 0.0).normalized().unwrap()
}
-#[test]
-fn an_opened_tube_end_capped_g1_and_g2_meets_the_wall() {
- let (open, rim) = open_tube();
- let mut kappas = Vec::new();
- for g in [Continuity::G1, Continuity::G2] {
- let name = format!("tube end {}", g.as_str());
- let started = std::time::Instant::now();
- let (fill, r) = patch_edges_report(&open, &rim, &spec(g)).unwrap();
- eprintln!("{name}: filled in {:?}", started.elapsed());
- report(&name, &r);
- assert!(r.general);
- let area = check_face(&name, &open, &fill);
- // The wall's normal is radial and it does not bend along its axis.
- let (gap, angle, kappa) = along_the_loop(&fill, &radial, &|_| 0.0);
- eprintln!(
- "{name}: along the rim (1600 points): within {gap:e} of it, normal within {angle:.5}° of the wall's, curvature across {kappa:e} /mm (the wall's 0)"
- );
- assert!(angle < 0.1, "{name}: the normal turns {angle}° from the wall's");
- kappas.push(kappa);
- // A dome over the rim, not a flat lid: more than the disc.
- assert!(area > std::f64::consts::PI * 100.0 * 1.05, "{name}: {area}");
- // Sealed: the tube's volume plus the dome's, the dome's by the divergence theorem over the
- // patch (∫∫ (z − 30)·n_z dA), independent of the mesher.
- let closed = stitch(&[&open, &fill], 0.0).unwrap();
- assert!(!closed.is_surface(), "{name}: the cap closes the tube");
- let dome = Faces::of(&fill).quadrature(500, &|p, n| (p.z - 30.0) * n.z).abs();
- let (got, want) = (measure(&closed).unwrap().volume, std::f64::consts::PI * 100.0 * 30.0 + dome);
- eprintln!("{name}: sealed volume {got:.3}, tube + dome {want:.3}");
- assert!((got - want).abs() < 2e-4 * want, "{name}: {got} vs {want}");
- }
- eprintln!("tube end: curvature across the rim g1 {:e}, g2 {:e} /mm", kappas[0], kappas[1]);
- assert!(kappas[1] < kappas[0], "g2 holds the wall's curvature closer than g1");
-}
-
/// A cylinder about z (radius 10, 40 high) with a pentagonal pocket cut into its wall from the
/// +x side (the pentagon in the yz plane about z = 20, circumradius 6): the wall and both ends
/// copied out, and a point on each of the pocket rim's five edges.
diff --git a/crates/kernel/src/step_in/tests.rs b/crates/kernel/src/step_in/tests.rs
index ba854a77fa..606f556099 100644
--- a/crates/kernel/src/step_in/tests.rs
+++ b/crates/kernel/src/step_in/tests.rs
@@ -1127,7 +1127,8 @@ fn surface_of_revolution_sense_follows_iso() {
/// A tube revolved about a line it touches (a horn torus, as a tight sweep makes) is written as
/// one rational B-spline face whose loop passes the pole twice, with no zero-length edge there:
-/// no TOROIDAL_SURFACE (it would be degenerate) and no surface of revolution.
+/// no TOROIDAL_SURFACE (it would be degenerate) and no surface of revolution. (Its volume, built
+/// and read back, is the rig's import/cov-step-horn-torus-quarter-round-trip.)
#[test]
fn horn_torus_written_as_one_spline_face() {
let prof = Region2 { outer: Loop2::circle(Vec2::new(5.0, 0.0), 5.0), holes: vec![] };
@@ -1135,9 +1136,6 @@ fn horn_torus_written_as_one_spline_face() {
let text = step_export(&[&b], "t").unwrap();
assert!(!text.contains("TOROIDAL_SURFACE") && !text.contains("SURFACE_OF_REVOLUTION"));
assert_eq!(text.matches("ADVANCED_FACE(").count(), 3, "{text}");
- let imp = round_trip(&b);
- let v = std::f64::consts::PI * 25.0 * std::f64::consts::TAU * 5.0 / 4.0;
- assert!(rel(measure(&imp.bodies[0].body).unwrap().volume, v) < 1e-3);
}
/// How a torus-capped cylinder ([`torus_capped_cylinder`]) ends.
diff --git a/skills/solidcraft-tests/SKILL.md b/skills/solidcraft-tests/SKILL.md
index 63ed8d6e9e..7c2ec4abd4 100644
--- a/skills/solidcraft-tests/SKILL.md
+++ b/skills/solidcraft-tests/SKILL.md
@@ -8,25 +8,28 @@ description: "Use when writing, placing or running tests in SolidCraft: a regres
The long form is `docs/book/src/dev/testing.md`.
## Placement
-- A regression test goes into the existing test file for its area (booleans, blends, shell, sweep, STEP, naming, ...), never a new file named after the bug (#3226).
-- Engine tests sit next to the code or in `*_tests.rs` files; they measure the result (volume, area, face/edge/vertex counts) against a value you can derive.
-- UI scenarios are JSON in `crates/ui-egui/tests/scenarios/*.json`; a new file is picked up automatically. Put `{"pending": "why"}` in a scenario that records a bug before it is fixed, and remove it in the fixing PR.
-- Reference tests are `tests/oracle/<case>/recipe.json` with an `expected.json` beside it, run by `cargo xtask oracle`. Expected values are worked out in closed form (`tools/oracle-analytic/`) or computed by FreeCAD run as a separate program (`tools/freecad-oracle/`). A case that fails on a known bug names its issue (`"known_failure": "#123"`). Never change an expected value to match SolidCraft's output, and never take one from a commercial CAD product.
-- Crash fixes: a regression test, started from the crash report's `design.solidcraft` and `replay.json` (`skills/solidcraft-crash-safety/SKILL.md`).
+- A regression test goes into its area's existing test file (booleans, blends, shell, STEP, naming, ...), never a new file named after the bug (#3226).
+- Engine tests sit next to the code or in `*_tests.rs` files, measured against a value you can derive.
+- UI scenarios are JSON in `crates/ui-egui/tests/scenarios/*.json`. Put `{"pending": "why"}` in a scenario that records a bug before it is fixed, and remove it in the fixing PR.
+- Reference tests are `tests/oracle/<case>/recipe.json` with an `expected.json` beside it, run by `cargo xtask oracle`, expected values in closed form (`tools/oracle-analytic/`) or from FreeCAD as a separate program (`tools/freecad-oracle/`). A known failure names its issue (`"known_failure": "#123"`). Never change an expected value to match SolidCraft's output, and never take one from a commercial CAD product.
+- Crash fixes: a regression test from the report's `design.solidcraft` and `replay.json` (`skills/solidcraft-crash-safety/SKILL.md`).
+
+## Unit test or rig case
+- Unit tests assert the code's logic: which edges a chain picks, name resolution, history labels, refusal wording, hostile input, parsing and saving (`corner_rounds_larger_than_their_faces_are_too_large`: per-edge radii, which no command takes, refused as `TooLarge`).
+- The rig (`tests/kernel-cases/`) asserts geometry: exact volumes, shapes, seam continuity, geometric refusals, through commands with a hand-derived answer, so it survives a kernel swap (`fillets/190-fillet-disc-rim-past-its-2mm-wall`). A test doing both keeps only its logic.
## A failing test needs its fix
-A failing test without its fix cannot merge: it turns `main` red for everyone. Include the fix in the same PR, or mark the test `#[ignore = "fails until #123 is fixed"]` and remove that line in the PR that fixes it.
+A failing test cannot merge without its fix (it turns `main` red): include the fix, or mark the test `#[ignore = "fails until #123 is fixed"]` and remove that line in the PR that fixes it.
## Running
-- `cargo xtask test` builds with the `ci` profile and runs every test binary at once; arguments after `--` go to each binary (`cargo xtask test -- shell`). Use the `ci` profile: it builds several times faster than `--release`, and debug assertions are off because truck's reject valid geometry. If a test fails only in a plain debug build, say so in the PR.
-- `SOLIDCRAFT_TEST_JOBS=N` bounds concurrent commands on a shared machine.
-- `cargo xtask ci` is the gate before a commit: fmt, assets, icons, licences, lists, layers, ui-containers, clippy `-D warnings`, tests and the wasm check.
-- Every test runs in its own process: do not rely on state left by another test, or on wall-clock timing.
+- `cargo xtask test` builds with the `ci` profile and runs every test binary at once; arguments after `--` go to each binary (`cargo xtask test -- shell`). It builds several times faster than `--release`; a test failing only in a debug build: say so in the PR.
+- `SOLIDCRAFT_TEST_JOBS=N` bounds concurrent commands. `cargo xtask ci` is the gate before a commit (fmt, lints, clippy `-D warnings`, tests, wasm).
+- Tests run in their own processes: no shared state, no wall-clock timing.
## Goldens, matrices and skipped tests
-- The reference for what the kernel builds is the kernel-cases ladder (`tests/kernel-cases/ladder/`, `cargo xtask kernel-cases --ladder`, `docs/kernel-ladder.md`).
-- Kernel PRs run `kernel-rig.yml`: the areas the diff reaches (`PATHS`) against `KNOWN_FAILING`, the ladder against its golden. In the same PR a fix removes its line, a new failing case adds one, a changed ladder result is re-recorded (`--record "why"`), a new command gets a case or an `EXEMPT` line; see `tests/kernel-cases/README.md`.
-- Maintainers' PRs run the native, GPU path and reference tests on the affected packages; others wait for `approved-for-ci`. `release-gate.yml` runs everything in full before develop replaces main.
-- The action matrix is a ratchet: record a newly passing action with `cargo xtask action-matrix --bless` (`docs/action-matrix.md`).
-- Pull requests skip a few heavy tests, which run in the merge queue, nightly and on `main`. Check that validation after merging. The list is in `.config/nextest.toml` and the testing page.
-- Mutation testing finds what the suites miss: `docs/mutation-testing.md`.
+- The kernel's reference is the ladder (`tests/kernel-cases/ladder/`, `cargo xtask kernel-cases --ladder`, `docs/kernel-ladder.md`).
+- Kernel PRs run `kernel-rig.yml` (areas by `PATHS` against `KNOWN_FAILING`, the ladder against its golden). In the same PR a fix drops its line, a new failing case adds one, a changed ladder result is re-recorded (`--record "why"`), a new command gets a case or an `EXEMPT` line (`tests/kernel-cases/README.md`).
+- Maintainers' PRs run native, GPU and reference tests on affected packages; others wait for `approved-for-ci`. `release-gate.yml` runs all before develop replaces main.
+- The action matrix is a ratchet: bless a newly passing action (`cargo xtask action-matrix --bless`, `docs/action-matrix.md`).
+- PRs skip a few heavy tests, run in the merge queue, nightly and on `main`. Check them after merging (`.config/nextest.toml`).
+- Mutation testing: `docs/mutation-testing.md`.
diff --git a/tests/kernel-cases/continuity/KNOWN_FAILING b/tests/kernel-cases/continuity/KNOWN_FAILING
index 6220878c6e..809b84e18e 100644
--- a/tests/kernel-cases/continuity/KNOWN_FAILING
+++ b/tests/kernel-cases/continuity/KNOWN_FAILING
@@ -2,3 +2,5 @@
# rig gate (.github/workflows/kernel-rig.yml) fails on a case that fails and is not listed here,
# and on a listed case that passes: a fix removes its line in the same pull request.
# Baseline: not seeded yet; seeded from a develop run after the SMLib pin bump.
+cov-patch-g1-caps-an-opened-tube-end not supported yet: the general fill refuses the cap (it folds)
+cov-patch-g2-caps-an-opened-tube-end not supported yet: the general fill refuses the cap (it folds)
diff --git a/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/expected.json b/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/expected.json
new file mode 100644
index 0000000000..dd85cf2fe7
--- /dev/null
+++ b/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/expected.json
@@ -0,0 +1,19 @@
+{
+ "sources": [
+ "tangency-labs/solidcraft#759"
+ ],
+ "what": "a cylinder r10 x 30 with its top face taken off, the open rim patched g1 (Tangent) and stitched: a dome over the tube that closes it",
+ "source": "invariants",
+ "method": "the patch meets the cylinder's wall along the rim circle: at G1 the dome's tangent plane is the wall's (vertical), so the cap rises from the rim. The dome's shape is the fill's own: no volume; one closed valid solid whose rim seam reaches g1 is the right answer.",
+ "body_count": 1,
+ "continuity": {
+ "order": "g1",
+ "edges": [
+ [
+ 10,
+ 0,
+ 30
+ ]
+ ]
+ }
+}
diff --git a/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/recipe.json b/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/recipe.json
new file mode 100644
index 0000000000..512d9f49c4
--- /dev/null
+++ b/tests/kernel-cases/continuity/cov-patch-g1-caps-an-opened-tube-end/recipe.json
@@ -0,0 +1,50 @@
+{
+ "commands": [
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "radius": 10,
+ "height": 30,
+ "body_name": "Tube"
+ }
+ },
+ {
+ "command": "face.delete",
+ "params": {
+ "body": "Tube",
+ "faces": [
+ [
+ 0,
+ 0,
+ 30
+ ]
+ ],
+ "heal": false
+ }
+ },
+ {
+ "command": "surface.patch",
+ "params": {
+ "body": "Tube",
+ "edges": [
+ [
+ 10,
+ 0,
+ 30
+ ]
+ ],
+ "continuity": "g1",
+ "body_name": "Cap"
+ }
+ },
+ {
+ "command": "surface.stitch",
+ "params": {
+ "bodies": [
+ "Tube",
+ "Cap"
+ ]
+ }
+ }
+ ]
+}
diff --git a/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/expected.json b/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/expected.json
new file mode 100644
index 0000000000..cd21265b64
--- /dev/null
+++ b/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/expected.json
@@ -0,0 +1,19 @@
+{
+ "sources": [
+ "tangency-labs/solidcraft#759"
+ ],
+ "what": "a cylinder r10 x 30 with its top face taken off, the open rim patched g2 (Curvature) and stitched: a dome over the tube that closes it",
+ "source": "invariants",
+ "method": "the patch meets the cylinder's wall along the rim circle: at G2 the dome's tangent plane is the wall's (vertical), so the cap rises from the rim, and its curvature across the rim is the wall's (0 along the axis). The dome's shape is the fill's own: no volume; one closed valid solid whose rim seam reaches g2 is the right answer.",
+ "body_count": 1,
+ "continuity": {
+ "order": "g2",
+ "edges": [
+ [
+ 10,
+ 0,
+ 30
+ ]
+ ]
+ }
+}
diff --git a/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/recipe.json b/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/recipe.json
new file mode 100644
index 0000000000..bab4a0a341
--- /dev/null
+++ b/tests/kernel-cases/continuity/cov-patch-g2-caps-an-opened-tube-end/recipe.json
@@ -0,0 +1,50 @@
+{
+ "commands": [
+ {
+ "command": "solid.cylinder",
+ "params": {
+ "radius": 10,
+ "height": 30,
+ "body_name": "Tube"
+ }
+ },
+ {
+ "command": "face.delete",
+ "params": {
+ "body": "Tube",
+ "faces": [
+ [
+ 0,
+ 0,
+ 30
+ ]
+ ],
+ "heal": false
+ }
+ },
+ {
+ "command": "surface.patch",
+ "params": {
+ "body": "Tube",
+ "edges": [
+ [
+ 10,
+ 0,
+ 30
+ ]
+ ],
+ "continuity": "g2",
+ "body_name": "Cap"
+ }
+ },
+ {
+ "command": "surface.stitch",
+ "params": {
+ "bodies": [
+ "Tube",
+ "Cap"
+ ]
+ }
+ }
+ ]
+}
diff --git a/tests/kernel-cases/import/KNOWN_FAILING b/tests/kernel-cases/import/KNOWN_FAILING
index 0f96696619..7eafa4152d 100644
--- a/tests/kernel-cases/import/KNOWN_FAILING
+++ b/tests/kernel-cases/import/KNOWN_FAILING
@@ -2,3 +2,4 @@
# rig gate (.github/workflows/kernel-rig.yml) fails on a case that fails and is not listed here,
# and on a listed case that passes: a fix removes its line in the same pull request.
# Baseline: develop 5ada4fc8a with SMLib 90aabff (the run on 60b1c6a, aarch64 Linux).
+cov-step-horn-torus-quarter-round-trip SMLib revolve status 1001 on a profile touching its axis (the part is never built)
diff --git a/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/expected.json b/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/expected.json
new file mode 100644
index 0000000000..57087204af
--- /dev/null
+++ b/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/expected.json
@@ -0,0 +1,8 @@
+{
+ "sources": [],
+ "what": "a quarter horn torus (a circle r5 touching its axis, revolved 90 deg) written to STEP and read back: the same solid",
+ "source": "analytic",
+ "method": "the disc r5 about (5, 0) on XZ touches the Z axis at the origin; Pappus, its centroid 5 from the axis: V = pi 25 x 2 pi 5 / 4 = 616.850275; read back into a new design, the same",
+ "body_count": 1,
+ "volume_mm3": 616.8502750680849
+}
diff --git a/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/recipe.json b/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/recipe.json
new file mode 100644
index 0000000000..c6fbabf62c
--- /dev/null
+++ b/tests/kernel-cases/import/cov-step-horn-torus-quarter-round-trip/recipe.json
@@ -0,0 +1,56 @@
+{
+ "commands": [
+ {
+ "command": "sketch.create",
+ "params": {
+ "plane": "XZ",
+ "name": "Tube"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 5,
+ 0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "sketch": "Tube",
+ "axis": "Z",
+ "angle": "90 deg",
+ "body_name": "Horn"
+ }
+ },
+ {
+ "command": "file.export",
+ "params": {
+ "path": "$OUT/kernel-case-horn-torus.step",
+ "format": "step",
+ "bodies": [
+ "Horn"
+ ]
+ }
+ },
+ {
+ "command": "file.new",
+ "params": {
+ "name": "Reimported"
+ }
+ },
+ {
+ "command": "file.insert_step",
+ "params": {
+ "path": "$OUT/kernel-case-horn-torus.step"
+ }
+ }
+ ]
+}
diff --git a/tests/kernel-cases/sweeps/KNOWN_FAILING b/tests/kernel-cases/sweeps/KNOWN_FAILING
index 82aa00854d..ed57ec761c 100644
--- a/tests/kernel-cases/sweeps/KNOWN_FAILING
+++ b/tests/kernel-cases/sweeps/KNOWN_FAILING
@@ -2,3 +2,4 @@
# rig gate (.github/workflows/kernel-rig.yml) fails on a case that fails and is not listed here,
# and on a listed case that passes: a fix removes its line in the same pull request.
# Baseline: not seeded yet; seeded from a develop run after the SMLib pin bump.
+cov-revolve-circle-touching-its-axis-a-quarter-turn SMLib revolve status 1001 on a profile touching its axis
diff --git a/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/expected.json b/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/expected.json
new file mode 100644
index 0000000000..04b6fa34b3
--- /dev/null
+++ b/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/expected.json
@@ -0,0 +1,8 @@
+{
+ "sources": [],
+ "what": "a circle r5 that touches the revolve axis, revolved 90 deg: a quarter of a horn torus, its tube pinched to a point on the axis",
+ "source": "analytic",
+ "method": "the disc r5 about (5, 0) on XZ touches the Z axis at the origin; Pappus, its centroid 5 from the axis: V = pi 25 x 2 pi 5 / 4 = 616.850275",
+ "body_count": 1,
+ "volume_mm3": 616.8502750680849
+}
diff --git a/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/recipe.json b/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/recipe.json
new file mode 100644
index 0000000000..5b0c4f311f
--- /dev/null
+++ b/tests/kernel-cases/sweeps/cov-revolve-circle-touching-its-axis-a-quarter-turn/recipe.json
@@ -0,0 +1,34 @@
+{
+ "commands": [
+ {
+ "command": "sketch.create",
+ "params": {
+ "plane": "XZ",
+ "name": "Tube"
+ }
+ },
+ {
+ "command": "sketch.circle.center",
+ "params": {
+ "center": [
+ 5,
+ 0
+ ],
+ "radius": 5
+ }
+ },
+ {
+ "command": "sketch.finish",
+ "params": {}
+ },
+ {
+ "command": "solid.revolve",
+ "params": {
+ "sketch": "Tube",
+ "axis": "Z",
+ "angle": "90 deg",
+ "body_name": "Horn"
+ }
+ }
+ ]
+}