Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
M16c: enable inner-shell sphere export path and run dotnet tests
Yuechen Lib2e95f430654
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.csindex 1ad828c2..2ce15876 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs@@ -82,7 +82,7 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests}[Fact]- public void ValidateNextSubtract_ContainedSphere_FailsWithMultiShellDiagnostic()+ public void ValidateNextSubtract_ContainedSphere_PassesForSingleContainedCavity(){var composition = new SafeBooleanComposition(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d),@@ -98,11 +98,46 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTestsout _,out var diagnostic);+ Assert.True(result);+ Assert.Null(diagnostic);+ }++ [Fact]+ public void ValidateNextSubtract_SphereAfterExistingHole_FailsWithUnsupportedAnalyticSurfaceDiagnostic()+ {+ var composition = new SafeBooleanComposition(+ new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d),+ [+ new SupportedBooleanHole(+ "hole_a",+ new AnalyticSurface(+ AnalyticSurfaceKind.Cylinder,+ Cylinder: new RecognizedCylinder(+ new Point3D(0d, 0d, -4d),+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ 0d,+ 20d,+ 3d)),+ 0d,+ 0d,+ 3d,+ 3d),+ ]);+ var sphere = new AnalyticSurface(+ AnalyticSurfaceKind.Sphere,+ Sphere: new RecognizedSphere(new Point3D(10d, 0d, 6d), 2d));++ var result = BrepBooleanSafeCompositionGraphValidator.TryValidateNextSubtract(+ composition,+ sphere,+ ToleranceContext.Default,+ out _,+ out var diagnostic);+Assert.False(result);Assert.NotNull(diagnostic);- Assert.Equal(BooleanDiagnosticCode.MultiBodyResult, diagnostic!.Code);- Assert.Equal("BrepBoolean.AnalyticHole.MultiBodyResult", diagnostic.Source);- Assert.Equal("Boolean Subtract would produce a fully enclosed spherical cavity that requires an inner shell; current explicit reconstruction and STEP export support only one shell per body.", diagnostic.Message);+ Assert.Equal(BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind, diagnostic!.Code);+ Assert.Equal("BrepBoolean.UnsupportedAnalyticSurfaceKind", diagnostic.Source);}private static BrepBody TransformBody(BrepBody body, Transform3D transform)diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 17c4d815..ae930639 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -608,18 +608,28 @@ public sealed class BrepBooleanTests[Fact]- public void Subtract_BoxSphereFullyContained_ReturnsMultiShellNotSupportedDiagnostic()+ public void Subtract_BoxSphereFullyContained_RebuildsToInnerShellCavityAndExportsDeterministically(){var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, -6d, 6d)).Value;var right = BrepPrimitives.CreateSphere(4d).Value;var result = BrepBoolean.Subtract(left, right);+ var repeated = BrepBoolean.Subtract(left, right);- Assert.False(result.IsSuccess);- var diagnostic = Assert.Single(result.Diagnostics);- Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("BrepBoolean.AnalyticHole.MultiBodyResult", diagnostic.Source);- Assert.Equal("Boolean Subtract would produce a fully enclosed spherical cavity that requires an inner shell; current explicit reconstruction and STEP export support only one shell per body.", diagnostic.Message);+ Assert.True(result.IsSuccess);+ Assert.True(repeated.IsSuccess);+ Assert.NotNull(result.Value.ShellRepresentation);+ Assert.Single(result.Value.ShellRepresentation!.InnerShellIds);+ Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);++ var export = Step242Exporter.ExportBody(result.Value);+ var repeatedExport = Step242Exporter.ExportBody(repeated.Value);+ Assert.True(export.IsSuccess);+ Assert.True(repeatedExport.IsSuccess);+ Assert.Equal(export.Value, repeatedExport.Value);+ Assert.Contains("SPHERICAL_SURFACE", export.Value, StringComparison.Ordinal);+ Assert.Contains("BREP_WITH_VOIDS", export.Value, StringComparison.Ordinal);+ Assert.DoesNotContain("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 1d37ffb9..fc940da4 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -25,9 +25,237 @@ public static class BrepBooleanBoxCylinderHoleBuilder{ArgumentNullException.ThrowIfNull(composition);_ = tolerance;+ if (composition.Holes.Count == 1+ && composition.Holes[0].Surface.Kind == AnalyticSurfaceKind.Sphere+ && composition.Holes[0].Surface.Sphere is RecognizedSphere sphere)+ {+ return CreateComposedContainedSphereCavityBody(composition.OuterBox, sphere);+ }++ if (composition.Holes.Any(hole => hole.Surface.Kind == AnalyticSurfaceKind.Sphere))+ {+ return KernelResult<BrepBody>.Failure([+ new BooleanDiagnostic(+ BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),+ null,+ "safe subtract composition only supports one contained spherical cavity when no prior holes have been accepted."),+ "BrepBoolean.AnalyticHole.UnsupportedAnalyticSurfaceKind").ToKernelDiagnostic(),+ ]);+ }+return CreateComposedThroughHoleBody(composition);}+ private static KernelResult<BrepBody> CreateComposedContainedSphereCavityBody(AxisAlignedBoxExtents outerBox, in RecognizedSphere sphere)+ {+ var outer = BrepBooleanBoxRecognition.CreateBoxFromExtents(outerBox);+ if (!outer.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(outer.Diagnostics);+ }++ var innerResult = CreateSphereShell(sphere);+ if (!innerResult.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(innerResult.Diagnostics);+ }++ var merged = MergeOuterAndInnerShell(outer.Value, innerResult.Value);+ var validation = BrepBindingValidator.Validate(merged, requireAllEdgeAndFaceBindings: true);+ return validation.IsSuccess+ ? KernelResult<BrepBody>.Success(merged, validation.Diagnostics)+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);+ }++ private static BrepBody MergeOuterAndInnerShell(BrepBody outer, BrepBody inner)+ {+ const int idOffset = 1000;+ var topology = new TopologyModel();++ foreach (var vertex in outer.Topology.Vertices.OrderBy(v => v.Id.Value))+ {+ topology.AddVertex(vertex);+ }++ foreach (var edge in outer.Topology.Edges.OrderBy(e => e.Id.Value))+ {+ topology.AddEdge(edge);+ }++ foreach (var coedge in outer.Topology.Coedges.OrderBy(c => c.Id.Value))+ {+ topology.AddCoedge(coedge);+ }++ foreach (var loop in outer.Topology.Loops.OrderBy(l => l.Id.Value))+ {+ topology.AddLoop(loop);+ }++ foreach (var face in outer.Topology.Faces.OrderBy(f => f.Id.Value))+ {+ topology.AddFace(face);+ }++ foreach (var shell in outer.Topology.Shells.OrderBy(s => s.Id.Value))+ {+ topology.AddShell(shell);+ }++ var innerVertexMap = inner.Topology.Vertices.ToDictionary(v => v.Id, v => new VertexId(v.Id.Value + idOffset));+ var innerEdgeMap = inner.Topology.Edges.ToDictionary(e => e.Id, e => new EdgeId(e.Id.Value + idOffset));+ var innerLoopMap = inner.Topology.Loops.ToDictionary(l => l.Id, l => new LoopId(l.Id.Value + idOffset));+ var innerCoedgeMap = inner.Topology.Coedges.ToDictionary(c => c.Id, c => new CoedgeId(c.Id.Value + idOffset));+ var innerFaceMap = inner.Topology.Faces.ToDictionary(f => f.Id, f => new FaceId(f.Id.Value + idOffset));+ var innerShellMap = inner.Topology.Shells.ToDictionary(s => s.Id, s => new ShellId(s.Id.Value + idOffset));++ foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value))+ {+ topology.AddVertex(new Vertex(innerVertexMap[vertex.Id]));+ }++ foreach (var edge in inner.Topology.Edges.OrderBy(e => e.Id.Value))+ {+ topology.AddEdge(new Edge(innerEdgeMap[edge.Id], innerVertexMap[edge.StartVertexId], innerVertexMap[edge.EndVertexId]));+ }++ foreach (var coedge in inner.Topology.Coedges.OrderBy(c => c.Id.Value))+ {+ topology.AddCoedge(new Coedge(+ innerCoedgeMap[coedge.Id],+ innerEdgeMap[coedge.EdgeId],+ innerLoopMap[coedge.LoopId],+ innerCoedgeMap[coedge.NextCoedgeId],+ innerCoedgeMap[coedge.PrevCoedgeId],+ coedge.IsReversed));+ }++ foreach (var loop in inner.Topology.Loops.OrderBy(l => l.Id.Value))+ {+ topology.AddLoop(new Loop(innerLoopMap[loop.Id], loop.CoedgeIds.Select(id => innerCoedgeMap[id]).ToArray()));+ }++ foreach (var face in inner.Topology.Faces.OrderBy(f => f.Id.Value))+ {+ topology.AddFace(new Face(innerFaceMap[face.Id], face.LoopIds.Select(id => innerLoopMap[id]).ToArray()));+ }++ foreach (var shell in inner.Topology.Shells.OrderBy(s => s.Id.Value))+ {+ topology.AddShell(new Shell(innerShellMap[shell.Id], shell.FaceIds.Select(id => innerFaceMap[id]).ToArray()));+ }++ var outerShellId = AssertSingleShellId(outer.Topology);+ var remappedInnerShellId = innerShellMap[AssertSingleShellId(inner.Topology)];+ topology.AddBody(new Body(new BodyId(1), [outerShellId, remappedInnerShellId]));++ var geometry = new BrepGeometryStore();+ foreach (var curve in outer.Geometry.Curves)+ {+ geometry.AddCurve(curve.Key, curve.Value);+ }++ foreach (var surface in outer.Geometry.Surfaces)+ {+ geometry.AddSurface(surface.Key, surface.Value);+ }++ foreach (var curve in inner.Geometry.Curves)+ {+ geometry.AddCurve(new CurveGeometryId(curve.Key.Value + idOffset), curve.Value);+ }++ foreach (var surface in inner.Geometry.Surfaces)+ {+ geometry.AddSurface(new SurfaceGeometryId(surface.Key.Value + idOffset), surface.Value);+ }++ var bindings = new BrepBindingModel();+ foreach (var edgeBinding in outer.Bindings.EdgeBindings.OrderBy(binding => binding.EdgeId.Value))+ {+ bindings.AddEdgeBinding(edgeBinding);+ }++ foreach (var faceBinding in outer.Bindings.FaceBindings.OrderBy(binding => binding.FaceId.Value))+ {+ bindings.AddFaceBinding(faceBinding);+ }++ foreach (var edgeBinding in inner.Bindings.EdgeBindings.OrderBy(binding => binding.EdgeId.Value))+ {+ bindings.AddEdgeBinding(edgeBinding with+ {+ EdgeId = innerEdgeMap[edgeBinding.EdgeId],+ CurveGeometryId = new CurveGeometryId(edgeBinding.CurveGeometryId.Value + idOffset),+ });+ }++ foreach (var faceBinding in inner.Bindings.FaceBindings.OrderBy(binding => binding.FaceId.Value))+ {+ bindings.AddFaceBinding(faceBinding with+ {+ FaceId = innerFaceMap[faceBinding.FaceId],+ SurfaceGeometryId = new SurfaceGeometryId(faceBinding.SurfaceGeometryId.Value + idOffset),+ });+ }++ var vertexPoints = new Dictionary<VertexId, Point3D>();+ foreach (var vertex in outer.Topology.Vertices.OrderBy(v => v.Id.Value))+ {+ if (outer.TryGetVertexPoint(vertex.Id, out var point))+ {+ vertexPoints[vertex.Id] = point;+ }+ }++ foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value))+ {+ if (inner.TryGetVertexPoint(vertex.Id, out var point))+ {+ vertexPoints[innerVertexMap[vertex.Id]] = point;+ }+ }++ return new BrepBody(+ topology,+ geometry,+ bindings,+ vertexPoints,+ safeBooleanComposition: null,+ shellRepresentation: new BrepBodyShellRepresentation(outerShellId, [remappedInnerShellId]));+ }++ private static ShellId AssertSingleShellId(TopologyModel topology)+ => topology.Bodies.Single().ShellIds.Single();++ private static KernelResult<BrepBody> CreateSphereShell(in RecognizedSphere sphere)+ {+ var builder = new TopologyBuilder();+ var sphereFace = builder.AddFace([]);+ var sphereShell = builder.AddShell([sphereFace]);+ builder.AddBody([sphereShell]);++ var geometry = new BrepGeometryStore();+ geometry.AddSurface(+ new SurfaceGeometryId(1),+ SurfaceGeometry.FromSphere(new SphereSurface(+ sphere.Center,+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ sphere.Radius,+ Direction3D.Create(new Vector3D(1d, 0d, 0d)))));++ var bindings = new BrepBindingModel();+ bindings.AddFaceBinding(new FaceGeometryBinding(sphereFace, new SurfaceGeometryId(1)));++ var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints: null, safeBooleanComposition: null);+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);+ return validation.IsSuccess+ ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);+ }+private static KernelResult<BrepBody> CreateComposedThroughHoleBody(SafeBooleanComposition composition){var box = composition.OuterBox;diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 71296b79..41eb5266 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -16,7 +16,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorupdatedComposition = composition;diagnostic = null;- if (!TryCreateSupportedHole(composition.OuterBox, surface, tolerance, out var nextHole, out diagnostic, nextFeatureId))+ if (!TryCreateSupportedHole(composition.OuterBox, surface, tolerance, composition.Holes.Count > 0, out var nextHole, out diagnostic, nextFeatureId)){return false;}@@ -61,6 +61,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorAxisAlignedBoxExtents outerBox,AnalyticSurface surface,ToleranceContext tolerance,+ bool hasExistingHoles,out SupportedBooleanHole hole,out BooleanDiagnostic? diagnostic,string? featureId)@@ -109,12 +110,24 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn false;}- diagnostic = BrepBooleanCylinderRecognition.CreateMultiBodyResultDiagnostic(- BooleanOperation.Subtract.ToString(),+ if (hasExistingHoles)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(+ BooleanOperation.Subtract.ToString(),+ AnalyticSurfaceKind.Sphere,+ featureId);+ hole = default;+ return false;+ }++ hole = new SupportedBooleanHole(featureId,- "would produce a fully enclosed spherical cavity that requires an inner shell; current explicit reconstruction and STEP export support only one shell per body.");- hole = default;- return false;+ surface,+ sphere.Center.X,+ sphere.Center.Y,+ sphere.Radius,+ sphere.Radius);+ return true;case AnalyticSurfaceKind.Sphere:case AnalyticSurfaceKind.Torus:diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.csindex 7e897649..dd56b5f3 100644--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs@@ -342,11 +342,8 @@ public static class Step242Exporter};}- private static bool CanExportLooplessFace(BrepBody body, Face face, SurfaceGeometry surface) =>+ private static bool CanExportLooplessFace(BrepBody _, Face face, SurfaceGeometry surface) =>surface.Kind == SurfaceGeometryKind.Sphere- && body.Topology.Faces.Count() == 1- && body.Topology.Edges.Count() == 0- && body.Topology.Vertices.Count() == 0&& face.LoopIds.Count == 0;private static string BuildAxisPlacement(Step242TextWriter writer, Point3D origin, Direction3D axis, Direction3D referenceAxis)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex 2e634a48..afb51e29 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -117,7 +117,6 @@ public sealed class FirmamentBooleanCanonicalSuccessTests{ "testdata/firmament/fixtures/m10j-unsupported-box-add-cylinder.firmament", "joined", "add" },{ "testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament", "hole", "subtract" },{ "testdata/firmament/fixtures/m10j-unsupported-box-intersect-cylinder.firmament", "overlap", "intersect" },- { "testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament", "cavity", "subtract" },{ "testdata/firmament/fixtures/m10l-unsupported-box-add-sphere.firmament", "joined", "add" },{ "testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "overlap", "intersect" },{ "testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament", "tapered_cut", "subtract" },@@ -162,8 +161,20 @@ public sealed class FirmamentBooleanCanonicalSuccessTests&& HasExpectedMixedPrimitiveFailure(diagnostic.Message));}+ [Fact]+ public void BoxSphereSubtract_ContainedCavity_Succeeds_WithoutFallback()+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament"));++ Assert.True(result.Compilation.IsSuccess);+ Assert.NotNull(result.Compilation.Value.PrimitiveExecutionResult);+ Assert.NotEmpty(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedBooleans);+ var body = result.Compilation.Value.PrimitiveExecutionResult.ExecutedBooleans.Single(booleanResult => booleanResult.FeatureId == "cavity").Body;+ Assert.NotNull(body.ShellRepresentation);+ Assert.Single(body.ShellRepresentation!.InnerShellIds);+ }+[Theory]- [InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament", "BrepBoolean.AnalyticHole.MultiBodyResult", "fully enclosed spherical cavity")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-touching-boundary.firmament", "BrepBoolean.AnalyticHole.TangentContact", "tangent to a box boundary plane")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-partially-outside.firmament", "BrepBoolean.AnalyticHole.RadiusExceedsBoundary", "must remain strictly contained inside the box")]public void BoxSphereSubtract_Diagnostics_ArePropagated_WithSpecificSources(string fixturePath, string expectedSource, string expectedMessageFragment)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex 9b07842c..99b1b5f5 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -173,6 +173,18 @@ public sealed class FirmamentBuildAndExportTests"subtract");}+ [Fact]+ public void Run_BooleanBoxSphereCavityExample_Writes_Default_Export_Artifact()+ {+ AssertExampleBuildAndExport(+ "testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament",+ "boolean_box_sphere_cavity_basic.step",+ "cavity",+ 1,+ "boolean",+ "subtract");+ }+[Fact]public void Run_UnsupportedBoxWithCylinderHoleFixture_Fails_And_Does_Not_Write_Fallback_Export(){@@ -186,7 +198,6 @@ public sealed class FirmamentBuildAndExportTests[Theory][InlineData("testdata/firmament/fixtures/m10j-unsupported-box-add-cylinder.firmament", "m10j-unsupported-box-add-cylinder.step", "joined", "add")][InlineData("testdata/firmament/fixtures/m10j-unsupported-box-intersect-cylinder.firmament", "m10j-unsupported-box-intersect-cylinder.step", "overlap", "intersect")]- [InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament", "m10l-unsupported-box-subtract-sphere-contained.step", "cavity", "subtract")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-add-sphere.firmament", "m10l-unsupported-box-add-sphere.step", "joined", "add")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "m10l-unsupported-box-intersect-sphere.step", "overlap", "intersect")][InlineData("testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament", "m10m-unsupported-box-subtract-cone.step", "tapered_cut", "subtract")]diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.csindex 8080c6ec..0a48c79c 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentExamplePackSmokeTests.cs@@ -18,6 +18,7 @@ public sealed class FirmamentExamplePackSmokeTests"testdata/firmament/examples/boolean_intersect_basic.firmament","testdata/firmament/examples/boolean_two_cylinder_holes_basic.firmament","testdata/firmament/examples/boolean_cylinder_cone_holes_basic.firmament",+ "testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament","testdata/firmament/examples/placed_primitive.firmament","testdata/firmament/examples/schema_box_basic.firmament"];@@ -49,6 +50,7 @@ public sealed class FirmamentExamplePackSmokeTests[InlineData("testdata/firmament/examples/boolean_intersect_basic.firmament", "overlap", 2, "boolean", "intersect")][InlineData("testdata/firmament/examples/boolean_two_cylinder_holes_basic.firmament", "hole_b", 2, "boolean", "subtract")][InlineData("testdata/firmament/examples/boolean_cylinder_cone_holes_basic.firmament", "cut_b", 2, "boolean", "subtract")]+ [InlineData("testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament", "cavity", 1, "boolean", "subtract")][InlineData("testdata/firmament/examples/placed_primitive.firmament", "post", 1, "primitive", "cylinder")][InlineData("testdata/firmament/examples/schema_box_basic.firmament", "schema_box", 0, "primitive", "box")]public void ExamplePack_GoldenPath_Examples_Export(string fixturePath, string expectedFeatureId, int expectedOpIndex, string expectedBodyCategory, string expectedFeatureKind)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentSchemaCncDfmValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentSchemaCncDfmValidationTests.csindex c5d0e628..5d56d172 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentSchemaCncDfmValidationTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentSchemaCncDfmValidationTests.cs@@ -143,9 +143,8 @@ ops[2]:var result = Compile(source);- Assert.False(result.Compilation.IsSuccess);+ Assert.True(result.Compilation.IsSuccess);Assert.DoesNotContain(result.Compilation.Diagnostics, diagnostic => diagnostic.Message.Contains(FirmamentDiagnosticCodes.SchemaCncMinimumToolRadiusViolated.Value, StringComparison.Ordinal));- Assert.Contains(result.Compilation.Diagnostics, diagnostic => diagnostic.Message.Contains("Requested boolean feature 'pocket' (subtract) could not be executed.", StringComparison.Ordinal));}[Fact]diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.csindex 705df013..154d3143 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs@@ -164,6 +164,29 @@ public sealed class FirmamentStepExporterTestsAssert.Equal(first.Value.StepText, File.ReadAllText(artifactPath));}+ [Fact]+ public void Export_SupportedBoxSphereCavity_Uses_BrepWithVoids_And_Is_Deterministic()+ {+ var first = ExportFixture("testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament");+ var second = ExportFixture("testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament");++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.Equal(first.Value.StepText, second.Value.StepText);+ Assert.Equal("cavity", first.Value.ExportedFeatureId);+ Assert.Equal(1, first.Value.ExportedOpIndex);+ Assert.Equal("boolean", first.Value.ExportedBodyCategory);+ Assert.Equal("subtract", first.Value.ExportedFeatureKind);+ Assert.Contains("SPHERICAL_SURFACE", first.Value.StepText, StringComparison.Ordinal);+ Assert.Contains("BREP_WITH_VOIDS", first.Value.StepText, StringComparison.Ordinal);+ Assert.Contains("ORIENTED_CLOSED_SHELL", first.Value.StepText, StringComparison.Ordinal);+ Assert.DoesNotContain("MANIFOLD_SOLID_BREP", first.Value.StepText, StringComparison.Ordinal);++ var artifactPath = WriteExportArtifact("boolean_box_sphere_cavity_basic.step", first.Value.StepText);+ Assert.True(File.Exists(artifactPath));+ Assert.Equal(first.Value.StepText, File.ReadAllText(artifactPath));+ }+[Fact]public void Export_NonCylinderOrFailedBooleanCases_DoNotEmit_SemanticPmi()@@ -171,7 +194,7 @@ public sealed class FirmamentStepExporterTestsvar boxSubtract = ExportFixture("testdata/firmament/examples/boolean_subtract_basic.firmament");var coneHole = ExportFixture("testdata/firmament/examples/boolean_box_cone_throughhole_basic.firmament");var unsupportedCylinder = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament");- var unsupportedSphere = ExportFixture("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament");+ var supportedSphereCavity = ExportFixture("testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament");var unsupportedTorus = ExportFixture("testdata/firmament/fixtures/m10n-unsupported-box-subtract-torus.firmament");Assert.True(boxSubtract.IsSuccess);@@ -185,7 +208,7 @@ public sealed class FirmamentStepExporterTestsAssert.DoesNotContain("ANNOTATION_PLANE", coneHole.Value.StepText, StringComparison.Ordinal);Assert.False(unsupportedCylinder.IsSuccess);- Assert.False(unsupportedSphere.IsSuccess);+ Assert.True(supportedSphereCavity.IsSuccess);Assert.False(unsupportedTorus.IsSuccess);}@@ -206,7 +229,6 @@ public sealed class FirmamentStepExporterTests[Theory]- [InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-contained.firmament", "cavity")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-touching-boundary.firmament", "tangent_cavity")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-subtract-sphere-partially-outside.firmament", "leaking_cavity")][InlineData("testdata/firmament/fixtures/m10l-unsupported-box-add-sphere.firmament", "joined")]diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.mdindex 6a2e6010..83b7d42f 100644--- a/testdata/firmament/examples/README.md+++ b/testdata/firmament/examples/README.md@@ -19,7 +19,8 @@ Other combinations may fail and are intentionally not supported yet.- `boolean_box_cone_throughhole_basic.firmament` — the narrow supported box+cone boolean case: subtracting a Z-aligned cone that cleanly spans the full box height, keeps both boundary circles strictly inside the box footprint, and reconstructs as one box-with-conical-through-hole solid; helper export path: `testdata/firmament/exports/boolean_box_cone_throughhole_basic.step`.- `boolean_two_cylinder_holes_basic.firmament` — canonical sequential safe composition case for `box → subtract cylinder → subtract cylinder`; helper export path: `testdata/firmament/exports/boolean_two_cylinder_holes_basic.step`.- `boolean_cylinder_cone_holes_basic.firmament` — canonical sequential safe composition case for `box → subtract cylinder → subtract cone`; helper export path: `testdata/firmament/exports/boolean_cylinder_cone_holes_basic.step`.+- `boolean_box_sphere_cavity_basic.firmament` — narrow supported `subtract(box, sphere)` cavity case only: the sphere must remain strictly contained and non-tangent so the result can be reconstructed as one outer shell plus one inner spherical shell; helper export path: `testdata/firmament/exports/boolean_box_sphere_cavity_basic.step`.- `placed_primitive.firmament` — selector-based placement using `place.on` and `offset[3]`; helper export path: `testdata/firmament/exports/placed_primitive.step`.- `schema_box_basic.firmament` — minimal schema-present export example showing schema presence without changing export body semantics; helper export path: `testdata/firmament/exports/schema_box_basic.step`.-Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The supported safe subtract family remains narrow and explicit: `subtract(box, cylinder)` and `subtract(box, cone)` still require a Z-aligned tool, full span through the current box shell, non-degenerate boundary circles for cones, and strict in-bounds clearance with no tangent/grazing contact. Sequential composition is limited to repeated document-order subtracts from that same safe family only: `box → subtract cylinder/cone → subtract cylinder/cone`, while the intermediate result must stay representable as one outer box shell plus non-interfering analytic through-holes. This is not general multi-feature boolean support. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, outside-footprint cuts, interfering multi-hole layouts, and unsupported subtract orderings remain unsupported. Box+cone `add`, box+cone `intersect`, tilted cones, partial-depth cone cuts, tangent/grazing cone cuts, apex-inside cases, outside-footprint cone cuts, and unsupported mixed-ordering requests remain unsupported. Box+sphere support remains intentionally narrow and truth-first: `subtract(box, sphere)` now performs contained-cavity classification diagnostics (tangent/outside/representation), but fully enclosed cavities are still rejected because the current explicit reconstruction + STEP export path supports one shell per body only; `add(box, sphere)` and `intersect(box, sphere)` remain unsupported. Box+torus booleans are currently unsupported in every audited form: `subtract(box, torus)`, `add(box, torus)`, and `intersect(box, torus)` all fail the real kernel boundary for centered, offset, fully contained, face-intersecting, and outside-footprint torus placements, so no box+torus example is included here. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.+Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The supported safe subtract family remains narrow and explicit: `subtract(box, cylinder)` and `subtract(box, cone)` still require a Z-aligned tool, full span through the current box shell, non-degenerate boundary circles for cones, and strict in-bounds clearance with no tangent/grazing contact. Sequential composition is limited to repeated document-order subtracts from that same safe family only: `box → subtract cylinder/cone → subtract cylinder/cone`, while the intermediate result must stay representable as one outer box shell plus non-interfering analytic through-holes. This is not general multi-feature boolean support. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, outside-footprint cuts, interfering multi-hole layouts, and unsupported subtract orderings remain unsupported. Box+cone `add`, box+cone `intersect`, tilted cones, partial-depth cone cuts, tangent/grazing cone cuts, apex-inside cases, outside-footprint cone cuts, and unsupported mixed-ordering requests remain unsupported. Box+sphere support is still narrow and truth-first: only `subtract(box, sphere)` with a strictly contained, non-tangent, fully enclosed cavity is supported, reconstructed via one outer shell plus one inner spherical shell. `add(box, sphere)`, `intersect(box, sphere)`, tangent cavity requests, and partially outside sphere requests remain unsupported. Box+torus booleans are currently unsupported in every audited form: `subtract(box, torus)`, `add(box, torus)`, and `intersect(box, torus)` all fail the real kernel boundary for centered, offset, fully contained, face-intersecting, and outside-footprint torus placements, so no box+torus example is included here. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.diff --git a/testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament b/testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmamentnew file mode 100644index 00000000..18e91fa4--- /dev/null+++ b/testdata/firmament/examples/boolean_box_sphere_cavity_basic.firmament@@ -0,0 +1,23 @@+firmament:+ version: 1++model:+ name: boolean_box_sphere_cavity_basic+ units: mm++ops[2]:+ -+ op: box+ id: base+ size[3]:+ 40+ 30+ 12++ -+ op: subtract+ id: cavity+ from: base+ with:+ op: sphere+ radius: 4diff --git a/testdata/firmament/exports/boolean_box_sphere_cavity_basic.step b/testdata/firmament/exports/boolean_box_sphere_cavity_basic.stepnew file mode 100644index 00000000..8016cbf5--- /dev/null+++ b/testdata/firmament/exports/boolean_box_sphere_cavity_basic.step@@ -0,0 +1,180 @@+ISO-10303-21;+HEADER;+FILE_DESCRIPTION(('Aetheris AP242 subset export'),'2;1');+FILE_NAME('aetheris_export.step','1970-01-01T00:00:00',('Aetheris'),('Aetheris'),'Aetheris.Kernel','Aetheris.Kernel','');+FILE_SCHEMA(('AP242_MANAGED_MODEL_BASED_3D_ENGINEERING_MIM_LF'));+ENDSEC;+DATA;+#1=CARTESIAN_POINT($,(0,0,-6));+#2=DIRECTION($,(0,0,-1));+#3=DIRECTION($,(1,0,0));+#4=AXIS2_PLACEMENT_3D($,#1,#2,#3);+#5=PLANE($,#4);+#6=CARTESIAN_POINT($,(-20,-15,-6));+#7=VERTEX_POINT($,#6);+#8=CARTESIAN_POINT($,(20,-15,-6));+#9=VERTEX_POINT($,#8);+#10=CARTESIAN_POINT($,(-20,-15,-6));+#11=DIRECTION($,(1,0,0));+#12=VECTOR($,#11,1);+#13=LINE($,#10,#12);+#14=EDGE_CURVE($,#7,#9,#13,.T.);+#15=ORIENTED_EDGE($,$,$,#14,.T.);+#16=CARTESIAN_POINT($,(20,15,-6));+#17=VERTEX_POINT($,#16);+#18=CARTESIAN_POINT($,(20,-15,-6));+#19=DIRECTION($,(0,1,0));+#20=VECTOR($,#19,1);+#21=LINE($,#18,#20);+#22=EDGE_CURVE($,#9,#17,#21,.T.);+#23=ORIENTED_EDGE($,$,$,#22,.T.);+#24=CARTESIAN_POINT($,(-20,15,-6));+#25=VERTEX_POINT($,#24);+#26=CARTESIAN_POINT($,(20,15,-6));+#27=DIRECTION($,(-1,0,0));+#28=VECTOR($,#27,1);+#29=LINE($,#26,#28);+#30=EDGE_CURVE($,#17,#25,#29,.T.);+#31=ORIENTED_EDGE($,$,$,#30,.T.);+#32=CARTESIAN_POINT($,(-20,15,-6));+#33=DIRECTION($,(0,-1,0));+#34=VECTOR($,#33,1);+#35=LINE($,#32,#34);+#36=EDGE_CURVE($,#25,#7,#35,.T.);+#37=ORIENTED_EDGE($,$,$,#36,.T.);+#38=EDGE_LOOP($,(#15,#23,#31,#37));+#39=FACE_OUTER_BOUND('',#38,.T.);+#40=ADVANCED_FACE('',(#39),#5,.T.);+#41=CARTESIAN_POINT($,(0,0,6));+#42=DIRECTION($,(0,0,1));+#43=DIRECTION($,(1,0,0));+#44=AXIS2_PLACEMENT_3D($,#41,#42,#43);+#45=PLANE($,#44);+#46=CARTESIAN_POINT($,(-20,-15,6));+#47=VERTEX_POINT($,#46);+#48=CARTESIAN_POINT($,(20,-15,6));+#49=VERTEX_POINT($,#48);+#50=CARTESIAN_POINT($,(-20,-15,6));+#51=DIRECTION($,(1,0,0));+#52=VECTOR($,#51,1);+#53=LINE($,#50,#52);+#54=EDGE_CURVE($,#47,#49,#53,.T.);+#55=ORIENTED_EDGE($,$,$,#54,.T.);+#56=CARTESIAN_POINT($,(20,15,6));+#57=VERTEX_POINT($,#56);+#58=CARTESIAN_POINT($,(20,-15,6));+#59=DIRECTION($,(0,1,0));+#60=VECTOR($,#59,1);+#61=LINE($,#58,#60);+#62=EDGE_CURVE($,#49,#57,#61,.T.);+#63=ORIENTED_EDGE($,$,$,#62,.T.);+#64=CARTESIAN_POINT($,(-20,15,6));+#65=VERTEX_POINT($,#64);+#66=CARTESIAN_POINT($,(20,15,6));+#67=DIRECTION($,(-1,0,0));+#68=VECTOR($,#67,1);+#69=LINE($,#66,#68);+#70=EDGE_CURVE($,#57,#65,#69,.T.);+#71=ORIENTED_EDGE($,$,$,#70,.T.);+#72=CARTESIAN_POINT($,(-20,15,6));+#73=DIRECTION($,(0,-1,0));+#74=VECTOR($,#73,1);+#75=LINE($,#72,#74);+#76=EDGE_CURVE($,#65,#47,#75,.T.);+#77=ORIENTED_EDGE($,$,$,#76,.T.);+#78=EDGE_LOOP($,(#55,#63,#71,#77));+#79=FACE_OUTER_BOUND('',#78,.T.);+#80=ADVANCED_FACE('',(#79),#45,.T.);+#81=CARTESIAN_POINT($,(0,-15,0));+#82=DIRECTION($,(0,-1,0));+#83=DIRECTION($,(1,0,0));+#84=AXIS2_PLACEMENT_3D($,#81,#82,#83);+#85=PLANE($,#84);+#86=ORIENTED_EDGE($,$,$,#14,.T.);+#87=CARTESIAN_POINT($,(20,-15,-6));+#88=DIRECTION($,(0,0,1));+#89=VECTOR($,#88,1);+#90=LINE($,#87,#89);+#91=EDGE_CURVE($,#9,#49,#90,.T.);+#92=ORIENTED_EDGE($,$,$,#91,.T.);+#93=ORIENTED_EDGE($,$,$,#54,.F.);+#94=CARTESIAN_POINT($,(-20,-15,-6));+#95=DIRECTION($,(0,0,1));+#96=VECTOR($,#95,1);+#97=LINE($,#94,#96);+#98=EDGE_CURVE($,#7,#47,#97,.T.);+#99=ORIENTED_EDGE($,$,$,#98,.F.);+#100=EDGE_LOOP($,(#86,#92,#93,#99));+#101=FACE_OUTER_BOUND('',#100,.T.);+#102=ADVANCED_FACE('',(#101),#85,.T.);+#103=CARTESIAN_POINT($,(20,0,0));+#104=DIRECTION($,(1,0,0));+#105=DIRECTION($,(0,1,0));+#106=AXIS2_PLACEMENT_3D($,#103,#104,#105);+#107=PLANE($,#106);+#108=ORIENTED_EDGE($,$,$,#22,.T.);+#109=CARTESIAN_POINT($,(20,15,-6));+#110=DIRECTION($,(0,0,1));+#111=VECTOR($,#110,1);+#112=LINE($,#109,#111);+#113=EDGE_CURVE($,#17,#57,#112,.T.);+#114=ORIENTED_EDGE($,$,$,#113,.T.);+#115=ORIENTED_EDGE($,$,$,#62,.F.);+#116=ORIENTED_EDGE($,$,$,#91,.F.);+#117=EDGE_LOOP($,(#108,#114,#115,#116));+#118=FACE_OUTER_BOUND('',#117,.T.);+#119=ADVANCED_FACE('',(#118),#107,.T.);+#120=CARTESIAN_POINT($,(0,15,0));+#121=DIRECTION($,(0,1,0));+#122=DIRECTION($,(-1,0,0));+#123=AXIS2_PLACEMENT_3D($,#120,#121,#122);+#124=PLANE($,#123);+#125=ORIENTED_EDGE($,$,$,#30,.T.);+#126=CARTESIAN_POINT($,(-20,15,-6));+#127=DIRECTION($,(0,0,1));+#128=VECTOR($,#127,1);+#129=LINE($,#126,#128);+#130=EDGE_CURVE($,#25,#65,#129,.T.);+#131=ORIENTED_EDGE($,$,$,#130,.T.);+#132=ORIENTED_EDGE($,$,$,#70,.F.);+#133=ORIENTED_EDGE($,$,$,#113,.F.);+#134=EDGE_LOOP($,(#125,#131,#132,#133));+#135=FACE_OUTER_BOUND('',#134,.T.);+#136=ADVANCED_FACE('',(#135),#124,.T.);+#137=CARTESIAN_POINT($,(-20,0,0));+#138=DIRECTION($,(-1,0,0));+#139=DIRECTION($,(0,1,0));+#140=AXIS2_PLACEMENT_3D($,#137,#138,#139);+#141=PLANE($,#140);+#142=ORIENTED_EDGE($,$,$,#36,.T.);+#143=ORIENTED_EDGE($,$,$,#98,.T.);+#144=ORIENTED_EDGE($,$,$,#76,.F.);+#145=ORIENTED_EDGE($,$,$,#130,.F.);+#146=EDGE_LOOP($,(#142,#143,#144,#145));+#147=FACE_OUTER_BOUND('',#146,.T.);+#148=ADVANCED_FACE('',(#147),#141,.T.);+#149=CLOSED_SHELL($,(#40,#80,#102,#119,#136,#148));+#150=CARTESIAN_POINT($,(0,0,0));+#151=DIRECTION($,(0,0,1));+#152=DIRECTION($,(1,0,0));+#153=AXIS2_PLACEMENT_3D($,#150,#151,#152);+#154=SPHERICAL_SURFACE($,#153,4);+#155=ADVANCED_FACE('',(),#154,.T.);+#156=CLOSED_SHELL($,(#155));+#157=ORIENTED_CLOSED_SHELL($,#156,.F.);+#158=BREP_WITH_VOIDS('AetherisBody',#149,(#157));+#159=APPLICATION_CONTEXT('mechanical design');+#160=PRODUCT_CONTEXT('',#159,'mechanical');+#161=PRODUCT('AETHERIS','AetherisBody','',(#160));+#162=PRODUCT_DEFINITION_FORMATION('','',#161);+#163=PRODUCT_DEFINITION_CONTEXT('design',#159,'design');+#164=PRODUCT_DEFINITION('','',#162,#163);+#165=PRODUCT_DEFINITION_SHAPE('','',#164);+#166=(LENGTH_UNIT()NAMED_UNIT(*)SI_UNIT(.MILLI.,.METRE.));+#167=(NAMED_UNIT(*)PLANE_ANGLE_UNIT()SI_UNIT($,.RADIAN.));+#168=(NAMED_UNIT(*)SI_UNIT($,.STERADIAN.)SOLID_ANGLE_UNIT());+#169=(GEOMETRIC_REPRESENTATION_CONTEXT(3)GLOBAL_UNIT_ASSIGNED_CONTEXT((#166,#167,#168))REPRESENTATION_CONTEXT('3','3D'));+#170=SHAPE_REPRESENTATION('AetherisBody',(#158),#169);+#171=SHAPE_DEFINITION_REPRESENTATION(#165,#170);+ENDSEC;+END-ISO-10303-21;