Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Restrict three-coedge revolved topology handling to cones
Yuechen Lifbed75894449
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.csindex 4d012570..64014c43 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs@@ -463,6 +463,65 @@ public sealed class Step242ImporterTestsAssert.True(patchA.TriangleIndices.SequenceEqual(patchB.TriangleIndices));}++ [Fact]+ public void Step242_HandcraftedConeFixture_UsesThreeCoedgeSeamTopology_AndTessellates()+ {+ var text = LoadFixture("testdata/step242/handcrafted/baseline/cone.step");++ var import = Step242Importer.ImportBody(text);+ Assert.True(import.IsSuccess);++ var coneFace = Assert.Single(import.Value.Topology.Faces, face =>+ {+ Assert.True(import.Value.Bindings.TryGetFaceBinding(face.Id, out var binding));+ Assert.True(import.Value.Geometry.TryGetSurface(binding.SurfaceGeometryId, out var surface));+ return surface!.Kind == SurfaceGeometryKind.Cone;+ });++ var loopIds = import.Value.GetLoopIds(coneFace.Id);+ var loopId = Assert.Single(loopIds);+ var coedges = import.Value.GetCoedgeIds(loopId)+ .Select(id => import.Value.Topology.GetCoedge(id))+ .ToArray();++ Assert.Equal(3, coedges.Length);+ Assert.Equal(2, coedges.Count(coedge => import.Value.GetEdgeCurve(coedge.EdgeId).Kind == CurveGeometryKind.Line3));+ Assert.Equal(1, coedges.Count(coedge => import.Value.GetEdgeCurve(coedge.EdgeId).Kind == CurveGeometryKind.Circle3));++ var seamUseCount = coedges.Count(coedge =>+ {+ var edge = import.Value.Topology.GetEdge(coedge.EdgeId);+ return edge.StartVertexId == edge.EndVertexId;+ });+ Assert.Equal(1, seamUseCount);++ var lineEdgeIds = coedges+ .Where(coedge => import.Value.GetEdgeCurve(coedge.EdgeId).Kind == CurveGeometryKind.Line3)+ .Select(coedge => coedge.EdgeId)+ .Distinct()+ .ToArray();+ Assert.Single(lineEdgeIds);++ var tessellationA = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellationA.IsSuccess);+ Assert.DoesNotContain(tessellationA.Diagnostics,+ d => d.Message.Contains("four-coedge torus/revolved loop layouts", StringComparison.OrdinalIgnoreCase));++ var tessellationB = BrepDisplayTessellator.Tessellate(import.Value);+ Assert.True(tessellationB.IsSuccess);++ var patchA = Assert.Single(tessellationA.Value.FacePatches, p => p.FaceId == coneFace.Id);+ var patchB = Assert.Single(tessellationB.Value.FacePatches, p => p.FaceId == coneFace.Id);++ Assert.Equal(patchA.Positions.Count, patchB.Positions.Count);+ Assert.Equal(patchA.Normals.Count, patchB.Normals.Count);+ Assert.Equal(patchA.TriangleIndices.Count, patchB.TriangleIndices.Count);+ Assert.True(patchA.Positions.SequenceEqual(patchB.Positions));+ Assert.True(patchA.Normals.SequenceEqual(patchB.Normals));+ Assert.True(patchA.TriangleIndices.SequenceEqual(patchB.TriangleIndices));+ }+[Fact]public void Step242_NistFile_WithToroidalSurface_AdvancesPastToroidalBlocker(){diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.csindex 73b7378a..2c678b04 100644--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs@@ -254,7 +254,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<DisplayFaceMeshPatch> TessellateConeFace(BrepBody body, FaceId faceId, ConeSurface cone, DisplayTessellationOptions options){- var parameters = GetRevolvedFaceParameters(body, faceId, options, radiusHint: 1d);+ var parameters = GetRevolvedFaceParameters(body, faceId, options, radiusHint: 1d, allowThreeCoedgeConeTopology: true);if (!parameters.IsSuccess){return KernelResult<DisplayFaceMeshPatch>.Failure(parameters.Diagnostics);@@ -325,7 +325,7 @@ public static class BrepDisplayTessellatorprivate static KernelResult<DisplayFaceMeshPatch> TessellateTorusFace(BrepBody body, FaceId faceId, TorusSurface torus, DisplayTessellationOptions options){- var parameters = GetRevolvedFaceParameters(body, faceId, options, radiusHint: torus.MajorRadius + torus.MinorRadius);+ var parameters = GetRevolvedFaceParameters(body, faceId, options, radiusHint: torus.MajorRadius + torus.MinorRadius, allowThreeCoedgeConeTopology: false);if (!parameters.IsSuccess){return KernelResult<DisplayFaceMeshPatch>.Failure(parameters.Diagnostics);@@ -345,7 +345,8 @@ public static class BrepDisplayTessellatorBrepBody body,FaceId faceId,DisplayTessellationOptions options,- double radiusHint)+ double radiusHint,+ bool allowThreeCoedgeConeTopology){var loopIds = body.GetLoopIds(faceId);if (loopIds.Count != 1)@@ -357,14 +358,10 @@ public static class BrepDisplayTessellator.Select(id => body.Topology.GetCoedge(id)).ToArray();- if (coedges.Length != 4)- {- return KernelResult<(double, double, int, int)>.Failure([CreateNotImplemented($"Face {faceId.Value} curved tessellation supports four-coedge torus/revolved loop layouts. Observed: {DescribeRevolvedLoopTopology(body, coedges)}")]);- }-var lineCoedges = coedges.Where(c => body.GetEdgeCurve(c.EdgeId).Kind == CurveGeometryKind.Line3).ToArray();var circleCoedges = coedges.Where(c => body.GetEdgeCurve(c.EdgeId).Kind == CurveGeometryKind.Circle3).ToArray();- if (lineCoedges.Length == 2 && circleCoedges.Length == 2)++ if (coedges.Length == 4 && lineCoedges.Length == 2 && circleCoedges.Length == 2){if (!body.Bindings.TryGetEdgeBinding(lineCoedges[0].EdgeId, out var seamBinding)){@@ -378,6 +375,32 @@ public static class BrepDisplayTessellatorreturn KernelResult<(double, double, int, int)>.Success((seamInterval.Start, seamInterval.End, angularSegments, axialSegments));}+ if (allowThreeCoedgeConeTopology && coedges.Length == 3 && lineCoedges.Length == 2 && circleCoedges.Length == 1)+ {+ var lineEdgeIds = lineCoedges.Select(c => c.EdgeId).Distinct().ToArray();+ if (lineEdgeIds.Length != 1)+ {+ return KernelResult<(double, double, int, int)>.Failure([CreateNotImplemented($"Face {faceId.Value} curved tessellation expected mirrored line uses for this cone/revolved topology. Observed: {DescribeRevolvedLoopTopology(body, coedges)}")]);+ }++ if (!body.Bindings.TryGetEdgeBinding(lineEdgeIds[0], out var lineTrimBinding))+ {+ return KernelResult<(double, double, int, int)>.Failure([CreateNotImplemented($"Face {faceId.Value} line trim edge is missing curve trim binding.")]);+ }++ var lineTrimInterval = lineTrimBinding.TrimInterval ?? new ParameterInterval(0d, 1d);+ var angularSegments = CalculateSegmentCount(2d * double.Pi, System.Math.Max(1e-6d, radiusHint), options);+ var axialSegments = System.Math.Max(1, System.Math.Clamp((int)double.Ceiling((lineTrimInterval.End - lineTrimInterval.Start) / options.ChordTolerance), 1, options.MaximumSegments));+ return KernelResult<(double, double, int, int)>.Success((lineTrimInterval.Start, lineTrimInterval.End, angularSegments, axialSegments));+ }++ if (coedges.Length != 4)+ {+ return KernelResult<(double, double, int, int)>.Failure([CreateNotImplemented(allowThreeCoedgeConeTopology+ ? $"Face {faceId.Value} curved tessellation supports four-coedge torus/revolved loop layouts and the three-coedge cone loop emitted by the handcrafted fixture. Observed: {DescribeRevolvedLoopTopology(body, coedges)}"+ : $"Face {faceId.Value} curved tessellation supports four-coedge torus/revolved loop layouts. Observed: {DescribeRevolvedLoopTopology(body, coedges)}")]);+ }+var uniqueEdgeIds = coedges.Select(c => c.EdgeId).Distinct()