Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add bounded blind cylinder/cone subtract support in safe boolean family

Yuechen Li5e8e71666eaa
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
index 2ce15876..193f9c54 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
@@ -29,7 +29,10 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests
-7d,
-2d,
4d,
- 4d)
+ 4d,
+ SupportedBooleanHoleSpanKind.Through,
+ 0d,
+ 12d)
]);
var next = new AnalyticSurface(
AnalyticSurfaceKind.Cone,
@@ -121,7 +124,10 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests
0d,
0d,
3d,
- 3d),
+ 3d,
+ SupportedBooleanHoleSpanKind.Through,
+ 0d,
+ 12d),
]);
var sphere = new AnalyticSurface(
AnalyticSurfaceKind.Sphere,
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index ae930639..74e8bf8c 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -274,18 +274,29 @@ public sealed class BrepBooleanTests
}
[Fact]
- public void Subtract_BoxCylinderPartialHeight_ReturnsDeterministicNotImplemented()
+ public void Subtract_BoxCylinderBlindTopEntry_ReturnsClosedBottomHole()
{
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 blind = TransformBody(BrepPrimitives.CreateCylinder(4d, 8d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 8d)));
- var result = BrepBoolean.Subtract(left, partial);
+ var result = BrepBoolean.Subtract(left, blind);
- 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 reach both box boundary planes; partial-depth cylinder cuts are outside the supported safe boolean family. Extend the cylinder so it spans the full box Z range.", diagnostic.Message);
+ Assert.True(result.IsSuccess);
+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);
+ Assert.Equal(8, result.Value.Topology.Faces.Count());
+
+ var topFace = Assert.Single(result.Value.Topology.Faces, face =>
+ result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)
+ && surface?.Kind == SurfaceGeometryKind.Plane
+ && surface.Plane!.Value.Normal.Z > 0.5d);
+ Assert.Equal(2, result.Value.GetLoopIds(topFace.Id).Count);
+
+ var bottomFace = Assert.Single(result.Value.Topology.Faces, face =>
+ result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)
+ && surface?.Kind == SurfaceGeometryKind.Plane
+ && surface.Plane!.Value.Normal.Z < -0.5d
+ && System.Math.Abs(surface.Plane!.Value.Origin.Z) < 1e-6d);
+ Assert.Single(result.Value.GetLoopIds(bottomFace.Id));
}
[Fact]
@@ -402,11 +413,51 @@ public sealed class BrepBooleanTests
Assert.Equal("Boolean Subtract requires the cone axis to be parallel to world Z; the current cone axis is not aligned with the box Z axis. Rotate or redefine the tool so the cone reconstructs as a world-Z through-hole.", diagnostic.Message);
}
+ [Fact]
+ public void Subtract_BoxCylinderMidSpanPartialHeight_ReturnsNotFullySpanningDiagnostic()
+ {
+ 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);
+ }
+
+ [Fact]
+ public void Subtract_BoxConeBlindTopEntry_ReturnsClosedBottomHole()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var blind = TransformBody(CreateCone(bottomRadius: 4d, topRadius: 2d, height: 8d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 4d)));
+
+ var result = BrepBoolean.Subtract(left, blind);
+
+ Assert.True(result.IsSuccess);
+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);
+ Assert.Equal(8, result.Value.Topology.Faces.Count());
+ var topFace = Assert.Single(result.Value.Topology.Faces, face =>
+ result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)
+ && surface?.Kind == SurfaceGeometryKind.Plane
+ && surface.Plane!.Value.Normal.Z > 0.5d);
+ Assert.Equal(2, result.Value.GetLoopIds(topFace.Id).Count);
+
+ var bottomFace = Assert.Single(result.Value.Topology.Faces, face =>
+ result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)
+ && surface?.Kind == SurfaceGeometryKind.Plane
+ && surface.Plane!.Value.Normal.Z < -0.5d
+ && System.Math.Abs(surface.Plane!.Value.Origin.Z) < 1e-6d);
+ Assert.Single(result.Value.GetLoopIds(bottomFace.Id));
+ }
+
[Fact]
public void Subtract_BoxConePartialHeight_ReturnsNotFullySpanningDiagnostic()
{
var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
- var partial = CreateCone(bottomRadius: 4d, topRadius: 2d, height: 8d);
+ var partial = TransformBody(CreateCone(bottomRadius: 4d, topRadius: 2d, height: 8d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 1d)));
var result = BrepBoolean.Subtract(left, partial);
@@ -414,7 +465,7 @@ public sealed class BrepBooleanTests
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 reach both box boundary planes; partial-depth cone cuts are outside the supported safe boolean family. Extend the cone so it spans the full box Z range.", diagnostic.Message);
+ 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);
}
[Fact]
@@ -540,6 +591,22 @@ public sealed class BrepBooleanTests
Assert.Contains("CONICAL_SURFACE", export.Value, StringComparison.Ordinal);
}
+ [Fact]
+ public void Subtract_ComposedThroughThenBlindCylinder_ReturnsUnsupportedBlindHoleCompositionDiagnostic()
+ {
+ 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)));
+ var blind = TransformBody(BrepPrimitives.CreateCylinder(3d, 8d).Value, Transform3D.CreateTranslation(new Vector3D(8d, 1d, 8d)));
+
+ var first = BrepBoolean.Subtract(baseBox, firstHole);
+ Assert.True(first.IsSuccess);
+
+ var result = BrepBoolean.Subtract(first.Value, blind);
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal("BrepBoolean.AnalyticHole.UnsupportedBlindHoleComposition", diagnostic.Source);
+ }
+
[Fact]
public void Subtract_ComposedOverlappingHoles_FailsWithDeterministicInterferenceDiagnostic()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnostic.cs b/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnostic.cs
index e54f810c..1c7daed1 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnostic.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnostic.cs
@@ -11,7 +11,8 @@ public enum BooleanDiagnosticCode
TangentContact,
MultiBodyResult,
HoleInterference,
- UnsupportedAnalyticSurfaceKind
+ UnsupportedAnalyticSurfaceKind,
+ UnsupportedBlindHoleComposition
}
public sealed record BooleanDiagnostic(
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
index 1a8efdd7..09507117 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
@@ -191,7 +191,7 @@ public static class BrepBoolean
leftRecognized ? leftBox : leftSafeComposition!.OuterBox,
rightRecognized ? rightBox : null,
rightAnalyticRecognized ? analyticSurface : null,
- $"Boolean {operation}: sequential safe composition only supports subtracting supported cylinder/cone through-holes from the current composed box shell.");
+ $"Boolean {operation}: sequential safe composition only supports subtracting supported cylinder/cone analytic holes from the current composed box shell.");
}
return new BooleanCaseClassification(
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
index fc940da4..76961c0d 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
@@ -260,6 +260,18 @@ public static class BrepBooleanBoxCylinderHoleBuilder
{
var box = composition.OuterBox;
var holes = composition.Holes;
+ if (holes.Count > 1 && holes.Any(h => h.IsBlind))
+ {
+ return KernelResult<BrepBody>.Failure([
+ new BooleanDiagnostic(
+ BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
+ BrepBooleanCylinderRecognition.CreateBooleanMessage(
+ BooleanOperation.Subtract.ToString(),
+ null,
+ "cannot rebuild a composition with more than one blind analytic hole in B1; blind-hole support is limited to single-feature subtracts."),
+ "BrepBoolean.AnalyticHole.UnsupportedBlindHoleComposition").ToKernelDiagnostic(),
+ ]);
+ }
var builder = new TopologyBuilder();
@@ -306,8 +318,19 @@ public static class BrepBooleanBoxCylinderHoleBuilder
var topLoops = new List<LoopId>(holes.Count + 1) { topOuterLoop };
foreach (var hole in holeTopology)
{
- topLoops.Add(AddLoop(builder, [Forward(hole.TopCircle)]));
- bottomLoops.Add(AddLoop(builder, [Reversed(hole.BottomCircle)]));
+ if (hole.Hole.SpanKind == SupportedBooleanHoleSpanKind.Through)
+ {
+ topLoops.Add(AddLoop(builder, [Forward(hole.TopCircle)]));
+ bottomLoops.Add(AddLoop(builder, [Reversed(hole.BottomCircle)]));
+ }
+ else if (hole.Hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop)
+ {
+ topLoops.Add(AddLoop(builder, [Forward(hole.TopCircle)]));
+ }
+ else
+ {
+ bottomLoops.Add(AddLoop(builder, [Reversed(hole.BottomCircle)]));
+ }
}
var bottomFace = builder.AddFace(bottomLoops);
@@ -325,6 +348,13 @@ public static class BrepBooleanBoxCylinderHoleBuilder
]));
}
+ var blindBottomFaces = new List<FaceId>();
+ foreach (var hole in holeTopology.Where(h => h.Hole.IsBlind))
+ {
+ var terminationEdge = hole.Hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop ? hole.BottomCircle : hole.TopCircle;
+ blindBottomFaces.Add(builder.AddFace([AddLoop(builder, [Forward(terminationEdge)])]));
+ }
+
var shellFaces = new List<FaceId>(6 + holeFaces.Count)
{
bottomFace,
@@ -335,6 +365,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder
yMinFace,
};
shellFaces.AddRange(holeFaces);
+ shellFaces.AddRange(blindBottomFaces);
var shell = builder.AddShell(shellFaces);
builder.AddBody([shell]);
@@ -412,6 +443,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder
var nextCurveId = 13;
var nextSurfaceId = 7;
+ var blindBottomFaceIndex = 0;
for (var i = 0; i < holeTopology.Count; i++)
{
var topology = holeTopology[i];
@@ -431,6 +463,19 @@ public static class BrepBooleanBoxCylinderHoleBuilder
bindings.AddEdgeBinding(new EdgeGeometryBinding(topology.Seam, seamCurveId, new ParameterInterval(0d, geometryData.SeamLength)));
bindings.AddFaceBinding(new FaceGeometryBinding(holeFaces[i], surfaceId));
+ if (topology.Hole.IsBlind)
+ {
+ var blindBottomCenter = topology.Hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop
+ ? geometryData.BottomCenter
+ : geometryData.TopCenter;
+ var blindBottomSurfaceId = new SurfaceGeometryId(nextSurfaceId++);
+ geometry.AddSurface(blindBottomSurfaceId, SurfaceGeometry.FromPlane(new PlaneSurface(
+ new Point3D(blindBottomCenter.X, blindBottomCenter.Y, blindBottomCenter.Z),
+ Direction3D.Create(new Vector3D(0d, 0d, -1d)),
+ xAxis)));
+ bindings.AddFaceBinding(new FaceGeometryBinding(blindBottomFaces[blindBottomFaceIndex++], blindBottomSurfaceId));
+ }
+
vertexPoints[topology.TopHoleVertex] = geometryData.SeamTopPoint;
vertexPoints[topology.BottomHoleVertex] = geometryData.SeamBottomPoint;
vertexPoints[topology.SeamTopVertex] = geometryData.SeamTopPoint;
@@ -447,40 +492,46 @@ public static class BrepBooleanBoxCylinderHoleBuilder
private static HoleGeometryData CreateHoleGeometry(SupportedBooleanHole hole, AxisAlignedBoxExtents box, Direction3D zAxis, Direction3D xAxis)
{
return hole.Surface.Kind switch
- {
- AnalyticSurfaceKind.Cylinder when hole.Surface.Cylinder is RecognizedCylinder cylinder => CreateCylinderHoleGeometry(box, xAxis, zAxis, cylinder),
- AnalyticSurfaceKind.Cone when hole.Surface.Cone is RecognizedCone cone => CreateConeHoleGeometry(box, xAxis, zAxis, cone),
+ {
+ AnalyticSurfaceKind.Cylinder when hole.Surface.Cylinder is RecognizedCylinder cylinder => CreateCylinderHoleGeometry(hole, xAxis, zAxis, cylinder),
+ AnalyticSurfaceKind.Cone when hole.Surface.Cone is RecognizedCone cone => CreateConeHoleGeometry(hole, xAxis, zAxis, cone),
_ => throw new InvalidOperationException($"Unsupported hole surface kind '{hole.Surface.Kind}'."),
};
}
- private static HoleGeometryData CreateCylinderHoleGeometry(AxisAlignedBoxExtents box, Direction3D xAxis, Direction3D zAxis, in RecognizedCylinder cylinder)
+ private static HoleGeometryData CreateCylinderHoleGeometry(SupportedBooleanHole hole, Direction3D xAxis, Direction3D zAxis, in RecognizedCylinder cylinder)
{
var centerX = cylinder.MinCenter.X;
var centerY = cylinder.MinCenter.Y;
- var bottomCenter = new Point3D(centerX, centerY, box.MinZ);
- var topCenter = new Point3D(centerX, centerY, box.MaxZ);
- var seamBottomPoint = new Point3D(centerX + cylinder.Radius, centerY, box.MinZ);
- var seamTopPoint = new Point3D(centerX + cylinder.Radius, centerY, box.MaxZ);
+ var topZ = System.Math.Max(hole.StartZ, hole.EndZ);
+ var bottomZ = System.Math.Min(hole.StartZ, hole.EndZ);
+ var topCenter = new Point3D(centerX, centerY, topZ);
+ var bottomCenter = new Point3D(centerX, centerY, bottomZ);
+ var seamBottomPoint = new Point3D(centerX + cylinder.Radius, centerY, bottomZ);
+ var seamTopPoint = new Point3D(centerX + cylinder.Radius, centerY, topZ);
return new HoleGeometryData(
CurveGeometry.FromCircle(new Circle3Curve(topCenter, zAxis, cylinder.Radius, xAxis)),
CurveGeometry.FromCircle(new Circle3Curve(bottomCenter, zAxis, cylinder.Radius, xAxis)),
CurveGeometry.FromLine(new Line3Curve(seamTopPoint, Direction3D.Create(seamBottomPoint - seamTopPoint))),
SurfaceGeometry.FromCylinder(new CylinderSurface(bottomCenter, zAxis, cylinder.Radius, xAxis)),
+ topCenter,
+ bottomCenter,
seamTopPoint,
seamBottomPoint,
(seamBottomPoint - seamTopPoint).Length);
}
- private static HoleGeometryData CreateConeHoleGeometry(AxisAlignedBoxExtents box, Direction3D xAxis, Direction3D zAxis, in RecognizedCone cone)
+ private static HoleGeometryData CreateConeHoleGeometry(SupportedBooleanHole hole, Direction3D xAxis, Direction3D zAxis, in RecognizedCone cone)
{
- var bottomAxisParameter = AxisParameterAtZ(cone, box.MinZ);
- var topAxisParameter = AxisParameterAtZ(cone, box.MaxZ);
+ var bottomZ = System.Math.Min(hole.StartZ, hole.EndZ);
+ var topZ = System.Math.Max(hole.StartZ, hole.EndZ);
+ var bottomAxisParameter = AxisParameterAtZ(cone, bottomZ);
+ var topAxisParameter = AxisParameterAtZ(cone, topZ);
var bottomCenter = cone.PointAtAxisParameter(bottomAxisParameter);
var topCenter = cone.PointAtAxisParameter(topAxisParameter);
- var bottomRadius = cone.RadiusAtAxisParameter(bottomAxisParameter);
- var topRadius = cone.RadiusAtAxisParameter(topAxisParameter);
+ var bottomRadius = hole.BottomRadius;
+ var topRadius = hole.TopRadius;
var seamBottomPoint = new Point3D(bottomCenter.X + bottomRadius, bottomCenter.Y, bottomCenter.Z);
var seamTopPoint = new Point3D(topCenter.X + topRadius, topCenter.Y, topCenter.Z);
var innerMinAxisParameter = System.Math.Min(bottomAxisParameter, topAxisParameter);
@@ -492,6 +543,8 @@ public static class BrepBooleanBoxCylinderHoleBuilder
CurveGeometry.FromCircle(new Circle3Curve(bottomCenter, zAxis, bottomRadius, xAxis)),
CurveGeometry.FromLine(new Line3Curve(seamTopPoint, Direction3D.Create(seamBottomPoint - seamTopPoint))),
SurfaceGeometry.FromCone(new ConeSurface(innerMinCenter, cone.Axis, innerMinRadius, cone.SemiAngleRadians, xAxis)),
+ topCenter,
+ bottomCenter,
seamTopPoint,
seamBottomPoint,
(seamBottomPoint - seamTopPoint).Length);
@@ -539,6 +592,8 @@ public static class BrepBooleanBoxCylinderHoleBuilder
CurveGeometry BottomCircle,
CurveGeometry Seam,
SurfaceGeometry Surface,
+ Point3D TopCenter,
+ Point3D BottomCenter,
Point3D SeamTopPoint,
Point3D SeamBottomPoint,
double SeamLength);
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
index c817306b..3d14e4c4 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
@@ -21,6 +21,15 @@ public readonly record struct RecognizedCylinder(
public Point3D MaxCenter => AxisOrigin + (Axis.ToVector() * MaxAxisParameter);
}
+public readonly record struct SupportedSubtractProfile(
+ SupportedBooleanHoleSpanKind SpanKind,
+ double CenterX,
+ double CenterY,
+ double StartZ,
+ double EndZ,
+ double StartRadius,
+ double EndRadius);
+
public static class BrepBooleanCylinderRecognition
{
public static bool TryRecognizeCylinder(BrepBody body, ToleranceContext tolerance, out RecognizedCylinder cylinder, out string reason)
@@ -154,6 +163,13 @@ public static class BrepBooleanCylinderRecognition
public static bool ValidateThroughHole(AxisAlignedBoxExtents box, in RecognizedCylinder cylinder, ToleranceContext tolerance, out BooleanDiagnostic? diagnostic, string? featureId = null)
{
+ var success = TryValidateCylinderSubtractProfile(box, cylinder, tolerance, out var profile, out diagnostic, featureId);
+ return success && profile.SpanKind == SupportedBooleanHoleSpanKind.Through;
+ }
+
+ public static bool TryValidateCylinderSubtractProfile(AxisAlignedBoxExtents box, in RecognizedCylinder cylinder, ToleranceContext tolerance, out SupportedSubtractProfile profile, out BooleanDiagnostic? diagnostic, string? featureId = null)
+ {
+ profile = default;
diagnostic = null;
if (!ValidateAxisAlignedZ(cylinder, tolerance))
@@ -175,12 +191,6 @@ public static class BrepBooleanCylinderRecognition
var minZ = System.Math.Min(minCenter.Z, maxCenter.Z);
var maxZ = System.Math.Max(minCenter.Z, maxCenter.Z);
- if (minZ > (box.MinZ + tolerance.Linear) || maxZ < (box.MaxZ - tolerance.Linear))
- {
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not reach both box boundary planes; partial-depth cylinder cuts are outside the supported safe boolean family. Extend the cylinder so it spans the full box Z range.");
- return false;
- }
-
var minFootprintX = centerX - cylinder.Radius;
var maxFootprintX = centerX + cylinder.Radius;
var minFootprintY = centerY - cylinder.Radius;
@@ -206,11 +216,54 @@ public static class BrepBooleanCylinderRecognition
return false;
}
- return true;
+ var touchesBottom = minZ <= (box.MinZ + tolerance.Linear);
+ var touchesTop = maxZ >= (box.MaxZ - tolerance.Linear);
+
+ if (touchesBottom && touchesTop)
+ {
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, centerX, centerY, box.MinZ, box.MaxZ, cylinder.Radius, cylinder.Radius);
+ return true;
+ }
+
+ if (touchesTop && minZ > (box.MinZ + tolerance.Linear))
+ {
+ var depth = box.MaxZ - minZ;
+ if (depth <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "has near-zero blind-hole depth after entering from the top box face; extend the tool farther into the box.");
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, centerX, centerY, box.MaxZ, minZ, cylinder.Radius, cylinder.Radius);
+ return true;
+ }
+
+ if (touchesBottom && maxZ < (box.MaxZ - tolerance.Linear))
+ {
+ var depth = maxZ - box.MinZ;
+ if (depth <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "has near-zero blind-hole depth after entering from the bottom box face; extend the tool farther into the box.");
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromBottom, centerX, centerY, box.MinZ, maxZ, cylinder.Radius, cylinder.Radius);
+ return true;
+ }
+
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
+ return false;
}
public static bool ValidateThroughHole(AxisAlignedBoxExtents box, in RecognizedCone cone, ToleranceContext tolerance, out BooleanDiagnostic? diagnostic, string? featureId = null)
{
+ var success = TryValidateConeSubtractProfile(box, cone, tolerance, out var profile, out diagnostic, featureId);
+ return success && profile.SpanKind == SupportedBooleanHoleSpanKind.Through;
+ }
+
+ public static bool TryValidateConeSubtractProfile(AxisAlignedBoxExtents box, in RecognizedCone cone, ToleranceContext tolerance, out SupportedSubtractProfile profile, out BooleanDiagnostic? diagnostic, string? featureId = null)
+ {
+ profile = default;
diagnostic = null;
var axis = cone.Axis.ToVector();
@@ -230,42 +283,100 @@ public static class BrepBooleanCylinderRecognition
return false;
}
+ var centerX = cone.AxisOrigin.X;
+ var centerY = cone.AxisOrigin.Y;
+
var bottomAxisParameter = AxisParameterAtZ(cone, box.MinZ, tolerance);
var topAxisParameter = AxisParameterAtZ(cone, box.MaxZ, tolerance);
+ var coversBottom = bottomAxisParameter >= (cone.MinAxisParameter - tolerance.Linear)
+ && bottomAxisParameter <= (cone.MaxAxisParameter + tolerance.Linear);
+ var coversTop = topAxisParameter >= (cone.MinAxisParameter - tolerance.Linear)
+ && topAxisParameter <= (cone.MaxAxisParameter + tolerance.Linear);
- if (bottomAxisParameter < (cone.MinAxisParameter - tolerance.Linear)
- || bottomAxisParameter > (cone.MaxAxisParameter + tolerance.Linear)
- || topAxisParameter < (cone.MinAxisParameter - tolerance.Linear)
- || topAxisParameter > (cone.MaxAxisParameter + tolerance.Linear))
+ if (coversBottom && coversTop)
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not reach both box boundary planes; partial-depth cone cuts are outside the supported safe boolean family. Extend the cone so it spans the full box Z range.");
- return false;
+ if (bottomAxisParameter <= tolerance.Linear || topAxisParameter <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "cannot produce circular sections on both box boundary planes because the apex or cone termination lands inside the box span. Move the apex outside the box span or lengthen the cone.");
+ return false;
+ }
+
+ var bottomRadius = cone.RadiusAtAxisParameter(bottomAxisParameter);
+ var topRadius = cone.RadiusAtAxisParameter(topAxisParameter);
+ if (bottomRadius <= tolerance.Linear || topRadius <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate circular sections where the cone meets the two box boundary planes. Increase the boundary radii at those planes by moving the apex farther away or changing the cone taper.");
+ return false;
+ }
+
+ if (!ValidateCircleInsideBoxFootprint(box, centerX, centerY, bottomRadius, tolerance, out diagnostic, "bottom boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, centerX, centerY, topRadius, tolerance, out diagnostic, "top boundary circle", featureId))
+ {
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, centerX, centerY, box.MinZ, box.MaxZ, bottomRadius, topRadius);
+ return true;
}
- if (bottomAxisParameter <= tolerance.Linear || topAxisParameter <= tolerance.Linear)
+ if (coversTop && !coversBottom)
{
- diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "cannot produce circular sections on both box boundary planes because the apex or cone termination lands inside the box span. Move the apex outside the box span or lengthen the cone.");
- return false;
- }
+ var minEndIsLower = cone.MinCenter.Z <= cone.MaxCenter.Z;
+ var terminationZ = System.Math.Min(cone.MinCenter.Z, cone.MaxCenter.Z);
+ if (terminationZ <= (box.MinZ + tolerance.Linear) || terminationZ >= (box.MaxZ - tolerance.Linear))
+ {
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
+ return false;
+ }
- var centerX = cone.AxisOrigin.X;
- var centerY = cone.AxisOrigin.Y;
- var bottomRadius = cone.RadiusAtAxisParameter(bottomAxisParameter);
- var topRadius = cone.RadiusAtAxisParameter(topAxisParameter);
+ var topRadius = cone.RadiusAtAxisParameter(topAxisParameter);
+ var endRadius = minEndIsLower ? cone.RadiusAtMinAxisParameter : cone.RadiusAtMaxAxisParameter;
+ if (topRadius <= tolerance.Linear || endRadius <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
+ return false;
+ }
- if (bottomRadius <= tolerance.Linear || topRadius <= tolerance.Linear)
- {
- diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate circular sections where the cone meets the two box boundary planes. Increase the boundary radii at those planes by moving the apex farther away or changing the cone taper.");
- return false;
+ if (!ValidateCircleInsideBoxFootprint(box, centerX, centerY, topRadius, tolerance, out diagnostic, "top boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, centerX, centerY, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ {
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, centerX, centerY, box.MaxZ, terminationZ, topRadius, endRadius);
+ return true;
}
- if (!ValidateCircleInsideBoxFootprint(box, centerX, centerY, bottomRadius, tolerance, out diagnostic, "bottom boundary circle", featureId)
- || !ValidateCircleInsideBoxFootprint(box, centerX, centerY, topRadius, tolerance, out diagnostic, "top boundary circle", featureId))
+ if (coversBottom && !coversTop)
{
- return false;
+ var maxEndIsHigher = cone.MaxCenter.Z >= cone.MinCenter.Z;
+ var terminationZ = System.Math.Max(cone.MinCenter.Z, cone.MaxCenter.Z);
+ if (terminationZ <= (box.MinZ + tolerance.Linear) || terminationZ >= (box.MaxZ - tolerance.Linear))
+ {
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
+ return false;
+ }
+
+ var bottomRadius = cone.RadiusAtAxisParameter(bottomAxisParameter);
+ var endRadius = maxEndIsHigher ? cone.RadiusAtMaxAxisParameter : cone.RadiusAtMinAxisParameter;
+ if (bottomRadius <= tolerance.Linear || endRadius <= tolerance.Linear)
+ {
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
+ return false;
+ }
+
+ if (!ValidateCircleInsideBoxFootprint(box, centerX, centerY, bottomRadius, tolerance, out diagnostic, "bottom boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, centerX, centerY, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ {
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromBottom, centerX, centerY, box.MinZ, terminationZ, bottomRadius, endRadius);
+ return true;
}
- return true;
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
+ return false;
}
private static double AxisParameterAtZ(in RecognizedCone cone, double z, ToleranceContext tolerance)
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
index 7b077e1d..703817d9 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
@@ -23,15 +23,26 @@ public sealed record SafeBooleanComposition(
}
}
+public enum SupportedBooleanHoleSpanKind
+{
+ Through,
+ BlindFromTop,
+ BlindFromBottom,
+}
+
public readonly record struct SupportedBooleanHole(
string? FeatureId,
AnalyticSurface Surface,
double CenterX,
double CenterY,
double BottomRadius,
- double TopRadius)
+ double TopRadius,
+ SupportedBooleanHoleSpanKind SpanKind,
+ double StartZ,
+ double EndZ)
{
public double MaxBoundaryRadius => System.Math.Max(BottomRadius, TopRadius);
+ public bool IsBlind => SpanKind != SupportedBooleanHoleSpanKind.Through;
public SupportedBooleanHole Translate(Vector3D translation)
=> this with
@@ -39,6 +50,8 @@ public readonly record struct SupportedBooleanHole(
Surface = Surface.Translate(translation),
CenterX = CenterX + translation.X,
CenterY = CenterY + translation.Y,
+ StartZ = StartZ + translation.Z,
+ EndZ = EndZ + translation.Z,
};
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
index 41eb5266..05babd3e 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
@@ -21,6 +21,18 @@ public static class BrepBooleanSafeCompositionGraphValidator
return false;
}
+ if (composition.Holes.Count > 0 && nextHole.IsBlind)
+ {
+ diagnostic = new BooleanDiagnostic(
+ BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
+ BrepBooleanCylinderRecognition.CreateBooleanMessage(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "cannot append a blind analytic hole to an existing safe subtract composition in B1; blind-hole support is currently limited to single-feature subtracts."),
+ "BrepBoolean.AnalyticHole.UnsupportedBlindHoleComposition");
+ return false;
+ }
+
foreach (var existingHole in composition.Holes)
{
var deltaX = existingHole.CenterX - nextHole.CenterX;
@@ -69,7 +81,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
switch (surface.Kind)
{
case AnalyticSurfaceKind.Cylinder when surface.Cylinder is RecognizedCylinder cylinder:
- if (!BrepBooleanCylinderRecognition.ValidateThroughHole(outerBox, cylinder, tolerance, out diagnostic, featureId))
+ if (!BrepBooleanCylinderRecognition.TryValidateCylinderSubtractProfile(outerBox, cylinder, tolerance, out var cylinderProfile, out diagnostic, featureId))
{
hole = default;
return false;
@@ -78,29 +90,32 @@ public static class BrepBooleanSafeCompositionGraphValidator
hole = new SupportedBooleanHole(
featureId,
surface,
- cylinder.MinCenter.X,
- cylinder.MinCenter.Y,
- cylinder.Radius,
- cylinder.Radius);
+ cylinderProfile.CenterX,
+ cylinderProfile.CenterY,
+ cylinderProfile.StartRadius,
+ cylinderProfile.EndRadius,
+ cylinderProfile.SpanKind,
+ cylinderProfile.StartZ,
+ cylinderProfile.EndZ);
return true;
case AnalyticSurfaceKind.Cone when surface.Cone is RecognizedCone cone:
- if (!BrepBooleanCylinderRecognition.ValidateThroughHole(outerBox, cone, tolerance, out diagnostic, featureId))
+ if (!BrepBooleanCylinderRecognition.TryValidateConeSubtractProfile(outerBox, cone, tolerance, out var coneProfile, out diagnostic, featureId))
{
hole = default;
return false;
}
- var bottomAxisParameter = AxisParameterAtZ(cone, outerBox.MinZ, tolerance);
- var topAxisParameter = AxisParameterAtZ(cone, outerBox.MaxZ, tolerance);
- var boundaryBottomCenter = cone.PointAtAxisParameter(bottomAxisParameter);
hole = new SupportedBooleanHole(
featureId,
surface,
- boundaryBottomCenter.X,
- boundaryBottomCenter.Y,
- cone.RadiusAtAxisParameter(bottomAxisParameter),
- cone.RadiusAtAxisParameter(topAxisParameter));
+ coneProfile.CenterX,
+ coneProfile.CenterY,
+ coneProfile.StartRadius,
+ coneProfile.EndRadius,
+ coneProfile.SpanKind,
+ coneProfile.StartZ,
+ coneProfile.EndZ);
return true;
case AnalyticSurfaceKind.Sphere when surface.Sphere is RecognizedSphere sphere:
@@ -126,7 +141,10 @@ public static class BrepBooleanSafeCompositionGraphValidator
sphere.Center.X,
sphere.Center.Y,
sphere.Radius,
- sphere.Radius);
+ sphere.Radius,
+ SupportedBooleanHoleSpanKind.Through,
+ outerBox.MinZ,
+ outerBox.MaxZ);
return true;
case AnalyticSurfaceKind.Sphere:
@@ -141,17 +159,6 @@ public static class BrepBooleanSafeCompositionGraphValidator
}
}
- private static double AxisParameterAtZ(in RecognizedCone cone, double z, ToleranceContext tolerance)
- {
- var axisZ = cone.Axis.ToVector().Z;
- if (ToleranceMath.AlmostEqual(axisZ, 0d, tolerance))
- {
- throw new InvalidOperationException("AxisParameterAtZ requires a cone axis aligned with Z.");
- }
-
- return (z - cone.AxisOrigin.Z) / axisZ;
- }
-
private static string FormatFeatureRef(string? featureId)
=> string.IsNullOrWhiteSpace(featureId) ? "<unknown>" : $"'{featureId}'";
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
index afb51e29..69286c7f 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs
@@ -249,7 +249,7 @@ public sealed class FirmamentBooleanCanonicalSuccessTests
private static bool HasExpectedMixedPrimitiveFailure(string message)
=> message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)
- || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone through-holes", StringComparison.Ordinal)
+ || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)
|| message.Contains("safe subtract", StringComparison.Ordinal)
|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)
|| message.Contains("Boolean feature", StringComparison.Ordinal)
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index 99b1b5f5..a48cedac 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -259,7 +259,7 @@ public sealed class FirmamentBuildAndExportTests
private static bool HasExpectedMixedPrimitiveFailure(string message)
=> message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)
- || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone through-holes", StringComparison.Ordinal)
+ || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)
|| message.Contains("safe subtract", StringComparison.Ordinal)
|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)
|| message.Contains("Boolean feature", StringComparison.Ordinal)
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
index 154d3143..d75205dc 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs
@@ -223,7 +223,7 @@ public sealed class FirmamentStepExporterTests
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 reach both box boundary planes", StringComparison.Ordinal));
+ && 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));
}
@@ -292,7 +292,7 @@ public sealed class FirmamentStepExporterTests
private static bool HasExpectedMixedPrimitiveFailure(string message)
=> message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)
- || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone through-holes", StringComparison.Ordinal)
+ || message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)
|| message.Contains("safe subtract", StringComparison.Ordinal)
|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)
|| message.Contains("Boolean feature", StringComparison.Ordinal)