Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Uniform rounding stabilization: radius sweep, degenerate edges, revolve caps

Claude761a318687b1
diff --git a/Aetheris.Kernel.Core/Brep/Blends/LocalRounding.cs b/Aetheris.Kernel.Core/Brep/Blends/LocalRounding.cs
index 62ddb00b..e607f60c 100644
--- a/Aetheris.Kernel.Core/Brep/Blends/LocalRounding.cs
+++ b/Aetheris.Kernel.Core/Brep/Blends/LocalRounding.cs
@@ -379,9 +379,12 @@ internal static class LocalRounding
s.Centre = centre.Value;
}
- return Build(body, radius, tol, points, supports, oriented, shapes, sharp, kept, seams, plans, boundaries);
+ try { return Build(body, radius, tol, points, supports, oriented, shapes, sharp, kept, seams, plans, boundaries); }
+ catch (Degenerate) { return TooLarge(radius, "the rounding shrinks an edge to nothing"); }
}
+ private sealed class Degenerate : Exception;
+
private static Outcome Build(BrepBody body, double radius, double tol, Dictionary<VertexId, Point3D> points, Dictionary<FaceId, Support> supports,
Dictionary<FaceId, List<List<(EdgeId Edge, bool Reversed)>>> oriented, Dictionary<EdgeId, Shape> shapes, Dictionary<EdgeId, Sharp> sharp,
Dictionary<EdgeId, (FaceId F0, FaceId F1, double Side)> kept, Dictionary<EdgeId, FaceId> seams, Dictionary<VertexId, Plan> plans,
@@ -398,6 +401,10 @@ internal static class LocalRounding
VertexId NewVertex(Point3D p) { var id = builder.AddVertex(); positions[id] = p; return id; }
EdgeId NewEdge(VertexId a, VertexId b, Shape shape)
{
+ // An edge too short or an arc too small to have a direction: the radius has used it up.
+ if (!Direction3D.TryCreate(shape.Arc ? shape.Normal : shape.End - shape.Start, out _) || shape.Arc && !Direction3D.TryCreate(shape.Start - shape.Center!.Value, out _)
+ || shape.Arc && shape.Sweep <= 1e-9)
+ throw new Degenerate();
var edge = builder.AddEdge(a, b); var id = new CurveGeometryId(geometry.Curves.Count() + 1);
if (shape.Arc)
{
diff --git a/Aetheris.Kernel.Core/Brep/Blends/UniformRounding.cs b/Aetheris.Kernel.Core/Brep/Blends/UniformRounding.cs
index 2a8a9ad0..f5615544 100644
--- a/Aetheris.Kernel.Core/Brep/Blends/UniformRounding.cs
+++ b/Aetheris.Kernel.Core/Brep/Blends/UniformRounding.cs
@@ -31,7 +31,10 @@ public static class UniformRounding
if (refusal.Code != TooLargeCode) return Failure(refusal.Code, refusal.Message);
var (lo, hi) = (0d, radius);
for (var i = 0; i < 40; i++) { var mid = 0.5 * (lo + hi); if (LocalRounding.RoundAll(body, mid).Body is not null) lo = mid; else hi = mid; }
- return Failure(refusal.Code, $"{refusal.Message}; the largest that fits is under {hi:G6} mm");
+ // Every smaller radius tried fits: the one asked for is the limit itself.
+ return Failure(refusal.Code, hi >= radius * (1 - 1e-9)
+ ? $"{refusal.Message}; {radius:G6} mm is the limit itself, so the largest that fits is under {radius:G6} mm"
+ : $"{refusal.Message}; the largest that fits is under {hi:G6} mm");
}
public static KernelResult<BrepBody> RoundAllEdges(BrepBody body, double radius)
diff --git a/Aetheris.Kernel.Firmament.Tests/Integration/RevolvedAnnulusCapTests.cs b/Aetheris.Kernel.Firmament.Tests/Integration/RevolvedAnnulusCapTests.cs
new file mode 100644
index 00000000..8051a086
--- /dev/null
+++ b/Aetheris.Kernel.Firmament.Tests/Integration/RevolvedAnnulusCapTests.cs
@@ -0,0 +1,25 @@
+using Aetheris.Kernel.Core.Brep.Tessellation;
+using Aetheris.Kernel.Core.Step242;
+
+namespace Aetheris.Kernel.Firmament.Tests.Integration;
+
+/// <summary>A full revolution of a profile off the axis has annular caps: the larger circle is their outer boundary
+/// whichever way the profile runs, so a STEP reader keeps each cap facing out of the material.</summary>
+public sealed class RevolvedAnnulusCapTests
+{
+ [Theory]
+ [InlineData("[[5mm, 0mm], [10mm, 0mm], [10mm, 20mm], [5mm, 20mm]]", 4712.389)]
+ [InlineData("[[5mm, 0mm], [5mm, 20mm], [10mm, 20mm], [10mm, 0mm]]", 4712.389)]
+ public void Sleeve_ReimportsWithItsCapsFacingOut(string points, double volume)
+ {
+ var built = FirmamentBuildAndExport.CompileSource($"Model Sleeve {{ units: mm\n Axis A {{ Origin: [0mm, 0mm, 0mm]; Direction: [0, 1, 0] }}\n Polygon2 Section {{ Points: {points} }}\n Revolve Body {{ Profile: Section; About: A; Angle: full }} }}");
+ Assert.True(built.IsSuccess, string.Join("\n", built.Diagnostics.Select(d => d.Message)));
+ var imported = Step242Importer.ImportBody(built.Value.StepText);
+ Assert.True(imported.IsSuccess);
+ Assert.DoesNotContain(imported.Diagnostics, d => d.Message.StartsWith("step-orientation-source-mismatch", StringComparison.Ordinal));
+ Assert.True(SurfaceMeshIrTessellator.TryBuild(imported.Value, SurfaceMeshPolicy.FromDisplayOptions(DisplayTessellationOptions.Default), out var document, out var failure), failure);
+ Assert.True(SurfaceMeshIrTessellator.TryLowerToTriangleMesh(document, out _, out var mesh));
+ Assert.True(mesh.IsWatertight && mesh.IsOutwardOriented);
+ Assert.True(double.Abs(mesh.SignedVolume - volume) < 0.01 * volume, $"{mesh.SignedVolume} vs {volume}");
+ }
+}
diff --git a/Aetheris.Kernel.Firmament.Tests/Integration/UniformRoundingRouteTests.cs b/Aetheris.Kernel.Firmament.Tests/Integration/UniformRoundingRouteTests.cs
index 109fec1c..739bd3f8 100644
--- a/Aetheris.Kernel.Firmament.Tests/Integration/UniformRoundingRouteTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/Integration/UniformRoundingRouteTests.cs
@@ -203,6 +203,47 @@ public sealed class UniformRoundingRouteTests
Assert.Contains(refused.Diagnostics, d => d.Code == UniformRoundingRoute.Code && d.Message.Contains("radius-too-large", StringComparison.Ordinal));
}
+ /// <summary>Every fixture across radii from far below to beyond its limit: each result is either a body that
+ /// meshes watertight and outward with every strip at the radius, or a named refusal whose reported fit, taken
+ /// just under, builds.</summary>
+ [Theory]
+ [InlineData("cylinder-rounded")]
+ [InlineData("frustum-rounded")]
+ [InlineData("box-hole-rounded")]
+ [InlineData("d-profile-rounded")]
+ [InlineData("bushing-rounded")]
+ [InlineData("counterbore-rounded")]
+ [InlineData("blind-hole-rounded")]
+ [InlineData("rounded-rect-rounded")]
+ [InlineData("ell-rounded")]
+ public void RadiusSweep_EitherSoundOrRefusedWithAFitThatBuilds(string name)
+ {
+ var source = File.ReadAllText(Path.Combine(Root(), "fixtures/Regression/UniformRounding", name + ".firmament"));
+ string With(double r) => System.Text.RegularExpressions.Regex.Replace(source, @"(target: AllEdges; radius: )[0-9.]+mm", m => m.Groups[1].Value + r.ToString(System.Globalization.CultureInfo.InvariantCulture) + "mm");
+ foreach (var r in new[] { 0.02, 0.5, 1.5, 3, 6 })
+ {
+ var built = FirmamentBuildAndExport.CompileSource(With(r));
+ if (!built.IsSuccess)
+ {
+ var message = Assert.Single(built.Diagnostics).Message;
+ Assert.Matches("uniform-rounding-[a-z-]+", message);
+ var fit = System.Text.RegularExpressions.Regex.Match(message, @"fits is under ([0-9.Ee+-]+) mm");
+ if (!fit.Success) continue;
+ var limit = double.Parse(fit.Groups[1].Value, System.Globalization.CultureInfo.InvariantCulture);
+ Assert.True(limit <= r, message);
+ Assert.True(FirmamentBuildAndExport.CompileSource(With(limit * 0.98)).IsSuccess, $"{limit * 0.98} should fit: {message}");
+ continue;
+ }
+ var body = Step242Importer.ImportBody(built.Value.StepText).Value;
+ Assert.All(body.Topology.Coedges.GroupBy(c => c.EdgeId), g => Assert.True(g.Count() == 2 && g.First().IsReversed != g.Last().IsReversed));
+ Assert.True(Aetheris.Kernel.Core.Brep.Tessellation.SurfaceMeshIrTessellator.TryBuild(body,
+ Aetheris.Kernel.Core.Brep.Tessellation.SurfaceMeshPolicy.FromDisplayOptions(Aetheris.Kernel.Core.Brep.Tessellation.DisplayTessellationOptions.Default), out var document, out var failure), $"r={r}: {failure}");
+ Assert.True(Aetheris.Kernel.Core.Brep.Tessellation.SurfaceMeshIrTessellator.TryLowerToTriangleMesh(document, out _, out var mesh));
+ Assert.True(mesh.IsWatertight && mesh.IsOutwardOriented && mesh.SignedVolume > 0, $"r={r}: watertight={mesh.IsWatertight} outward={mesh.IsOutwardOriented}");
+ Assert.All(BlendRecognition.Recognize(body).Where(x => x.Role == BlendFaceRole.Strip), x => Assert.Equal(r, x.Blend!.Size, 6));
+ }
+ }
+
private static string Root()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
diff --git a/Aetheris.Kernel.Firmament/Materializer/ResolvedProfileRevolveEmitter.cs b/Aetheris.Kernel.Firmament/Materializer/ResolvedProfileRevolveEmitter.cs
index eb648bb5..a1e83c1a 100644
--- a/Aetheris.Kernel.Firmament/Materializer/ResolvedProfileRevolveEmitter.cs
+++ b/Aetheris.Kernel.Firmament/Materializer/ResolvedProfileRevolveEmitter.cs
@@ -189,11 +189,7 @@ public static class ResolvedProfileRevolveEmitter
Use.Forward(startEdges[i]!.Value), Use.Forward(angularEdges[next]),
Use.Reversed(endEdges[i]!.Value), Use.Reversed(angularEdges[i])
])
- : AddFaceWithLoops(builder,
- [
- [Use.Forward(angularEdges[next])],
- [Use.Reversed(angularEdges[i])]
- ]);
+ : AddAnnulus(builder, bindings, (Use.Forward(angularEdges[next]), radii[next]), (Use.Reversed(angularEdges[i]), radii[i]));
sideFaces.Add(face);
semanticFaces["RevolvedSpan:" + segments[i].Name] = face;
var sid = new SurfaceGeometryId(surfaceId++);
@@ -342,6 +338,17 @@ public static class ResolvedProfileRevolveEmitter
}
return builder.AddFace(loops);
}
+ /// <summary>A full revolution's planar annulus: the larger circle is the outer boundary, bound as such, whichever
+ /// way the profile runs (a reader takes the face's side from its outer bound).</summary>
+ private static FaceId AddAnnulus(TopologyBuilder builder, BrepBindingModel bindings, (Use Use, double Radius) a, (Use Use, double Radius) b)
+ {
+ var (outer, inner) = a.Radius >= b.Radius ? (a.Use, b.Use) : (b.Use, a.Use);
+ var face = AddFaceWithLoops(builder, [[outer], [inner]]);
+ var loops = builder.Model.GetFace(face).LoopIds;
+ bindings.AddFaceBoundaryRoleBinding(new FaceBoundaryRoleBinding(face, loops[0], FaceBoundaryRole.Outer));
+ bindings.AddFaceBoundaryRoleBinding(new FaceBoundaryRoleBinding(face, loops[1], FaceBoundaryRole.Inner));
+ return face;
+ }
private readonly record struct Use(EdgeId Edge, bool IsReversed)
{
public static Use Forward(EdgeId edge) => new(edge, false);
diff --git a/docs/development/reports/2026-11/UNIFORM-ROUNDING.md b/docs/development/reports/2026-11/UNIFORM-ROUNDING.md
index 598d4e38..6d2c8ebc 100644
--- a/docs/development/reports/2026-11/UNIFORM-ROUNDING.md
+++ b/docs/development/reports/2026-11/UNIFORM-ROUNDING.md
@@ -170,3 +170,39 @@ outward, read back at r, and Remove(Round(x)) restores x's faces and edges.
Refused by name: `boss-mixed-corner` (two concave and one convex at each foot
corner), `pocket-split-face` (the composed plate's walls are split in two
coplanar faces at the pocket's depth: needs a coplanar-face merge first).
+
+## Stabilization
+
+Swept every fixture plus off-centre variants (14 bodies) over r = 0.02 … 5 mm
+through the real Firmament path (112 cases). Checked per success: every edge
+used once each way after STEP, watertight and outward SurfaceMeshIR mesh,
+certificate strips at r, STEP face count, volume change bounded by area·r;
+per refusal: a named code, a reported fit not above r, and 0.98·fit building.
+
+Found and fixed:
+
+- A contact edge just over the construction tolerance but too short for a
+ direction crashed `NewEdge` near the limit; degenerate edges now refuse as a
+ size limit, so the fit bisection treats them like any other.
+- Asking for exactly the limit read "largest that fits is under 2 mm" for r = 2;
+ now says the radius asked for is the limit itself.
+- Firmament's profile revolve wrote a full revolution's annular caps in profile
+ order with no boundary roles, so an inward-walking profile put the hole first
+ and STEP re-import flipped the cap (a sleeve measured 1553 mm³ for 4712; a
+ stepped bushing did not mesh at all). Caps now put the larger circle first
+ and bind outer/inner roles: the sleeve meshes at 4688.5 (tessellated) and
+ re-imports with no orientation mismatch, either profile direction.
+
+Limits are exact against hand checks: a R10 cylinder r < 5 (rim torus major
+R − r > r), a 6 mm-cornered rounded rect r < 3, a 3 mm-walled bushing or
+counterbore shoulder r < 1.5, a Ø8 blind floor r < 2, a Ø6 bore 10 mm from a
+wall r < 3.5 and 8 mm off-centre r < 2.5. Volume losses follow Pappus (R10
+cylinder, r = 2: 103 mm³ exact, 107 tessellated).
+
+Wireframes (`aetheris wireframe … --view iso`) of the fixtures show the
+expected strips, tori, corners and the L's filled inner corner. The renderer
+draws no isolines on periodic faces with seams (cylinder sides, closed-rim
+tori) even on unrounded bodies: a renderer limit, not the rounding.
+
+Regression: `RadiusSweep_EitherSoundOrRefusedWithAFitThatBuilds` (9 fixtures ×
+5 radii) and `RevolvedAnnulusCapTests`.