Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement bounded stepped/coaxial analytic hole family (G3)

Yuechen Li7af1e343514d
diff --git a/Aetheris.Firmament.FrictionLab/Cases/blind-hole-mount-block/part.firmament b/Aetheris.Firmament.FrictionLab/Cases/blind-hole-mount-block/part.firmament
index ffb99450..022e394b 100644
--- a/Aetheris.Firmament.FrictionLab/Cases/blind-hole-mount-block/part.firmament
+++ b/Aetheris.Firmament.FrictionLab/Cases/blind-hole-mount-block/part.firmament
@@ -13,6 +13,12 @@ ops[2]:
50
40
20
+ place:
+ on: origin
+ offset[3]:
+ 0
+ 0
+ -5
-
op: subtract
@@ -22,9 +28,3 @@ ops[2]:
op: cylinder
radius: 5
height: 10
- place:
- on_face: base.top_face
- offset[3]:
- 0
- 0
- -10
diff --git a/Aetheris.Firmament.FrictionLab/Cases/counterbore-hole/part.firmament b/Aetheris.Firmament.FrictionLab/Cases/counterbore-hole/part.firmament
index 2abf13b1..ad8bbfb5 100644
--- a/Aetheris.Firmament.FrictionLab/Cases/counterbore-hole/part.firmament
+++ b/Aetheris.Firmament.FrictionLab/Cases/counterbore-hole/part.firmament
@@ -13,6 +13,12 @@ ops[3]:
70
40
16
+ place:
+ on: origin
+ offset[3]:
+ 0
+ 0
+ -5
-
op: subtract
@@ -22,12 +28,6 @@ ops[3]:
op: cylinder
radius: 7
height: 6
- place:
- on: origin
- offset[3]:
- 0
- 0
- 5
-
op: subtract
@@ -36,4 +36,4 @@ ops[3]:
with:
op: cylinder
radius: 3.5
- height: 24
+ height: 26
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 4c73bb52..0784ec68 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -826,6 +826,50 @@ public sealed class BrepBooleanTests
Assert.Equal("BrepBoolean.AnalyticHole.UnsupportedBlindHoleComposition", diagnostic.Source);
}
+ [Fact]
+ public void Subtract_ComposedBlindPocketThenCoaxialThrough_Succeeds_AsBoundedSteppedHole()
+ {
+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;
+ var pocket = TransformBody(BrepPrimitives.CreateCylinder(7d, 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);
+ var repeated = BrepBoolean.Subtract(first.Value, through);
+
+ Assert.True(second.IsSuccess);
+ Assert.True(repeated.IsSuccess);
+ Assert.True(BrepBindingValidator.Validate(second.Value, true).IsSuccess);
+ Assert.Equal(9, second.Value.Topology.Faces.Count());
+ Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);
+
+ var export = Step242Exporter.ExportBody(second.Value);
+ var repeatedExport = Step242Exporter.ExportBody(repeated.Value);
+ Assert.True(export.IsSuccess);
+ Assert.True(repeatedExport.IsSuccess);
+ Assert.Equal(export.Value, repeatedExport.Value);
+ Assert.Contains("CYLINDRICAL_SURFACE", export.Value, StringComparison.Ordinal);
+ Assert.Contains("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void Subtract_ComposedBlindPocketThenOffsetThrough_ReturnsCoaxialSteppedDiagnostic()
+ {
+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;
+ var pocket = TransformBody(BrepPrimitives.CreateCylinder(7d, 6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 5d)));
+ var offsetThrough = TransformBody(BrepPrimitives.CreateCylinder(3.5d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(1.5d, 0d, 0d)));
+
+ var first = BrepBoolean.Subtract(baseBox, pocket);
+ Assert.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);
+ }
+
[Fact]
public void Subtract_ComposedOverlappingHoles_FailsWithDeterministicInterferenceDiagnostic()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
index b4efd6ef..6f385031 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
@@ -51,6 +51,25 @@ public static class BrepBooleanBoxCylinderHoleBuilder
]);
}
+ if (composition.Holes.Count == 2 && composition.Holes.Any(h => h.IsBlind))
+ {
+ if (BrepBooleanSteppedHoleFamily.TryClassifyPair(
+ composition.OuterBox,
+ composition.Holes[0],
+ composition.Holes[1],
+ tolerance,
+ out var steppedProfile,
+ out var steppedDiagnostic))
+ {
+ return CreateSteppedCoaxialCylinderBody(composition, steppedProfile);
+ }
+
+ if (steppedDiagnostic is not null)
+ {
+ return KernelResult<BrepBody>.Failure([steppedDiagnostic.ToKernelDiagnostic()]);
+ }
+ }
+
return CreateComposedThroughHoleBody(composition);
}
@@ -572,6 +591,250 @@ public static class BrepBooleanBoxCylinderHoleBuilder
: KernelResult<BrepBody>.Failure(validation.Diagnostics);
}
+ private static KernelResult<BrepBody> CreateSteppedCoaxialCylinderBody(
+ SafeBooleanComposition composition,
+ in SteppedCoaxialHoleProfile steppedProfile)
+ {
+ var box = composition.OuterBox;
+ var builder = new TopologyBuilder();
+
+ var v1 = builder.AddVertex();
+ var v2 = builder.AddVertex();
+ var v3 = builder.AddVertex();
+ var v4 = builder.AddVertex();
+ var v5 = builder.AddVertex();
+ var v6 = builder.AddVertex();
+ var v7 = builder.AddVertex();
+ var v8 = builder.AddVertex();
+
+ var e1 = builder.AddEdge(v1, v2);
+ var e2 = builder.AddEdge(v2, v3);
+ var e3 = builder.AddEdge(v3, v4);
+ var e4 = builder.AddEdge(v4, v1);
+ var e5 = builder.AddEdge(v5, v6);
+ var e6 = builder.AddEdge(v6, v7);
+ var e7 = builder.AddEdge(v7, v8);
+ var e8 = builder.AddEdge(v8, v5);
+ var e9 = builder.AddEdge(v1, v5);
+ var e10 = builder.AddEdge(v2, v6);
+ var e11 = builder.AddEdge(v3, v7);
+ var e12 = builder.AddEdge(v4, v8);
+
+ var entryVertex = builder.AddVertex();
+ var shoulderOuterVertex = builder.AddVertex();
+ var shoulderInnerVertex = builder.AddVertex();
+ var deepEndVertex = builder.AddVertex();
+ var outerSeamStartVertex = builder.AddVertex();
+ var outerSeamEndVertex = builder.AddVertex();
+ var innerSeamStartVertex = builder.AddVertex();
+ var innerSeamEndVertex = builder.AddVertex();
+
+ var entryCircle = builder.AddEdge(entryVertex, entryVertex);
+ var shoulderOuterCircle = builder.AddEdge(shoulderOuterVertex, shoulderOuterVertex);
+ var shoulderInnerCircle = builder.AddEdge(shoulderInnerVertex, shoulderInnerVertex);
+ var deepEndCircle = builder.AddEdge(deepEndVertex, deepEndVertex);
+ var outerSeam = builder.AddEdge(outerSeamStartVertex, outerSeamEndVertex);
+ var innerSeam = builder.AddEdge(innerSeamStartVertex, innerSeamEndVertex);
+
+ var bottomOuterLoop = AddLoop(builder, [Forward(e1), Forward(e2), Forward(e3), Forward(e4)]);
+ var topOuterLoop = AddLoop(builder, [Forward(e5), Forward(e6), Forward(e7), Forward(e8)]);
+ var bottomLoops = new List<LoopId>(2) { bottomOuterLoop };
+ var topLoops = new List<LoopId>(2) { topOuterLoop };
+ if (steppedProfile.EntryFromTop)
+ {
+ topLoops.Add(AddLoop(builder, [Forward(entryCircle)]));
+ if (steppedProfile.DeepHole.SpanKind == SupportedBooleanHoleSpanKind.Through)
+ {
+ bottomLoops.Add(AddLoop(builder, [Reversed(deepEndCircle)]));
+ }
+ }
+ else
+ {
+ bottomLoops.Add(AddLoop(builder, [Reversed(entryCircle)]));
+ if (steppedProfile.DeepHole.SpanKind == SupportedBooleanHoleSpanKind.Through)
+ {
+ topLoops.Add(AddLoop(builder, [Forward(deepEndCircle)]));
+ }
+ }
+
+ var bottomFace = builder.AddFace(bottomLoops);
+ var topFace = builder.AddFace(topLoops);
+ var xMinFace = builder.AddFace([AddLoop(builder, [Forward(e1), Forward(e10), Reversed(e5), Reversed(e9)])]);
+ var xMaxFace = builder.AddFace([AddLoop(builder, [Forward(e2), Forward(e11), Reversed(e6), Reversed(e10)])]);
+ var yMaxFace = builder.AddFace([AddLoop(builder, [Forward(e3), Forward(e12), Reversed(e7), Reversed(e11)])]);
+ var yMinFace = builder.AddFace([AddLoop(builder, [Forward(e4), Forward(e9), Reversed(e8), Reversed(e12)])]);
+
+ var outerWallFace = builder.AddFace([
+ AddLoop(builder, [Forward(outerSeam), Reversed(entryCircle), Reversed(outerSeam), Forward(shoulderOuterCircle)])
+ ]);
+ var shoulderFace = builder.AddFace([
+ AddLoop(builder, [Forward(shoulderOuterCircle)]),
+ AddLoop(builder, [Reversed(shoulderInnerCircle)])
+ ]);
+ var innerWallFace = builder.AddFace([
+ AddLoop(builder, [Forward(innerSeam), Reversed(shoulderInnerCircle), Reversed(innerSeam), Forward(deepEndCircle)])
+ ]);
+
+ FaceId? deepBottomFace = null;
+ if (steppedProfile.DeepHole.IsBlind)
+ {
+ deepBottomFace = builder.AddFace([AddLoop(builder, [Forward(deepEndCircle)])]);
+ }
+
+ var shellFaces = new List<FaceId>
+ {
+ bottomFace,
+ topFace,
+ xMinFace,
+ xMaxFace,
+ yMaxFace,
+ yMinFace,
+ outerWallFace,
+ shoulderFace,
+ innerWallFace,
+ };
+ if (deepBottomFace is FaceId deepBottom)
+ {
+ shellFaces.Add(deepBottom);
+ }
+
+ var shell = builder.AddShell(shellFaces);
+ builder.AddBody([shell]);
+
+ var zAxis = Direction3D.Create(new Vector3D(0d, 0d, 1d));
+ var xAxis = Direction3D.Create(new Vector3D(1d, 0d, 0d));
+ var yAxis = Direction3D.Create(new Vector3D(0d, 1d, 0d));
+ var width = box.MaxX - box.MinX;
+ var depth = box.MaxY - box.MinY;
+ var height = box.MaxZ - box.MinZ;
+ var p1 = new Point3D(box.MinX, box.MinY, box.MinZ);
+ var p2 = new Point3D(box.MaxX, box.MinY, box.MinZ);
+ var p3 = new Point3D(box.MaxX, box.MaxY, box.MinZ);
+ var p4 = new Point3D(box.MinX, box.MaxY, box.MinZ);
+ var p5 = new Point3D(box.MinX, box.MinY, box.MaxZ);
+ var p6 = new Point3D(box.MaxX, box.MinY, box.MaxZ);
+ var p7 = new Point3D(box.MaxX, box.MaxY, box.MaxZ);
+ var p8 = new Point3D(box.MinX, box.MaxY, box.MaxZ);
+
+ var entryZ = steppedProfile.EntryFromTop ? box.MaxZ : box.MinZ;
+ var shoulderZ = steppedProfile.ShoulderZ;
+ var deepEndZ = steppedProfile.DeepHole.SpanKind == SupportedBooleanHoleSpanKind.Through
+ ? (steppedProfile.EntryFromTop ? box.MinZ : box.MaxZ)
+ : steppedProfile.DeepHole.EndCenter.Z;
+ var center = new Point3D(steppedProfile.EntryHole.CenterX, steppedProfile.EntryHole.CenterY, 0d);
+ var entryCenter = new Point3D(center.X, center.Y, entryZ);
+ var shoulderCenter = new Point3D(center.X, center.Y, shoulderZ);
+ var deepEndCenter = new Point3D(center.X, center.Y, deepEndZ);
+ var entryRadius = steppedProfile.EntryHole.BottomRadius;
+ var deepRadius = steppedProfile.DeepHole.BottomRadius;
+ var seamAxis = steppedProfile.EntryFromTop ? Direction3D.Create(new Vector3D(0d, 0d, -1d)) : Direction3D.Create(new Vector3D(0d, 0d, 1d));
+ var outerSeamStart = entryCenter + (xAxis.ToVector() * entryRadius);
+ var outerSeamEnd = shoulderCenter + (xAxis.ToVector() * entryRadius);
+ var innerSeamStart = shoulderCenter + (xAxis.ToVector() * deepRadius);
+ var innerSeamEnd = deepEndCenter + (xAxis.ToVector() * deepRadius);
+
+ var geometry = new BrepGeometryStore();
+ var lineCurves = new[]
+ {
+ (p1, new Vector3D(width, 0d, 0d)),
+ (p2, new Vector3D(0d, depth, 0d)),
+ (p3, new Vector3D(-width, 0d, 0d)),
+ (p4, new Vector3D(0d, -depth, 0d)),
+ (p5, new Vector3D(width, 0d, 0d)),
+ (p6, new Vector3D(0d, depth, 0d)),
+ (p7, new Vector3D(-width, 0d, 0d)),
+ (p8, new Vector3D(0d, -depth, 0d)),
+ (p1, new Vector3D(0d, 0d, height)),
+ (p2, new Vector3D(0d, 0d, height)),
+ (p3, new Vector3D(0d, 0d, height)),
+ (p4, new Vector3D(0d, 0d, height)),
+ };
+ for (var i = 0; i < lineCurves.Length; i++)
+ {
+ geometry.AddCurve(new CurveGeometryId(i + 1), CurveGeometry.FromLine(new Line3Curve(lineCurves[i].Item1, Direction3D.Create(lineCurves[i].Item2))));
+ }
+
+ var entryCurveId = new CurveGeometryId(13);
+ var shoulderOuterCurveId = new CurveGeometryId(14);
+ var shoulderInnerCurveId = new CurveGeometryId(15);
+ var deepEndCurveId = new CurveGeometryId(16);
+ var outerSeamCurveId = new CurveGeometryId(17);
+ var innerSeamCurveId = new CurveGeometryId(18);
+ geometry.AddCurve(entryCurveId, CurveGeometry.FromCircle(new Circle3Curve(entryCenter, zAxis, entryRadius, xAxis)));
+ geometry.AddCurve(shoulderOuterCurveId, CurveGeometry.FromCircle(new Circle3Curve(shoulderCenter, zAxis, entryRadius, xAxis)));
+ geometry.AddCurve(shoulderInnerCurveId, CurveGeometry.FromCircle(new Circle3Curve(shoulderCenter, zAxis, deepRadius, xAxis)));
+ geometry.AddCurve(deepEndCurveId, CurveGeometry.FromCircle(new Circle3Curve(deepEndCenter, zAxis, deepRadius, xAxis)));
+ geometry.AddCurve(outerSeamCurveId, CurveGeometry.FromLine(new Line3Curve(outerSeamStart, seamAxis)));
+ geometry.AddCurve(innerSeamCurveId, CurveGeometry.FromLine(new Line3Curve(innerSeamStart, seamAxis)));
+
+ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, box.MinZ), Direction3D.Create(new Vector3D(0d, 0d, -1d)), xAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(2), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, box.MaxZ), zAxis, xAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(3), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, box.MinY, 0d), Direction3D.Create(new Vector3D(0d, -1d, 0d)), xAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(4), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(box.MaxX, 0d, 0d), Direction3D.Create(new Vector3D(1d, 0d, 0d)), yAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(5), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, box.MaxY, 0d), Direction3D.Create(new Vector3D(0d, 1d, 0d)), Direction3D.Create(new Vector3D(-1d, 0d, 0d)))));
+ geometry.AddSurface(new SurfaceGeometryId(6), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(box.MinX, 0d, 0d), Direction3D.Create(new Vector3D(-1d, 0d, 0d)), yAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(7), SurfaceGeometry.FromCylinder(new CylinderSurface(shoulderCenter, zAxis, entryRadius, xAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(8), SurfaceGeometry.FromPlane(new PlaneSurface(shoulderCenter, Direction3D.Create(new Vector3D(0d, 0d, steppedProfile.EntryFromTop ? -1d : 1d)), xAxis)));
+ geometry.AddSurface(new SurfaceGeometryId(9), SurfaceGeometry.FromCylinder(new CylinderSurface(deepEndCenter, zAxis, deepRadius, xAxis)));
+ if (deepBottomFace is not null)
+ {
+ geometry.AddSurface(new SurfaceGeometryId(10), SurfaceGeometry.FromPlane(new PlaneSurface(deepEndCenter, Direction3D.Create(new Vector3D(0d, 0d, steppedProfile.EntryFromTop ? -1d : 1d)), xAxis)));
+ }
+
+ var bindings = new BrepBindingModel();
+ for (var i = 0; i < 12; i++)
+ {
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(new EdgeId(i + 1), new CurveGeometryId(i + 1), new ParameterInterval(0d, 1d)));
+ }
+
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(entryCircle, entryCurveId, new ParameterInterval(0d, 2d * double.Pi)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(shoulderOuterCircle, shoulderOuterCurveId, new ParameterInterval(0d, 2d * double.Pi)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(shoulderInnerCircle, shoulderInnerCurveId, new ParameterInterval(0d, 2d * double.Pi)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(deepEndCircle, deepEndCurveId, new ParameterInterval(0d, 2d * double.Pi)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(outerSeam, outerSeamCurveId, new ParameterInterval(0d, (outerSeamEnd - outerSeamStart).Length)));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(innerSeam, innerSeamCurveId, new ParameterInterval(0d, (innerSeamEnd - innerSeamStart).Length)));
+
+ bindings.AddFaceBinding(new FaceGeometryBinding(bottomFace, new SurfaceGeometryId(1)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(topFace, new SurfaceGeometryId(2)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(xMinFace, new SurfaceGeometryId(3)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(xMaxFace, new SurfaceGeometryId(4)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(yMaxFace, new SurfaceGeometryId(5)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(yMinFace, new SurfaceGeometryId(6)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(outerWallFace, new SurfaceGeometryId(7)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(shoulderFace, new SurfaceGeometryId(8)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(innerWallFace, new SurfaceGeometryId(9)));
+ if (deepBottomFace is FaceId deepBottomBinding)
+ {
+ bindings.AddFaceBinding(new FaceGeometryBinding(deepBottomBinding, new SurfaceGeometryId(10)));
+ }
+
+ var vertexPoints = new Dictionary<VertexId, Point3D>
+ {
+ [v1] = p1,
+ [v2] = p2,
+ [v3] = p3,
+ [v4] = p4,
+ [v5] = p5,
+ [v6] = p6,
+ [v7] = p7,
+ [v8] = p8,
+ [entryVertex] = outerSeamStart,
+ [shoulderOuterVertex] = outerSeamEnd,
+ [shoulderInnerVertex] = innerSeamStart,
+ [deepEndVertex] = innerSeamEnd,
+ [outerSeamStartVertex] = outerSeamStart,
+ [outerSeamEndVertex] = outerSeamEnd,
+ [innerSeamStartVertex] = innerSeamStart,
+ [innerSeamEndVertex] = innerSeamEnd,
+ };
+
+ var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints, composition);
+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);
+ return validation.IsSuccess
+ ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)
+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);
+ }
+
private static HoleGeometryData CreateHoleGeometry(SupportedBooleanHole hole, AxisAlignedBoxExtents box, Direction3D zAxis, Direction3D xAxis)
{
return hole.Surface.Kind switch
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
index 92980ca0..74738e31 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
@@ -64,6 +64,29 @@ public static class BrepBooleanSafeCompositionGraphValidator
var centerDistance = System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));
var requiredDistance = existingHole.MaxBoundaryRadius + nextHole.MaxBoundaryRadius;
+ if (composition.Holes.Count == 1
+ && (existingHole.IsBlind || nextHole.IsBlind)
+ && centerDistance < (requiredDistance + tolerance.Linear))
+ {
+ if (BrepBooleanSteppedHoleFamily.TryClassifyPair(
+ composition.OuterBox,
+ existingHole,
+ nextHole,
+ tolerance,
+ out _,
+ out var steppedDiagnostic,
+ nextFeatureId))
+ {
+ continue;
+ }
+
+ if (steppedDiagnostic is not null)
+ {
+ diagnostic = steppedDiagnostic;
+ return false;
+ }
+ }
+
if (ToleranceMath.AlmostEqual(centerDistance, requiredDistance, tolerance))
{
diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.cs
new file mode 100644
index 00000000..adc316c7
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSteppedHoleFamily.cs
@@ -0,0 +1,142 @@
+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);
+ }
+}