Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Preserve rechained planar traversal direction during curve sampling
Yuechen Li8c6b967f1884
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.csindex d5a42810..15823e6a 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs@@ -152,7 +152,7 @@ public sealed class Step242ConicalSurfaceRegressionTests"testdata/step242/nist/STC/nist_stc_10_asme1_ap242-e2.stp","tessellator","Viewer.Tessellation.PlanarNonConvexTriangulationFailed",- "Face 3 planar loop triangulation failed because the polygon is not simple.")]+ "Face 11 planar loop triangulation failed")]public void Step242_NistTargets_AdvancePastCircleTrim_AndKeepDeterministicNextBlocker(string relativePath,string expectedLayer,diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.csindex d82b6207..09ec9a28 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242UnsupportedSurfaceForHolesRegressionTests.cs@@ -7,10 +7,10 @@ public sealed class Step242UnsupportedSurfaceForHolesRegressionTests[Theory][InlineData("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp",- "tessellator",+ "","Topology.GraphValidator",- "Viewer.Tessellation.PlanarNonConvexTriangulationFailed",- "Face 4 planar loop triangulation failed because the polygon is not simple.")]+ "Audit.None",+ "No diagnostics.")][InlineData("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp",null,diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.csindex d662f12c..596d0248 100644--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs@@ -2423,13 +2423,15 @@ public static class BrepDisplayTessellator}var orderedIndices = new List<int>(coedges.Count) { 0 };+ var chainedEndpoints = new List<(Point3D Start, Point3D End)>(coedges.Count) { orientedEndpoints[0] };+ var traversalSwapped = new List<bool>(coedges.Count) { false };var used = new bool[coedges.Count];used[0] = true;var currentEnd = orientedEndpoints[0].End;for (var step = 1; step < coedges.Count; step++){- var nextIndex = FindNextCoedgeIndex(orientedEndpoints, used, currentEnd, out _, out var nextEnd);+ var nextIndex = FindNextCoedgeIndex(orientedEndpoints, used, currentEnd, out var nextStart, out var nextEnd, out var swapped);if (nextIndex < 0){return KernelResult<IReadOnlyList<Point3D>>.Failure([CreateInvalidArgument($"Face {faceId.Value} planar loop coedges do not form a contiguous chain.", PlanarCurveFlatteningFailedSource)]);@@ -2437,21 +2439,25 @@ public static class BrepDisplayTessellatorused[nextIndex] = true;orderedIndices.Add(nextIndex);+ chainedEndpoints.Add((nextStart, nextEnd));+ traversalSwapped.Add(swapped);currentEnd = nextEnd;}- if (!PointsAlmostEqual(orientedEndpoints[orderedIndices[0]].Start, currentEnd))+ if (!PointsAlmostEqual(chainedEndpoints[0].Start, currentEnd)){return KernelResult<IReadOnlyList<Point3D>>.Failure([CreateInvalidArgument($"Face {faceId.Value} planar loop coedges did not close after chaining.", PlanarCurveFlatteningFailedSource)]);}var flattened = new List<Point3D>();- AppendUniquePoint(flattened, orientedEndpoints[orderedIndices[0]].Start);+ AppendUniquePoint(flattened, chainedEndpoints[0].Start);- foreach (var index in orderedIndices)+ for (var chainIndex = 0; chainIndex < orderedIndices.Count; chainIndex++){+ var index = orderedIndices[chainIndex];var coedge = coedges[index];- var (segmentStart, segmentEnd) = orientedEndpoints[index];+ var (segmentStart, segmentEnd) = chainedEndpoints[chainIndex];+ var isTraversalSwapped = traversalSwapped[chainIndex];var curve = body.GetEdgeCurve(coedge.EdgeId);switch (curve.Kind)@@ -2460,7 +2466,7 @@ public static class BrepDisplayTessellatorAppendUniquePoint(flattened, segmentEnd);break;case CurveGeometryKind.Circle3:- var arcPointsResult = SampleCircleArc(body, coedge, curve.Circle3!.Value, segmentStart, segmentEnd, plane, faceId);+ var arcPointsResult = SampleCircleArc(body, coedge, isTraversalSwapped, curve.Circle3!.Value, segmentStart, segmentEnd, plane, faceId);if (!arcPointsResult.IsSuccess){return KernelResult<IReadOnlyList<Point3D>>.Failure(arcPointsResult.Diagnostics);@@ -2473,7 +2479,7 @@ public static class BrepDisplayTessellatorbreak;case CurveGeometryKind.BSpline3:- var splinePointsResult = SamplePlanarBSpline(body, coedge, curve.BSpline3!.Value, segmentStart, segmentEnd);+ var splinePointsResult = SamplePlanarBSpline(body, coedge, isTraversalSwapped, curve.BSpline3!.Value, segmentStart, segmentEnd);if (!splinePointsResult.IsSuccess){return KernelResult<IReadOnlyList<Point3D>>.Failure(splinePointsResult.Diagnostics);@@ -2486,7 +2492,7 @@ public static class BrepDisplayTessellatorbreak;case CurveGeometryKind.Ellipse3:- var ellipsePointsResult = SamplePlanarEllipse(body, coedge, curve.Ellipse3!.Value, segmentStart, segmentEnd, plane, faceId);+ var ellipsePointsResult = SamplePlanarEllipse(body, coedge, isTraversalSwapped, curve.Ellipse3!.Value, segmentStart, segmentEnd, plane, faceId);if (!ellipsePointsResult.IsSuccess){return KernelResult<IReadOnlyList<Point3D>>.Failure(ellipsePointsResult.Diagnostics);@@ -2516,6 +2522,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<IReadOnlyList<Point3D>> SampleCircleArc(BrepBody body,Coedge coedge,+ bool traversalSwapped,Circle3Curve circle,Point3D start,Point3D end,@@ -2553,7 +2560,7 @@ public static class BrepDisplayTessellatorreturn KernelResult<IReadOnlyList<Point3D>>.Success(points);}- var deltaResult = ResolveArcDelta(body, coedge, circle, start, end, plane, faceId);+ var deltaResult = ResolveArcDelta(body, coedge, traversalSwapped, circle, start, end, plane, faceId);if (!deltaResult.IsSuccess){return KernelResult<IReadOnlyList<Point3D>>.Failure(deltaResult.Diagnostics);@@ -2573,20 +2580,22 @@ public static class BrepDisplayTessellatorprivate static KernelResult<IReadOnlyList<Point3D>> SamplePlanarBSpline(BrepBody body,Coedge coedge,+ bool traversalSwapped,BSpline3Curve spline,Point3D start,Point3D end){var interval = new ParameterInterval(spline.DomainStart, spline.DomainEnd);var reverseSampleOrder = false;+ var effectiveIsReversed = coedge.IsReversed ^ traversalSwapped;if (body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var binding) && binding.TrimInterval is ParameterInterval trim){interval = trim;- reverseSampleOrder = coedge.IsReversed;+ reverseSampleOrder = effectiveIsReversed;}else{- reverseSampleOrder = coedge.IsReversed;+ reverseSampleOrder = effectiveIsReversed;}var sampled = CurveSampler.SampleBSpline(spline, interval).ToArray();@@ -2616,6 +2625,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<IReadOnlyList<Point3D>> SamplePlanarEllipse(BrepBody body,Coedge coedge,+ bool traversalSwapped,Ellipse3Curve ellipse,Point3D start,Point3D end,@@ -2632,7 +2642,7 @@ public static class BrepDisplayTessellatorCreateNotImplemented($"Face {faceId.Value} edge {coedge.EdgeId.Value} planar ellipse flattening requires the ellipse plane to match the face plane.", PlanarCurveFlatteningUnsupportedSource)]);}- var trimResult = ResolvePlanarEllipseTrim(body, coedge, ellipse, start, end, plane, faceId);+ var trimResult = ResolvePlanarEllipseTrim(body, coedge, traversalSwapped, ellipse, start, end, plane, faceId);if (!trimResult.IsSuccess){return KernelResult<IReadOnlyList<Point3D>>.Failure(trimResult.Diagnostics);@@ -2656,6 +2666,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<ParameterInterval> ResolvePlanarEllipseTrim(BrepBody body,Coedge coedge,+ bool traversalSwapped,Ellipse3Curve ellipse,Point3D start,Point3D end,@@ -2664,7 +2675,8 @@ public static class BrepDisplayTessellator{if (body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var binding) && binding.TrimInterval is ParameterInterval trim){- return KernelResult<ParameterInterval>.Success(coedge.IsReversed+ var effectiveIsReversed = coedge.IsReversed ^ traversalSwapped;+ return KernelResult<ParameterInterval>.Success(effectiveIsReversed? new ParameterInterval(trim.End, trim.Start): trim);}@@ -2690,6 +2702,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<(double StartAngle, double Delta)> ResolveArcDelta(BrepBody body,Coedge coedge,+ bool traversalSwapped,Circle3Curve circle,Point3D start,Point3D end,@@ -2701,8 +2714,9 @@ public static class BrepDisplayTessellatorif (body.Bindings.TryGetEdgeBinding(coedge.EdgeId, out var binding) && binding.TrimInterval is ParameterInterval trim){- var trimStart = coedge.IsReversed ? trim.End : trim.Start;- var trimEnd = coedge.IsReversed ? trim.Start : trim.End;+ var effectiveIsReversed = coedge.IsReversed ^ traversalSwapped;+ var trimStart = effectiveIsReversed ? trim.End : trim.Start;+ var trimEnd = effectiveIsReversed ? trim.Start : trim.End;var trimDelta = trimEnd - trimStart;if (double.IsFinite(trimDelta) && double.Abs(trimDelta) > 1e-9d){@@ -2805,11 +2819,13 @@ public static class BrepDisplayTessellatorIReadOnlyList<bool> used,Point3D currentEnd,out Point3D nextStart,- out Point3D nextEnd)+ out Point3D nextEnd,+ out bool swapped){var matchIndex = -1;nextStart = default;nextEnd = default;+ swapped = false;for (var i = 0; i < endpoints.Count; i++){@@ -2824,6 +2840,7 @@ public static class BrepDisplayTessellatormatchIndex = i;nextStart = start;nextEnd = end;+ swapped = false;break;}@@ -2832,6 +2849,7 @@ public static class BrepDisplayTessellatormatchIndex = i;nextStart = end;nextEnd = start;+ swapped = true;break;}}diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex a6fe8516..cc7204af 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -195,14 +195,14 @@"fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e2","path": "testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp","sizeBytes": 4658022,- "status": "importFail",- "firstFailureLayer": "tessellator",+ "status": "success",+ "firstFailureLayer": "","firstDiagnostic": {- "code": "NotImplemented",- "source": "Viewer.Tessellation.PlanarNonConvexTriangulationFailed",- "messagePrefix": "Face 4 planar loop triangulation failed because the polygon is not simple."+ "code": "Unknown",+ "source": "Audit.None",+ "messagePrefix": "No diagnostics."},- "diagnosticCount": 1,+ "diagnosticCount": 0,"exceptionEscaped": false,"topologyCounts": {"vertices": 396,@@ -210,10 +210,10 @@"faces": 247},"tessellationCounts": {- "facePatches": 0,- "edgePolylines": 0+ "facePatches": 247,+ "edgePolylines": 616},- "canonicalSha256": null+ "canonicalSha256": "bdc8e56bfd10539aa2d73c2bdecbcc94d7ffc3821517ffb77687f316590cd213"},{"fileId": "testdata_step242_nist_FTC_nist_ftc_09_asme1_ap242-e1",@@ -392,7 +392,7 @@"firstDiagnostic": {"code": "NotImplemented","source": "Viewer.Tessellation.PlanarNonConvexTriangulationFailed",- "messagePrefix": "Face 3 planar loop triangulation failed because the polygon is not simple."+ "messagePrefix": "Face 11 planar loop triangulation failed because the polygon is not simple."},"diagnosticCount": 1,"exceptionEscaped": false,