Skip to content

Linear sweep: a curve straight to the body's tolerance is swept as itself, not as a cylinder - #131

Open
H1D wants to merge 2 commits into
tangency-labs:mainfrom
H1D:fix/near-straight-sweep
Open

H1D wants to merge 2 commits into
tangency-labs:mainfrom
H1D:fix/near-straight-sweep

Conversation

@H1D

@H1D H1D commented Nov 3, 2026

Copy link
Copy Markdown

🤖 on behalf of 👤; (not yet proofread)

The SMLib half of tangency-labs/solidcraft#11394: a spline 7e-7 mm off its 0.89 mm chord, extruded, got a cylinder wall of radius 216 985.56 mm, and every boolean with the body was refused.

Summary

 CreateLinearSweep, CreateLinearSweepSimple: the wall of each profile curve
   if IsLinear()                                  -> SmPlane
-  else if IsArc(8, ArcZero)                      -> ArcSweepCylinder
+  else if !IsLinear(dTol) && IsArc(8, ArcZero)   -> ArcSweepCylinder    (IsSweptArc)
   otherwise                                      -> SmSurfOfExtrusion of the curve
  • The sweep. The cubic sweeps 4.1e-6 rad of a circle. That is above IsArc's only flatness floor, 1e-6 rad (SmCurve.cpp:13580), so its wall became an SmCylinder of radius 216 985.56 mm. That body passes the check.
  • The import. smlib_brep_import rebuilds an analytic face from its NURB (smlib_flat.cpp:3210 → AnalyticOfNurbs → SmCylinder::IsNurbSurfaceCylinder). It fits three-point circles to the bottom and top iso curves and takes the axis through their centres. For an arc this flat the centres are off by about eps·|p|·(r/chord)², so SmSurfOfRevolution test Fillet: rounds reaching past their faces — overlapping bands too large, rails past a side edge's end #10 fails by 5.19e-4 against 7.0e-9.
  • SolidCraft. It keeps its bodies as flat arrays, so it refused every boolean with this body.

The fix

  • The sweep. Both linear sweeps in SmPrimitiveCreation.cpp now ask IsSweptArc: is the curve an arc to ArcZero, and not straight to the body's tolerance dTol? A curve within dTol of its chord lies on a circle only through a bulge below the tolerance. Such a curve is now swept as itself, an SmSurfOfExtrusion, like any other spline. An arc that bulges more than dTol keeps its cylinder.
  • Tests. In capi/tests/sweeps.cpp, "extrude a near-straight spline, round trip" extrudes the #11394 profile 10 up and requires no cylinder face. It then imports the flat arrays and checks the body: valid, manifold, volume. It is its own commit, failing on main.
  • Docs. One CHANGELOG.md entry under [Unreleased] → Fixed.

Evidence

The build was capi CMake Release with -DSMLIB_STRICT_WARNINGS=ON, on x86_64 Linux, GCC 14.2. GCC 14 also needs -Wno-template-id-cdtor, because it flags the existing SmHealProbArray.h:302, a warning CI's GCC 13 does not have.

  • Before (fffc8f1, the test alone): smlib_test_sweeps exits 1.
    sweeps.cpp:417: CHECK(n == 6 && std::count(types, types + n, SMLIB_FLAT_SURFACE_CYLINDER) == 0) failed
    extrude a near-straight spline, round trip  volume 69.763349 expected 69.763346 (rel 3.82e-08) check
      SmSurfOfRevolution::Test #10 Dist U: Bad GenCurve eval does not map to Surface eval within dScaledZero
      (offset=0.00051897691, tolerance=7.0446366e-09) [owner SmCylinder]
    
    After (5b6a573): 0 warnings, and ctest passes 23/23, the nine known-failing lists included.

The issue's scripts. These ran on SolidCraft develop (f3b507c05), with SMLib built from source through SOLIDCRAFT_SMLIB_DIR: base fffc8f1, fix 5b6a573.

Script Base Fix
f2: the spline profile, extruded 10, joined to a box step 9 solid.combine refused: test #10, offset 5.1897691e-4 joins. Side face is not a cylinder. Volume 69.76334900132437 (the spline profile × 10 is 69.76334900132827)
f2_round: a spline on a circle of radius 135 000 side face is a cylinder of radius 135000.00000032622 side face is not a cylinder. Volume 44.99999548965403
f2_line: the chord instead of the spline volume 69.76334646610005 same

Flat round trip in C++ alone (export, import, check, union with a box), on the same two builds:

Profile wall (0.89 mm chord) Base Fix
the #11394 spline round trip fails test #10, offset 5.19e-4 valid
an exact arc of radius 233 366, sagitta 4e-7 round trip fails test #10, offset 1.2e-3 valid (extrusion of the SmCircle)
an exact arc of radius 142 114, sagitta 7e-7 valid (cylinder) valid (extrusion of the SmCircle)
an exact arc of radius 3 316, sagitta 3e-5 round trip fails test #9/#10, offset 2.4e-7 same: not changed here, see below
an exact arc of radius 99.5, a half circle of radius 10 valid (cylinder) same

SolidCraft's own suites, base and fix:

  • The kernel-cases rig (cargo xtask kernel-cases, 1017 cases) gives 981 pass, 22 fail and 14 unsupported on both. No case changed status or any measured value.
  • cargo test -p solidcraft-kernel --features smlib: the lib tests give 787 passed and 16 failed on both, the same 16, all of them in tests/KNOWN_FAILING_TESTS.
  • The integration tests give 19 passed and 2 failed on both, with identical panics. The two are boolean_props::edge_only_box_join_is_refused_in_both_orders and boolean_props::translation_invariant (a sphere's control net). They are not in the list, nothing in them sweeps a near-straight curve, and they fail the same way on the base build. I have not looked into them.

Merge Danger

Door: two-way

Revert the commit and these walls are cylinders again. No file format or API changes.

Blast Radius: narrow

  • Which walls change. Only a profile curve that is straight to the body's tolerance, yet passes IsArc, changes. Its wall goes from an SmCylinder to the curve's own extrusion. That includes an exact arc this flat, such as radius 233 366 over 0.89 mm, whose sagitta is 4e-7.
  • Consumers. A consumer that asked such a face for its cylinder (radius, axis) no longer gets one. Nothing in the SolidCraft rig is that flat.

Not changed here. An arc that bulges more than the tolerance but is still flat, such as radius 3 316 over 0.89 mm, keeps its cylinder. Such a cylinder still fails the check after a flat round trip, because the import rebuilds its frame from the NURB. The exact frame is already in the arrays: the export writes the face's origin, axis, reference direction and radius. Taking those on import, and only the parametrisation from the NURB, would close it. That reverses the import's choice to pass over the canonical entry, so it is left to you.

H1D added 2 commits November 3, 2026 10:39
…gh the flat round trip (failing test)

A cubic 7e-7 off its 0.89 mm chord (SolidCraft #11394), closed by three lines and extruded 10 up, gets a cylinder wall of radius 217 m. smlib_brep_import rebuilds it outside SMLib's check (SmSurfOfRevolution test tangency-labs#10, offset 5.2e-4).
…self, not as a cylinder

CreateLinearSweep and CreateLinearSweepSimple made any curve that IsArc to ArcZero a cylinder wall, so a spline 7e-7 off its 0.89 mm chord became a cylinder of radius 217 m (sweep 4.1e-6 rad, over IsArc's 1e-6 floor). A cylinder that flat is not rebuilt from its NURB to its check's zero after the flat round trip. Both sweeps now ask IsSweptArc: an arc to ArcZero that is not straight to dTol. (SolidCraft #11394)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant