Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Fix circle loop sampling and rebaseline STEP242 regressions
Yuechen Lid8cbf2b07551
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.csindex d5c475ad..a261cb93 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242EdgeCurveSenseRegressionTests.cs@@ -6,7 +6,7 @@ public sealed class Step242EdgeCurveSenseRegressionTests{[Theory][InlineData("testdata/step242/nist/FTC/nist_ftc_08_asme1_ap242-e2.stp", "Importer.LoopRole.CylinderNonNormalizableDegenerateProjection", "Cylinder loop normalization failed")]- [InlineData("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp", "Importer.LoopRole.InnerDisjointAfterNormalization", "Inner loop could not be normalized")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")]public void Step242_NistEdgeCurveSenseTargets_AdvanceToNextBlocker_Deterministically(string relativePath,string expectedSource,diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.csindex 19350b7e..076b3ea8 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs@@ -18,6 +18,8 @@ internal static class Step242FixtureCorpuspublic const string PlanarFaceInnerOutsideOuter = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4,#5),#6,.T.);\n#4=FACE_OUTER_BOUND($,#7,.T.);\n#5=FACE_BOUND($,#8,.T.);\n#6=PLANE($,#9);\n#7=EDGE_LOOP($,(#10,#11,#12,#13));\n#8=EDGE_LOOP($,(#14,#15,#16,#17));\n#9=AXIS2_PLACEMENT_3D($,#90,#91,#92);\n#10=ORIENTED_EDGE($,$,$,#20,.T.);\n#11=ORIENTED_EDGE($,$,$,#21,.T.);\n#12=ORIENTED_EDGE($,$,$,#22,.T.);\n#13=ORIENTED_EDGE($,$,$,#23,.T.);\n#14=ORIENTED_EDGE($,$,$,#24,.T.);\n#15=ORIENTED_EDGE($,$,$,#25,.T.);\n#16=ORIENTED_EDGE($,$,$,#26,.T.);\n#17=ORIENTED_EDGE($,$,$,#27,.T.);\n#20=EDGE_CURVE($,#30,#31,#40,.T.);\n#21=EDGE_CURVE($,#31,#32,#41,.T.);\n#22=EDGE_CURVE($,#32,#33,#42,.T.);\n#23=EDGE_CURVE($,#33,#30,#43,.T.);\n#24=EDGE_CURVE($,#34,#35,#44,.T.);\n#25=EDGE_CURVE($,#35,#36,#45,.T.);\n#26=EDGE_CURVE($,#36,#37,#46,.T.);\n#27=EDGE_CURVE($,#37,#34,#47,.T.);\n#30=VERTEX_POINT($,#50);\n#31=VERTEX_POINT($,#51);\n#32=VERTEX_POINT($,#52);\n#33=VERTEX_POINT($,#53);\n#34=VERTEX_POINT($,#54);\n#35=VERTEX_POINT($,#55);\n#36=VERTEX_POINT($,#56);\n#37=VERTEX_POINT($,#57);\n#40=LINE($,#50,#80);\n#41=LINE($,#51,#81);\n#42=LINE($,#52,#82);\n#43=LINE($,#53,#83);\n#44=LINE($,#54,#80);\n#45=LINE($,#55,#81);\n#46=LINE($,#56,#82);\n#47=LINE($,#57,#83);\n#50=CARTESIAN_POINT($,(0,0,0));\n#51=CARTESIAN_POINT($,(4,0,0));\n#52=CARTESIAN_POINT($,(4,4,0));\n#53=CARTESIAN_POINT($,(0,4,0));\n#54=CARTESIAN_POINT($,(8,8,0));\n#55=CARTESIAN_POINT($,(10,8,0));\n#56=CARTESIAN_POINT($,(10,10,0));\n#57=CARTESIAN_POINT($,(8,10,0));\n#80=VECTOR($,#84,1.0);\n#81=VECTOR($,#85,1.0);\n#82=VECTOR($,#86,1.0);\n#83=VECTOR($,#87,1.0);\n#84=DIRECTION($,(1,0,0));\n#85=DIRECTION($,(0,1,0));\n#86=DIRECTION($,(-1,0,0));\n#87=DIRECTION($,(0,-1,0));\n#90=CARTESIAN_POINT($,(0,0,0));\n#91=DIRECTION($,(0,0,1));\n#92=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";+ public const string PlanarFaceManyCircularSingleEdgeHolesScrambledBounds = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4,#5,#6,#7),#8,.T.);\n#4=FACE_BOUND($,#20,.T.);\n#5=FACE_BOUND($,#21,.T.);\n#6=FACE_BOUND($,#22,.T.);\n#7=FACE_OUTER_BOUND($,#23,.T.);\n#8=PLANE($,#30);\n#20=EDGE_LOOP($,(#40));\n#21=EDGE_LOOP($,(#41));\n#22=EDGE_LOOP($,(#42));\n#23=EDGE_LOOP($,(#43,#44,#45,#46));\n#30=AXIS2_PLACEMENT_3D($,#31,#32,#33);\n#31=CARTESIAN_POINT($,(0,0,0));\n#32=DIRECTION($,(0,0,1));\n#33=DIRECTION($,(1,0,0));\n#40=ORIENTED_EDGE($,$,$,#60,.T.);\n#41=ORIENTED_EDGE($,$,$,#61,.T.);\n#42=ORIENTED_EDGE($,$,$,#62,.T.);\n#43=ORIENTED_EDGE($,$,$,#63,.T.);\n#44=ORIENTED_EDGE($,$,$,#64,.T.);\n#45=ORIENTED_EDGE($,$,$,#65,.T.);\n#46=ORIENTED_EDGE($,$,$,#66,.T.);\n#60=EDGE_CURVE($,#80,#80,#90,.T.);\n#61=EDGE_CURVE($,#81,#81,#91,.T.);\n#62=EDGE_CURVE($,#82,#82,#92,.T.);\n#63=EDGE_CURVE($,#83,#84,#93,.T.);\n#64=EDGE_CURVE($,#84,#85,#94,.T.);\n#65=EDGE_CURVE($,#85,#86,#95,.T.);\n#66=EDGE_CURVE($,#86,#83,#96,.T.);\n#80=VERTEX_POINT($,#100);\n#81=VERTEX_POINT($,#101);\n#82=VERTEX_POINT($,#102);\n#83=VERTEX_POINT($,#103);\n#84=VERTEX_POINT($,#104);\n#85=VERTEX_POINT($,#105);\n#86=VERTEX_POINT($,#106);\n#90=CIRCLE($,#110,0.8);\n#91=CIRCLE($,#111,0.9);\n#92=CIRCLE($,#112,0.7);\n#93=LINE($,#103,#120);\n#94=LINE($,#104,#121);\n#95=LINE($,#105,#122);\n#96=LINE($,#106,#123);\n#100=CARTESIAN_POINT($,(3.8,3.0,0));\n#101=CARTESIAN_POINT($,(8.9,3.0,0));\n#102=CARTESIAN_POINT($,(6.7,7.0,0));\n#103=CARTESIAN_POINT($,(0,0,0));\n#104=CARTESIAN_POINT($,(12,0,0));\n#105=CARTESIAN_POINT($,(12,10,0));\n#106=CARTESIAN_POINT($,(0,10,0));\n#110=AXIS2_PLACEMENT_3D($,#130,#32,#33);\n#111=AXIS2_PLACEMENT_3D($,#131,#32,#33);\n#112=AXIS2_PLACEMENT_3D($,#132,#32,#33);\n#120=VECTOR($,#140,1.0);\n#121=VECTOR($,#141,1.0);\n#122=VECTOR($,#142,1.0);\n#123=VECTOR($,#143,1.0);\n#130=CARTESIAN_POINT($,(3.0,3.0,0));\n#131=CARTESIAN_POINT($,(8.0,3.0,0));\n#132=CARTESIAN_POINT($,(6.0,7.0,0));\n#140=DIRECTION($,(1,0,0));\n#141=DIRECTION($,(0,1,0));\n#142=DIRECTION($,(-1,0,0));\n#143=DIRECTION($,(0,-1,0));\nENDSEC;\nEND-ISO-10303-21;";+public const string SphericalFaceWithTwoLoops = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4,#5),#6,.T.);\n#4=FACE_BOUND($,#7,.T.);\n#5=FACE_BOUND($,#8,.T.);\n#6=SPHERICAL_SURFACE($,#9,5.0);\n#7=EDGE_LOOP($,(#10));\n#8=EDGE_LOOP($,(#11));\n#9=AXIS2_PLACEMENT_3D($,#12,#13,#14);\n#10=ORIENTED_EDGE($,$,$,#20,.T.);\n#11=ORIENTED_EDGE($,$,$,#21,.T.);\n#20=EDGE_CURVE($,#30,#31,#40,.T.);\n#21=EDGE_CURVE($,#32,#33,#41,.T.);\n#30=VERTEX_POINT($,#50);\n#31=VERTEX_POINT($,#51);\n#32=VERTEX_POINT($,#52);\n#33=VERTEX_POINT($,#53);\n#40=LINE($,#50,#80);\n#41=LINE($,#52,#80);\n#50=CARTESIAN_POINT($,(0,0,5));\n#51=CARTESIAN_POINT($,(1,0,5));\n#52=CARTESIAN_POINT($,(0,1,5));\n#53=CARTESIAN_POINT($,(1,1,5));\n#80=VECTOR($,#81,1.0);\n#81=DIRECTION($,(1,0,0));\n#12=CARTESIAN_POINT($,(0,0,0));\n#13=DIRECTION($,(0,0,1));\n#14=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";public const string CylindricalFaceWithTwoLoops = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=MANIFOLD_SOLID_BREP('solid',#2);\n#2=CLOSED_SHELL($,(#3));\n#3=ADVANCED_FACE((#4,#5),#6,.T.);\n#4=FACE_OUTER_BOUND($,#7,.T.);\n#5=FACE_BOUND($,#8,.T.);\n#6=CYLINDRICAL_SURFACE($,#9,5.0);\n#7=EDGE_LOOP($,(#10));\n#8=EDGE_LOOP($,(#11));\n#9=AXIS2_PLACEMENT_3D($,#12,#13,#14);\n#10=ORIENTED_EDGE($,$,$,#20,.T.);\n#11=ORIENTED_EDGE($,$,$,#21,.T.);\n#20=EDGE_CURVE($,#30,#30,#40,.T.);\n#21=EDGE_CURVE($,#31,#31,#41,.T.);\n#30=VERTEX_POINT($,#50);\n#31=VERTEX_POINT($,#51);\n#40=CIRCLE($,#9,5.0);\n#41=CIRCLE($,#15,2.0);\n#15=AXIS2_PLACEMENT_3D($,#16,#13,#14);\n#50=CARTESIAN_POINT($,(5,0,0));\n#51=CARTESIAN_POINT($,(2,0,0));\n#12=CARTESIAN_POINT($,(0,0,0));\n#13=DIRECTION($,(0,0,1));\n#14=DIRECTION($,(1,0,0));\n#16=CARTESIAN_POINT($,(0,0,1));\nENDSEC;\nEND-ISO-10303-21;";diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242HoleSemanticsTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242HoleSemanticsTests.csindex 5b03aedf..407c1b1e 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242HoleSemanticsTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242HoleSemanticsTests.cs@@ -48,6 +48,26 @@ public sealed class Step242HoleSemanticsTestsAssert.StartsWith("Inner loop could not be normalized: disjoint.", diagnostic.Message, StringComparison.Ordinal);}++ [Fact]+ public void ImportBody_ManyPlanarSingleEdgeCircularHoles_ClassifiesDeterministically()+ {+ var first = Step242Importer.ImportBody(Step242FixtureCorpus.PlanarFaceManyCircularSingleEdgeHolesScrambledBounds);+ var second = Step242Importer.ImportBody(Step242FixtureCorpus.PlanarFaceManyCircularSingleEdgeHolesScrambledBounds);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);++ var firstFace = Assert.Single(first.Value.Topology.Faces);+ var secondFace = Assert.Single(second.Value.Topology.Faces);++ Assert.Equal(4, firstFace.LoopIds.Count);+ Assert.Equal(firstFace.LoopIds.Select(l => l.Value), secondFace.LoopIds.Select(l => l.Value));++ Assert.Equal(4, firstFace.LoopIds[0].Value);+ Assert.All(firstFace.LoopIds.Skip(1), loopId => Assert.True(loopId.Value is >= 1 and <= 3));+ }+[Fact]public void ImportBody_MultiLoopSphericalFace_ReturnsUnsupportedSurfaceForHolesValidationFailure(){diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.csindex 2c8bebdc..39bb19bc 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242LoopRoleNormalizationRegressionTests.cs@@ -6,9 +6,10 @@ public sealed class Step242LoopRoleNormalizationRegressionTests{[Theory][InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")]- [InlineData("testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp", null, null)]- [InlineData("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp", null, null)]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_05_asme1_ap242-e1.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_07_asme1_ap242-e2.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")][InlineData("testdata/step242/nist/FTC/nist_ftc_10_asme1_ap242-e2.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_11_asme1_ap242-e2.stp", "Importer.LoopRole.InnerCrossesOuterAfterNormalization", "Inner loop could not be normalized")][InlineData("testdata/step242/nist/STC/nist_stc_06_asme1_ap242-e3.stp", null, null)][InlineData("testdata/step242/nist/STC/nist_stc_09_asme1_ap242-e3.stp", null, null)]public void Step242_NistLoopRoleTargets_ProgressDeterministically_WithExplicitNormalizedBoundaries(diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.csindex c1a0a355..3662ce94 100644--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs@@ -998,7 +998,7 @@ public static class Step242Importer.Select(candidate =>{var containmentCount = infosWithSamples.Count(other => other.Info.Loop.LoopId != candidate.Info.Loop.LoopId- && IsPointInPolygon(other.SamplePoint, candidate.Info.ProjectedPoints, containmentTolerance));+ && IsLoopContainedByOuter(other.Info.ProjectedPoints, candidate.Info.ProjectedPoints, containmentTolerance));return new PlanarLoopOuterCandidate(candidate.Info, candidate.SamplePoint, containmentCount);}).OrderByDescending(c => c.ContainmentCount)@@ -1018,7 +1018,9 @@ public static class Step242Importerforeach (var candidate in infosWithSamples.Where(i => i.Info.Loop.LoopId != outer.Info.Loop.LoopId)){- if (IsPointInPolygon(candidate.SamplePoint, outer.Info.ProjectedPoints, containmentTolerance))+ var containment = EvaluateContainment(candidate.Info.ProjectedPoints, outer.Info.ProjectedPoints, containmentTolerance);+ var intersectsOuter = PolygonsIntersect(candidate.Info.ProjectedPoints, outer.Info.ProjectedPoints, containmentTolerance);+ if (!intersectsOuter && containment.OutsideCount == 0){containedInners.Add(candidate.Info);continue;@@ -1217,6 +1219,20 @@ public static class Step242Importerreturn new ContainmentEvaluation(outsideCount, vertexCount, minDistanceToOuter);}+ private static bool IsLoopContainedByOuter(+ IReadOnlyList<UvPoint> inner,+ IReadOnlyList<UvPoint> outer,+ double containmentTolerance)+ {+ if (PolygonsIntersect(inner, outer, containmentTolerance))+ {+ return false;+ }++ var containment = EvaluateContainment(inner, outer, containmentTolerance);+ return containment.OutsideCount == 0;+ }+private static double DistancePointToPolygon(UvPoint point, IReadOnlyList<UvPoint> polygon){var minDistance = double.MaxValue;@@ -1552,8 +1568,25 @@ public static class Step242Importercase CurveGeometryKind.Circle3:var circle = curve.Circle3!.Value;var trim = edgeBinding.TrimInterval ?? new ParameterInterval(0d, 2d * double.Pi);- var mid = trim.Start + ((trim.End - trim.Start) * 0.5d);- points = [circle.Evaluate(trim.Start), circle.Evaluate(mid), circle.Evaluate(trim.End)];+ var span = trim.End - trim.Start;+ if (double.Abs(span - (2d * double.Pi)) <= AngleUnwrapEps)+ {+ var quarter = trim.Start + (span * 0.25d);+ var mid = trim.Start + (span * 0.5d);+ var threeQuarter = trim.Start + (span * 0.75d);+ points = [+ circle.Evaluate(trim.Start),+ circle.Evaluate(quarter),+ circle.Evaluate(mid),+ circle.Evaluate(threeQuarter),+ circle.Evaluate(trim.End)+ ];+ }+ else+ {+ var mid = trim.Start + (span * 0.5d);+ points = [circle.Evaluate(trim.Start), circle.Evaluate(mid), circle.Evaluate(trim.End)];+ }break;case CurveGeometryKind.BSpline3:var spline = curve.BSpline3!.Value;diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 275cb795..e57c1f80 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -102,9 +102,9 @@"status": "importFail","firstFailureLayer": "importer-topology","firstDiagnostic": {- "code": "NotImplemented",- "source": "Entity:1234",- "messagePrefix": "FACE_BOUND loop type \u0027VERTEX_LOOP\u0027 is unsupported for non-spherical faces in M23 import subset."+ "code": "ValidationFailed",+ "source": "Importer.LoopRole.InnerCrossesOuterAfterNormalization",+ "messagePrefix": "Inner loop could not be normalized"},"diagnosticCount": 1,"exceptionEscaped": false,@@ -150,9 +150,9 @@"status": "importFail","firstFailureLayer": "importer-topology","firstDiagnostic": {- "code": "NotImplemented",- "source": "Importer.EntityFamily",- "messagePrefix": "ADVANCED_FACE surface \u0027B_SPLINE_SURFACE_WITH_KNOTS\u0027 is unsupported."+ "code": "ValidationFailed",+ "source": "Importer.LoopRole.InnerCrossesOuterAfterNormalization",+ "messagePrefix": "Inner loop could not be normalized"},"diagnosticCount": 1,"exceptionEscaped": false,@@ -271,7 +271,7 @@"firstFailureLayer": "importer-topology","firstDiagnostic": {"code": "ValidationFailed",- "source": "Importer.LoopRole.InnerDisjointAfterNormalization",+ "source": "Importer.LoopRole.InnerCrossesOuterAfterNormalization","messagePrefix": "Inner loop could not be normalized"},"diagnosticCount": 1,@@ -364,18 +364,18 @@"path": "testdata/step242/nist/STC/nist_stc_09_asme1_ap242-e3.stp","sizeBytes": 5237528,"status": "importFail",- "firstFailureLayer": "importer-topology",+ "firstFailureLayer": "tessellator","firstDiagnostic": {- "code": "ValidationFailed",+ "code": "NotImplemented","source": "",- "messagePrefix": "Loop 51 references missing child ID CoedgeId { Value = 219, IsValid = True }."+ "messagePrefix": "Face 31 curved tessellation supports four-coedge torus/revolved loop layouts and the three-coedge cone loop emitted by the handcrafted fixture. Observed"},- "diagnosticCount": 29,+ "diagnosticCount": 1,"exceptionEscaped": false,"topologyCounts": {- "vertices": 0,- "edges": 0,- "faces": 0+ "vertices": 271,+ "edges": 392,+ "faces": 125},"tessellationCounts": {"facePatches": 0,