Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Fix sphere outside test to avoid tangent boundary case
Yuechen Li2978487cc471
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.csindex 9cacc71c..1ad828c2 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs@@ -82,14 +82,14 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests}[Fact]- public void ValidateNextSubtract_Sphere_FailsWithUnsupportedSurfaceDiagnostic()+ public void ValidateNextSubtract_ContainedSphere_FailsWithMultiShellDiagnostic(){var composition = new SafeBooleanComposition(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d),[]);var sphere = new AnalyticSurface(AnalyticSurfaceKind.Sphere,- Sphere: new RecognizedSphere(Point3D.Origin, 3d));+ Sphere: new RecognizedSphere(new Point3D(0d, 0d, 6d), 3d));var result = BrepBooleanSafeCompositionGraphValidator.TryValidateNextSubtract(composition,@@ -100,9 +100,9 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTestsAssert.False(result);Assert.NotNull(diagnostic);- Assert.Equal(BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind, diagnostic!.Code);- Assert.Equal("BrepBoolean.UnsupportedAnalyticSurfaceKind", diagnostic.Source);- Assert.Equal("Boolean Subtract does not support analytic tool surface kind 'Sphere' in the safe boolean family. Use a cylinder or cone through-hole instead.", diagnostic.Message);+ 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);}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 55a87850..17c4d815 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -608,7 +608,7 @@ public sealed class BrepBooleanTests[Fact]- public void Subtract_BoxSphereFullyContained_StillReturnsDeterministicNotImplemented()+ public void Subtract_BoxSphereFullyContained_ReturnsMultiShellNotSupportedDiagnostic(){var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, -6d, 6d)).Value;var right = BrepPrimitives.CreateSphere(4d).Value;@@ -618,8 +618,38 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("BrepBoolean.UnsupportedAnalyticSurfaceKind", diagnostic.Source);- Assert.Equal("Boolean Subtract does not support analytic tool surface kind 'Sphere' in the safe boolean family. Use a cylinder or cone through-hole instead.", diagnostic.Message);+ 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);+ }++ [Fact]+ public void Subtract_BoxSphereTangentBoundary_ReturnsTangentContactDiagnostic()+ {+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, -6d, 6d)).Value;+ var right = TransformBody(BrepPrimitives.CreateSphere(6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 0d)));++ var result = BrepBoolean.Subtract(left, right);++ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);+ Assert.Equal("BrepBoolean.AnalyticHole.TangentContact", diagnostic.Source);+ Assert.Equal("Boolean Subtract is tangent to a box boundary plane; tangent spherical cavities are rejected to avoid zero-thickness boundary contact.", diagnostic.Message);+ }++ [Fact]+ public void Subtract_BoxSpherePartiallyOutside_ReturnsRadiusExceedsBoundaryDiagnostic()+ {+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, -6d, 6d)).Value;+ var right = TransformBody(BrepPrimitives.CreateSphere(4d).Value, Transform3D.CreateTranslation(new Vector3D(17d, 0d, 0d)));++ var result = BrepBoolean.Subtract(left, right);++ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);+ Assert.Equal("BrepBoolean.AnalyticHole.RadiusExceedsBoundary", diagnostic.Source);+ Assert.Equal("Boolean Subtract extends outside the box boundary; spherical cavity tools must remain strictly contained inside the box.", diagnostic.Message);}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.csindex 919d85dc..c817306b 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs@@ -361,6 +361,12 @@ public static class BrepBooleanCylinderRecognitionCreateBooleanMessage(operation, featureId, detail),"BrepBoolean.AnalyticHole.TangentContact");+ public static BooleanDiagnostic CreateMultiBodyResultDiagnostic(string operation, string? featureId, string detail)+ => new(+ BooleanDiagnosticCode.MultiBodyResult,+ CreateBooleanMessage(operation, featureId, detail),+ "BrepBoolean.AnalyticHole.MultiBodyResult");+public static BooleanDiagnostic CreateUnsupportedAnalyticSurfaceKindDiagnostic(string operation, AnalyticSurfaceKind kind)=> CreateUnsupportedAnalyticSurfaceKindDiagnostic(operation, kind, null);diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex dd6b5e1f..71296b79 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -102,6 +102,20 @@ public static class BrepBooleanSafeCompositionGraphValidatorcone.RadiusAtAxisParameter(topAxisParameter));return true;+ case AnalyticSurfaceKind.Sphere when surface.Sphere is RecognizedSphere sphere:+ if (!ValidateContainedSphereCavity(outerBox, sphere, tolerance, out diagnostic, featureId))+ {+ hole = default;+ return false;+ }++ diagnostic = BrepBooleanCylinderRecognition.CreateMultiBodyResultDiagnostic(+ BooleanOperation.Subtract.ToString(),+ 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;+case AnalyticSurfaceKind.Sphere:case AnalyticSurfaceKind.Torus:default:@@ -127,4 +141,53 @@ public static class BrepBooleanSafeCompositionGraphValidatorprivate static string FormatFeatureRef(string? featureId)=> string.IsNullOrWhiteSpace(featureId) ? "<unknown>" : $"'{featureId}'";++ private static bool ValidateContainedSphereCavity(+ AxisAlignedBoxExtents outerBox,+ in RecognizedSphere sphere,+ ToleranceContext tolerance,+ out BooleanDiagnostic? diagnostic,+ string? featureId)+ {+ diagnostic = null;++ var minX = sphere.Center.X - sphere.Radius;+ var maxX = sphere.Center.X + sphere.Radius;+ var minY = sphere.Center.Y - sphere.Radius;+ var maxY = sphere.Center.Y + sphere.Radius;+ var minZ = sphere.Center.Z - sphere.Radius;+ var maxZ = sphere.Center.Z + sphere.Radius;++ var tangentContact =+ ToleranceMath.AlmostEqual(minX, outerBox.MinX, tolerance)+ || ToleranceMath.AlmostEqual(maxX, outerBox.MaxX, tolerance)+ || ToleranceMath.AlmostEqual(minY, outerBox.MinY, tolerance)+ || ToleranceMath.AlmostEqual(maxY, outerBox.MaxY, tolerance)+ || ToleranceMath.AlmostEqual(minZ, outerBox.MinZ, tolerance)+ || ToleranceMath.AlmostEqual(maxZ, outerBox.MaxZ, tolerance);+ if (tangentContact)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "is tangent to a box boundary plane; tangent spherical cavities are rejected to avoid zero-thickness boundary contact.");+ return false;+ }++ if (minX < (outerBox.MinX - tolerance.Linear)+ || maxX > (outerBox.MaxX + tolerance.Linear)+ || minY < (outerBox.MinY - tolerance.Linear)+ || maxY > (outerBox.MaxY + tolerance.Linear)+ || minZ < (outerBox.MinZ - tolerance.Linear)+ || maxZ > (outerBox.MaxZ + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "extends outside the box boundary; spherical cavity tools must remain strictly contained inside the box.");+ return false;+ }++ return true;+ }}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex 02bb3282..2e634a48 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -162,6 +162,21 @@ public sealed class FirmamentBooleanCanonicalSuccessTests&& HasExpectedMixedPrimitiveFailure(diagnostic.Message));}+ [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)+ {+ var result = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText(fixturePath));++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Code == KernelDiagnosticCode.NotImplemented+ && diagnostic.Source == expectedSource+ && diagnostic.Message.Contains(expectedMessageFragment, StringComparison.Ordinal));+ }+[Theory][InlineData("testdata/firmament/fixtures/m13a-unsupported-overlapping-composed-holes.firmament", "hole_b", "overlaps previously accepted hole")][InlineData("testdata/firmament/fixtures/m13a-unsupported-tangent-composed-holes.firmament", "hole_b", "would be tangent to previously accepted hole")]@@ -227,7 +242,8 @@ public sealed class FirmamentBooleanCanonicalSuccessTests|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)|| message.Contains("Boolean feature", StringComparison.Ordinal)- || message.Contains("analytic hole surface kind", StringComparison.Ordinal);+ || message.Contains("analytic hole surface kind", StringComparison.Ordinal)+ || message.Contains("fully enclosed spherical cavity", StringComparison.Ordinal);private static int CountOccurrences(string text, string token){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex f411ec5a..9b07842c 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -252,5 +252,6 @@ public sealed class FirmamentBuildAndExportTests|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)|| message.Contains("Boolean feature", StringComparison.Ordinal)- || message.Contains("analytic hole surface kind", StringComparison.Ordinal);+ || message.Contains("analytic hole surface kind", StringComparison.Ordinal)+ || message.Contains("fully enclosed spherical cavity", StringComparison.Ordinal);}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.csindex e02948a2..705df013 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs@@ -274,7 +274,8 @@ public sealed class FirmamentStepExporterTests|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)|| message.Contains("Boolean feature", StringComparison.Ordinal)- || message.Contains("analytic hole surface kind", StringComparison.Ordinal);+ || message.Contains("analytic hole surface kind", StringComparison.Ordinal)+ || message.Contains("fully enclosed spherical cavity", StringComparison.Ordinal);private static int CountOccurrences(string text, string token){diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.mdindex a64e7100..6a2e6010 100644--- a/testdata/firmament/examples/README.md+++ b/testdata/firmament/examples/README.md@@ -22,4 +22,4 @@ Other combinations may fail and are intentionally not supported yet.- `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 booleans are currently unsupported in all audited forms, including `subtract(box, sphere)` with a fully contained sphere, boundary-touching sphere, or partially outside sphere, plus all current box+sphere `add` and `intersect` requests. 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 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.