Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Fix loop orientation in revolved shells and the NIST import volume outliers

Claude656c9453234c
diff --git a/Aetheris.Kernel.Core.Tests/Brep/BrepHollowRadialCutPatternTests.cs b/Aetheris.Kernel.Core.Tests/Brep/BrepHollowRadialCutPatternTests.cs
index cb8ae133..fc2d346c 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/BrepHollowRadialCutPatternTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/BrepHollowRadialCutPatternTests.cs
@@ -21,6 +21,7 @@ public sealed class BrepHollowRadialCutPatternTests
Assert.True(result.IsSuccess, string.Join(" | ", result.Diagnostics.Select(d => $"{d.Source}: {d.Message}")));
var body = result.Value.Body;
Assert.Equal(9, body.Topology.Faces.Count());
+ MeridianHollowTests.AssertEdgesUsedOnceEachWay(body);
var tori = body.Geometry.Surfaces.Where(s => s.Value.Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Torus)
.Select(s => s.Value.Torus!.Value).ToArray();
Assert.Equal(2, tori.Length);
diff --git a/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs b/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs
index a8bedf3f..12e2b853 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/MeridianHollowTests.cs
@@ -43,6 +43,53 @@ public sealed class MeridianHollowTests
Assert.Equal(2, shell.Value.Body.Geometry.Surfaces.Count(s => s.Value.Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Torus));
}
+ [Fact]
+ public void BlendedCupLoopsFollowTheOutwardNormal()
+ {
+ // Each edge is used once each way, and the torus faces bound the quarter tube that the wall's arcs sweep. Loops
+ // XOR'd with the surface's sense passed the first check for planes and cylinders, but on a torus the loop picked
+ // the complementary band and the blended cup measured twice its volume.
+ PlanarSpan[] cup = [L(0, 0, 48, 0), new PlanarArc((48, 8), 8, -double.Pi / 2, double.Pi / 2), L(56, 8, 56, 142), L(56, 142, 0, 142), L(0, 142, 0, 0)];
+ var wall = MeridianHollow.Wall(cup, 0.8, openTop: true, openBottom: false);
+ Assert.True(wall.IsSuccess);
+ var shell = BrepRevolvedShell.Build(wall.Value, RevolutionFrame.WorldZ);
+ Assert.True(shell.IsSuccess);
+ AssertEdgesUsedOnceEachWay(shell.Value.Body);
+ AssertSolid(shell.Value.Body, PappusVolume(wall.Value));
+ }
+
+ internal static void AssertEdgesUsedOnceEachWay(BrepBody body)
+ {
+ foreach (var uses in body.Topology.Coedges.GroupBy(c => c.EdgeId))
+ {
+ Assert.Equal(2, uses.Count());
+ Assert.Single(uses, c => c.IsReversed);
+ }
+ }
+
+ /// <summary>The volume a closed meridian sweeps in a full turn: pi times the loop integral of r^2 dz.</summary>
+ private static double PappusVolume(IReadOnlyList<PlanarSpan> meridian)
+ {
+ var sum = 0d;
+ foreach (var span in meridian)
+ {
+ const int steps = 4096;
+ for (var i = 0; i < steps; i++)
+ {
+ var (a, b) = (At(span, (double)i / steps), At(span, (double)(i + 1) / steps));
+ sum += (a.R * a.R + a.R * b.R + b.R * b.R) / 3d * (b.Z - a.Z);
+ }
+ }
+ return double.Abs(double.Pi * sum);
+
+ static (double R, double Z) At(PlanarSpan span, double t) => span switch
+ {
+ PlanarLine line => (line.Start.X + t * (line.End.X - line.Start.X), line.Start.Y + t * (line.End.Y - line.Start.Y)),
+ PlanarArc arc => (arc.Center.X + arc.Radius * double.Cos(arc.StartAngle + t * arc.Sweep), arc.Center.Y + arc.Radius * double.Sin(arc.StartAngle + t * arc.Sweep)),
+ _ => throw new NotSupportedException()
+ };
+ }
+
[Fact]
public void ClosedVesselsAndApexesAreRefused()
{
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAndVertexLoopTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAndVertexLoopTests.cs
index c2673df4..499ee99c 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAndVertexLoopTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242PcurveAndVertexLoopTests.cs
@@ -155,7 +155,7 @@ public sealed class Step242PcurveAndVertexLoopTests
[Trait("Category", "SlowCorpus")]
[Fact]
- public void ConeApexVertexLoops_ArePreservedAndStc06RemainsAmbiguous()
+ public void ConeApexVertexLoops_ArePreservedAndStc06Resolves()
{
var imported = Import("testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp");
var apexLoops = imported.Topology.Loops.Where(loop => loop.Kind == LoopKind.Vertex).ToArray();
@@ -165,8 +165,8 @@ public sealed class Step242PcurveAndVertexLoopTests
var binding = imported.Bindings.GetVertexLoopParameterBinding(loop.Id);
Assert.Equal(SurfaceGeometryKind.Cone, imported.GetFaceSurface(binding.FaceId).Kind);
});
- Assert.Contains(imported.FaceOrientationReport!.Shells,
- shell => shell.Qualification == FaceOrientationQualification.Ambiguous);
+ Assert.All(imported.FaceOrientationReport!.Shells,
+ shell => Assert.Equal(FaceOrientationQualification.DerivedQualified, shell.Qualification));
var exported = Step242Exporter.ExportBody(imported);
Assert.True(exported.IsSuccess, string.Join(" | ", exported.Diagnostics.Select(diagnostic => diagnostic.Message)));
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242PeriodicBoundaryOrientationTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242PeriodicBoundaryOrientationTests.cs
index cb24f818..0a81e5f5 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242PeriodicBoundaryOrientationTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242PeriodicBoundaryOrientationTests.cs
@@ -1,3 +1,4 @@
+using Aetheris.Kernel.Core.Brep.Verification;
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Geometry;
using Aetheris.Kernel.Core.Step242;
@@ -89,12 +90,17 @@ public sealed class Step242PeriodicBoundaryOrientationTests
}
[Fact]
- public void Stc06_RemainsExplicitlyAmbiguous()
+ public void Stc06_ResolvesWithMislabelledOuterBoundsCapsAndNotchedBores()
{
+ // STC-06 puts FACE_OUTER_BOUND on hole loops, has single-loop sphere faces that are large caps, drill-point
+ // cones closed by an apex, and bores whose end is notched. Each once resolved to the wrong side.
var imported = Step242Corpus.Import(NistPath("STC/nist_stc_06_asme1_ap242-e3.stp"));
Assert.True(imported.IsSuccess);
- Assert.Contains(imported.Value.FaceOrientationReport!.Shells,
- shell => shell.Qualification == FaceOrientationQualification.Ambiguous);
+ Assert.All(imported.Value.FaceOrientationReport!.Shells,
+ shell => Assert.Equal(FaceOrientationQualification.DerivedQualified, shell.Qualification));
+ var volume = BrepMassProperties.Evaluate(imported.Value, new(0.01d, double.Pi / 90d, 1d, MaximumSegments: 256)).SignedVolume;
+ // OCCT: 3323540.5 mm^3 (exact, Gauss-Kronrod and mesh agree).
+ Assert.InRange(volume, 3323540.5 * (1 - 1e-4), 3323540.5 * (1 + 1e-4));
}
private static string NistPath(string relativePath) => $"testdata/step242/nist/{relativePath}";
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCut.cs b/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCut.cs
index 8a90910a..da36b3d5 100644
--- a/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCut.cs
+++ b/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCut.cs
@@ -52,6 +52,8 @@ public static class BrepHollowRadialCut
var tol = tolerance ?? ToleranceContext.Default;
if (hollow.Feature.PrimitiveKind != "Cylinder" || hollow.Feature.Openings.Count != 1 || hollow.Feature.Openings[0] != "Top")
return Failure("Only a top-open Cylinder<Hollow> authority is admitted.", "Brep.HollowRadialCut.UnsupportedHost");
+ if (hollow.Feature.PrimitiveParameters.GetValueOrDefault("BottomBlendRadius") > 0)
+ return Failure("A bottom-blended host is cut by BrepHollowRadialCutPattern.", "Brep.HollowRadialCut.UnsupportedHost");
var radius = hollow.Feature.PrimitiveParameters["Radius"];
var height = hollow.Feature.PrimitiveParameters["Height"];
var thickness = hollow.Feature.WallThickness;
@@ -118,15 +120,16 @@ public static class BrepHollowRadialCut
var innerFirst = b.AddEdge(i0, iPi); var innerSecond = b.AddEdge(iPi, i0);
var toolSeam = b.AddEdge(o0, i0);
- var outerEnvelope = AddLoop(b, [new(outerSeam), new(outerTop), new(outerSeam, true), new(outerBottom, true)]);
+ // Loops run counter-clockwise about the face's outward normal; see BrepHollowRadialCutPattern.
+ var outerEnvelope = AddLoop(b, [new(outerSeam), new(outerTop, true), new(outerSeam, true), new(outerBottom)]);
var outerOpening = AddLoop(b, [new(outerSecond, true), new(outerFirst, true)]);
var innerEnvelope = AddLoop(b, [new(innerSeam), new(innerTop), new(innerSeam, true), new(innerBottom, true)]);
var innerOpening = AddLoop(b, [new(innerFirst), new(innerSecond)]);
var outerFace = b.AddFace([outerEnvelope.Id, outerOpening.Id]);
var innerFace = b.AddFace([innerEnvelope.Id, innerOpening.Id]);
- var bottomOutside = AddLoop(b, [new(outerBottom)]); var outerBottomFace = b.AddFace([bottomOutside.Id]);
+ var bottomOutside = AddLoop(b, [new(outerBottom, true)]); var outerBottomFace = b.AddFace([bottomOutside.Id]);
var bottomInside = AddLoop(b, [new(innerBottom)]); var innerBottomFace = b.AddFace([bottomInside.Id]);
- var rimOuter = AddLoop(b, [new(outerTop, true)]);
+ var rimOuter = AddLoop(b, [new(outerTop)]);
var rimInner = AddLoop(b, [new(innerTop, true)]);
var rimFace = b.AddFace([rimOuter.Id, rimInner.Id]);
var wall = AddLoop(b, [new(outerFirst), new(outerSecond), new(toolSeam),
@@ -174,16 +177,17 @@ public static class BrepHollowRadialCut
void Bind(CoedgeId id, FaceId face, int surface, PcurveGeometry uv)
=> bindings.AddPcurveBinding(new CoedgePcurveBinding(id, face, new SurfaceGeometryId(surface), uv));
- void HostEnvelope((LoopId Id, CoedgeId[] Coedges) loop, FaceId face, int surface, double bottomZ)
+ void HostEnvelope((LoopId Id, CoedgeId[] Coedges) loop, FaceId face, int surface, double bottomZ, bool upAtEnd)
{
var length = height - bottomZ;
- Bind(loop.Coedges[0], face, surface, PcurveGeometry.Line(new(0d, length), new(0d, 0d), new(0d, length)));
+ var (up, down) = upAtEnd ? (2d * double.Pi, 0d) : (0d, 2d * double.Pi);
+ Bind(loop.Coedges[0], face, surface, PcurveGeometry.Line(new(0d, length), new(up, 0d), new(up, length)));
Bind(loop.Coedges[1], face, surface, PcurveGeometry.Line(full, new(0d, length), new(2d * double.Pi, length)));
- Bind(loop.Coedges[2], face, surface, PcurveGeometry.Line(new(0d, length), new(2d * double.Pi, 0d), new(2d * double.Pi, length)));
+ Bind(loop.Coedges[2], face, surface, PcurveGeometry.Line(new(0d, length), new(down, 0d), new(down, length)));
Bind(loop.Coedges[3], face, surface, PcurveGeometry.Line(full, new(0d, 0d), new(2d * double.Pi, 0d)));
}
- HostEnvelope(outerEnvelope, outerFace, 1, 0d);
- HostEnvelope(innerEnvelope, innerFace, 2, thickness);
+ HostEnvelope(outerEnvelope, outerFace, 1, 0d, upAtEnd: true);
+ HostEnvelope(innerEnvelope, innerFace, 2, thickness, upAtEnd: false);
Bind(outerOpening.Coedges[0], outerFace, 1, PcurveGeometry.Polynomial(second, outerUv.Value.Host));
Bind(outerOpening.Coedges[1], outerFace, 1, PcurveGeometry.Polynomial(first, outerUv.Value.Host));
Bind(innerOpening.Coedges[0], innerFace, 2, PcurveGeometry.Polynomial(first, innerUv.Value.Host));
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCutPattern.cs b/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCutPattern.cs
index 8e43a7c8..1bf7c138 100644
--- a/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCutPattern.cs
+++ b/Aetheris.Kernel.Core/Brep/Features/BrepHollowRadialCutPattern.cs
@@ -87,7 +87,9 @@ public static class BrepHollowRadialCutPattern
var innerFloorVertex = blended ? V(new Point3D(0, 0, thickness) + hostReference.ToVector() * floorRadius) : ib;
var outerFloor = blended ? builder.AddEdge(outerFloorVertex, outerFloorVertex) : outerBottom;
var innerFloor = blended ? builder.AddEdge(innerFloorVertex, innerFloorVertex) : innerBottom;
- var outerEnvelope = AddLoop(builder, [new(outerSeam), new(outerTop), new(outerSeam, true), new(outerBottom, true)]);
+ // Loops run counter-clockwise about the face's outward normal: the outer wall goes round +u at its bottom circle,
+ // the inner wall (whose outward normal faces the axis) round +u at its top circle.
+ var outerEnvelope = AddLoop(builder, [new(outerSeam), new(outerTop, true), new(outerSeam, true), new(outerBottom)]);
var innerEnvelope = AddLoop(builder, [new(innerSeam), new(innerTop), new(innerSeam, true), new(innerBottom, true)]);
var geometry = new BrepGeometryStore();
geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromLine(new Line3Curve(points[ob], z)));
@@ -213,15 +215,15 @@ public static class BrepHollowRadialCutPattern
}
var outerFace = builder.AddFace([outerEnvelope.Id, .. holes.Select(h => h.Outer.Id)]);
var innerFace = builder.AddFace([innerEnvelope.Id, .. holes.Select(h => h.Inner.Id)]);
- var bottomOutside = AddLoop(builder, [new(outerFloor)]); var outerBottomFace = builder.AddFace([bottomOutside.Id]);
+ var bottomOutside = AddLoop(builder, [new(outerFloor, true)]); var outerBottomFace = builder.AddFace([bottomOutside.Id]);
var bottomInside = AddLoop(builder, [new(innerFloor)]); var innerBottomFace = builder.AddFace([bottomInside.Id]);
- var outerBlendFloor = blended ? AddLoop(builder, [new(outerFloor, true)]) : default;
+ var outerBlendFloor = blended ? AddLoop(builder, [new(outerFloor)]) : default;
var outerBlendWall = blended ? AddLoop(builder, [new(outerBottom, true)]) : default;
var innerBlendFloor = blended ? AddLoop(builder, [new(innerFloor, true)]) : default;
- var innerBlendWall = blended ? AddLoop(builder, [new(innerBottom, true)]) : default;
+ var innerBlendWall = blended ? AddLoop(builder, [new(innerBottom)]) : default;
var outerBlendFace = blended ? builder.AddFace([outerBlendFloor.Id, outerBlendWall.Id]) : default;
var innerBlendFace = blended ? builder.AddFace([innerBlendFloor.Id, innerBlendWall.Id]) : default;
- var rimOuter = AddLoop(builder, [new(outerTop, true)]); var rimInner = AddLoop(builder, [new(innerTop, true)]);
+ var rimOuter = AddLoop(builder, [new(outerTop)]); var rimInner = AddLoop(builder, [new(innerTop, true)]);
var rimFace = builder.AddFace([rimOuter.Id, rimInner.Id]);
var shell = builder.AddShell(blended
? [outerFace, innerFace, outerBottomFace, innerBottomFace, rimFace, outerBlendFace, innerBlendFace, .. holes.Select(h => h.WallFace)]
@@ -258,16 +260,19 @@ public static class BrepHollowRadialCutPattern
Role(innerBlendFace, innerBlendFloor.Id, FaceBoundaryRole.Outer);
Role(innerBlendFace, innerBlendWall.Id, FaceBoundaryRole.Inner);
}
- void HostEnvelope((LoopId Id, CoedgeId[] Coedges) loop, FaceId face, int surface, double startZ, double originZ)
+ // The seam is walked up one side of the envelope and down the other: up at u = 2π on the outer wall, whose
+ // loop runs +u along its bottom, and up at u = 0 on the inner wall, whose loop runs +u along its top.
+ void HostEnvelope((LoopId Id, CoedgeId[] Coedges) loop, FaceId face, int surface, double startZ, double originZ, bool upAtEnd)
{
var length = height - startZ; var uvStart = startZ - originZ; var uvEnd = height - originZ;
- Bind(loop.Coedges[0], face, surface, PcurveGeometry.Line(new(0, length), new(0, uvStart), new(0, uvEnd)));
+ var (up, down) = upAtEnd ? (2 * System.Math.PI, 0d) : (0d, 2 * System.Math.PI);
+ Bind(loop.Coedges[0], face, surface, PcurveGeometry.Line(new(0, length), new(up, uvStart), new(up, uvEnd)));
Bind(loop.Coedges[1], face, surface, PcurveGeometry.Line(full, new(0, uvEnd), new(2 * System.Math.PI, uvEnd)));
- Bind(loop.Coedges[2], face, surface, PcurveGeometry.Line(new(0, length), new(2 * System.Math.PI, uvStart), new(2 * System.Math.PI, uvEnd)));
+ Bind(loop.Coedges[2], face, surface, PcurveGeometry.Line(new(0, length), new(down, uvStart), new(down, uvEnd)));
Bind(loop.Coedges[3], face, surface, PcurveGeometry.Line(full, new(0, uvStart), new(2 * System.Math.PI, uvStart)));
}
- HostEnvelope(outerEnvelope, outerFace, 1, wallStart, 0);
- HostEnvelope(innerEnvelope, innerFace, 2, blended ? wallStart : thickness, thickness);
+ HostEnvelope(outerEnvelope, outerFace, 1, wallStart, 0, upAtEnd: true);
+ HostEnvelope(innerEnvelope, innerFace, 2, blended ? wallStart : thickness, thickness, upAtEnd: false);
Bind(bottomOutside.Coedges[0], outerBottomFace, 3, PcurveGeometry.Circle(full, new(0, 0), floorRadius, -floorRadius));
Bind(bottomInside.Coedges[0], innerBottomFace, 4, PcurveGeometry.Circle(full, new(0, 0), blended ? floorRadius : innerRadius, blended ? floorRadius : innerRadius));
Bind(rimOuter.Coedges[0], rimFace, 5, PcurveGeometry.Circle(full, new(0, 0), radius, radius));
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs b/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs
index e33d3344..88dd397d 100644
--- a/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs
+++ b/Aetheris.Kernel.Core/Brep/Features/BrepRevolvedShell.cs
@@ -122,13 +122,14 @@ public static class BrepRevolvedShell
return Failure("revolve-shell-meridian-invalid", $"Meridian span {i} is not a line or arc.");
}
// The circle at the span's start bounds the face counter-clockwise about its outward normal, the circle at
- // its end clockwise. The stored sense is relative to the surface's own normal.
+ // its end clockwise. Loops follow the face's outward normal, whatever the surface's own normal, so each
+ // circle is walked once each way by the two faces it joins.
var loops = new List<LoopId>();
void AddLoop(EdgeId edge, bool reversedAboutOutward)
{
var loopId = builder.AllocateLoopId();
var coedge = builder.AllocateCoedgeId();
- builder.AddCoedge(new Coedge(coedge, edge, loopId, coedge, coedge, reversedAboutOutward ^ !sameSense));
+ builder.AddCoedge(new Coedge(coedge, edge, loopId, coedge, coedge, reversedAboutOutward));
builder.AddLoop(new Loop(loopId, [coedge]));
loops.Add(loopId);
}
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
index 2006b6b9..8aab5400 100644
--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
@@ -791,7 +791,7 @@ public static class BrepDisplayTessellator
return TrimmedSurfaceTessellator.Tessellate(
faceId,
- uvLoopsResult.Value,
+ StitchWrappingLoops(uvLoopsResult.Value),
(u, v) => cylinder.Evaluate(u, v),
(u, _) => cylinder.Normal(u).ToVector(),
options,
@@ -838,7 +838,7 @@ public static class BrepDisplayTessellator
return TrimmedSurfaceTessellator.Tessellate(
faceId,
- uvLoopsResult.Value,
+ StitchWrappingLoops(uvLoopsResult.Value),
(u, v) => cone.Evaluate(u, v),
(u, _) => cone.Normal(u).ToVector(),
options,
@@ -1346,6 +1346,61 @@ public static class BrepDisplayTessellator
return KernelResult<IReadOnlyList<(double U, double V)>>.Success(uvPoints);
}
+ /// <summary>
+ /// Two loops that each run once round a periodic surface bound the band between them. In the unrolled chart each is
+ /// an open polyline one period long, so treated as polygons they enclose only what lies between each polyline and
+ /// its own closing chord: a wavy loop (a slot cut into a bore's end) keeps only its notch and loses the band. The
+ /// band is one polygon: one loop over a period from a common seam, then the other back along it.
+ /// </summary>
+ internal static IReadOnlyList<IReadOnlyList<(double U, double V)>> StitchWrappingLoops(IReadOnlyList<IReadOnlyList<(double U, double V)>> loops)
+ {
+ const double period = 2d * double.Pi;
+ static double Turn(IReadOnlyList<(double U, double V)> loop) => loop.Count < 2 ? 0d : loop[^1].U - loop[0].U;
+ var wrapping = Enumerable.Range(0, loops.Count)
+ .Where(i => loops[i].Count >= 2 && double.Abs(double.Abs(Turn(loops[i])) - period) < 1e-3d)
+ .ToArray();
+ if (wrapping.Length != 2) return loops;
+ // A period of each loop running +u from where it first crosses the seam; the seam avoids every vertex, so each
+ // crossing is a proper one.
+ var seam = loops[wrapping[0]][0].U + 1e-3d * double.Pi;
+ List<(double U, double V)>? Period(IReadOnlyList<(double U, double V)> loop)
+ {
+ var forward = Turn(loop) > 0d ? loop.ToList() : loop.Reverse().ToList();
+ var shift = double.Floor((seam - forward[0].U) / period) * period;
+ var extended = new List<(double U, double V)>();
+ for (var k = 0; k < 3; k++) extended.AddRange(forward.Skip(k == 0 ? 0 : 1).Select(p => (U: p.U + shift + k * period, p.V)));
+ for (var i = 0; i + 1 < extended.Count; i++)
+ {
+ var (a, b) = (extended[i], extended[i + 1]);
+ if (!(a.U <= seam && b.U > seam)) continue;
+ var t = (seam - a.U) / (b.U - a.U);
+ (double U, double V) start = (seam, a.V + t * (b.V - a.V));
+ var result = new List<(double U, double V)> { start };
+ for (var j = i + 1; j + 1 < extended.Count; j++)
+ {
+ var (c, d) = (extended[j], extended[j + 1]);
+ result.Add(c);
+ if (c.U < seam + period && d.U >= seam + period)
+ {
+ var s = (seam + period - c.U) / (d.U - c.U);
+ result.Add((seam + period, c.V + s * (d.V - c.V)));
+ return result;
+ }
+ }
+ return null;
+ }
+ return null;
+ }
+ var lower = Period(loops[wrapping[0]]);
+ var upper = Period(loops[wrapping[1]]);
+ if (lower is null || upper is null) return loops;
+ upper.Reverse();
+ var band = lower.Concat(upper).ToList();
+ var stitched = new List<IReadOnlyList<(double U, double V)>> { band };
+ stitched.AddRange(Enumerable.Range(0, loops.Count).Where(i => !wrapping.Contains(i)).Select(i => loops[i]));
+ return stitched;
+ }
+
private static KernelResult<IReadOnlyList<IReadOnlyList<(double U, double V)>>> TryBuildPeriodicTrimmedSurfaceUvLoops(
BrepBody body,
FaceId faceId,
diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
index 5bc0de1a..876ef50f 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs
@@ -671,7 +671,7 @@ public static class Step242Importer
faceSameSenseResult.Value,
faceEntity.Id,
surfaceResult.Value.ReferenceId)));
- var loopOrientation = DeriveSupportAlignedBoundaries(classifyResult.Value, surfaceGeometry);
+ var loopOrientation = DeriveSupportAlignedBoundaries(classifyResult.Value, surfaceGeometry, faceSameSenseResult.Value);
supportAlignedBoundary[faceId] = loopOrientation.FaceAligned;
foreach (var pair in loopOrientation.Loops) supportAlignedLoopBoundary[pair.Key] = pair.Value;
}
@@ -2639,11 +2639,15 @@ public static class Step242Importer
private static (bool FaceAligned, IReadOnlyDictionary<LoopId, bool> Loops) DeriveSupportAlignedBoundaries(
IReadOnlyList<LoopBuildData> loops,
- SurfaceGeometry surface)
+ SurfaceGeometry surface,
+ bool sourceSameSense)
{
if (loops.Count == 0) return (true, new Dictionary<LoopId, bool>());
- var outer = loops.SingleOrDefault(loop => loop.IsDeclaredOuter) ?? loops[0];
- var resolved = new Dictionary<LoopId, bool>();
+ // One loop on a sphere splits it into two caps, and the loop alone cannot say which is the face: the small cap
+ // traversed one way and the large cap the other wind identically. STEP's same_sense with the loop's direction
+ // can, since the loop runs counter-clockwise about the face's outward normal.
+ if (surface.Kind == SurfaceGeometryKind.Sphere && loops.Count == 1)
+ return (sourceSameSense, new Dictionary<LoopId, bool> { [loops[0].LoopId] = sourceSameSense });
IReadOnlyList<UvPoint>? Project(LoopBuildData loop) => surface.Kind switch
{
SurfaceGeometryKind.Plane => SimplifyClosedPolygon(ProjectLoopToPlane(loop.Samples, surface.Plane!.Value), ContainmentEps),
@@ -2654,6 +2658,17 @@ public static class Step242Importer
_ => null,
};
var projections = loops.ToDictionary(loop => loop.LoopId, Project);
+ // The material side follows from the loops' winding, not from which one carries FACE_OUTER_BOUND. Some writers
+ // put that label on a hole (NIST STC-06 does, on 23 planar faces), so on a plane the loop enclosing the most
+ // area is the outer boundary whatever it is called.
+ var outer = surface.Kind == SurfaceGeometryKind.Plane && loops.Count > 1 && loops.All(loop => projections[loop.LoopId] is { Count: >= 3 })
+ ? loops.MaxBy(loop => double.Abs(ComputeSignedArea(projections[loop.LoopId]!)))!
+ : loops.SingleOrDefault(loop => loop.IsDeclaredOuter) ?? loops[0];
+ // Likewise two circles running round a torus bound two bands, the short way round the tube and the long way.
+ if (surface.Kind == SurfaceGeometryKind.Torus && loops.All(loop => projections[loop.LoopId] is { } p
+ && TryDeriveFullPeriodTraversalAlignment(p, SurfacePeriodicity.Of(surface), out _)))
+ return (sourceSameSense, loops.ToDictionary(loop => loop.LoopId, _ => sourceSameSense));
+ var resolved = new Dictionary<LoopId, bool>();
foreach (var loop in loops)
{
var isOuter = loop.LoopId == outer.LoopId;
@@ -2680,14 +2695,15 @@ public static class Step242Importer
return (resolved[outer.LoopId], resolved);
// A loop running once round a cylinder or cone says nothing by itself about which side the face lies on. When the
- // face has another loop, the face lies between them: a loop with the face on its +v side bounds an aligned face
+ // face has another loop, the face lies between them; a lone loop on a cone bounds the side holding the apex: a loop with the face on its +v side bounds an aligned face
// when it runs +u. The answer is the face's, so an inner loop reports it negated, as the caller expects.
bool FullTurnLoopAlignment(LoopBuildData loop, IReadOnlyList<UvPoint> projected, bool runsPositiveU, bool isOuter)
{
- if (surface.Kind is not (SurfaceGeometryKind.Cylinder or SurfaceGeometryKind.Cone) || loops.Count < 2) return runsPositiveU;
+ if (surface.Kind is not (SurfaceGeometryKind.Cylinder or SurfaceGeometryKind.Cone)) return runsPositiveU;
var others = loops.Where(other => other.LoopId != loop.LoopId).Select(other => projections[other.LoopId]).Where(p => p is { Count: > 0 }).ToArray();
- if (others.Length == 0) return runsPositiveU;
- var side = others.Average(p => p!.Average(point => point.Y)) - projected.Average(point => point.Y);
+ // Alone on a cone (a drill point), the loop bounds the finite side: the face runs to the apex, where v is 0.
+ if (others.Length == 0 && surface.Kind != SurfaceGeometryKind.Cone) return runsPositiveU;
+ var side = (others.Length == 0 ? 0d : others.Average(p => p!.Average(point => point.Y))) - projected.Average(point => point.Y);
if (double.Abs(side) <= ContainmentEps) return runsPositiveU;
var faceAligned = (side > 0d) == runsPositiveU;
return isOuter ? faceAligned : !faceAligned;
diff --git a/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md b/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
index b1eb96e0..4d40d19b 100644
--- a/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
+++ b/docs/development/reports/2026-11/HOLLOW-GENERALIZATION.md
@@ -166,16 +166,62 @@ kernel volume moves towards OCCT's:
| CTC-05 | 4837978.1 | 9277231.0 | 12694917.8 |
| STC-06 | 94655.2 | 179703.7 | 3323540.5 |
-CTC-05 and STC-06 are still far from OCCT (STC-06 by a factor of 18), so their kernel volumes have another defect; it is not chased here.
+CTC-05 and STC-06 were still far from OCCT; see "Loop orientation and the NIST volumes" below.
-Found, not caused here: the perforated blended utensil holder (`ordning-utensil-holder-blended`) exports with OCCT
-volume −21002 mm³, before and after this change. Its shell is inside out; the Perforation radial-cut builder owns that
-topology.
+## Loop orientation and the NIST volumes
+
+### The perforated holder
+
+The bespoke thin-wall planner bound coedge directions to the surface's own normal XOR'd with the face sense, and
+`BrepRevolvedShell` and both radial-cut builders inherited it. STEP (and OCCT) read a loop as counter-clockwise about
+the face's outward normal. Planes and cylinders tolerate the wrong winding in OCCT, so their volumes looked right; on a
+torus the loop selects the band, and OCCT took the 270° complement of the blend. The blended cup measured 95528.8 mm³
+for 46411.3, and the perforated holder came out inside out (−21002 mm³).
+
+Loops now follow the outward normal in `BrepRevolvedShell`, `BrepHollowRadialCut` and `BrepHollowRadialCutPattern`:
+each edge is used once each way. The single radial cut refuses bottom-blended hosts; the pattern builder owns those.
+`ordning-utensil-holder-blended` measures 39636.9 mm³ in OCCT (blank 40569.2 less 932.4 of vents).
+
+### The NIST volumes
+
+The two outliers had four unrelated import defects, each of which picked the wrong side of a face:
+
+| Defect | Where | Fix |
+| --- | --- | --- |
+| FACE_OUTER_BOUND on a hole loop (23 planar faces of STC-06) | orientation baseline taken from the declared outer loop | on a plane, the loop enclosing the most area is the outer boundary |
+| One loop on a sphere: small cap one way, large cap the other wind alike | baseline assumed the small cap | trust same_sense |
+| Two full circles on a torus: quarter tube or three-quarter tube | baseline from u direction alone | trust same_sense |
+| Lone full-turn loop on a cone (drill point) | face side not decided | the face holds the apex |
+| Two loops each running once round a cylinder or cone, one wavy (a notch in a bore end) | each tessellated as its own polygon, losing the band | stitched into one band polygon at a common seam |
+
+| File | Before | After | OCCT |
+| --- | --- | --- | --- |
+| STC-06 | 179703.7 | 3323539.5 | 3323540.5 |
+| CTC-05 | 9277231.0 | 12726632.0 | 12694917.8 |
+| FTC-11 | 5271.3 | 5134.4 | 5135.1 |
+| STC-10 | 190412.0 | 187534.6 | 188312.8 |
+
+Those four files re-hash; FTC-08 does not move (503632.9 against OCCT's 503633.0). The two tests
+that asserted STC-06 stays orientation-ambiguous now assert it resolves, and to OCCT's volume.
+
+CTC-05's remaining +0.25% is one torus face (a quarter-tube fillet 63° long): the mass-property tessellation hits its
+65536-triangle budget before refining the trim, and chord-to-arc slivers along its circular edges add 986 mm² of area.
+The display tessellation of the same face matches OCCT's area. It is an estimator limit, not a topology defect.
+
+### Found, not fixed: cap loops across the kernel
+
+A sweep of the 278 canonical fixtures that export STEP found edges used the same way twice in 230 of them, starting
+with `Basics/box`: `BrepExtrude` and the hand-built box routes (`BrepBooleanBoxCylinderHoleBuilder` and others) wind both
+caps counter-clockwise about +Z, so the bottom cap is clockwise about its outward normal. OCCT's volume is right, and the
+importer re-solves orientation, so nothing in the kernel noticed. Gear routes have hundreds of such edges each. A
+receiving system that trusts the loops (or heals them) sees inverted caps. Fixing it changes every box-derived STEP
+hash and needs its own pass; the test this change adds (`AssertEdgesUsedOnceEachWay`) is the check to extend to those
+builders.
## Next
- Closed vessels: the cavity is a second shell; the section stack and the revolved shell both need void shells.
- Apexes and poles in `BrepRevolvedShell` (pointed cones, domed bottoms).
-- Perforation onto the general hollow body instead of its own cylinder builder, which would also retire the
- inside-out shell above.
+- Perforation onto the general hollow body instead of its own cylinder builder.
+- Cap loop orientation in `BrepExtrude` and the box builders (above).
- Phases 4 and 5 as planned.
diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.json
index 15ec85d5..e8f88d7e 100644
--- a/testdata/step242/manifests/nist.v0.report.json
+++ b/testdata/step242/manifests/nist.v0.report.json
@@ -97,7 +97,7 @@
"edges": 331,
"faces": 156
},
- "canonicalSha256": "f93eb4de341d8bc03271498a8f7b31d910af1c4ac76732a7e1cc22c73469ed87"
+ "canonicalSha256": "1ea6e51ac5c38861793ace53a0f5978c976eaab0850864c99c4718aaa0f21c3a"
},
{
"fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",
@@ -237,7 +237,7 @@
"edges": 104,
"faces": 42
},
- "canonicalSha256": "211aef84a6524a25297a4d84c6f6e15dfc847dd26090e13815cd1b2e4be6bd58"
+ "canonicalSha256": "aca94e93670974731aee5b8307e58544ec8c47adf097ed2ea1a47ec2d33e7fa0"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3",
@@ -257,7 +257,7 @@
"edges": 310,
"faces": 144
},
- "canonicalSha256": "7fb76c2335ecfca4ebf88bfb08fc57545d9ed884220096ac9bcb4a87c0229827"
+ "canonicalSha256": "a7585d1f177d54696a13b44bf9980496bddbde301805e3e80963643d32918bed"
},
{
"fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",
@@ -337,6 +337,6 @@
"edges": 551,
"faces": 256
},
- "canonicalSha256": "999e5873342b098991263c2b9347068803af42e41ca0c368f9726d44cf94eb12"
+ "canonicalSha256": "5d0c70b6ffd0e1634492f222d3697dfc1e0b5857aedc8aaeaf7f3c752d8995ac"
}
]