Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add M24 AP242 round-trip reliability coverage
Yuechen Lice1a8ff75abb
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.csnew file mode 100644index 00000000..4eeac635--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242FixtureCorpus.cs@@ -0,0 +1,31 @@+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Step242;++internal static class Step242FixtureCorpus+{+ // M24 generated golden: regenerate by exporting CreateBox(2,2,2) via Step242Exporter.+ public static readonly string CanonicalBoxGolden = CreateCanonicalBoxGolden();++ public const string UnsupportedSphericalSurface = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=SPHERICAL_SURFACE($,#2,1.0);\n#2=AXIS2_PLACEMENT_3D($,#3,#4,#5);\n#3=CARTESIAN_POINT($,(0,0,0));\n#4=DIRECTION($,(0,0,1));\n#5=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";++ public const string MalformedMissingParen = "ISO-10303-21; DATA; #1=MANIFOLD_SOLID_BREP('bad',#2 ENDSEC; END-ISO-10303-21;";++ private static string CreateCanonicalBoxGolden()+ {+ var boxResult = BrepPrimitives.CreateBox(2d, 2d, 2d);+ if (!boxResult.IsSuccess)+ {+ throw new InvalidOperationException("Failed to build canonical box fixture.");+ }++ var export = Step242Exporter.ExportBody(boxResult.Value);+ if (!export.IsSuccess)+ {+ throw new InvalidOperationException("Failed to export canonical box fixture.");+ }++ return export.Value;+ }+}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.csindex b91bdd24..588369d0 100644--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs@@ -10,7 +10,7 @@ public sealed class Step242ImporterTests[Fact]public void ImportBody_KnownGoodM22SubsetText_ReturnsValidatedBody(){- var fixtureText = CreateM22BoxFixtureText();+ var fixtureText = Step242FixtureCorpus.CanonicalBoxGolden;var import = Step242Importer.ImportBody(fixtureText);@@ -46,7 +46,7 @@ public sealed class Step242ImporterTests[Fact]public void ImportBody_MalformedStep_ReturnsDiagnosticWithoutThrowing(){- var malformed = "ISO-10303-21; DATA; #1=MANIFOLD_SOLID_BREP('bad',#2) ENDSEC; END-ISO-10303-21;";+ var malformed = Step242FixtureCorpus.MalformedMissingParen;var import = Step242Importer.ImportBody(malformed);@@ -60,7 +60,7 @@ public sealed class Step242ImporterTests[Fact]public void ImportBody_UnsupportedEntityInParseableText_ReturnsNotImplementedDiagnostic(){- var unsupported = "ISO-10303-21;\nHEADER;\nENDSEC;\nDATA;\n#1=SPHERICAL_SURFACE($,#2,1.0);\n#2=AXIS2_PLACEMENT_3D($,#3,#4,#5);\n#3=CARTESIAN_POINT($,(0,0,0));\n#4=DIRECTION($,(0,0,1));\n#5=DIRECTION($,(1,0,0));\nENDSEC;\nEND-ISO-10303-21;";+ var unsupported = Step242FixtureCorpus.UnsupportedSphericalSurface;var import = Step242Importer.ImportBody(unsupported);@@ -72,13 +72,4 @@ public sealed class Step242ImporterTestsAssert.Contains("unsupported", diagnostic.Message, StringComparison.OrdinalIgnoreCase);}- private static string CreateM22BoxFixtureText()- {- var boxResult = BrepPrimitives.CreateBox(2d, 2d, 2d);- Assert.True(boxResult.IsSuccess);-- var export = Step242Exporter.ExportBody(boxResult.Value);- Assert.True(export.IsSuccess);- return export.Value;- }}diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242RoundTripReliabilityTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242RoundTripReliabilityTests.csnew file mode 100644index 00000000..4d89b33c--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242RoundTripReliabilityTests.cs@@ -0,0 +1,117 @@+using System.Text.RegularExpressions;+using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Picking;+using Aetheris.Kernel.Core.Brep.Tessellation;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Step242;++namespace Aetheris.Kernel.Core.Tests.Step242;++public sealed class Step242RoundTripReliabilityTests+{+ [Fact]+ public void RoundTrip_MultiCycle_BoxSubset_TextIsStableAcrossCycles()+ {+ var cycle0 = Step242FixtureCorpus.CanonicalBoxGolden;+ var cycle1 = RoundTripExport(cycle0);+ var cycle2 = RoundTripExport(cycle1);+ var cycle3 = RoundTripExport(cycle2);++ Assert.Equal(cycle0, cycle1);+ Assert.Equal(cycle1, cycle2);+ Assert.Equal(cycle2, cycle3);+ }++ [Fact]+ public void RoundTrip_BoxSubset_PreservesStructuralInvariants_AndSmokeOperations()+ {+ var original = BrepPrimitives.CreateBox(4d, 6d, 8d);+ Assert.True(original.IsSuccess);++ var imported = Import(Step242Exporter.ExportBody(original.Value).Value);++ AssertTopologyInvariantMatch(original.Value, imported);+ AssertGeometryKindsAreSubset(imported);++ var tessellation = BrepDisplayTessellator.Tessellate(imported);+ Assert.True(tessellation.IsSuccess);+ Assert.Equal(6, tessellation.Value.FacePatches.Count);+ Assert.Equal(12, tessellation.Value.EdgePolylines.Count);++ var ray = new Ray3D(new Point3D(0d, 0d, 6d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));+ var pick = BrepPicker.Pick(imported, tessellation.Value, ray, PickQueryOptions.Default with { NearestOnly = true });+ Assert.True(pick.IsSuccess);+ Assert.Single(pick.Value);+ }++ [Fact]+ public void ImportBody_BrokenReference_ReturnsDeterministicDiagnosticWithoutThrowing()+ {+ var brokenReference = CorruptManifoldShellReference(Step242FixtureCorpus.CanonicalBoxGolden);++ var import = Step242Importer.ImportBody(brokenReference);++ Assert.False(import.IsSuccess);+ var diagnostic = Assert.Single(import.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);+ Assert.Equal("Entity:9999", diagnostic.Source);+ Assert.Contains("Missing referenced entity", diagnostic.Message, StringComparison.Ordinal);+ }++ [Fact]+ public void ExportBody_SameImportedBody_ProducesDeterministicText()+ {+ var imported = Import(Step242FixtureCorpus.CanonicalBoxGolden);++ var first = Step242Exporter.ExportBody(imported);+ var second = Step242Exporter.ExportBody(imported);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.Equal(first.Value, second.Value);+ }++ private static BrepBody Import(string stepText)+ {+ var import = Step242Importer.ImportBody(stepText);+ Assert.True(import.IsSuccess);+ return import.Value;+ }++ private static string RoundTripExport(string inputStep)+ {+ var body = Import(inputStep);+ var export = Step242Exporter.ExportBody(body);+ Assert.True(export.IsSuccess);+ return export.Value;+ }++ private static void AssertTopologyInvariantMatch(BrepBody expected, BrepBody actual)+ {+ Assert.Equal(expected.Topology.Bodies.Count(), actual.Topology.Bodies.Count());+ Assert.Equal(expected.Topology.Shells.Count(), actual.Topology.Shells.Count());+ Assert.Equal(expected.Topology.Faces.Count(), actual.Topology.Faces.Count());+ Assert.Equal(expected.Topology.Loops.Count(), actual.Topology.Loops.Count());+ Assert.Equal(expected.Topology.Coedges.Count(), actual.Topology.Coedges.Count());+ Assert.Equal(expected.Topology.Edges.Count(), actual.Topology.Edges.Count());+ Assert.Equal(expected.Topology.Vertices.Count(), actual.Topology.Vertices.Count());+ }++ private static void AssertGeometryKindsAreSubset(BrepBody body)+ {+ Assert.All(body.Geometry.Curves, curve => Assert.Equal(CurveGeometryKind.Line3, curve.Value.Kind));+ Assert.All(body.Geometry.Surfaces, surface => Assert.Equal(SurfaceGeometryKind.Plane, surface.Value.Kind));+ }++ private static string CorruptManifoldShellReference(string stepText)+ {+ return Regex.Replace(+ stepText,+ "(MANIFOLD_SOLID_BREP\\('.*?',)#\\d+(\\);)",+ "$1#9999$2",+ RegexOptions.CultureInvariant,+ TimeSpan.FromSeconds(1));+ }+}diff --git a/docs/milestones.md b/docs/milestones.mdindex d3c39592..4930b810 100644--- a/docs/milestones.md+++ b/docs/milestones.md@@ -217,3 +217,12 @@- [x] Add importer-focused tests for success, M22 export→import round-trip (box subset), and malformed/unsupported no-throw behavior.- [x] Explicitly keep support narrow: arbitrary third-party STEP/AP242 files are expected to fail with diagnostics; broader schema/entity coverage is deferred.- [x] Defer import scope expansion and broader round-trip reliability hardening to M24.+++## M24 — AP242 Round-Trip Reliability v1 (Subset Stability)++- [x] Add subset-focused reliability coverage for repeated AP242 cycles (`export -> import -> export`) on the existing box-like planar/line topology scope.+- [x] Lock an explicit round-trip equivalence strategy: topology count invariants + geometry kind invariants (line edges / planar faces) + tessellation/picking smoke checks.+- [x] Confirm deterministic STEP text behavior for the supported subset: M22 canonical export is byte-stable from the first cycle and remains stable across subsequent cycles.+- [x] Add a minimal generated golden/fixture corpus for supported subset and importer failure-path diagnostics (malformed input, unsupported entity, broken reference).+- [x] Keep AP242 support scope intentionally narrow (single-body/single-shell solids with planar faces and line edges); broader entity/schema coverage remains deferred.