Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Import: honour FACE_BOUND orientation .F. by using the loop reversed
Claude62325b50f892
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242FaceBoundOrientationTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242FaceBoundOrientationTests.csnew file mode 100644index 00000000..6c1b0f24--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242FaceBoundOrientationTests.cs@@ -0,0 +1,49 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Step242;++/// <summary>FACE_BOUND orientation .F. means the face uses its EDGE_LOOP reversed.</summary>+public sealed class Step242FaceBoundOrientationTests+{+ // 405 of CTC-04's bounds are .F.; its inside pocket corners are concave sphere octants.+ private const string Ctc04 = "testdata/step242/nist/CTC/nist_ctc_04_asme1_ap242-e1.stp";++ [Fact]+ public void ReversedBounds_KeepConcaveSphereCornersAsOctants_ThroughExportAndReimport()+ {+ var imported = Step242Corpus.Body(Ctc04);+ AssertSphereCornersAreOctants(imported);++ var exported = Step242Exporter.ExportBody(imported);+ Assert.True(exported.IsSuccess, string.Join("\n", exported.Diagnostics.Select(d => d.Message)));+ var reimported = Step242Importer.ImportBody(exported.Value);+ Assert.True(reimported.IsSuccess, string.Join("\n", reimported.Diagnostics.Select(d => d.Message)));+ AssertSphereCornersAreOctants(reimported.Value);+ }++ private static void AssertSphereCornersAreOctants(BrepBody body)+ {+ var mesh = BrepDisplayTessellator.Tessellate(body);+ Assert.True(mesh.IsSuccess);+ var spheres = 0;+ foreach (var patch in mesh.Value.FacePatches)+ {+ if (!body.TryGetFaceSurfaceGeometry(patch.FaceId, out var surface) || surface!.Kind != SurfaceGeometryKind.Sphere) continue;+ spheres++;+ var area = Enumerable.Range(0, patch.TriangleIndices.Count / 3).Sum(t =>+ {+ var a = patch.Positions[patch.TriangleIndices[3 * t]];+ var b = patch.Positions[patch.TriangleIndices[3 * t + 1]];+ var c = patch.Positions[patch.TriangleIndices[3 * t + 2]];+ return (b - a).Cross(c - a).Length / 2;+ });+ var r = surface.Sphere!.Value.Radius;+ // A corner patch is at most an octant; a reversed loop draws the other seven eighths.+ Assert.True(area <= 4 * System.Math.PI * r * r / 8 * 1.05, $"sphere face {patch.FaceId.Value}: area {area:F2} exceeds an octant of r={r}");+ }+ Assert.Equal(22, spheres);+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242OrientationSemanticsTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242OrientationSemanticsTests.csindex 0fc1b9da..6b5f2596 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242OrientationSemanticsTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242OrientationSemanticsTests.cs@@ -20,8 +20,13 @@ public sealed class Step242OrientationSemanticsTestsAssert.Equal(forwardCoedge.IsReversed, reversedCoedge.IsReversed);}+ /// <summary>+ /// FACE_BOUND orientation .F. means the face uses its EDGE_LOOP reversed (ISO 10303-42): the loop order+ /// reverses and every oriented edge flips. Flipping senses without reversing order (the pre-March 2026+ /// handler) breaks loop connectivity; ignoring the flag leaves loops running against their faces.+ /// </summary>[Fact]- public void ImportBody_FaceBoundOrientationFalse_DoesNotFlipCoedgeReversalStateDuringAssembly()+ public void ImportBody_FaceBoundOrientationFalse_UsesTheLoopReversed(){var forward = Step242Importer.ImportBody(BuildSingleTriangleStep(edgeCurveSameSense: true, faceBoundOrientation: true, advancedFaceSameSense: true));var reversed = Step242Importer.ImportBody(BuildSingleTriangleStep(edgeCurveSameSense: true, faceBoundOrientation: false, advancedFaceSameSense: true));@@ -31,7 +36,7 @@ public sealed class Step242OrientationSemanticsTestsvar forwardCoedge = Assert.Single(forward.Value.Topology.Coedges);var reversedCoedge = Assert.Single(reversed.Value.Topology.Coedges);- Assert.Equal(forwardCoedge.IsReversed, reversedCoedge.IsReversed);+ Assert.NotEqual(forwardCoedge.IsReversed, reversedCoedge.IsReversed);}/// <summary>diff --git a/Aetheris.Kernel.Core/Step242/Step242Importer.cs b/Aetheris.Kernel.Core/Step242/Step242Importer.csindex 5d918498..5bb5f231 100644--- a/Aetheris.Kernel.Core/Step242/Step242Importer.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Importer.cs@@ -356,7 +356,7 @@ public static class Step242Importerreturn KernelResult<BrepBody>.Failure(boundOrientationResult.Diagnostics);}- _ = boundOrientationResult.Value;+ var boundAgreesWithLoop = boundOrientationResult.Value;var isDeclaredOuter = string.Equals(boundEntity.Name, "FACE_OUTER_BOUND", StringComparison.OrdinalIgnoreCase);var loopEntityResult = document.TryGetEntity(loopRefResult.Value.TargetId);@@ -545,6 +545,22 @@ public static class Step242Importer"step-import-loop-order-recovered: " + message, $"Entity:{faceEntity.Id}"));}+ // FACE_BOUND orientation .F. means the face uses its EDGE_LOOP reversed (ISO 10303-42).+ // Dropping it left the loop running against the face, which reversed spherical caps+ // (a concave corner drew as the rest of its sphere) and was written back out on export.+ if (!boundAgreesWithLoop)+ {+ loopCoedges.Reverse();+ var count = loopCoedges.Count;+ loopCoedges = loopCoedges.Select((c, index) => c with+ {+ IsReversed = !c.IsReversed,+ NextCoedgeId = loopCoedges[(index + 1) % count].Id,+ PrevCoedgeId = loopCoedges[(index + count - 1) % count].Id,+ }).ToList();+ loopSamples.Reverse();+ }+var closingGap = ClassifyCoedgeGap(loopSamples[^1], loopSamples[0], bindSurfaceResult.Value.SurfaceGeometry);ReportCoedgeGapDiagnostic(new LoopRoleCoedgeGapDiagnostic(FaceEntityId: faceEntity.Id,diff --git a/testdata/step242/manifests/nist.v0.report.json b/testdata/step242/manifests/nist.v0.report.jsonindex 7ed62367..fd2353df 100644--- a/testdata/step242/manifests/nist.v0.report.json+++ b/testdata/step242/manifests/nist.v0.report.json@@ -77,7 +77,7 @@"edges": 1108,"faces": 483},- "canonicalSha256": "9d454f422d94c8a4375cc741d596491648e15d8fb1ec4a2385fbc60ac61e4120"+ "canonicalSha256": "b7365758fefec2411f8083dd123a524ffa68cb8a28556762050c15420d4307d5"},{"fileId": "testdata_step242_nist_CTC_nist_ctc_05_asme1_ap242-e1",@@ -97,7 +97,7 @@"edges": 331,"faces": 156},- "canonicalSha256": "24e5a7ea124779f9389c367ff2e3a31cdae9d76ec5a8cef555e9f79f778f5ca7"+ "canonicalSha256": "12713bf95b7ca001684c2dbce72123f7b42c1399d19fa73e2573535b52740467"},{"fileId": "testdata_step242_nist_FTC_nist_ftc_06_asme1_ap242-e2",@@ -137,7 +137,7 @@"edges": 865,"faces": 304},- "canonicalSha256": "ea03b61c119b5b72c369a5b879cded916df4eece654a612fa3641845192060a7"+ "canonicalSha256": "42fa13c37bf42f5516d4e31cf31fd9bcebc1f115eee1ea94e62c40391f2eb6a6"},{"fileId": "testdata_step242_nist_FTC_nist_ftc_08_asme1_ap242-e1-tg",@@ -217,7 +217,7 @@"edges": 799,"faces": 264},- "canonicalSha256": "eff9d4990ed0509a2105389cfa785c9ba253a69ff0f7f1f2b8c2bfe4c07b73b5"+ "canonicalSha256": "4d3ae6cae8c0cd3245c3929c40ded1e381f570e9113e0aa4edee003da3e06923"},{"fileId": "testdata_step242_nist_FTC_nist_ftc_11_asme1_ap242-e2",