Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
G4: generalize bounded coaxial subtract-stack validation
Yuechen Li5e49bedd3196
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 0784ec68..7448aaac 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -586,18 +586,17 @@ public sealed class BrepBooleanTests}[Fact]- public void Subtract_BoxCylinderMidSpanPartialHeight_ReturnsNotFullySpanningDiagnostic()+ public void Subtract_BoxCylinderMidSpanPartialHeight_RebuildsAsContainedCylinderCavity(){var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;var partial = TransformBody(BrepPrimitives.CreateCylinder(4d, 6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 6d)));var result = BrepBoolean.Subtract(left, partial);- Assert.False(result.IsSuccess);- var diagnostic = Assert.Single(result.Diagnostics);- Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);- Assert.Equal("Boolean Subtract does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.", diagnostic.Message);+ Assert.True(result.IsSuccess);+ Assert.NotNull(result.Value.ShellRepresentation);+ Assert.Single(result.Value.ShellRepresentation!.InnerShellIds);+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);}[Fact]@@ -870,6 +869,64 @@ public sealed class BrepBooleanTestsAssert.Contains("requires coaxial cylinders", diagnostic.Message, StringComparison.Ordinal);}+ [Fact]+ public void Subtract_BoxContainedCylinderCavity_Succeeds_WithInnerShell_And_DeterministicExport()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-25d, 25d, -20d, 20d, -10d, 10d)).Value;+ var containedPocket = BrepPrimitives.CreateCylinder(5d, 6d).Value;++ var first = BrepBoolean.Subtract(baseBox, containedPocket);+ var second = BrepBoolean.Subtract(baseBox, containedPocket);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.NotNull(first.Value.ShellRepresentation);+ Assert.Single(first.Value.ShellRepresentation!.InnerShellIds);+ Assert.True(BrepBindingValidator.Validate(first.Value, true).IsSuccess);++ var export = Step242Exporter.ExportBody(first.Value);+ var repeatedExport = Step242Exporter.ExportBody(second.Value);+ Assert.True(export.IsSuccess);+ Assert.True(repeatedExport.IsSuccess);+ Assert.Equal(export.Value, repeatedExport.Value);+ Assert.Contains("BREP_WITH_VOIDS", export.Value, StringComparison.Ordinal);+ Assert.Contains("CYLINDRICAL_SURFACE", export.Value, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_ComposedContainedThenThroughCoaxial_ReturnsUnsupportedTwoSidedEntryStackDiagnostic()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-25d, 25d, -20d, 20d, -10d, 10d)).Value;+ var containedPocket = BrepPrimitives.CreateCylinder(6d, 6d).Value;+ var through = BrepPrimitives.CreateCylinder(3d, 30d).Value;++ var first = BrepBoolean.Subtract(baseBox, containedPocket);+ Assert.True(first.IsSuccess);++ var result = BrepBoolean.Subtract(first.Value, through);+ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);+ Assert.Contains("open on the same top entry face", diagnostic.Message, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_ComposedBlindPocketThenEqualRadiusThrough_ReturnsDegenerateShoulderDiagnostic()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;+ var pocket = TransformBody(BrepPrimitives.CreateCylinder(3.5d, 6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 5d)));+ var through = BrepPrimitives.CreateCylinder(3.5d, 24d).Value;++ var first = BrepBoolean.Subtract(baseBox, pocket);+ Assert.True(first.IsSuccess);++ var second = BrepBoolean.Subtract(first.Value, through);+ Assert.False(second.IsSuccess);+ var diagnostic = Assert.Single(second.Diagnostics);+ Assert.Equal("BrepBoolean.AnalyticHole.TangentContact", diagnostic.Source);+ Assert.Contains("strictly larger entry-segment radius", diagnostic.Message, StringComparison.Ordinal);+ }+[Fact]public void Subtract_ComposedOverlappingHoles_FailsWithDeterministicInterferenceDiagnostic(){diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 6f385031..414289d7 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -38,6 +38,14 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn CreateComposedContainedSphereCavityBody(composition.OuterBox, sphere);}+ if (composition.Holes.Count == 1+ && composition.Holes[0].SpanKind == SupportedBooleanHoleSpanKind.Contained+ && composition.Holes[0].Surface.Kind == AnalyticSurfaceKind.Cylinder+ && composition.Holes[0].Surface.Cylinder is RecognizedCylinder containedCylinder)+ {+ return CreateComposedContainedCylinderCavityBody(composition.OuterBox, containedCylinder, composition);+ }+if (composition.Holes.Any(hole => hole.Surface.Kind == AnalyticSurfaceKind.Sphere)){return KernelResult<BrepBody>.Failure([@@ -53,7 +61,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderif (composition.Holes.Count == 2 && composition.Holes.Any(h => h.IsBlind)){- if (BrepBooleanSteppedHoleFamily.TryClassifyPair(+ if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(composition.OuterBox,composition.Holes[0],composition.Holes[1],@@ -144,10 +152,40 @@ public static class BrepBooleanBoxCylinderHoleBuilder: KernelResult<BrepBody>.Failure(validation.Diagnostics);}- private static BrepBody MergeOuterAndInnerShell(BrepBody outer, BrepBody inner)- => MergeOuterAndInnerShells(outer, [inner]);+ private static KernelResult<BrepBody> CreateComposedContainedCylinderCavityBody(+ AxisAlignedBoxExtents outerBox,+ in RecognizedCylinder cylinder,+ SafeBooleanComposition composition)+ {+ var outer = BrepBooleanBoxRecognition.CreateBoxFromExtents(outerBox);+ if (!outer.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(outer.Diagnostics);+ }++ var height = System.Math.Abs(cylinder.MaxAxisParameter - cylinder.MinAxisParameter);+ var innerResult = BrepPrimitives.CreateCylinder(cylinder.Radius, height);+ if (!innerResult.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(innerResult.Diagnostics);+ }++ var center = new Point3D(+ (cylinder.MinCenter.X + cylinder.MaxCenter.X) * 0.5d,+ (cylinder.MinCenter.Y + cylinder.MaxCenter.Y) * 0.5d,+ (cylinder.MinCenter.Z + cylinder.MaxCenter.Z) * 0.5d);+ var inner = TranslateBody(innerResult.Value, new Vector3D(center.X, center.Y, center.Z));+ var body = MergeOuterAndInnerShell(outer.Value, inner, composition);+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);+ return validation.IsSuccess+ ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);+ }++ private static BrepBody MergeOuterAndInnerShell(BrepBody outer, BrepBody inner, SafeBooleanComposition? composition = null)+ => MergeOuterAndInnerShells(outer, [inner], composition);- private static BrepBody MergeOuterAndInnerShells(BrepBody outer, IReadOnlyList<BrepBody> innerShells)+ private static BrepBody MergeOuterAndInnerShells(BrepBody outer, IReadOnlyList<BrepBody> innerShells, SafeBooleanComposition? composition = null){var topology = new TopologyModel();@@ -325,7 +363,7 @@ public static class BrepBooleanBoxCylinderHoleBuildergeometry,bindings,vertexPoints,- safeBooleanComposition: null,+ safeBooleanComposition: composition,shellRepresentation: new BrepBodyShellRepresentation(outerShellId, remappedInnerShellIds));}@@ -593,7 +631,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderprivate static KernelResult<BrepBody> CreateSteppedCoaxialCylinderBody(SafeBooleanComposition composition,- in SteppedCoaxialHoleProfile steppedProfile)+ in CoaxialCylinderSubtractStackProfile steppedProfile){var box = composition.OuterBox;var builder = new TopologyBuilder();diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.csnew file mode 100644index 00000000..8f998c4b--- /dev/null+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs@@ -0,0 +1,182 @@+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Numerics;++namespace Aetheris.Kernel.Core.Brep.Boolean;++internal readonly record struct CoaxialCylinderSubtractStackProfile(+ SupportedBooleanHole EntryHole,+ SupportedBooleanHole DeepHole,+ bool EntryFromTop,+ double ShoulderZ);++internal static class BrepBooleanCoaxialSubtractStackFamily+{+ public static bool TryClassifyPair(+ AxisAlignedBoxExtents outerBox,+ in SupportedBooleanHole first,+ in SupportedBooleanHole second,+ ToleranceContext tolerance,+ out CoaxialCylinderSubtractStackProfile profile,+ out BooleanDiagnostic? diagnostic,+ string? featureId = null)+ {+ profile = default;+ diagnostic = null;++ if (first.Surface.Kind != AnalyticSurfaceKind.Cylinder || second.Surface.Kind != AnalyticSurfaceKind.Cylinder)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(BooleanOperation.Subtract.ToString(), AnalyticSurfaceKind.Cylinder, featureId);+ return false;+ }++ if (!IsWorldZAligned(first.Axis, tolerance) || !IsWorldZAligned(second.Axis, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires world-Z aligned cylinder tools.");+ return false;+ }++ var deltaX = first.CenterX - second.CenterX;+ var deltaY = first.CenterY - second.CenterY;+ if (System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)) > tolerance.Linear)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires coaxial cylinders with matching XY axis centers.");+ return false;+ }++ var firstTop = ResolveTop(first);+ var firstBottom = ResolveBottom(first);+ var secondTop = ResolveTop(second);+ var secondBottom = ResolveBottom(second);++ var firstTopEntry = IsTopEntry(first, outerBox, tolerance);+ var secondTopEntry = IsTopEntry(second, outerBox, tolerance);+ var firstBottomEntry = IsBottomEntry(first, outerBox, tolerance);+ var secondBottomEntry = IsBottomEntry(second, outerBox, tolerance);+ var hasTopEntry = firstTopEntry || secondTopEntry;+ var hasBottomEntry = firstBottomEntry || secondBottomEntry;+ var hasTopBlindEntry = IsTopBlindEntry(first, outerBox, tolerance) || IsTopBlindEntry(second, outerBox, tolerance);+ var hasBottomBlindEntry = IsBottomBlindEntry(first, outerBox, tolerance) || IsBottomBlindEntry(second, outerBox, tolerance);++ if (!hasTopEntry && !hasBottomEntry)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires at least one segment to open on a box entry face.");+ return false;+ }++ if (hasTopBlindEntry && hasBottomBlindEntry)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires all segments in a two-cylinder stack to share one entry side.");+ return false;+ }++ var entryFromTop = hasTopEntry;+ var entryIsFirst = firstTopEntry || firstBottomEntry;+ var entryHole = entryIsFirst ? first : second;+ var deepHole = entryIsFirst ? second : first;++ if (entryHole.SpanKind == SupportedBooleanHoleSpanKind.Contained)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires the entry segment to intersect the chosen entry face; fully contained-first stacks remain deferred.");+ return false;+ }++ var entryShoulder = entryFromTop ? ResolveBottom(entryHole) : ResolveTop(entryHole);+ var deepTop = ResolveTop(deepHole);+ var deepBottom = ResolveBottom(deepHole);++ if (entryFromTop)+ {+ if (deepTop < (outerBox.MaxZ - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires the deeper segment to open on the same top entry face.");+ return false;+ }++ if (deepBottom >= (entryShoulder - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires the deeper segment to extend below the shoulder plane.");+ return false;+ }+ }+ else+ {+ if (deepBottom > (outerBox.MinZ + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires the deeper segment to open on the same bottom entry face.");+ return false;+ }++ if (deepTop <= (entryShoulder + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires the deeper segment to extend above the shoulder plane.");+ return false;+ }+ }++ if (entryHole.BottomRadius <= (deepHole.BottomRadius + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires a strictly larger entry-segment radius than the deeper segment radius to avoid degenerate shoulder geometry.");+ return false;+ }++ profile = new CoaxialCylinderSubtractStackProfile(entryHole, deepHole, entryFromTop, entryShoulder);+ return true;+ }++ private static double ResolveTop(in SupportedBooleanHole hole) => System.Math.Max(hole.StartCenter.Z, hole.EndCenter.Z);++ private static double ResolveBottom(in SupportedBooleanHole hole) => System.Math.Min(hole.StartCenter.Z, hole.EndCenter.Z);++ private static bool IsTopEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => ResolveTop(hole) >= (outerBox.MaxZ - tolerance.Linear);++ private static bool IsBottomEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => ResolveBottom(hole) <= (outerBox.MinZ + tolerance.Linear);++ private static bool IsTopBlindEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop+ || (hole.SpanKind == SupportedBooleanHoleSpanKind.Contained && IsTopEntry(hole, outerBox, tolerance));++ private static bool IsBottomBlindEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromBottom+ || (hole.SpanKind == SupportedBooleanHoleSpanKind.Contained && IsBottomEntry(hole, outerBox, tolerance));++ private static bool IsWorldZAligned(Direction3D axis, ToleranceContext tolerance)+ {+ var axisVector = axis.ToVector();+ return ToleranceMath.AlmostZero(axisVector.X, tolerance)+ && ToleranceMath.AlmostZero(axisVector.Y, tolerance)+ && ToleranceMath.AlmostEqual(System.Math.Abs(axisVector.Z), 1d, tolerance);+ }+}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.csindex 108fde57..abdec195 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs@@ -85,6 +85,7 @@ public enum SupportedBooleanHoleSpanKindThrough,BlindFromTop,BlindFromBottom,+ Contained,}public readonly record struct SupportedBooleanHole(diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 74738e31..777b89fb 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -68,7 +68,7 @@ public static class BrepBooleanSafeCompositionGraphValidator&& (existingHole.IsBlind || nextHole.IsBlind)&& centerDistance < (requiredDistance + tolerance.Linear)){- if (BrepBooleanSteppedHoleFamily.TryClassifyPair(+ if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(composition.OuterBox,existingHole,nextHole,@@ -262,8 +262,12 @@ public static class BrepBooleanSafeCompositionGraphValidatorcase AnalyticSurfaceKind.Cylinder when surface.Cylinder is RecognizedCylinder cylinder:if (!BrepBooleanCylinderRecognition.TryValidateCylinderSubtractProfile(outerBox, cylinder, tolerance, out var cylinderProfile, out diagnostic, featureId)){- hole = default;- return false;+ if (!ShouldTryContainedCylinderSegment(outerBox, cylinder, tolerance)+ || !TryValidateContainedCylinderSubtractSegment(outerBox, cylinder, tolerance, out cylinderProfile, out diagnostic, featureId))+ {+ hole = default;+ return false;+ }}hole = new SupportedBooleanHole(@@ -350,6 +354,127 @@ public static class BrepBooleanSafeCompositionGraphValidator}}+ private static bool ShouldTryContainedCylinderSegment(AxisAlignedBoxExtents outerBox, in RecognizedCylinder cylinder, ToleranceContext tolerance)+ {+ if (!BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(cylinder, tolerance))+ {+ return false;+ }++ var minCenter = cylinder.MinCenter;+ var maxCenter = cylinder.MaxCenter;+ var bottomZ = System.Math.Min(minCenter.Z, maxCenter.Z);+ var topZ = System.Math.Max(minCenter.Z, maxCenter.Z);+ return topZ < (outerBox.MaxZ - tolerance.Linear)+ && bottomZ > (outerBox.MinZ + tolerance.Linear);+ }++ private static bool TryValidateContainedCylinderSubtractSegment(+ AxisAlignedBoxExtents outerBox,+ in RecognizedCylinder cylinder,+ ToleranceContext tolerance,+ out SupportedSubtractProfile profile,+ out BooleanDiagnostic? diagnostic,+ string? featureId)+ {+ profile = default;+ diagnostic = null;++ if (!BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(cylinder, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded contained coaxial subtract-stack support requires world-Z aligned contained cylinder segments.");+ return false;+ }++ var minCenter = cylinder.MinCenter;+ var maxCenter = cylinder.MaxCenter;+ var bottomCenter = minCenter.Z <= maxCenter.Z ? minCenter : maxCenter;+ var topCenter = minCenter.Z > maxCenter.Z ? minCenter : maxCenter;++ if (topCenter.Z >= (outerBox.MaxZ - tolerance.Linear)+ || bottomCenter.Z <= (outerBox.MinZ + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "is outside the bounded contained coaxial subtract-stack family; contained cylinder segments must remain strictly between box entry planes.");+ return false;+ }++ if (!ValidateCircleInsideBoxFootprint(outerBox, topCenter.X, topCenter.Y, cylinder.Radius, tolerance, out diagnostic, "top contained section", featureId)+ || !ValidateCircleInsideBoxFootprint(outerBox, bottomCenter.X, bottomCenter.Y, cylinder.Radius, tolerance, out diagnostic, "bottom contained section", featureId))+ {+ return false;+ }++ profile = new SupportedSubtractProfile(+ SupportedBooleanHoleSpanKind.Contained,+ (topCenter.X + bottomCenter.X) * 0.5d,+ (topCenter.Y + bottomCenter.Y) * 0.5d,+ topCenter,+ bottomCenter,+ cylinder.Axis,+ ResolveReferenceAxis(cylinder.Axis),+ topCenter.Z,+ bottomCenter.Z,+ cylinder.Radius,+ cylinder.Radius);+ return true;+ }++ private static Direction3D ResolveReferenceAxis(Direction3D axis)+ {+ var candidate = System.Math.Abs(axis.ToVector().X) > 0.5d+ ? Direction3D.Create(new Vector3D(0d, 1d, 0d))+ : Direction3D.Create(new Vector3D(1d, 0d, 0d));+ var projected = candidate.ToVector() - (axis.ToVector() * candidate.ToVector().Dot(axis.ToVector()));+ return projected.Length <= 1e-12d+ ? Direction3D.Create(new Vector3D(0d, 1d, 0d))+ : Direction3D.Create(projected);+ }++ private static bool ValidateCircleInsideBoxFootprint(+ AxisAlignedBoxExtents box,+ double centerX,+ double centerY,+ double radius,+ ToleranceContext tolerance,+ out BooleanDiagnostic? diagnostic,+ string section,+ string? featureId)+ {+ diagnostic = null;+ var tangent = ToleranceMath.AlmostEqual(centerX - radius, box.MinX, tolerance)+ || ToleranceMath.AlmostEqual(centerX + radius, box.MaxX, tolerance)+ || ToleranceMath.AlmostEqual(centerY - radius, box.MinY, tolerance)+ || ToleranceMath.AlmostEqual(centerY + radius, box.MaxY, tolerance);+ if (tangent)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ $"has tangent contact at the box side walls ({section}); tangent support is rejected to avoid zero-thickness boundary sections.");+ return false;+ }++ if (centerX - radius < (box.MinX - tolerance.Linear)+ || centerX + radius > (box.MaxX + tolerance.Linear)+ || centerY - radius < (box.MinY - tolerance.Linear)+ || centerY + radius > (box.MaxY + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ $"extends outside the box side walls ({section}); supported subtract tools must remain inside the box footprint.");+ return false;+ }++ return true;+ }+private static string FormatFeatureRef(string? featureId)=> string.IsNullOrWhiteSpace(featureId) ? "<unknown>" : $"'{featureId}'";diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.csdeleted file mode 100644index adc316c7..00000000--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.cs+++ /dev/null@@ -1,142 +0,0 @@-using Aetheris.Kernel.Core.Math;-using Aetheris.Kernel.Core.Numerics;-using Aetheris.Kernel.Core.Geometry;--namespace Aetheris.Kernel.Core.Brep.Boolean;--internal readonly record struct SteppedCoaxialHoleProfile(- SupportedBooleanHole EntryHole,- SupportedBooleanHole DeepHole,- bool EntryFromTop,- double ShoulderZ);--internal static class BrepBooleanSteppedHoleFamily-{- public static bool TryClassifyPair(- AxisAlignedBoxExtents outerBox,- in SupportedBooleanHole first,- in SupportedBooleanHole second,- ToleranceContext tolerance,- out SteppedCoaxialHoleProfile profile,- out BooleanDiagnostic? diagnostic,- string? featureId = null)- {- profile = default;- diagnostic = null;-- if (first.Surface.Kind != AnalyticSurfaceKind.Cylinder || second.Surface.Kind != AnalyticSurfaceKind.Cylinder)- {- return false;- }-- if (!IsWorldZAligned(first.Axis, tolerance) || !IsWorldZAligned(second.Axis, tolerance))- {- diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded stepped-hole support requires world-Z aligned cylinder tools.");- return false;- }-- var deltaX = first.CenterX - second.CenterX;- var deltaY = first.CenterY - second.CenterY;- if (System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)) > tolerance.Linear)- {- diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded stepped-hole support requires coaxial cylinders with matching XY axis centers.");- return false;- }-- var firstTopEntry = first.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop;- var secondTopEntry = second.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop;- var firstBottomEntry = first.SpanKind == SupportedBooleanHoleSpanKind.BlindFromBottom;- var secondBottomEntry = second.SpanKind == SupportedBooleanHoleSpanKind.BlindFromBottom;- var hasTopBlind = firstTopEntry || secondTopEntry;- var hasBottomBlind = firstBottomEntry || secondBottomEntry;- if (hasTopBlind && hasBottomBlind)- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded stepped-hole support requires all blind segments in the stack to share one entry side.");- return false;- }-- if (!hasTopBlind && !hasBottomBlind)- {- return false;- }-- var entryFromTop = hasTopBlind;- var entryHole = first.IsBlind ? first : second;- var deepHole = first.IsBlind ? second : first;- var shoulderZ = entryHole.EndCenter.Z;-- if (entryFromTop)- {- var deepTop = System.Math.Max(deepHole.StartCenter.Z, deepHole.EndCenter.Z);- var deepBottom = System.Math.Min(deepHole.StartCenter.Z, deepHole.EndCenter.Z);- if (deepTop < (outerBox.MaxZ - tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded top-entry stepped holes require the deeper coaxial segment to open on the same top entry face.");- return false;- }-- if (deepBottom >= (shoulderZ - tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded top-entry stepped holes require the deeper segment to extend below the shoulder plane.");- return false;- }- }- else- {- var deepTop = System.Math.Max(deepHole.StartCenter.Z, deepHole.EndCenter.Z);- var deepBottom = System.Math.Min(deepHole.StartCenter.Z, deepHole.EndCenter.Z);- if (deepBottom > (outerBox.MinZ + tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded bottom-entry stepped holes require the deeper coaxial segment to open on the same bottom entry face.");- return false;- }-- if (deepTop <= (shoulderZ + tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded bottom-entry stepped holes require the deeper segment to extend above the shoulder plane.");- return false;- }- }-- if (entryHole.BottomRadius <= (deepHole.BottomRadius + tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(- BooleanOperation.Subtract.ToString(),- featureId,- "bounded stepped-hole support requires a strictly larger entry-pocket radius than the deeper coaxial segment radius to avoid tangent/degenerate shoulder geometry.");- return false;- }-- profile = new SteppedCoaxialHoleProfile(entryHole, deepHole, entryFromTop, shoulderZ);- return true;- }-- private static bool IsWorldZAligned(Direction3D axis, ToleranceContext tolerance)- {- var axisVector = axis.ToVector();- return ToleranceMath.AlmostZero(axisVector.X, tolerance)- && ToleranceMath.AlmostZero(axisVector.Y, tolerance)- && ToleranceMath.AlmostEqual(System.Math.Abs(axisVector.Z), 1d, tolerance);- }-}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex 69286c7f..944355dd 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -82,7 +82,7 @@ public sealed class FirmamentBooleanCanonicalSuccessTestsFirmamentCorpusHarness.ReadFixtureText("testdata/firmament/fixtures/m3d-valid-subtract-exec.firmament"));var supportedCylinderHoleExport = ExportFixture("testdata/firmament/examples/boolean_box_cylinder_hole.firmament");var supportedConeHoleExport = ExportFixture("testdata/firmament/examples/boolean_box_cone_throughhole_basic.firmament");- var unsupportedCylinderHoleExport = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament");+ var containedCylinderHoleExport = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament");var unsupportedConeHoleExport = ExportFixture("testdata/firmament/fixtures/m10m-unsupported-box-subtract-cone.firmament");Assert.False(unsupportedSingleBoxSubtract.Compilation.IsSuccess);@@ -96,12 +96,8 @@ public sealed class FirmamentBooleanCanonicalSuccessTestsAssert.True(supportedConeHoleExport.IsSuccess);Assert.Contains("CONICAL_SURFACE", supportedConeHoleExport.Value.StepText, StringComparison.Ordinal);- Assert.False(unsupportedCylinderHoleExport.IsSuccess);- Assert.Contains(unsupportedCylinderHoleExport.Diagnostics, diagnostic =>- diagnostic.Code == KernelDiagnosticCode.NotImplemented- && diagnostic.Message.Contains("Requested boolean feature 'hole' (subtract) could not be executed.", StringComparison.Ordinal));- Assert.DoesNotContain(unsupportedCylinderHoleExport.Diagnostics, diagnostic =>- diagnostic.Message.Contains("requires at least one executed primitive or boolean body", StringComparison.Ordinal));+ Assert.True(containedCylinderHoleExport.IsSuccess);+ Assert.Contains("BREP_WITH_VOIDS", containedCylinderHoleExport.Value.StepText, StringComparison.Ordinal);Assert.False(unsupportedConeHoleExport.IsSuccess);Assert.Contains(unsupportedConeHoleExport.Diagnostics, diagnostic =>@@ -115,7 +111,6 @@ public sealed class FirmamentBooleanCanonicalSuccessTestsnew(){{ "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-add-sphere.firmament", "joined", "add" },{ "testdata/firmament/fixtures/m10l-unsupported-box-intersect-sphere.firmament", "overlap", "intersect" },diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex f29a1693..dcb43f57 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -258,6 +258,22 @@ public sealed class FirmamentBuildAndExportTests"subtract");}+ [Fact]+ public void Run_FrictionLabBlindHoleMountBlock_NowBuildsAndExports()+ {+ var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/blind-hole-mount-block/part.firmament");++ var first = FirmamentBuildAndExport.Run(fullSourcePath);+ var second = FirmamentBuildAndExport.Run(fullSourcePath);++ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.NotEmpty(first.Value.Export.StepText);+ Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);+ Assert.Contains("BREP_WITH_VOIDS", first.Value.Export.StepText, StringComparison.Ordinal);+ Assert.Contains("CYLINDRICAL_SURFACE", first.Value.Export.StepText, StringComparison.Ordinal);+ }+[Fact]public void Semantic_Placement_Build_Is_Deterministic(){@@ -283,12 +299,14 @@ public sealed class FirmamentBuildAndExportTests}[Fact]- public void Run_UnsupportedBoxWithCylinderHoleFixture_Fails_And_Does_Not_Write_Fallback_Export()+ public void Run_ContainedBoxWithCylinderHoleFixture_Builds_And_Writes_Export(){- AssertUnsupportedBuildAndExport(+ AssertExampleBuildAndExport("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament","m10h1-unsupported-box-with-cylinder-hole.step","hole",+ 1,+ "boolean","subtract");}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.csindex d75205dc..c1b01803 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs@@ -193,7 +193,7 @@ public sealed class FirmamentStepExporterTests{var 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 containedCylinder = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.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");@@ -207,24 +207,22 @@ public sealed class FirmamentStepExporterTestsAssert.DoesNotContain("DRAUGHTING_CALLOUT", coneHole.Value.StepText, StringComparison.Ordinal);Assert.DoesNotContain("ANNOTATION_PLANE", coneHole.Value.StepText, StringComparison.Ordinal);- Assert.False(unsupportedCylinder.IsSuccess);+ Assert.True(containedCylinder.IsSuccess);+ Assert.Contains("SHAPE_ASPECT", containedCylinder.Value.StepText, StringComparison.Ordinal);Assert.True(supportedSphereCavity.IsSuccess);Assert.False(unsupportedTorus.IsSuccess);}[Fact]- public void Export_UnsupportedBoxWithCylinderHole_Fails_Instead_Of_Falling_Back_To_Base_Primitive()+ public void Export_ContainedBoxWithCylinderHole_Succeeds_Deterministically_Without_Fallback(){var first = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament");var second = ExportFixture("testdata/firmament/fixtures/m10h1-unsupported-box-with-cylinder-hole.firmament");- Assert.False(first.IsSuccess);- Assert.False(second.IsSuccess);- Assert.Equal(first.Diagnostics, second.Diagnostics);- Assert.Contains(first.Diagnostics, diagnostic => diagnostic.Message.Contains("Requested boolean feature 'hole' (subtract) could not be executed.", StringComparison.Ordinal));- Assert.Contains(first.Diagnostics, diagnostic => diagnostic.Source == "BrepBoolean.AnalyticHole.NotFullySpanning"- && diagnostic.Message.Contains("Boolean feature 'hole' (subtract) does not match the supported subtract span family", StringComparison.Ordinal));- Assert.DoesNotContain(first.Diagnostics, diagnostic => diagnostic.Message.Contains("requires at least one executed primitive or boolean body", StringComparison.Ordinal));+ Assert.True(first.IsSuccess);+ Assert.True(second.IsSuccess);+ Assert.Equal(first.Value.StepText, second.Value.StepText);+ Assert.Contains("BREP_WITH_VOIDS", first.Value.StepText, StringComparison.Ordinal);}