Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
G8: support bounded independent multi-hole continuation on additive roots
Yuechen Li33c4e8f8e210
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.csindex 238c002b..b03a75e9 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs@@ -109,6 +109,59 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTestsAssert.Null(diagnostic);}+ [Fact]+ public void ValidateNextSubtract_IndependentHoleContinuationOnRecognizedRoot_RejectsUnsupportedAxisFamily()+ {+ var composition = new SafeBooleanComposition(+ new AxisAlignedBoxExtents(-30d, 30d, -15d, 15d, -4d, 44d),+ [+ new SupportedBooleanHole(+ "hole_a",+ new AnalyticSurface(+ AnalyticSurfaceKind.Cylinder,+ Cylinder: new RecognizedCylinder(+ new Point3D(-15d, 0d, 0d),+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ 0d,+ 20d,+ 3.5d)),+ -15d,+ 0d,+ new Point3D(-15d, 0d, -4d),+ new Point3D(-15d, 0d, 44d),+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),+ 3.5d,+ 3.5d,+ SupportedBooleanHoleSpanKind.Through,+ -4d,+ 44d)+ ],+ SafeBooleanRootDescriptor.FromBox(new AxisAlignedBoxExtents(-30d, 30d, -15d, 15d, -4d, 44d)),+ [new AxisAlignedBoxExtents(-30d, 30d, -15d, 15d, -4d, 4d), new AxisAlignedBoxExtents(22d, 30d, -15d, 15d, 4d, 44d)]);+ var next = new AnalyticSurface(+ AnalyticSurfaceKind.Cylinder,+ Cylinder: new RecognizedCylinder(+ new Point3D(26d, 0d, 18d),+ Direction3D.Create(new Vector3D(0.2d, 0d, 1d)),+ 0d,+ 20d,+ 3.5d));++ var result = BrepBooleanSafeCompositionGraphValidator.TryValidateNextSubtract(+ composition,+ next,+ ToleranceContext.Default,+ out _,+ out var diagnostic);++ Assert.False(result);+ Assert.NotNull(diagnostic);+ Assert.Equal(BooleanDiagnosticCode.NotFullySpanning, diagnostic!.Code);+ Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);+ Assert.Contains("does not match the supported subtract span family", diagnostic.Message, StringComparison.Ordinal);+ }+[Fact]public void ValidateNextSubtract_SphereAfterExistingHole_FailsWithUnsupportedAnalyticSurfaceDiagnostic(){diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex e294093b..8699e80e 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -937,6 +937,30 @@ public sealed class BrepBooleanTestsAssert.Contains("requires coaxial cylinders", diagnostic.Message, StringComparison.Ordinal);}+ [Fact]+ public void Subtract_RecognizedOrthogonalAdditiveRoot_WithIndependentBlindHoles_Succeeds_And_Exports()+ {+ var basePlate = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-30d, 30d, -15d, 15d, -4d, 4d)).Value;+ var upright = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(22d, 30d, -15d, 15d, 4d, 44d)).Value;+ var bracket = BrepBoolean.Union(basePlate, upright);+ Assert.True(bracket.IsSuccess);++ var baseHole = TransformBody(BrepPrimitives.CreateCylinder(3.5d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(-15d, 0d, 0d)));+ var uprightHole = TransformBody(BrepPrimitives.CreateCylinder(3.5d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(26d, 0d, 18d)));++ var first = BrepBoolean.Subtract(bracket.Value, baseHole);+ Assert.True(first.IsSuccess);++ var second = BrepBoolean.Subtract(first.Value, uprightHole);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(second.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);++ var export = Step242Exporter.ExportBody(second.Value);+ Assert.True(export.IsSuccess);+ Assert.Contains("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);+ }+[Fact]public void Subtract_BoxContainedCylinderCavity_Succeeds_WithInnerShell_And_DeterministicExport(){diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 1c785fcd..97cecb32 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -59,7 +59,9 @@ public static class BrepBooleanBoxCylinderHoleBuilder]);}- if (composition.Holes.Count == 2 && composition.Holes.Any(h => h.IsBlind))+ if (composition.Holes.Count == 2+ && composition.Holes.Any(h => h.IsBlind)+ && IsCoaxialHolePair(composition.Holes[0], composition.Holes[1], tolerance)){if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(composition.OuterBox,@@ -81,6 +83,14 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn CreateComposedThroughHoleBody(composition, tolerance);}+ private static bool IsCoaxialHolePair(in SupportedBooleanHole first, in SupportedBooleanHole second, ToleranceContext tolerance)+ {+ var deltaX = first.CenterX - second.CenterX;+ var deltaY = first.CenterY - second.CenterY;+ return ToleranceMath.AlmostZero(deltaX, tolerance)+ && ToleranceMath.AlmostZero(deltaY, tolerance);+ }+private static KernelResult<BrepBody> CreateBoundedCylinderRootHoleChainBody(SafeBooleanComposition composition, ToleranceContext tolerance){if (composition.RootDescriptor.Cylinder is not RecognizedCylinder rootCylinderdiff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 38cfe99a..ae2f35fc 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -66,24 +66,45 @@ public static class BrepBooleanSafeCompositionGraphValidatorvar requiredDistance = existingHole.MaxBoundaryRadius + nextHole.MaxBoundaryRadius;if (composition.Holes.Count == 1- && (existingHole.IsBlind || nextHole.IsBlind)- && centerDistance < (requiredDistance + tolerance.Linear))+ && (existingHole.IsBlind || nextHole.IsBlind)){- if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(- composition.OuterBox,- existingHole,- nextHole,- tolerance,- out _,- out var steppedDiagnostic,- nextFeatureId))+ if (IsCoaxialHolePair(existingHole, nextHole, tolerance)){- continue;- }+ if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(+ composition.OuterBox,+ existingHole,+ nextHole,+ tolerance,+ out _,+ out var steppedDiagnostic,+ nextFeatureId))+ {+ continue;+ }- if (steppedDiagnostic is not null)+ if (steppedDiagnostic is not null)+ {+ diagnostic = steppedDiagnostic;+ return false;+ }+ }+ else if (!SupportsBoundedIndependentHoleContinuationOnRecognizedOrthogonalAdditiveRoot(composition, nextHole, tolerance)){- diagnostic = steppedDiagnostic;+ BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(+ composition.OuterBox,+ existingHole,+ nextHole,+ tolerance,+ out _,+ out var steppedDiagnostic,+ nextFeatureId);+ diagnostic = steppedDiagnostic ?? new BooleanDiagnostic(+ BooleanDiagnosticCode.UnsupportedBlindHoleComposition,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ "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."),+ "BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily");return false;}}@@ -489,6 +510,49 @@ public static class BrepBooleanSafeCompositionGraphValidator&& ToleranceMath.AlmostEqual(System.Math.Abs(v.Z), 1d, tolerance);}+ private static bool IsCoaxialHolePair(in SupportedBooleanHole first, in SupportedBooleanHole second, ToleranceContext tolerance)+ {+ var deltaX = first.CenterX - second.CenterX;+ var deltaY = first.CenterY - second.CenterY;+ return ToleranceMath.AlmostZero(deltaX, tolerance)+ && ToleranceMath.AlmostZero(deltaY, tolerance);+ }++ private static bool SupportsBoundedIndependentHoleContinuationOnRecognizedOrthogonalAdditiveRoot(+ SafeBooleanComposition composition,+ in SupportedBooleanHole nextHole,+ ToleranceContext tolerance)+ {+ if (composition.OccupiedCells is null || composition.OccupiedCells.Count < 2)+ {+ return false;+ }++ if (!IsAxisAlignedWithWorldZ(nextHole.Axis, tolerance))+ {+ return false;+ }++ if (!IsSupportedIndependentHoleShape(nextHole.Surface.Kind))+ {+ return false;+ }++ foreach (var existingHole in composition.Holes)+ {+ if (!IsAxisAlignedWithWorldZ(existingHole.Axis, tolerance)+ || !IsSupportedIndependentHoleShape(existingHole.Surface.Kind))+ {+ return false;+ }+ }++ return true;+ }++ private static bool IsSupportedIndependentHoleShape(AnalyticSurfaceKind kind)+ => kind is AnalyticSurfaceKind.Cylinder or AnalyticSurfaceKind.Cone;+private static bool SupportsBoundedBlindContinuationOnRecognizedOrthogonalAdditiveRoot(SafeBooleanComposition composition,in SupportedBooleanHole nextHole,diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex b7e1b198..e0e2636d 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -366,18 +366,16 @@ public sealed class FirmamentBuildAndExportTests}[Fact]- public void Run_FrictionLabMountingBracketBasic_ProgressesToCoaxialStackConstraint()+ public void Run_FrictionLabMountingBracketBasic_Builds_And_Exports_After_G8_IndependentHoleSupport(){var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/mounting-bracket-basic/part.firmament");var result = FirmamentBuildAndExport.Run(fullSourcePath);- Assert.False(result.IsSuccess);- Assert.Contains(result.Diagnostics, diagnostic =>- diagnostic.Message.Contains("Requested boolean feature 'upright_hole' (subtract) could not be executed.", StringComparison.Ordinal));- Assert.Contains(result.Diagnostics, diagnostic =>- diagnostic.Message.Contains("requires coaxial cylinders with matching XY axis centers", StringComparison.Ordinal));- Assert.DoesNotContain(result.Diagnostics, diagnostic =>- diagnostic.Message.Contains("cannot append a blind analytic hole to an existing safe subtract composition", StringComparison.Ordinal));+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.Equal("upright_hole", result.Value.Export.ExportedFeatureId);+ Assert.Equal("boolean", result.Value.Export.ExportedBodyCategory);+ Assert.Equal("subtract", result.Value.Export.ExportedFeatureKind);+ Assert.Contains("MANIFOLD_SOLID_BREP", result.Value.Export.StepText, StringComparison.Ordinal);}[Fact]