Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Handle spherical single-coedge latitude-cap trim in tessellator
Yuechen Lif7d41137b2de
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.csindex e89bf46a..2f976ce5 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs@@ -31,9 +31,9 @@ public sealed class Step242EdgeCurveSenseRegressionTestsif (string.Equals(relativePath, "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp", StringComparison.Ordinal)){- Assert.Equal("tessellator", first.FirstFailureLayer);- Assert.Equal(string.Empty, first.FirstDiagnostic.Source);- Assert.StartsWith("Face 33 spherical trim loop must contain at least three coedges. Observed 1.", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ Assert.Equal(string.Empty, first.FirstFailureLayer);+ Assert.Equal("Audit.None", first.FirstDiagnostic.Source);+ Assert.Equal("No diagnostics.", first.FirstDiagnostic.MessagePrefix);}Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.csnew file mode 100644index 00000000..3ec3ce8b--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242SphericalTrimSingleCoedgeDiagnosticsTests.cs@@ -0,0 +1,64 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Step242;+using Aetheris.Kernel.Core.Topology;++namespace Aetheris.Kernel.Core.Tests.Step242;++public sealed class Step242SphericalTrimSingleCoedgeDiagnosticsTests+{+ [Fact]+ public void Step242_Stc06_Face33_IsSingleCoedgeClosedFullCircleLatitudeLoop_OnSphere()+ {+ const string relativePath = "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp";+ var fullPath = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), relativePath.Replace('/', Path.DirectorySeparatorChar));++ var import = Step242Importer.ImportBody(File.ReadAllText(fullPath));+ Assert.True(import.IsSuccess);++ var body = import.Value;+ var faceId = new FaceId(33);+ var surface = body.GetFaceSurface(faceId);+ Assert.Equal(SurfaceGeometryKind.Sphere, surface.Kind);++ var loopId = Assert.Single(body.GetLoopIds(faceId));+ var coedgeId = Assert.Single(body.GetCoedgeIds(loopId));+ var coedge = body.Topology.GetCoedge(coedgeId);+ var curve = body.GetEdgeCurve(coedge.EdgeId);+ Assert.Equal(CurveGeometryKind.Circle3, curve.Kind);++ Assert.True(body.TryGetEdgeVertices(coedge.EdgeId, out var startVertexId, out var endVertexId));+ Assert.Equal(startVertexId, endVertexId);++ var trim = body.Bindings.GetEdgeBinding(coedge.EdgeId).TrimInterval;+ Assert.NotNull(trim);+ Assert.Equal(0d, trim!.Value.Start, 6);+ Assert.Equal(2d * double.Pi, trim.Value.End, 6);+ }++ [Fact]+ public void Step242_Stc06_AdvancesPastSingleCoedgeSphereTrim_Deterministically()+ {+ const string relativePath = "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp";+ var entry = new Step242CorpusManifestEntry(+ Id: Path.GetFileNameWithoutExtension(relativePath),+ Path: relativePath,+ Group: "nist-sphere-single-coedge-regression",+ Notes: "single-coedge spherical trim family progression",+ ExpectedFirstDiagnostic: null,+ ExpectHashStableAfterCanonicalization: null,+ ExpectTopologyCounts: null,+ ExpectGeometryKinds: null);++ var first = Step242CorpusManifestRunner.RunOne(entry);+ var second = Step242CorpusManifestRunner.RunOne(entry);++ Assert.Equal(string.Empty, first.FirstFailureLayer);+ Assert.Equal("Audit.None", first.FirstDiagnostic.Source);+ Assert.Equal("No diagnostics.", first.FirstDiagnostic.MessagePrefix);++ Assert.Equal(first.FirstFailureLayer, second.FirstFailureLayer);+ Assert.Equal(first.FirstDiagnostic.Source, second.FirstDiagnostic.Source);+ Assert.Equal(first.FirstDiagnostic.MessagePrefix, second.FirstDiagnostic.MessagePrefix);+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.csindex 1db34e99..4a79299c 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs@@ -27,10 +27,10 @@ public sealed class Step242UnsupportedSurfaceForHolesRegressionTests[InlineData("testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp",- "tessellator",- "Importer.LoopRole.UnsupportedSurfaceForHoles","",- "Face 33 spherical trim loop must contain at least three coedges. Observed 1.")]+ "Importer.LoopRole.UnsupportedSurfaceForHoles",+ "Audit.None",+ "No diagnostics.")]public void Step242_NistTargets_AdvancePastGenericUnsupportedSurfaceForHoles_Deterministically(string relativePath,diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.csindex dc63e204..0031d382 100644--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs@@ -25,6 +25,8 @@ public static class BrepDisplayTessellatorprivate const string CylinderTrimAmbiguousUsedShorterSpanSource = "Viewer.Tessellation.CylinderTrimAmbiguousUsedShorterSpan";private const string CurvedTopologyUnsupportedSource = "Viewer.Tessellation.CurvedTopologyUnsupported";private const string BSplineSurfaceTrimUnsupportedSource = "Viewer.Tessellation.BSplineSurfaceTrimUnsupported";+ private const string SphereTrimSingleCoedgeLatitudeCapSource = "Viewer.Tessellation.SphereTrim.SingleCoedgeLatitudeCap";+ private const string SphereTrimSingleCoedgeUnsupportedSource = "Viewer.Tessellation.SphereTrim.SingleCoedgeUnsupported";public static KernelResult<DisplayTessellationResult> Tessellate(BrepBody body, DisplayTessellationOptions? options = null){@@ -1734,6 +1736,17 @@ public static class BrepDisplayTessellator}var coedges = body.GetCoedgeIds(loopIds[0]).Select(id => body.Topology.GetCoedge(id)).ToArray();+ if (coedges.Length == 1)+ {+ var singleCoedgeResolution = TryResolveSingleCoedgeSphereTrimPatch(body, faceId, sphere, coedges[0]);+ if (singleCoedgeResolution.IsSuccess)+ {+ return singleCoedgeResolution;+ }++ return KernelResult<(double, double, double, double)>.Failure(singleCoedgeResolution.Diagnostics);+ }+if (coedges.Length < 3){return KernelResult<(double, double, double, double)>.Failure([@@ -1811,6 +1824,101 @@ public static class BrepDisplayTessellatorreturn KernelResult<(double, double, double, double)>.Success((angularBounds.Value.Start, angularBounds.Value.Span, vStart, vEnd));}+ private static KernelResult<(double UStart, double USpan, double VStart, double VEnd)> TryResolveSingleCoedgeSphereTrimPatch(+ BrepBody body,+ FaceId faceId,+ SphereSurface sphere,+ Coedge coedge)+ {+ const double fullWrapTolerance = 1e-3d;+ const double axisAlignmentTolerance = 1e-4d;+ const double axisOffsetTolerance = 1e-4d;+ const double circleRadiusTolerance = 1e-4d;+ const double minElevationSpan = 1e-6d;++ var curve = body.GetEdgeCurve(coedge.EdgeId);+ if (curve.Kind != CurveGeometryKind.Circle3)+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim supports only closed full-circle latitude loops. Observed curve kind '{curve.UnsupportedKind ?? curve.Kind.ToString()}'.",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ if (!body.TryGetEdgeVertices(coedge.EdgeId, out var startVertexId, out var endVertexId) || startVertexId != endVertexId)+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim expected a closed edge use. Observed edge {coedge.EdgeId.Value} with distinct vertices {startVertexId.Value}->{endVertexId.Value}.",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ if (!body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var edgeBinding)+ || edgeBinding.TrimInterval is not ParameterInterval trimInterval+ || !double.IsFinite(trimInterval.Start)+ || !double.IsFinite(trimInterval.End)+ || double.Abs((trimInterval.End - trimInterval.Start) - (2d * double.Pi)) > fullWrapTolerance)+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim expected a full-circle edge trim interval. Observed trim [{edgeBinding.TrimInterval?.Start:R}, {edgeBinding.TrimInterval?.End:R}].",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ var circle = curve.Circle3!.Value;+ var axisDot = circle.Normal.ToVector().Dot(sphere.Axis.ToVector());+ if (double.Abs(double.Abs(axisDot) - 1d) > axisAlignmentTolerance)+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim classified as unsupported subfamily (edge={coedge.EdgeId.Value}, axisAlignment={axisDot:R}); expected circle normal parallel to sphere axis.",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ var centerOffset = circle.Center - sphere.Center;+ var axialDistance = centerOffset.Dot(sphere.Axis.ToVector());+ var radialOffsetVector = centerOffset - (sphere.Axis.ToVector() * axialDistance);+ var radialOffset = radialOffsetVector.Length;+ if (radialOffset > (sphere.Radius * axisOffsetTolerance))+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim classified as unsupported subfamily (edge={coedge.EdgeId.Value}, circle-center-axis-offset={radialOffset:R}); expected latitude circle centered on sphere axis.",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ var latitude = double.Asin(System.Math.Clamp(axialDistance / sphere.Radius, -1d, 1d));+ var expectedCircleRadius = sphere.Radius * double.Cos(latitude);+ var circleRadiusDelta = double.Abs(circle.Radius - expectedCircleRadius);+ if (circleRadiusDelta > (sphere.Radius * circleRadiusTolerance))+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim classified as unsupported subfamily (edge={coedge.EdgeId.Value}, circleRadius={circle.Radius:R}, expectedLatitudeRadius={expectedCircleRadius:R}); expected latitude circle.",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ var positivePoleDistance = double.Abs((double.Pi / 2d) - latitude);+ var negativePoleDistance = double.Abs((-double.Pi / 2d) - latitude);+ var pole = positivePoleDistance <= negativePoleDistance ? (double.Pi / 2d) : (-double.Pi / 2d);++ var vStart = System.Math.Min(latitude, pole);+ var vEnd = System.Math.Max(latitude, pole);+ if ((vEnd - vStart) <= minElevationSpan)+ {+ return KernelResult<(double, double, double, double)>.Failure([+ CreateNotImplemented(+ $"Face {faceId.Value} spherical single-coedge trim collapsed at a pole (latitude {latitude:R}).",+ SphereTrimSingleCoedgeUnsupportedSource)]);+ }++ return KernelResult<(double, double, double, double)>.Success(+ (0d, 2d * double.Pi, vStart, vEnd),+ [CreateValidationWarning(+ $"Face {faceId.Value} spherical single-coedge trim classified as closed full-wrap constant-latitude cap (edge {coedge.EdgeId.Value}, latitude {latitude:R}, pole {(pole > 0d ? "+pi/2" : "-pi/2")}).",+ SphereTrimSingleCoedgeLatitudeCapSource)]);+ }+private static KernelResult<(double UStart, double UEnd, double VStart, double VEnd)> TryResolveCylinderTrimPatch(BrepBody body,FaceId faceId,diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex ed6c90db..c3ab37cd 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -291,14 +291,14 @@"fileId": "testdata_step242_nist_STC_nist_stc_06_asme1_ap242-e3","path": "testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp","sizeBytes": 993459,- "status": "importFail",- "firstFailureLayer": "tessellator",+ "status": "success",+ "firstFailureLayer": "","firstDiagnostic": {- "code": "NotImplemented",- "source": "",- "messagePrefix": "Face 33 spherical trim loop must contain at least three coedges. Observed 1."+ "code": "Unknown",+ "source": "Audit.None",+ "messagePrefix": "No diagnostics."},- "diagnosticCount": 1,+ "diagnosticCount": 0,"exceptionEscaped": false,"topologyCounts": {"vertices": 225,@@ -306,10 +306,10 @@"faces": 144},"tessellationCounts": {- "facePatches": 0,- "edgePolylines": 0+ "facePatches": 144,+ "edgePolylines": 310},- "canonicalSha256": null+ "canonicalSha256": "39ade16e0c609e93a20286c72754214d49931a2d5d73b8664ce8732e97792d65"},{"fileId": "testdata_step242_nist_STC_nist_stc_07_asme1_ap242-e3",