Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Generalize safe composition validator for N-level coaxial stacks
Yuechen Li31ad2ca0c00d
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.csindex a1cc6066..3b6117e9 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs@@ -265,6 +265,31 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTestsAssert.Equal(2, updated.Holes.Count);}+ [Fact]+ public void ValidateNextSubtract_NLevelCoaxialSteppedContinuation_AdmitsThirdHole()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-15d, 15d, -15d, 15d, -10d, 10d)).Value;+ var through = BrepPrimitives.CreateCylinder(2d, 30d).Value;+ var mediumBlind = TransformBody(BrepPrimitives.CreateCylinder(3d, 6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 7d)));+ var shallowBlind = TransformBody(BrepPrimitives.CreateCylinder(4d, 3d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 8.5d)));+ var first = BrepBoolean.Subtract(baseBox, through);+ var second = BrepBoolean.Subtract(first.Value, mediumBlind);+ Assert.True(second.IsSuccess);+ Assert.True(BrepBooleanAnalyticSurfaceRecognition.TryRecognizeCylinder(shallowBlind, ToleranceContext.Default, out var next, out _));++ var result = BrepBooleanSafeCompositionGraphValidator.TryValidateNextSubtract(+ second.Value.SafeBooleanComposition!,+ next,+ ToleranceContext.Default,+ out var updated,+ out var diagnostic,+ "hole3");++ Assert.True(result, diagnostic?.Message);+ Assert.Null(diagnostic);+ Assert.Equal(3, updated.Holes.Count);+ }+private static BrepBody TransformBody(BrepBody body, Transform3D transform){var geometry = new BrepGeometryStore();diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSteppedStackRootCauseTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSteppedStackRootCauseTests.csindex a0e9fb59..6a520a8c 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSteppedStackRootCauseTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSteppedStackRootCauseTests.cs@@ -13,7 +13,7 @@ namespace Aetheris.Kernel.Core.Tests.Brep.Boolean;public sealed class BrepBooleanSteppedStackRootCauseTests{[Fact]- public void SteppedThirdSubtract_FailsWithObservedValidatorDiagnostic()+ public void SteppedThirdSubtract_NoLongerFailsWithHoleInterference(){var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-15d, 15d, -15d, 15d, -10d, 10d)).Value;var through = BrepPrimitives.CreateCylinder(2d, 30d).Value;@@ -28,12 +28,11 @@ public sealed class BrepBooleanSteppedStackRootCauseTestsAssert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);var third = BrepBoolean.Subtract(second.Value, shallowBlind);- Assert.False(third.IsSuccess);-- var diagnostic = Assert.Single(third.Diagnostics);- Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("BrepBoolean.AnalyticHole.HoleInterference", diagnostic.Source);- Assert.Contains("overlaps previously accepted hole", diagnostic.Message, StringComparison.Ordinal);+ if (!third.IsSuccess)+ {+ var diagnostic = Assert.Single(third.Diagnostics);+ Assert.NotEqual("BrepBoolean.AnalyticHole.HoleInterference", diagnostic.Source);+ }}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.csindex 7e734ccb..d841b203 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs@@ -12,6 +12,83 @@ internal readonly record struct CoaxialCylinderSubtractStackProfile(internal static class BrepBooleanCoaxialSubtractStackFamily{+ public static bool TryClassifyNLevel(+ AxisAlignedBoxExtents outerBox,+ IReadOnlyList<SupportedBooleanHole> existingHoles,+ in SupportedBooleanHole nextHole,+ ToleranceContext tolerance,+ out BooleanDiagnostic? diagnostic,+ string? featureId = null)+ {+ diagnostic = null;+ if (existingHoles.Count == 0)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "N-level coaxial stack classification requires at least one existing hole.");+ return false;+ }++ var all = existingHoles.Append(nextHole).ToArray();+ if (all.Any(h => h.Surface.Kind != AnalyticSurfaceKind.Cylinder))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(BooleanOperation.Subtract.ToString(), AnalyticSurfaceKind.Cylinder, featureId);+ return false;+ }++ if (all.Any(h => !IsWorldZAligned(h.Axis, tolerance)))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires world-Z aligned cylinders.");+ return false;+ }++ var seed = all[0];+ if (all.Any(h => System.Math.Sqrt(((h.CenterX - seed.CenterX) * (h.CenterX - seed.CenterX)) + ((h.CenterY - seed.CenterY) * (h.CenterY - seed.CenterY))) > tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires matching XY centers.");+ return false;+ }++ var through = all.Where(h => h.SpanKind == SupportedBooleanHoleSpanKind.Through).ToArray();+ if (through.Length != 1)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires exactly one through segment.");+ return false;+ }++ var topBlinds = all.Where(h => h.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop).ToArray();+ if (topBlinds.Length == 0 || all.Any(h => h.SpanKind is SupportedBooleanHoleSpanKind.BlindFromBottom or SupportedBooleanHoleSpanKind.Contained))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support is limited to top-entry blind segments with one through segment.");+ return false;+ }++ var ordered = topBlinds.OrderBy(h => ResolveBottom(h)).ToArray(); // deeper first (smaller Z)+ for (var i = 0; i < ordered.Length - 1; i++)+ {+ if (!(ordered[i].BottomRadius < (ordered[i + 1].BottomRadius - tolerance.Linear)))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires strictly increasing blind radii toward top entry.");+ return false;+ }++ if (!(ResolveBottom(ordered[i]) < (ResolveBottom(ordered[i + 1]) - tolerance.Linear)))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires strictly decreasing blind depths toward top entry.");+ return false;+ }+ }++ if (all.Any(h => !IsTopEntry(h, outerBox, tolerance) && h.SpanKind != SupportedBooleanHoleSpanKind.Through))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "N-level coaxial subtract-stack support requires all blind segments to enter from the top face.");+ return false;+ }++ return true;+ }+public static bool TryClassifyPair(AxisAlignedBoxExtents outerBox,in SupportedBooleanHole first,diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 1518c2a0..6a013161 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -60,49 +60,15 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn false;}- foreach (var existingHole in composition.Holes)+ if (composition.Holes.Count > 0){- var deltaX = existingHole.CenterX - nextHole.CenterX;- var deltaY = existingHole.CenterY - nextHole.CenterY;- var centerDistance = System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));- var requiredDistance = existingHole.MaxBoundaryRadius + nextHole.MaxBoundaryRadius;-- if (composition.Holes.Count == 1- && (existingHole.IsBlind || nextHole.IsBlind))+ if (!TryValidateHoleContinuationCandidate(composition, nextHole, tolerance, nextFeatureId, out var applyIndependentInterferenceChecks, out diagnostic)){- if (!TryValidateBlindContinuationCandidate(- composition,- existingHole,- nextHole,- tolerance,- nextFeatureId,- out var skipPairChecks,- out diagnostic))- {- return false;- }-- if (skipPairChecks)- {- continue;- }- }-- if (ToleranceMath.AlmostEqual(centerDistance, requiredDistance, tolerance))- {- diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- $"would be tangent to previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; tangent safe-hole composition is rejected to avoid zero-thickness geometry.");return false;}- if (centerDistance < (requiredDistance - tolerance.Linear))+ if (applyIndependentInterferenceChecks && !TryValidateIndependentHoleInterference(composition, nextHole, tolerance, diagnosticContext, out diagnostic)){- diagnostic = new BooleanDiagnostic(- BooleanDiagnosticCode.HoleInterference,- diagnosticContext.FormatMessage($"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping safe-hole composition is not supported. Separate the hole centers or reduce one of the boundary radii."),- "BrepBoolean.AnalyticHole.HoleInterference");return false;}}@@ -609,24 +575,28 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn nextHole.Surface.Kind is AnalyticSurfaceKind.Cylinder or AnalyticSurfaceKind.Cone;}- private static bool TryValidateBlindContinuationCandidate(+ private static bool TryValidateHoleContinuationCandidate(SafeBooleanComposition composition,- in SupportedBooleanHole existingHole,in SupportedBooleanHole nextHole,ToleranceContext tolerance,string? featureId,- out bool skipPairChecks,+ out bool applyIndependentInterferenceChecks,out BooleanDiagnostic? diagnostic){- skipPairChecks = false;- var pairIsCoaxial = IsCoaxialHolePair(existingHole, nextHole, tolerance);+ applyIndependentInterferenceChecks = false;+ var nextHoleLocal = nextHole;+ var pairIsCoaxial = composition.Holes.Count > 0 && composition.Holes.All(existingHole => IsCoaxialHolePair(existingHole, nextHoleLocal, tolerance));+ var requiresBlindPairFamily = composition.Holes.Count == 1 && (composition.Holes[0].IsBlind || nextHoleLocal.IsBlind) && pairIsCoaxial;var countersinkSupported = false;BooleanDiagnostic? countersinkDiagnostic = null;var stackSupported = false;BooleanDiagnostic? stackDiagnostic = null;+ var nLevelSupported = false;+ BooleanDiagnostic? nLevelDiagnostic = null;- if (pairIsCoaxial)+ if (composition.Holes.Count == 1 && pairIsCoaxial){+ var existingHole = composition.Holes[0];countersinkSupported = BrepBooleanCoaxialCountersinkSubtractFamily.TryClassifyPair(composition.OuterBox,existingHole,@@ -644,15 +614,14 @@ public static class BrepBooleanSafeCompositionGraphValidatorout stackDiagnostic,featureId);}- else+ else if (pairIsCoaxial && composition.Holes.Count >= 2){- BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(+ nLevelSupported = BrepBooleanCoaxialSubtractStackFamily.TryClassifyNLevel(composition.OuterBox,- existingHole,+ composition.Holes,nextHole,tolerance,- out _,- out stackDiagnostic,+ out nLevelDiagnostic,featureId);}@@ -660,13 +629,16 @@ public static class BrepBooleanSafeCompositionGraphValidatorOperation: BooleanOperation.Subtract,HasRecognizedSafeCompositionRoot: true,HasRecognizedOrthogonalAdditiveRoot: SupportsIndependentHoleContinuationRoot(composition),- ExistingHole: existingHole,+ ExistingHole: composition.Holes[0],NextHole: nextHole,PairIsCoaxial: pairIsCoaxial,IsCountersinkSupported: countersinkSupported,CountersinkDiagnostic: countersinkDiagnostic,IsSubtractStackSupported: stackSupported,SubtractStackDiagnostic: stackDiagnostic,+ IsNLevelSubtractStackSupported: nLevelSupported,+ NLevelSubtractStackDiagnostic: nLevelDiagnostic,+ RequiresBlindPairFamily: requiresBlindPairFamily,SupportsIndependentContinuationOnAdditiveRoot: SupportsBoundedIndependentHoleContinuationOnRecognizedOrthogonalAdditiveRoot(composition, nextHole, tolerance));var result = ContinuationJudgmentEngine.Evaluate(context, ContinuationCandidates);@@ -684,8 +656,12 @@ public static class BrepBooleanSafeCompositionGraphValidator{case BooleanContinuationFamily.CoaxialCountersinkPair:case BooleanContinuationFamily.CoaxialSubtractStack:+ case BooleanContinuationFamily.NLevelCoaxialSubtractStack:+ applyIndependentInterferenceChecks = false;+ diagnostic = null;+ return true;case BooleanContinuationFamily.IndependentHolesOnAdditiveRoot:- skipPairChecks = true;+ applyIndependentInterferenceChecks = true;diagnostic = null;return true;case BooleanContinuationFamily.UnsupportedContinuationFromRecognizedRoot:@@ -722,13 +698,18 @@ public static class BrepBooleanSafeCompositionGraphValidatorRejectionReason: context => context.PairIsCoaxial? context.SubtractStackDiagnostic?.Message ?? "Coaxial subtract-stack continuation predicates were not satisfied.": "Coaxial subtract-stack continuation requires a coaxial pair."),+ new JudgmentCandidate<BooleanContinuationContext>(+ Name: BooleanContinuationFamily.NLevelCoaxialSubtractStack.ToString(),+ IsAdmissible: context => context.PairIsCoaxial && context.IsNLevelSubtractStackSupported,+ Score: _ => 450d,+ RejectionReason: context => context.PairIsCoaxial+ ? context.NLevelSubtractStackDiagnostic?.Message ?? "N-level coaxial subtract-stack continuation predicates were not satisfied."+ : "N-level coaxial subtract-stack continuation requires coaxial holes."),new JudgmentCandidate<BooleanContinuationContext>(Name: BooleanContinuationFamily.IndependentHolesOnAdditiveRoot.ToString(),- IsAdmissible: context => !context.PairIsCoaxial && context.SupportsIndependentContinuationOnAdditiveRoot,+ IsAdmissible: context => !context.RequiresBlindPairFamily && context.SupportsIndependentContinuationOnAdditiveRoot,Score: _ => 300d,- RejectionReason: context => context.PairIsCoaxial- ? "Independent-hole continuation requires a non-coaxial pair."- : "Independent-hole continuation requires a recognized orthogonal additive root (or simple box root) with world-Z cylinder/cone holes."),+ RejectionReason: _ => "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,@@ -803,6 +784,7 @@ public static class BrepBooleanSafeCompositionGraphValidator{CoaxialCountersinkPair,CoaxialSubtractStack,+ NLevelCoaxialSubtractStack,IndependentHolesOnAdditiveRoot,UnsupportedContinuationFromRecognizedRoot,UnsupportedGeneral@@ -819,8 +801,47 @@ public static class BrepBooleanSafeCompositionGraphValidatorBooleanDiagnostic? CountersinkDiagnostic,bool IsSubtractStackSupported,BooleanDiagnostic? SubtractStackDiagnostic,+ bool IsNLevelSubtractStackSupported,+ BooleanDiagnostic? NLevelSubtractStackDiagnostic,+ bool RequiresBlindPairFamily,bool SupportsIndependentContinuationOnAdditiveRoot);+ private static bool TryValidateIndependentHoleInterference(+ SafeBooleanComposition composition,+ in SupportedBooleanHole nextHole,+ ToleranceContext tolerance,+ in BooleanDiagnosticContext diagnosticContext,+ out BooleanDiagnostic? diagnostic)+ {+ foreach (var existingHole in composition.Holes)+ {+ var deltaX = existingHole.CenterX - nextHole.CenterX;+ var deltaY = existingHole.CenterY - nextHole.CenterY;+ var centerDistance = System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));+ var requiredDistance = existingHole.MaxBoundaryRadius + nextHole.MaxBoundaryRadius;+ if (ToleranceMath.AlmostEqual(centerDistance, requiredDistance, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ nextHole.FeatureId,+ $"would be tangent to previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; tangent safe-hole composition is rejected to avoid zero-thickness geometry.");+ return false;+ }++ if (centerDistance < (requiredDistance - tolerance.Linear))+ {+ diagnostic = new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ diagnosticContext.FormatMessage($"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping safe-hole composition is not supported. Separate the hole centers or reduce one of the boundary radii."),+ "BrepBoolean.AnalyticHole.HoleInterference");+ return false;+ }+ }++ diagnostic = null;+ return true;+ }+private static bool TryValidateBoundedSphereSubtract(AxisAlignedBoxExtents outerBox,in RecognizedSphere sphere,diff --git a/docs/brep-boolean-stack-a1-nlevel-coaxial-validator.md b/docs/brep-boolean-stack-a1-nlevel-coaxial-validator.mdnew file mode 100644index 00000000..82e6fcb4--- /dev/null+++ b/docs/brep-boolean-stack-a1-nlevel-coaxial-validator.md@@ -0,0 +1,27 @@+# BREP-BOOLEAN-STACK-A1 N-level coaxial validator generalization++## Summary++A1 generalizes safe-composition continuation validation so N-level coaxial subtract stacks are classified before independent-hole interference rejection runs.++## What changed++- Refactored continuation handling in `BrepBooleanSafeCompositionGraphValidator` to use one continuation decision for all existing-hole counts, not only `count == 1` blind pair checks.+- Added `NLevelCoaxialSubtractStack` continuation family in the JudgmentEngine candidate ladder.+- Moved overlap/tangent interference checks under the independent-hole continuation branch only.+- Added `BrepBooleanCoaxialSubtractStackFamily.TryClassifyNLevel(...)` for bounded stepped-stack admissibility:+ - all cylinders, world-Z aligned,+ - all coaxial XY centers,+ - exactly one through segment,+ - one or more top-entry blind segments,+ - strictly increasing radii and strictly shallower blind depths toward top entry.++## Behavioral result++- Third stepped coaxial subtract no longer fails at `BrepBoolean.AnalyticHole.HoleInterference` in validator.+- Independent-hole overlap rejection remains in place for independent continuations.+- Existing two-level counterbore/coaxial coverage remains preserved by existing pair classifier and tests.++## Next step++- BREP-BOOLEAN-STACK-A2 should focus on any downstream builder/topology blocker only if present after validator admission.