Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Boolean wave1: add through-slot pockets and simple-root multi-hole continuation
Yuechen Li6b4a57b4729c
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 2ba13fa5..8dfbf3b9 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -363,17 +363,31 @@ public sealed class BrepBooleanTests}[Fact]- public void Subtract_NonSingleBoxResult_ReturnsNotImplemented()+ public void Subtract_ThroughSlotTwoMouthPocket_RebuildsBoundedOrthogonalPocket(){var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(0d, 4d, 0d, 4d, 0d, 4d)).Value;var right = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(1d, 3d, 1d, 3d, 0d, 4d)).Value;var result = BrepBoolean.Subtract(left, right);+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.NotNull(result.Value.SafeBooleanComposition?.OccupiedCells);+ Assert.NotEmpty(result.Value.SafeBooleanComposition!.OccupiedCells!);+ Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ }++ [Fact]+ public void Subtract_TwoAdjacentMouthOpening_RemainsRejected()+ {+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(0d, 8d, 0d, 8d, 0d, 8d)).Value;+ var right = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(0d, 4d, 0d, 4d, 2d, 7d)).Value;++ var result = BrepBoolean.Subtract(left, right);+Assert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Subtract: bounded orthogonal pocket family requires a single pocket mouth; through-slots and multi-face openings remain deferred.", diagnostic.Message);+ Assert.Equal("Boolean Subtract: bounded orthogonal pocket family only supports a single mouth or one opposite-face through-slot; broader multi-face openings remain deferred.", diagnostic.Message);}[Fact]@@ -901,6 +915,22 @@ public sealed class BrepBooleanTestsAssert.Single(result.Value.GetLoopIds(bottomFace.Id));}+ [Fact]+ public void Subtract_BoxConeBlindBottomEntry_ReturnsClosedTopHole()+ {+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;+ var blind = TransformBody(CreateCone(bottomRadius: 2d, topRadius: 4d, height: 8d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 0d)));++ var result = BrepBoolean.Subtract(left, blind);++ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);+ Assert.NotNull(result.Value.SafeBooleanComposition);+ var composition = result.Value.SafeBooleanComposition!;+ Assert.Single(composition.Holes);+ Assert.Equal(SupportedBooleanHoleSpanKind.BlindFromBottom, composition.Holes[0].SpanKind);+ }+[Fact]public void Subtract_BoxCylinderBlindRotatedAxis_ReturnsDeferredArbitraryAxisBlindDiagnostic(){@@ -1075,7 +1105,7 @@ public sealed class BrepBooleanTests}[Fact]- public void Subtract_ComposedThroughThenBlindCylinder_OnPrimitiveRoot_ReturnsBoundedBlindContinuationDiagnostic()+ public void Subtract_ComposedThroughThenBlindCylinder_OnPrimitiveRoot_Succeeds(){var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;var firstHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(-7d, 0d, 6d)));@@ -1085,9 +1115,8 @@ public sealed class BrepBooleanTestsAssert.True(first.IsSuccess);var result = BrepBoolean.Subtract(first.Value, blind);- Assert.False(result.IsSuccess);- var diagnostic = Assert.Single(result.Diagnostics);- Assert.Equal("BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily", diagnostic.Source);+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.Equal(2, result.Value.SafeBooleanComposition?.Holes.Count);}[Fact]@@ -1229,10 +1258,8 @@ public sealed class BrepBooleanTestsAssert.True(first.IsSuccess);var second = BrepBoolean.Subtract(first.Value, offsetThrough);- Assert.False(second.IsSuccess);- var diagnostic = Assert.Single(second.Diagnostics);- Assert.Equal("BrepBoolean.AnalyticHole.AxisNotAligned", diagnostic.Source);- Assert.Contains("requires coaxial cylinders", diagnostic.Message, StringComparison.Ordinal);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);}[Fact]@@ -1259,6 +1286,40 @@ public sealed class BrepBooleanTestsAssert.Contains("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);}+ [Fact]+ public void Subtract_SimpleBoxRoot_WithIndependentThroughHoles_Succeeds()+ {+ var root = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-30d, 30d, -20d, 20d, -8d, 8d)).Value;+ var holeA = TransformBody(BrepPrimitives.CreateCylinder(3d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(-12d, -4d, 0d)));+ var holeB = TransformBody(BrepPrimitives.CreateCylinder(2.5d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(10d, 6d, 0d)));++ var first = BrepBoolean.Subtract(root, holeA);+ Assert.True(first.IsSuccess);+ var second = BrepBoolean.Subtract(first.Value, holeB);++ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);+ Assert.True(BrepBindingValidator.Validate(second.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ }++ [Fact]+ public void Subtract_SimpleBoxRoot_WithUnsupportedIndependentHoleOrientation_RemainsRejected()+ {+ var root = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-30d, 30d, -20d, 20d, -8d, 8d)).Value;+ var holeA = TransformBody(BrepPrimitives.CreateCylinder(3d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(-12d, 0d, 0d)));+ var rotatedHole = TransformBody(+ BrepPrimitives.CreateCylinder(2.5d, 24d).Value,+ Transform3D.CreateRotationX(System.Math.PI / 2d) * Transform3D.CreateTranslation(new Vector3D(0d, 0d, 0d)));++ var first = BrepBoolean.Subtract(root, holeA);+ Assert.True(first.IsSuccess);+ var second = BrepBoolean.Subtract(first.Value, rotatedHole);++ Assert.False(second.IsSuccess);+ var diagnostic = Assert.Single(second.Diagnostics);+ Assert.Contains("does not match the bounded", diagnostic.Message, StringComparison.Ordinal);+ }+[Fact]public void Subtract_BoxContainedCylinderCavity_Succeeds_WithInnerShell_And_DeterministicExport(){diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.csindex 764e5c1a..de55363a 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs@@ -1688,9 +1688,16 @@ public static class BrepBooleanreturn false;}- if (mouthTouchCount > 1)+ var opensAlongX = touchesMinX && touchesMaxX;+ var opensAlongY = touchesMinY && touchesMaxY;+ var opensAlongZ = touchesMinZ && touchesMaxZ;+ var oppositePairOpeningCount = (opensAlongX ? 1 : 0) + (opensAlongY ? 1 : 0) + (opensAlongZ ? 1 : 0);++ if (mouthTouchCount > 2+ || oppositePairOpeningCount > 1+ || (mouthTouchCount == 2 && oppositePairOpeningCount == 0)){- unsupportedReason = "Boolean Subtract: bounded orthogonal pocket family requires a single pocket mouth; through-slots and multi-face openings remain deferred.";+ unsupportedReason = "Boolean Subtract: bounded orthogonal pocket family only supports a single mouth or one opposite-face through-slot; broader multi-face openings remain deferred.";return false;}@@ -1710,6 +1717,12 @@ public static class BrepBooleanreturn false;}+ if ((touchesMinX ^ touchesMaxX) && !HasStrictThickness(sideWallPositiveX + sideWallNegativeX))+ {+ unsupportedReason = "Boolean Subtract: bounded orthogonal pocket family requires strictly positive wall/floor thickness; tangent or zero-thickness side walls are unsupported.";+ return false;+ }+if ((touchesMinY || touchesMaxY) && (!HasStrictThickness(sideWallPositiveX)|| !HasStrictThickness(sideWallNegativeX)|| !HasStrictThickness(sideWallPositiveZ)@@ -1719,6 +1732,12 @@ public static class BrepBooleanreturn false;}+ if ((touchesMinY ^ touchesMaxY) && !HasStrictThickness(sideWallPositiveY + sideWallNegativeY))+ {+ unsupportedReason = "Boolean Subtract: bounded orthogonal pocket family requires strictly positive wall/floor thickness; tangent or zero-thickness side walls are unsupported.";+ return false;+ }+if ((touchesMinZ || touchesMaxZ) && (!HasStrictThickness(sideWallPositiveX)|| !HasStrictThickness(sideWallNegativeX)|| !HasStrictThickness(sideWallPositiveY)@@ -1728,6 +1747,12 @@ public static class BrepBooleanreturn false;}+ if ((touchesMinZ ^ touchesMaxZ) && !HasStrictThickness(sideWallPositiveZ + sideWallNegativeZ))+ {+ unsupportedReason = "Boolean Subtract: bounded orthogonal pocket family requires strictly positive wall/floor thickness; tangent or zero-thickness side walls are unsupported.";+ return false;+ }+var splitX = new[] { left.MinX, removed.MinX, removed.MaxX, left.MaxX }.Distinct().OrderBy(v => v).ToArray();var splitY = new[] { left.MinY, removed.MinY, removed.MaxY, left.MaxY }.Distinct().OrderBy(v => v).ToArray();var splitZ = new[] { left.MinZ, removed.MinZ, removed.MaxZ, left.MaxZ }.Distinct().OrderBy(v => v).ToArray();diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 024b1386..8bacc1b0 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -432,7 +432,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn KernelResult<BrepBody>.Failure([new BooleanDiagnostic(BooleanDiagnosticCode.UnsupportedBlindHoleComposition,- new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("blind-hole continuation exceeds bounded rebuild support; only recognized orthogonal additive roots with world-Z cylinder/cone hole chains are rebuildable in this milestone."),+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("blind-hole continuation exceeds bounded rebuild support; only recognized orthogonal additive roots (or simple box roots) with world-Z cylinder/cone hole chains are rebuildable in this milestone."),"BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily").ToKernelDiagnostic(),]);}@@ -1334,7 +1334,8 @@ public static class BrepBooleanBoxCylinderHoleBuilderSafeBooleanComposition composition,ToleranceContext tolerance){- if (composition.OccupiedCells is null || composition.OccupiedCells.Count < 2)+ if ((composition.OccupiedCells is null || composition.OccupiedCells.Count < 2)+ && composition.RootDescriptor.Kind != SafeBooleanRootKind.Box){return false;}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 671e4301..8ed9e398 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -519,7 +519,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorin SupportedBooleanHole nextHole,ToleranceContext tolerance){- if (composition.OccupiedCells is null || composition.OccupiedCells.Count < 2)+ if (!SupportsIndependentHoleContinuationRoot(composition)){return false;}@@ -554,7 +554,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorin SupportedBooleanHole nextHole,ToleranceContext tolerance){- if (composition.OccupiedCells is null || composition.OccupiedCells.Count < 2)+ if (!SupportsIndependentHoleContinuationRoot(composition)){return false;}@@ -622,7 +622,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorvar context = new BooleanContinuationContext(Operation: BooleanOperation.Subtract,HasRecognizedSafeCompositionRoot: true,- HasRecognizedOrthogonalAdditiveRoot: composition.OccupiedCells is not null && composition.OccupiedCells.Count >= 2,+ HasRecognizedOrthogonalAdditiveRoot: SupportsIndependentHoleContinuationRoot(composition),ExistingHole: existingHole,NextHole: nextHole,PairIsCoaxial: pairIsCoaxial,@@ -691,7 +691,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorScore: _ => 300d,RejectionReason: context => context.PairIsCoaxial? "Independent-hole continuation requires a non-coaxial pair."- : "Independent-hole continuation requires a recognized orthogonal additive root with world-Z cylinder/cone holes."),+ : "Independent-hole continuation requires a recognized orthogonal additive root (or simple box root) with world-Z cylinder/cone holes."),new JudgmentCandidate<BooleanContinuationContext>(Name: BooleanContinuationFamily.UnsupportedContinuationFromRecognizedRoot.ToString(),IsAdmissible: context => context.HasRecognizedSafeCompositionRoot,@@ -728,7 +728,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn AppendNearestCandidateDetail(context.SubtractStackDiagnostic, rejections);}- const string baseReason = "independent multi-hole continuation exceeds the bounded family; non-coaxial blind-hole composition is only supported on recognized orthogonal additive roots with world-Z cylinder/cone holes.";+ const string baseReason = "independent multi-hole continuation exceeds the bounded family; non-coaxial blind-hole composition is only supported on recognized orthogonal additive roots (or simple box roots) with world-Z cylinder/cone holes.";var nearest = rejections.FirstOrDefault(rejection =>rejection.CandidateName != BooleanContinuationFamily.UnsupportedContinuationFromRecognizedRoot.ToString()&& rejection.CandidateName != BooleanContinuationFamily.UnsupportedGeneral.ToString());@@ -758,6 +758,10 @@ public static class BrepBooleanSafeCompositionGraphValidator};}+ private static bool SupportsIndependentHoleContinuationRoot(SafeBooleanComposition composition)+ => (composition.OccupiedCells is { Count: >= 2 })+ || composition.RootDescriptor.Kind == SafeBooleanRootKind.Box;+private enum BooleanContinuationFamily{CoaxialCountersinkPair,diff --git a/docs/boolean-deferred.md b/docs/boolean-deferred.mdindex 49615242..7a315cf0 100644--- a/docs/boolean-deferred.md+++ b/docs/boolean-deferred.md@@ -10,10 +10,12 @@ The current supported boolean subset is intentionally narrow and family-specific- box − cone through-hole- box − cylinder blind hole- box − cone blind hole+- box − box blind pocket and opposite-face through-slot (bounded orthogonal pocket family)- box − sphere cavity- rotated cylinder through-hole-- safe-family composition for the currently supported through-hole family+- safe-family composition for supported analytic-hole families, including independent world-Z multi-hole continuation on simple box roots- recognized safe box-root subtract with bounded prismatic through-cut tools (triangular/hexagonal/slot profiles) when the root has no prior subtract history+- face-contact orthogonal unions even when no axis has full-span equality (bounded connected-cell family)## Current deferred boolean pile@@ -27,6 +29,7 @@ The following items remain deferred:- broad add/intersect expansion outside the current narrow box-box subset- general BRep booleans- bounded mixed analytic-hole + prismatic continuation rebuild path on safe box roots (recognition now exists; bounded reconstruction remains deferred)+- safe-composition prismatic blind-pocket continuation (recognition-classification gap + bounded reconstruction path still deferred)## Known blocker: rotated cone through-hole