Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Stabilize B2a truth boundary for arbitrary-axis safe subtract

Yuechen Li9c35d34aa381
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
index 193f9c54..238c002b 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanSafeCompositionGraphValidatorTests.cs
@@ -28,6 +28,10 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests
4d)),
-7d,
-2d,
+ new Point3D(-7d, -2d, 0d),
+ new Point3D(-7d, -2d, 12d),
+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),
+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),
4d,
4d,
SupportedBooleanHoleSpanKind.Through,
@@ -123,6 +127,10 @@ public sealed class BrepBooleanSafeCompositionGraphValidatorTests
3d)),
0d,
0d,
+ new Point3D(0d, 0d, 0d),
+ new Point3D(0d, 0d, 12d),
+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),
+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),
3d,
3d,
SupportedBooleanHoleSpanKind.Through,
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 74e8bf8c..3192ec79 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -259,18 +259,18 @@ public sealed class BrepBooleanTests
}
[Fact]
- public void Subtract_BoxCylinderRotatedAxis_ReturnsDeterministicNotImplemented()
+ public void Subtract_BoxCylinderRotatedAxis_SucceedsWithinBoundedSubset()
{
var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
- var rotated = TransformBody(BrepPrimitives.CreateCylinder(4d, 20d).Value, Transform3D.CreateRotationX(System.Math.PI / 2d) * Transform3D.CreateTranslation(new Vector3D(0d, 0d, 6d)));
+ var rotated = TransformBody(BrepPrimitives.CreateCylinder(4d, 20d).Value, Transform3D.CreateRotationX(System.Math.PI / 6d) * Transform3D.CreateTranslation(new Vector3D(0d, -3d, 6d)));
var result = BrepBoolean.Subtract(left, rotated);
- Assert.False(result.IsSuccess);
- var diagnostic = Assert.Single(result.Diagnostics);
- Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
- Assert.Equal("BrepBoolean.AnalyticHole.AxisNotAligned", diagnostic.Source);
- Assert.Equal("Boolean Subtract requires the cylinder axis to be parallel to world Z; the current cylinder axis is not aligned with the box Z axis. Rotate or redefine the tool so both cylinder caps stay on a world-Z through-hole axis.", diagnostic.Message);
+ Assert.True(result.IsSuccess);
+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);
+ var export = Step242Exporter.ExportBody(result.Value);
+ Assert.True(export.IsSuccess);
+ Assert.Contains("ELLIPSE", export.Value, StringComparison.Ordinal);
}
[Fact]
@@ -311,7 +311,7 @@ public sealed class BrepBooleanTests
var diagnostic = Assert.Single(result.Diagnostics);
Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
Assert.Equal("BrepBoolean.AnalyticHole.RadiusExceedsBoundary", diagnostic.Source);
- Assert.Equal("Boolean Subtract extends outside the box side-wall footprint. Reduce the cylinder radius or move the center farther inside the box XY boundary.", diagnostic.Message);
+ Assert.Contains("extending outside the box side-wall footprint", diagnostic.Message, StringComparison.Ordinal);
}
[Fact]
@@ -326,7 +326,7 @@ public sealed class BrepBooleanTests
var diagnostic = Assert.Single(result.Diagnostics);
Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
Assert.Equal("BrepBoolean.AnalyticHole.TangentContact", diagnostic.Source);
- Assert.Equal("Boolean Subtract is tangent to a box side wall; tangent analytic-hole cases are rejected to avoid zero-thickness geometry. Move the hole inward or reduce the radius.", diagnostic.Message);
+ Assert.Contains("tangent to a box side wall", diagnostic.Message, StringComparison.Ordinal);
}
[Fact]
@@ -399,18 +399,16 @@ public sealed class BrepBooleanTests
}
[Fact]
- public void Subtract_BoxConeRotatedAxis_ReturnsAxisNotAlignedDiagnostic()
+ public void Subtract_BoxConeRotatedAxis_ReturnsDeferredArbitraryAxisDiagnostic()
{
var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
- var rotated = TransformBody(CreateCone(bottomRadius: 4d, topRadius: 8d, height: 20d), Transform3D.CreateRotationX(System.Math.PI / 2d));
+ var rotated = TransformBody(CreateCone(bottomRadius: 2d, topRadius: 3d, height: 20d), Transform3D.CreateRotationX(System.Math.PI / 12d) * Transform3D.CreateTranslation(new Vector3D(0d, -1d, 2d)));
var result = BrepBoolean.Subtract(left, rotated);
Assert.False(result.IsSuccess);
var diagnostic = Assert.Single(result.Diagnostics);
Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
- Assert.Equal("BrepBoolean.AnalyticHole.AxisNotAligned", diagnostic.Source);
- 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]
@@ -428,6 +426,17 @@ public sealed class BrepBooleanTests
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_BoxCylinderAxisNearlyParallelToTopPlane_ReturnsAxisNotAlignedDiagnostic()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var rotated = TransformBody(BrepPrimitives.CreateCylinder(3d, 20d).Value, Transform3D.CreateRotationX(System.Math.PI / 2d) * Transform3D.CreateTranslation(new Vector3D(0d, 0d, 6d)));
+ var result = BrepBoolean.Subtract(left, rotated);
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal("BrepBoolean.AnalyticHole.AxisNotAligned", diagnostic.Source);
+ }
+
[Fact]
public void Subtract_BoxConeBlindTopEntry_ReturnsClosedBottomHole()
{
@@ -442,7 +451,8 @@ public sealed class BrepBooleanTests
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);
+ && surface.Plane!.Value.Normal.Z > 0.5d
+ && System.Math.Abs(surface.Plane!.Value.Origin.Z - 12d) < 1e-6d);
Assert.Equal(2, result.Value.GetLoopIds(topFace.Id).Count);
var bottomFace = Assert.Single(result.Value.Topology.Faces, face =>
@@ -453,6 +463,41 @@ public sealed class BrepBooleanTests
Assert.Single(result.Value.GetLoopIds(bottomFace.Id));
}
+ [Fact]
+ public void Subtract_BoxCylinderBlindRotatedAxis_ReturnsDeferredArbitraryAxisBlindDiagnostic()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var blind = TransformBody(BrepPrimitives.CreateCylinder(2.5d, 8d).Value, Transform3D.CreateRotationX(System.Math.PI / 12d) * Transform3D.CreateTranslation(new Vector3D(-1d, -1d, 8d)));
+ var result = BrepBoolean.Subtract(left, blind);
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);
+ Assert.Contains("does not match the supported subtract span family", diagnostic.Message, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void Subtract_BoxConeBlindRotatedAxis_ReturnsDeferredArbitraryAxisDiagnostic()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var blind = TransformBody(CreateCone(bottomRadius: 2.5d, topRadius: 1.5d, height: 8d), Transform3D.CreateRotationX(System.Math.PI / 12d) * Transform3D.CreateTranslation(new Vector3D(1d, -1d, 4d)));
+ var result = BrepBoolean.Subtract(left, blind);
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);
+ }
+
+ [Fact]
+ public void Subtract_BoxConeRotatedAxis_RejectionIsDeterministic()
+ {
+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, 0d, 12d)).Value;
+ var rotated = TransformBody(CreateCone(bottomRadius: 2d, topRadius: 3d, height: 20d), Transform3D.CreateRotationX(System.Math.PI / 12d) * Transform3D.CreateTranslation(new Vector3D(0d, -1d, 2d)));
+ var first = BrepBoolean.Subtract(left, rotated);
+ var second = BrepBoolean.Subtract(left, rotated);
+ Assert.False(first.IsSuccess);
+ Assert.False(second.IsSuccess);
+ Assert.Equal(Assert.Single(first.Diagnostics).Message, Assert.Single(second.Diagnostics).Message);
+ }
+
[Fact]
public void Subtract_BoxConePartialHeight_ReturnsNotFullySpanningDiagnostic()
{
@@ -521,7 +566,7 @@ public sealed class BrepBooleanTests
Assert.NotNull(diagnostic);
Assert.Equal(BooleanDiagnosticCode.DegenerateBoundarySection, diagnostic!.Code);
Assert.Equal("BrepBoolean.AnalyticHole.DegenerateBoundarySection", diagnostic.Source);
- Assert.Equal("Boolean Subtract 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.", diagnostic.Message);
+ Assert.Equal("Boolean Subtract 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.", diagnostic.Message);
}
[Fact]
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
index 76961c0d..bf25897e 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
@@ -470,9 +470,9 @@ public static class BrepBooleanBoxCylinderHoleBuilder
: 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)));
+ blindBottomCenter,
+ Direction3D.Create(topology.Hole.Axis.ToVector() * -1d),
+ topology.Hole.ReferenceAxis)));
bindings.AddFaceBinding(new FaceGeometryBinding(blindBottomFaces[blindBottomFaceIndex++], blindBottomSurfaceId));
}
@@ -501,20 +501,20 @@ public static class BrepBooleanBoxCylinderHoleBuilder
private static HoleGeometryData CreateCylinderHoleGeometry(SupportedBooleanHole hole, Direction3D xAxis, Direction3D zAxis, in RecognizedCylinder cylinder)
{
- var centerX = cylinder.MinCenter.X;
- var centerY = cylinder.MinCenter.Y;
- 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);
+ var topCenter = hole.StartCenter.Z >= hole.EndCenter.Z ? hole.StartCenter : hole.EndCenter;
+ var bottomCenter = hole.StartCenter.Z < hole.EndCenter.Z ? hole.StartCenter : hole.EndCenter;
+ var axis = hole.Axis;
+ var referenceAxis = hole.ReferenceAxis;
+ var topEllipse = hole.SpanKind != SupportedBooleanHoleSpanKind.BlindFromBottom;
+ var bottomEllipse = hole.SpanKind != SupportedBooleanHoleSpanKind.BlindFromTop;
+ var (topCurve, seamTopPoint) = CreateSectionCurve(topCenter, cylinder.Radius, axis, referenceAxis, topEllipse, zAxis);
+ var (bottomCurve, seamBottomPoint) = CreateSectionCurve(bottomCenter, cylinder.Radius, axis, referenceAxis, bottomEllipse, zAxis);
return new HoleGeometryData(
- CurveGeometry.FromCircle(new Circle3Curve(topCenter, zAxis, cylinder.Radius, xAxis)),
- CurveGeometry.FromCircle(new Circle3Curve(bottomCenter, zAxis, cylinder.Radius, xAxis)),
+ topCurve,
+ bottomCurve,
CurveGeometry.FromLine(new Line3Curve(seamTopPoint, Direction3D.Create(seamBottomPoint - seamTopPoint))),
- SurfaceGeometry.FromCylinder(new CylinderSurface(bottomCenter, zAxis, cylinder.Radius, xAxis)),
+ SurfaceGeometry.FromCylinder(new CylinderSurface(bottomCenter, axis, cylinder.Radius, referenceAxis)),
topCenter,
bottomCenter,
seamTopPoint,
@@ -524,25 +524,25 @@ public static class BrepBooleanBoxCylinderHoleBuilder
private static HoleGeometryData CreateConeHoleGeometry(SupportedBooleanHole hole, Direction3D xAxis, Direction3D zAxis, in RecognizedCone cone)
{
- 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 = 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);
- var innerMinCenter = cone.PointAtAxisParameter(innerMinAxisParameter);
- var innerMinRadius = cone.RadiusAtAxisParameter(innerMinAxisParameter);
+ var startIsTop = hole.StartCenter.Z >= hole.EndCenter.Z;
+ var topCenter = startIsTop ? hole.StartCenter : hole.EndCenter;
+ var bottomCenter = startIsTop ? hole.EndCenter : hole.StartCenter;
+ var topRadius = startIsTop ? hole.BottomRadius : hole.TopRadius;
+ var bottomRadius = startIsTop ? hole.TopRadius : hole.BottomRadius;
+ var axis = hole.Axis;
+ var referenceAxis = hole.ReferenceAxis;
+ var topEllipse = hole.SpanKind != SupportedBooleanHoleSpanKind.BlindFromBottom;
+ var bottomEllipse = hole.SpanKind != SupportedBooleanHoleSpanKind.BlindFromTop;
+ var (topCurve, seamTopPoint) = CreateSectionCurve(topCenter, topRadius, axis, referenceAxis, topEllipse, zAxis);
+ var (bottomCurve, seamBottomPoint) = CreateSectionCurve(bottomCenter, bottomRadius, axis, referenceAxis, bottomEllipse, zAxis);
+ var innerMinCenter = cone.PointAtAxisParameter(System.Math.Min(cone.MinAxisParameter, cone.MaxAxisParameter));
+ var innerMinRadius = cone.RadiusAtAxisParameter(System.Math.Min(cone.MinAxisParameter, cone.MaxAxisParameter));
return new HoleGeometryData(
- CurveGeometry.FromCircle(new Circle3Curve(topCenter, zAxis, topRadius, xAxis)),
- CurveGeometry.FromCircle(new Circle3Curve(bottomCenter, zAxis, bottomRadius, xAxis)),
+ topCurve,
+ bottomCurve,
CurveGeometry.FromLine(new Line3Curve(seamTopPoint, Direction3D.Create(seamBottomPoint - seamTopPoint))),
- SurfaceGeometry.FromCone(new ConeSurface(innerMinCenter, cone.Axis, innerMinRadius, cone.SemiAngleRadians, xAxis)),
+ SurfaceGeometry.FromCone(new ConeSurface(innerMinCenter, cone.Axis, innerMinRadius, cone.SemiAngleRadians, referenceAxis)),
topCenter,
bottomCenter,
seamTopPoint,
@@ -550,6 +550,28 @@ public static class BrepBooleanBoxCylinderHoleBuilder
(seamBottomPoint - seamTopPoint).Length);
}
+ private static (CurveGeometry Curve, Point3D SeamPoint) CreateSectionCurve(
+ Point3D center,
+ double radius,
+ Direction3D axis,
+ Direction3D referenceAxis,
+ bool forceEllipse,
+ Direction3D zAxis)
+ {
+ var axisDotZ = System.Math.Abs(axis.ToVector().Dot(zAxis.ToVector()));
+ if (forceEllipse && axisDotZ < 0.999d)
+ {
+ var majorRadius = radius / axisDotZ;
+ var projected = axis.ToVector() - (zAxis.ToVector() * axis.ToVector().Dot(zAxis.ToVector()));
+ var majorAxis = Direction3D.Create(projected);
+ var seamPoint = center + (majorAxis.ToVector() * majorRadius);
+ return (CurveGeometry.FromEllipse(new Ellipse3Curve(center, zAxis, majorRadius, radius, majorAxis)), seamPoint);
+ }
+
+ var seam = center + (referenceAxis.ToVector() * radius);
+ return (CurveGeometry.FromCircle(new Circle3Curve(center, axis, radius, referenceAxis)), seam);
+ }
+
private static double AxisParameterAtZ(in RecognizedCone cone, double z)
{
var axisZ = cone.Axis.ToVector().Z;
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
index 3d14e4c4..f1f0236e 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
@@ -25,6 +25,10 @@ public readonly record struct SupportedSubtractProfile(
SupportedBooleanHoleSpanKind SpanKind,
double CenterX,
double CenterY,
+ Point3D StartCenter,
+ Point3D EndCenter,
+ Direction3D Axis,
+ Direction3D ReferenceAxis,
double StartZ,
double EndZ,
double StartRadius,
@@ -171,83 +175,79 @@ public static class BrepBooleanCylinderRecognition
{
profile = default;
diagnostic = null;
-
- if (!ValidateAxisAlignedZ(cylinder, tolerance))
+ if (!TryResolveBoundaryAxisParameter(cylinder.AxisOrigin, cylinder.Axis, box.MinZ, tolerance, out var bottomAtZ)
+ || !TryResolveBoundaryAxisParameter(cylinder.AxisOrigin, cylinder.Axis, box.MaxZ, tolerance, out var topAtZ))
{
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires the cylinder axis to be parallel to world Z; the current cylinder axis is not aligned with the box Z axis. Rotate or redefine the tool so both cylinder caps stay on a world-Z through-hole axis.");
+ diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
return false;
}
- var minCenter = cylinder.MinCenter;
- var maxCenter = cylinder.MaxCenter;
- if (!ToleranceMath.AlmostEqual(minCenter.X, maxCenter.X, tolerance) || !ToleranceMath.AlmostEqual(minCenter.Y, maxCenter.Y, tolerance))
- {
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires one vertical through-hole centerline; the cylinder cap centers drift in XY instead of staying on a single world-Z axis. Rebuild the tool so the cap centers share the same X/Y location.");
- return false;
- }
+ var coversBottom = bottomAtZ >= (cylinder.MinAxisParameter - tolerance.Linear) && bottomAtZ <= (cylinder.MaxAxisParameter + tolerance.Linear);
+ var coversTop = topAtZ >= (cylinder.MinAxisParameter - tolerance.Linear) && topAtZ <= (cylinder.MaxAxisParameter + tolerance.Linear);
+ var bottomCenter = cylinder.AxisOrigin + (cylinder.Axis.ToVector() * bottomAtZ);
+ var topCenter = cylinder.AxisOrigin + (cylinder.Axis.ToVector() * topAtZ);
+ var averageCenter = new Point3D((bottomCenter.X + topCenter.X) * 0.5d, (bottomCenter.Y + topCenter.Y) * 0.5d, (bottomCenter.Z + topCenter.Z) * 0.5d);
+ var radialBound = cylinder.Radius / System.Math.Abs(cylinder.Axis.ToVector().Z);
- var centerX = minCenter.X;
- var centerY = minCenter.Y;
- var minZ = System.Math.Min(minCenter.Z, maxCenter.Z);
- var maxZ = System.Math.Max(minCenter.Z, maxCenter.Z);
-
- var minFootprintX = centerX - cylinder.Radius;
- var maxFootprintX = centerX + cylinder.Radius;
- var minFootprintY = centerY - cylinder.Radius;
- var maxFootprintY = centerY + cylinder.Radius;
-
- var tangentContact =
- ToleranceMath.AlmostEqual(minFootprintX, box.MinX, tolerance)
- || ToleranceMath.AlmostEqual(maxFootprintX, box.MaxX, tolerance)
- || ToleranceMath.AlmostEqual(minFootprintY, box.MinY, tolerance)
- || ToleranceMath.AlmostEqual(maxFootprintY, box.MaxY, tolerance);
- if (tangentContact)
+ if (coversBottom && coversTop)
{
- diagnostic = CreateTangentContactDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "is tangent to a box side wall; tangent analytic-hole cases are rejected to avoid zero-thickness geometry. Move the hole inward or reduce the radius.");
- return false;
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", featureId))
+ {
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, averageCenter.X, averageCenter.Y, bottomCenter, topCenter, cylinder.Axis, ResolveReferenceAxis(cylinder.Axis), box.MinZ, box.MaxZ, cylinder.Radius, cylinder.Radius);
+ return true;
}
- if (minFootprintX < (box.MinX - tolerance.Linear)
- || maxFootprintX > (box.MaxX + tolerance.Linear)
- || minFootprintY < (box.MinY - tolerance.Linear)
- || maxFootprintY > (box.MaxY + tolerance.Linear))
+ if (coversTop)
{
- diagnostic = CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "extends outside the box side-wall footprint. Reduce the cylinder radius or move the center farther inside the box XY boundary.");
- return false;
- }
+ if (!ValidateAxisAlignedZ(cylinder, tolerance))
+ {
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
+ return false;
+ }
- var touchesBottom = minZ <= (box.MinZ + tolerance.Linear);
- var touchesTop = maxZ >= (box.MaxZ - tolerance.Linear);
+ var termination = cylinder.MinCenter.Z < cylinder.MaxCenter.Z ? cylinder.MinCenter : cylinder.MaxCenter;
+ if (termination.Z <= (box.MinZ + tolerance.Linear) || termination.Z >= (box.MaxZ - tolerance.Linear))
+ {
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
+ return false;
+ }
- if (touchesBottom && touchesTop)
- {
- profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, centerX, centerY, box.MinZ, box.MaxZ, cylinder.Radius, cylinder.Radius);
+ if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ {
+ return false;
+ }
+
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, topCenter.X, topCenter.Y, topCenter, termination, cylinder.Axis, ResolveReferenceAxis(cylinder.Axis), box.MaxZ, termination.Z, cylinder.Radius, cylinder.Radius);
return true;
}
- if (touchesTop && minZ > (box.MinZ + tolerance.Linear))
+ if (coversBottom)
{
- var depth = box.MaxZ - minZ;
- if (depth <= tolerance.Linear)
+ if (!ValidateAxisAlignedZ(cylinder, tolerance))
{
- 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.");
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
return false;
}
- profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, centerX, centerY, box.MaxZ, minZ, cylinder.Radius, cylinder.Radius);
- return true;
- }
+ var termination = cylinder.MinCenter.Z > cylinder.MaxCenter.Z ? cylinder.MinCenter : cylinder.MaxCenter;
+ if (termination.Z <= (box.MinZ + tolerance.Linear) || termination.Z >= (box.MaxZ - tolerance.Linear))
+ {
+ diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
+ return false;
+ }
- if (touchesBottom && maxZ < (box.MaxZ - tolerance.Linear))
- {
- var depth = maxZ - box.MinZ;
- if (depth <= tolerance.Linear)
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", featureId))
{
- 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);
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromBottom, bottomCenter.X, bottomCenter.Y, bottomCenter, termination, cylinder.Axis, ResolveReferenceAxis(cylinder.Axis), box.MinZ, termination.Z, cylinder.Radius, cylinder.Radius);
return true;
}
@@ -265,42 +265,31 @@ public static class BrepBooleanCylinderRecognition
{
profile = default;
diagnostic = null;
-
- var axis = cone.Axis.ToVector();
- if (!ToleranceMath.AlmostZero(axis.X, tolerance)
- || !ToleranceMath.AlmostZero(axis.Y, tolerance)
- || !ToleranceMath.AlmostEqual(double.Abs(axis.Z), 1d, tolerance))
+ if (!IsAxisAlignedWithWorldZ(cone.Axis, tolerance))
{
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "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 = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently defers arbitrary-axis cone subtract in the safe family; only world-Z cone subtract is supported in this milestone.");
return false;
}
- var minCenter = cone.MinCenter;
- var maxCenter = cone.MaxCenter;
- if (!ToleranceMath.AlmostEqual(minCenter.X, maxCenter.X, tolerance) || !ToleranceMath.AlmostEqual(minCenter.Y, maxCenter.Y, tolerance))
+ if (!TryResolveBoundaryAxisParameter(cone.AxisOrigin, cone.Axis, box.MinZ, tolerance, out var bottomAxisParameter)
+ || !TryResolveBoundaryAxisParameter(cone.AxisOrigin, cone.Axis, box.MaxZ, tolerance, out var topAxisParameter))
{
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires one vertical through-hole centerline; the cone boundary circles do not share a single X/Y center. Rebuild the cone so both boundary sections stay on one world-Z axis.");
+ diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
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 bottomCenter = cone.PointAtAxisParameter(bottomAxisParameter);
+ var topCenter = cone.PointAtAxisParameter(topAxisParameter);
+ var centerX = (bottomCenter.X + topCenter.X) * 0.5d;
+ var centerY = (bottomCenter.Y + topCenter.Y) * 0.5d;
var coversBottom = bottomAxisParameter >= (cone.MinAxisParameter - tolerance.Linear)
&& bottomAxisParameter <= (cone.MaxAxisParameter + tolerance.Linear);
var coversTop = topAxisParameter >= (cone.MinAxisParameter - tolerance.Linear)
&& topAxisParameter <= (cone.MaxAxisParameter + tolerance.Linear);
+ var axisZ = System.Math.Abs(cone.Axis.ToVector().Z);
if (coversBottom && coversTop)
{
- 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)
@@ -309,13 +298,13 @@ public static class BrepBooleanCylinderRecognition
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))
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", featureId))
{
return false;
}
- profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, centerX, centerY, box.MinZ, box.MaxZ, bottomRadius, topRadius);
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.Through, centerX, centerY, bottomCenter, topCenter, cone.Axis, ResolveReferenceAxis(cone.Axis), box.MinZ, box.MaxZ, bottomRadius, topRadius);
return true;
}
@@ -337,13 +326,14 @@ public static class BrepBooleanCylinderRecognition
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))
+ var endCenter = minEndIsLower ? cone.MinCenter : cone.MaxCenter;
+ if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
{
return false;
}
- profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, centerX, centerY, box.MaxZ, terminationZ, topRadius, endRadius);
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromTop, topCenter.X, topCenter.Y, topCenter, endCenter, cone.Axis, ResolveReferenceAxis(cone.Axis), box.MaxZ, terminationZ, topRadius, endRadius);
return true;
}
@@ -365,13 +355,14 @@ public static class BrepBooleanCylinderRecognition
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))
+ var endCenter = maxEndIsHigher ? cone.MaxCenter : cone.MinCenter;
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", featureId)
+ || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
{
return false;
}
- profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromBottom, centerX, centerY, box.MinZ, terminationZ, bottomRadius, endRadius);
+ profile = new SupportedSubtractProfile(SupportedBooleanHoleSpanKind.BlindFromBottom, bottomCenter.X, bottomCenter.Y, bottomCenter, endCenter, cone.Axis, ResolveReferenceAxis(cone.Axis), box.MinZ, terminationZ, bottomRadius, endRadius);
return true;
}
@@ -379,14 +370,41 @@ public static class BrepBooleanCylinderRecognition
return false;
}
- private static double AxisParameterAtZ(in RecognizedCone cone, double z, ToleranceContext tolerance)
+ private static bool TryResolveBoundaryAxisParameter(Point3D axisOrigin, Direction3D axis, double z, ToleranceContext tolerance, out double axisParameter)
{
- var axisZ = cone.Axis.ToVector().Z;
+ var axisZ = axis.ToVector().Z;
if (ToleranceMath.AlmostZero(axisZ, tolerance))
{
- throw new InvalidOperationException("AxisParameterAtZ requires a cone axis aligned with Z.");
+ axisParameter = 0d;
+ return false;
}
+ axisParameter = (z - axisOrigin.Z) / axisZ;
+ return true;
+ }
+
+ private static Direction3D ResolveReferenceAxis(Direction3D axis)
+ {
+ var axisVector = axis.ToVector();
+ var seed = System.Math.Abs(axisVector.Z) < 0.9d
+ ? new Vector3D(0d, 0d, 1d)
+ : new Vector3D(1d, 0d, 0d);
+ var projected = seed - (axisVector * seed.Dot(axisVector));
+ return Direction3D.Create(projected);
+ }
+
+ private static bool IsAxisAlignedWithWorldZ(Direction3D axis, ToleranceContext tolerance)
+ {
+ var v = axis.ToVector();
+ return ToleranceMath.AlmostZero(v.X, tolerance)
+ && ToleranceMath.AlmostZero(v.Y, tolerance)
+ && ToleranceMath.AlmostEqual(System.Math.Abs(v.Z), 1d, tolerance);
+ }
+
+ private static double AxisParameterAtZ(in RecognizedCone cone, double z, ToleranceContext tolerance)
+ {
+ _ = tolerance;
+ var axisZ = cone.Axis.ToVector().Z;
return (z - cone.AxisOrigin.Z) / axisZ;
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
index 703817d9..c8d7bc94 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
@@ -1,4 +1,5 @@
using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Geometry;
using Aetheris.Kernel.Core.Numerics;
namespace Aetheris.Kernel.Core.Brep.Boolean;
@@ -35,6 +36,10 @@ public readonly record struct SupportedBooleanHole(
AnalyticSurface Surface,
double CenterX,
double CenterY,
+ Point3D StartCenter,
+ Point3D EndCenter,
+ Direction3D Axis,
+ Direction3D ReferenceAxis,
double BottomRadius,
double TopRadius,
SupportedBooleanHoleSpanKind SpanKind,
@@ -50,6 +55,8 @@ public readonly record struct SupportedBooleanHole(
Surface = Surface.Translate(translation),
CenterX = CenterX + translation.X,
CenterY = CenterY + translation.Y,
+ StartCenter = StartCenter + translation,
+ EndCenter = EndCenter + translation,
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 05babd3e..40024d31 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
@@ -1,4 +1,5 @@
using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Geometry;
using Aetheris.Kernel.Core.Numerics;
namespace Aetheris.Kernel.Core.Brep.Boolean;
@@ -33,6 +34,16 @@ public static class BrepBooleanSafeCompositionGraphValidator
return false;
}
+ if (composition.Holes.Count > 0
+ && (!IsAxisAlignedWithWorldZ(nextHole.Axis, tolerance) || composition.Holes.Any(h => !IsAxisAlignedWithWorldZ(h.Axis, tolerance))))
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ nextFeatureId,
+ "currently keeps arbitrary-axis subtract support to single-feature rebuilds; composed safe-hole chains remain limited to world-Z family in this milestone.");
+ return false;
+ }
+
foreach (var existingHole in composition.Holes)
{
var deltaX = existingHole.CenterX - nextHole.CenterX;
@@ -92,6 +103,10 @@ public static class BrepBooleanSafeCompositionGraphValidator
surface,
cylinderProfile.CenterX,
cylinderProfile.CenterY,
+ cylinderProfile.StartCenter,
+ cylinderProfile.EndCenter,
+ cylinderProfile.Axis,
+ cylinderProfile.ReferenceAxis,
cylinderProfile.StartRadius,
cylinderProfile.EndRadius,
cylinderProfile.SpanKind,
@@ -111,6 +126,10 @@ public static class BrepBooleanSafeCompositionGraphValidator
surface,
coneProfile.CenterX,
coneProfile.CenterY,
+ coneProfile.StartCenter,
+ coneProfile.EndCenter,
+ coneProfile.Axis,
+ coneProfile.ReferenceAxis,
coneProfile.StartRadius,
coneProfile.EndRadius,
coneProfile.SpanKind,
@@ -140,6 +159,10 @@ public static class BrepBooleanSafeCompositionGraphValidator
surface,
sphere.Center.X,
sphere.Center.Y,
+ sphere.Center,
+ sphere.Center,
+ Direction3D.Create(new Vector3D(0d, 0d, 1d)),
+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),
sphere.Radius,
sphere.Radius,
SupportedBooleanHoleSpanKind.Through,
@@ -162,6 +185,14 @@ public static class BrepBooleanSafeCompositionGraphValidator
private static string FormatFeatureRef(string? featureId)
=> string.IsNullOrWhiteSpace(featureId) ? "<unknown>" : $"'{featureId}'";
+ private static bool IsAxisAlignedWithWorldZ(Direction3D axis, ToleranceContext tolerance)
+ {
+ var v = axis.ToVector();
+ return ToleranceMath.AlmostZero(v.X, tolerance)
+ && ToleranceMath.AlmostZero(v.Y, tolerance)
+ && ToleranceMath.AlmostEqual(System.Math.Abs(v.Z), 1d, tolerance);
+ }
+
private static bool ValidateContainedSphereCavity(
AxisAlignedBoxExtents outerBox,
in RecognizedSphere sphere,