Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Document conical semi-angle degree normalization as compatibility heuristic
Yuechen Li6b8b5bb40cf7
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.csnew file mode 100644index 00000000..aa7ba1b6--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ConicalSurfaceRegressionTests.cs@@ -0,0 +1,66 @@+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Step242;++public sealed class Step242ConicalSurfaceRegressionTests+{+ [Fact]+ public void Step242_ConicalSurfaceDecoder_AcceptsZeroRadiusWithDegreeSemiAngle()+ {+ const string text = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n"+ + "#10=CONICAL_SURFACE('',#20,0.,59.);\n"+ + "#20=AXIS2_PLACEMENT_3D('',#21,#22,#23);\n"+ + "#21=CARTESIAN_POINT('',(1.,2.,3.));\n"+ + "#22=DIRECTION('',(0.,0.,1.));\n"+ + "#23=DIRECTION('',(1.,0.,0.));\n"+ + "ENDSEC;\nEND-ISO-10303-21;";++ var parse = Step242SubsetParser.Parse(text);+ Assert.True(parse.IsSuccess);++ var coneEntityResult = parse.Value.TryGetEntity(10, "CONICAL_SURFACE");+ Assert.True(coneEntityResult.IsSuccess);++ var cone = Step242SubsetDecoder.ReadConicalSurface(parse.Value, coneEntityResult.Value);+ Assert.True(cone.IsSuccess);++ Assert.Equal(1d, cone.Value.Apex.X, 9);+ Assert.Equal(2d, cone.Value.Apex.Y, 9);+ Assert.Equal(3d, cone.Value.Apex.Z, 9);+ Assert.Equal(59d * (double.Pi / 180d), cone.Value.SemiAngleRadians, 12);+ }++ [Theory]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp", "tessellator", "Viewer.Tessellation.CylinderTrimUnsupported", "Cylindrical face tessellation could not derive a bounded trim patch.")]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_02_asme1_ap242-e2.stp", "importer-geometry", "Importer.Geometry.CircleTrim", "Unable to compute circle trim from supplied vertices.")]+ [InlineData("testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp", "importer-topology", "Importer.LoopRole.InnerNotContained", "Inner loop is not contained by outer loop.")]+ [InlineData("testdata/step242/nist/FTC/nist_ftc_06_asme1_ap242-e2.stp", "tessellator", "", "Face 2 curved tessellation does not support this torus/revolved boundary topology yet. Observed")]+ public void Step242_NistConicalTargets_AdvancePastConicalRadius_AndReportDeterministicNextBlocker(+ string relativePath,+ string expectedLayer,+ string expectedSource,+ string expectedMessagePrefix)+ {+ var entry = new Step242CorpusManifestEntry(+ Id: Path.GetFileNameWithoutExtension(relativePath),+ Path: relativePath,+ Group: "nist-conical-regression",+ Notes: "regression",+ ExpectedFirstDiagnostic: null,+ ExpectHashStableAfterCanonicalization: null,+ ExpectTopologyCounts: null,+ ExpectGeometryKinds: null);++ var first = Step242CorpusManifestRunner.RunOne(entry);+ var second = Step242CorpusManifestRunner.RunOne(entry);++ Assert.DoesNotContain("CONICAL_SURFACE radius", first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);+ Assert.Equal(expectedLayer, first.FirstFailureLayer);+ Assert.Equal(expectedSource, first.FirstDiagnostic.Source);+ Assert.StartsWith(expectedMessagePrefix, first.FirstDiagnostic.MessagePrefix, StringComparison.Ordinal);++ 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/Step242/Step242SubsetDecoder.cs b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.csindex 74e221d1..ae793425 100644--- a/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs+++ b/Aetheris.Kernel.Core/Step242/Step242SubsetDecoder.cs@@ -501,7 +501,7 @@ internal static class Step242SubsetDecoderreturn KernelResult<ConeSurface>.Failure(placementResult.Diagnostics);}- var radiusResult = ReadPositiveNumber(coneEntity, 2, "CONICAL_SURFACE radius", "Importer.Geometry.Cone");+ var radiusResult = ReadNonNegativeNumber(coneEntity, 2, "CONICAL_SURFACE radius", "Importer.Geometry.Cone");if (!radiusResult.IsSuccess){return KernelResult<ConeSurface>.Failure(radiusResult.Diagnostics);@@ -513,17 +513,19 @@ internal static class Step242SubsetDecoderreturn KernelResult<ConeSurface>.Failure(semiAngleResult.Diagnostics);}- if (semiAngleResult.Value <= 0d || semiAngleResult.Value >= (double.Pi / 2d))+ var normalizedSemiAngleResult = NormalizeConicalSemiAngle(semiAngleResult.Value);+ if (!normalizedSemiAngleResult.IsSuccess){- return FailureCone("CONICAL_SURFACE semi-angle must be in the range (0, pi/2).", "Importer.Geometry.Cone");+ return KernelResult<ConeSurface>.Failure(normalizedSemiAngleResult.Diagnostics);}- var offset = placementResult.Value.Axis.ToVector() * (radiusResult.Value / double.Tan(semiAngleResult.Value));+ var normalizedSemiAngle = normalizedSemiAngleResult.Value;+ var offset = placementResult.Value.Axis.ToVector() * (radiusResult.Value / double.Tan(normalizedSemiAngle));var apex = placementResult.Value.Origin - offset;try{- return KernelResult<ConeSurface>.Success(new ConeSurface(apex, placementResult.Value.Axis, semiAngleResult.Value, placementResult.Value.ReferenceAxis));+ return KernelResult<ConeSurface>.Success(new ConeSurface(apex, placementResult.Value.Axis, normalizedSemiAngle, placementResult.Value.ReferenceAxis));}catch (ArgumentException){@@ -531,6 +533,29 @@ internal static class Step242SubsetDecoder}}+ private static KernelResult<double> NormalizeConicalSemiAngle(double rawSemiAngle)+ {+ if (!double.IsFinite(rawSemiAngle) || rawSemiAngle <= 0d)+ {+ return FailureNumberCode("CONICAL_SURFACE semi-angle must be greater than zero.", "Importer.Geometry.Cone");+ }++ if (rawSemiAngle < (double.Pi / 2d))+ {+ return KernelResult<double>.Success(rawSemiAngle);+ }++ if (rawSemiAngle < 90d)+ {+ // Compatibility heuristic: observed NIST/AP242 corpus inputs contain degree-form cone semi-angle values+ // (for example near 59). This normalization is intentionally limited and is not a claim that AP242+ // generically encodes CONICAL_SURFACE semi-angle in degrees.+ return KernelResult<double>.Success(rawSemiAngle * (double.Pi / 180d));+ }++ return FailureNumberCode("CONICAL_SURFACE semi-angle must be in the range (0, pi/2) or (0, 90) degrees.", "Importer.Geometry.Cone");+ }+private static KernelResult<(Point3D Origin, Direction3D Axis, Direction3D ReferenceAxis)> ReadAxis2Placement3D(Step242ParsedDocument document,Step242ParsedEntity ownerEntity,@@ -640,6 +665,22 @@ internal static class Step242SubsetDecoderreturn numberResult;}+ private static KernelResult<double> ReadNonNegativeNumber(Step242ParsedEntity entity, int argumentIndex, string context, string source)+ {+ var numberResult = ReadNumberArgument(entity, argumentIndex, context, source);+ if (!numberResult.IsSuccess)+ {+ return numberResult;+ }++ if (numberResult.Value < 0d)+ {+ return FailureNumberCode($"{context}: value must be greater than or equal to zero.", source);+ }++ return numberResult;+ }+private static KernelResult<Point3D> ReadCartesianPoint(Step242ParsedEntity pointEntity, string context){if (pointEntity.Arguments.Count < 2)diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 38a676d8..38246c1b 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -4,18 +4,18 @@"path": "testdata/step242/nist/CTC/nist_ctc_01_asme1_ap242-e1.stp","sizeBytes": 391739,"status": "importFail",- "firstFailureLayer": "importer-geometry",+ "firstFailureLayer": "tessellator","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Importer.Geometry.Cone",- "messagePrefix": "CONICAL_SURFACE radius"+ "code": "NotImplemented",+ "source": "Viewer.Tessellation.CylinderTrimUnsupported",+ "messagePrefix": "Cylindrical face tessellation could not derive a bounded trim patch."},"diagnosticCount": 1,"exceptionEscaped": false,"topologyCounts": {- "vertices": 0,- "edges": 0,- "faces": 0+ "vertices": 206,+ "edges": 318,+ "faces": 117},"tessellationCounts": {"facePatches": 0,@@ -30,9 +30,9 @@"status": "importFail","firstFailureLayer": "importer-geometry","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Importer.Geometry.Cone",- "messagePrefix": "CONICAL_SURFACE radius"+ "code": "ValidationFailed",+ "source": "Importer.Geometry.CircleTrim",+ "messagePrefix": "Unable to compute circle trim from supplied vertices."},"diagnosticCount": 1,"exceptionEscaped": false,@@ -76,11 +76,11 @@"path": "testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp","sizeBytes": 1265846,"status": "importFail",- "firstFailureLayer": "importer-geometry",+ "firstFailureLayer": "importer-topology","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Importer.Geometry.Cone",- "messagePrefix": "CONICAL_SURFACE radius"+ "code": "ValidationFailed",+ "source": "Importer.LoopRole.InnerNotContained",+ "messagePrefix": "Inner loop is not contained by outer loop."},"diagnosticCount": 1,"exceptionEscaped": false,@@ -124,18 +124,18 @@"path": "testdata/step242/nist/FTC/nist_ftc_06_asme1_ap242-e2.stp","sizeBytes": 1960222,"status": "importFail",- "firstFailureLayer": "importer-geometry",+ "firstFailureLayer": "tessellator","firstDiagnostic": {- "code": "InvalidArgument",- "source": "Importer.Geometry.Cone",- "messagePrefix": "CONICAL_SURFACE radius"+ "code": "NotImplemented",+ "source": "",+ "messagePrefix": "Face 2 curved tessellation does not support this torus/revolved boundary topology yet. Observed"},"diagnosticCount": 1,"exceptionEscaped": false,"topologyCounts": {- "vertices": 0,- "edges": 0,- "faces": 0+ "vertices": 310,+ "edges": 476,+ "faces": 187},"tessellationCounts": {"facePatches": 0,