Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement Wave 2 bounded blind-bore and sphere cavity support
Yuechen Li99204abf4c61
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 8dfbf3b9..ba5d44bb 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -623,6 +623,51 @@ public sealed class BrepBooleanTestsAssert.Equal(firstExport.Value, secondExport.Value);}+ [Fact]+ public void Subtract_CylinderRootBlindBoreFromTop_Coaxial_Succeeds()+ {+ var root = BrepPrimitives.CreateCylinder(20d, 40d).Value;+ var bore = TransformBody(BrepPrimitives.CreateCylinder(6d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 10d)));++ var result = BrepBoolean.Subtract(root, bore);++ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ Assert.NotNull(result.Value.SafeBooleanComposition);+ Assert.Single(result.Value.SafeBooleanComposition!.Holes);+ Assert.Equal(SupportedBooleanHoleSpanKind.BlindFromTop, result.Value.SafeBooleanComposition.Holes[0].SpanKind);+ }++ [Fact]+ public void Subtract_CylinderRootBlindBoreFromBottom_Coaxial_Succeeds()+ {+ var root = BrepPrimitives.CreateCylinder(20d, 40d).Value;+ var bore = TransformBody(BrepPrimitives.CreateCylinder(6d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, -10d)));++ var result = BrepBoolean.Subtract(root, bore);++ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ Assert.NotNull(result.Value.SafeBooleanComposition);+ Assert.Single(result.Value.SafeBooleanComposition!.Holes);+ Assert.Equal(SupportedBooleanHoleSpanKind.BlindFromBottom, result.Value.SafeBooleanComposition.Holes[0].SpanKind);+ }++ [Fact]+ public void Subtract_CylinderRootBlindBoreNonCoaxial_ReturnsExplicitDiagnostic()+ {+ var root = BrepPrimitives.CreateCylinder(20d, 40d).Value;+ var bore = TransformBody(BrepPrimitives.CreateCylinder(6d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(3d, 0d, 10d)));++ var result = BrepBoolean.Subtract(root, bore);++ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);+ Assert.Equal("BrepBoolean.AnalyticHole.AxisNotAligned", diagnostic.Source);+ Assert.Contains("coaxial centerline alignment", diagnostic.Message, StringComparison.Ordinal);+ }+[Fact]public void Subtract_CylinderRootOffsetHoleThenCenterBore_Succeeds(){@@ -1486,6 +1531,24 @@ public sealed class BrepBooleanTestsAssert.DoesNotContain("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);}+ [Fact]+ public void Subtract_BoxSphereExteriorTopOpening_RebuildsSphericalPocket()+ {+ var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-20d, 20d, -15d, 15d, -6d, 6d)).Value;+ var right = TransformBody(BrepPrimitives.CreateSphere(6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 4d)));++ var result = BrepBoolean.Subtract(left, right);++ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);+ Assert.NotNull(result.Value.SafeBooleanComposition);+ Assert.Single(result.Value.SafeBooleanComposition!.Holes);+ Assert.Equal(SupportedBooleanHoleSpanKind.BlindFromTop, result.Value.SafeBooleanComposition.Holes[0].SpanKind);+ Assert.Contains(result.Value.Topology.Faces, face =>+ result.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)+ && surface?.Kind == SurfaceGeometryKind.Sphere);+ }+[Fact]public void Subtract_BoxSphereTangentBoundary_ReturnsTangentContactDiagnostic(){diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 8bacc1b0..08940073 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -40,7 +40,22 @@ public static class BrepBooleanBoxCylinderHoleBuilder&& composition.Holes[0].Surface.Kind == AnalyticSurfaceKind.Sphere&& composition.Holes[0].Surface.Sphere is RecognizedSphere sphere){- return CreateComposedContainedSphereCavityBody(composition.OuterBox, sphere);+ if (composition.Holes[0].SpanKind == SupportedBooleanHoleSpanKind.Contained)+ {+ return CreateComposedContainedSphereCavityBody(composition.OuterBox, sphere);+ }++ if (composition.Holes[0].SpanKind is SupportedBooleanHoleSpanKind.BlindFromTop or SupportedBooleanHoleSpanKind.BlindFromBottom)+ {+ return CreateComposedSphereOpeningCavityBody(composition.OuterBox, sphere, composition.Holes[0], composition);+ }++ return KernelResult<BrepBody>.Failure([+ new BooleanDiagnostic(+ BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("bounded sphere subtract supports only contained or one-sided exterior-opening spherical cavities."),+ "BrepBoolean.AnalyticHole.UnsupportedAnalyticSurfaceKind").ToKernelDiagnostic(),+ ]);}if (composition.Holes.Count == 1@@ -56,7 +71,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn KernelResult<BrepBody>.Failure([new BooleanDiagnostic(BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,- new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("safe subtract composition only supports one contained spherical cavity when no prior holes have been accepted."),+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("safe subtract composition supports exactly one spherical cavity operation and does not support mixed sphere continuation with other tools."),"BrepBoolean.AnalyticHole.UnsupportedAnalyticSurfaceKind").ToKernelDiagnostic(),]);}@@ -123,6 +138,25 @@ public static class BrepBooleanBoxCylinderHoleBuilder]);}+ if (composition.Holes.Any(hole => hole.IsBlind))+ {+ var blindHoles = composition.Holes.Where(hole => hole.IsBlind).ToArray();+ if (blindHoles.Length != 1+ || composition.Holes.Count != 1+ || !ToleranceMath.AlmostZero(blindHoles[0].CenterX, tolerance)+ || !ToleranceMath.AlmostZero(blindHoles[0].CenterY, tolerance))+ {+ return KernelResult<BrepBody>.Failure([+ new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("bounded cylinder-root blind-bore rebuild supports only one coaxial blind bore in this milestone."),+ "BrepBoolean.AnalyticHole.HoleInterference").ToKernelDiagnostic(),+ ]);+ }++ return CreateCylinderRootBlindBoreBody(rootCylinder, blindHoles[0], composition);+ }+var rootCenter = new Point3D((rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d,(rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d,@@ -156,6 +190,101 @@ public static class BrepBooleanBoxCylinderHoleBuilder: KernelResult<BrepBody>.Failure(validation.Diagnostics);}+ private static KernelResult<BrepBody> CreateCylinderRootBlindBoreBody(+ in RecognizedCylinder rootCylinder,+ in SupportedBooleanHole hole,+ SafeBooleanComposition composition)+ {+ var entryFromTop = hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop;+ var rootHeight = rootCylinder.Height;+ var halfHeight = rootHeight * 0.5d;+ var rootMinZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);+ var rootMaxZ = System.Math.Max(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);+ var rootCenterZ = (rootMinZ + rootMaxZ) * 0.5d;++ var entryZ = entryFromTop ? rootMaxZ : rootMinZ;+ var blindBottomZ = hole.EndZ;+ var entryLocalZ = entryZ - rootCenterZ;+ var blindBottomLocalZ = blindBottomZ - rootCenterZ;++ var builder = new TopologyBuilder();+ var seamStart = builder.AddVertex();+ var seamEnd = builder.AddVertex();+ var topVertex = builder.AddVertex();+ var bottomVertex = builder.AddVertex();+ var boreEntryVertex = builder.AddVertex();+ var boreBottomVertex = builder.AddVertex();+ var boreSeamEntry = builder.AddVertex();+ var boreSeamBottom = builder.AddVertex();++ var outerSeam = builder.AddEdge(seamStart, seamEnd);+ var topCircle = builder.AddEdge(topVertex, topVertex);+ var bottomCircle = builder.AddEdge(bottomVertex, bottomVertex);+ var boreEntryCircle = builder.AddEdge(boreEntryVertex, boreEntryVertex);+ var boreBottomCircle = builder.AddEdge(boreBottomVertex, boreBottomVertex);+ var boreSeam = builder.AddEdge(boreSeamEntry, boreSeamBottom);++ var outerSideFace = builder.AddFace([AddLoop(builder, [Forward(outerSeam), Forward(topCircle), Reversed(outerSeam), Reversed(bottomCircle)])]);+ var topFace = entryFromTop+ ? builder.AddFace([AddLoop(builder, [Reversed(topCircle)]), AddLoop(builder, [Forward(boreEntryCircle)])])+ : builder.AddFace([AddLoop(builder, [Reversed(topCircle)])]);+ var bottomFace = entryFromTop+ ? builder.AddFace([AddLoop(builder, [Forward(bottomCircle)])])+ : builder.AddFace([AddLoop(builder, [Forward(bottomCircle)]), AddLoop(builder, [Reversed(boreEntryCircle)])]);+ var boreWallFace = builder.AddFace([AddLoop(builder, [Forward(boreSeam), Reversed(boreEntryCircle), Reversed(boreSeam), Forward(boreBottomCircle)])]);+ var boreBottomFace = builder.AddFace([AddLoop(builder, [Forward(boreBottomCircle)])]);++ var shell = builder.AddShell([outerSideFace, topFace, bottomFace, boreWallFace, boreBottomFace]);+ builder.AddBody([shell]);++ var geometry = new BrepGeometryStore();+ 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 downAxis = Direction3D.Create(new Vector3D(0d, 0d, -1d));++ geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromLine(new Line3Curve(new Point3D(rootCylinder.Radius, 0d, -halfHeight), zAxis)));+ geometry.AddCurve(new CurveGeometryId(2), CurveGeometry.FromCircle(new Circle3Curve(new Point3D(0d, 0d, halfHeight), zAxis, rootCylinder.Radius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(3), CurveGeometry.FromCircle(new Circle3Curve(new Point3D(0d, 0d, -halfHeight), zAxis, rootCylinder.Radius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(4), CurveGeometry.FromCircle(new Circle3Curve(new Point3D(0d, 0d, entryLocalZ), zAxis, hole.BottomRadius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(5), CurveGeometry.FromCircle(new Circle3Curve(new Point3D(0d, 0d, blindBottomLocalZ), zAxis, hole.BottomRadius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(6), CurveGeometry.FromLine(new Line3Curve(new Point3D(hole.BottomRadius, 0d, System.Math.Min(entryLocalZ, blindBottomLocalZ)), zAxis)));++ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0d, 0d, -halfHeight), zAxis, rootCylinder.Radius, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(2), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, halfHeight), zAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(3), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, -halfHeight), downAxis, yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(4), SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(0d, 0d, System.Math.Min(entryLocalZ, blindBottomLocalZ)), zAxis, hole.BottomRadius, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(5), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, blindBottomLocalZ), entryFromTop ? zAxis : downAxis, xAxis)));++ var bindings = new BrepBindingModel();+ bindings.AddEdgeBinding(new EdgeGeometryBinding(outerSeam, new CurveGeometryId(1), new ParameterInterval(0d, rootHeight)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(topCircle, new CurveGeometryId(2), new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(bottomCircle, new CurveGeometryId(3), new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(boreEntryCircle, new CurveGeometryId(4), new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(boreBottomCircle, new CurveGeometryId(5), new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(boreSeam, new CurveGeometryId(6), new ParameterInterval(0d, System.Math.Abs(entryLocalZ - blindBottomLocalZ))));++ bindings.AddFaceBinding(new FaceGeometryBinding(outerSideFace, new SurfaceGeometryId(1)));+ bindings.AddFaceBinding(new FaceGeometryBinding(topFace, new SurfaceGeometryId(2)));+ bindings.AddFaceBinding(new FaceGeometryBinding(bottomFace, new SurfaceGeometryId(3)));+ bindings.AddFaceBinding(new FaceGeometryBinding(boreWallFace, new SurfaceGeometryId(4)));+ bindings.AddFaceBinding(new FaceGeometryBinding(boreBottomFace, new SurfaceGeometryId(5)));++ var localBody = new BrepBody(builder.Model, geometry, bindings);+ var translated = TranslateBody(localBody, new Vector3D(0d, 0d, rootCenterZ));+ var bodyWithComposition = new BrepBody(+ translated.Topology,+ translated.Geometry,+ translated.Bindings,+ GetVertexPoints(translated),+ composition,+ translated.ShellRepresentation);+ var validation = BrepBindingValidator.Validate(bodyWithComposition, requireAllEdgeAndFaceBindings: true);+ return validation.IsSuccess+ ? KernelResult<BrepBody>.Success(bodyWithComposition, validation.Diagnostics)+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);+ }+private static KernelResult<BrepBody> CreateComposedContainedSphereCavityBody(AxisAlignedBoxExtents outerBox, in RecognizedSphere sphere){var outer = BrepBooleanBoxRecognition.CreateBoxFromExtents(outerBox);@@ -177,6 +306,146 @@ public static class BrepBooleanBoxCylinderHoleBuilder: KernelResult<BrepBody>.Failure(validation.Diagnostics);}+ private static KernelResult<BrepBody> CreateComposedSphereOpeningCavityBody(+ AxisAlignedBoxExtents outerBox,+ in RecognizedSphere sphere,+ in SupportedBooleanHole hole,+ SafeBooleanComposition composition)+ {+ if (hole.SpanKind is not (SupportedBooleanHoleSpanKind.BlindFromTop or SupportedBooleanHoleSpanKind.BlindFromBottom))+ {+ return KernelResult<BrepBody>.Failure([+ new BooleanDiagnostic(+ BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("sphere opening builder requires BlindFromTop or BlindFromBottom span classification."),+ "BrepBoolean.AnalyticHole.UnsupportedAnalyticSurfaceKind").ToKernelDiagnostic(),+ ]);+ }++ var openingPlaneZ = hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop ? outerBox.MaxZ : outerBox.MinZ;+ var delta = openingPlaneZ - sphere.Center.Z;+ var openingRadius = System.Math.Sqrt(System.Math.Max(0d, (sphere.Radius * sphere.Radius) - (delta * delta)));++ 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 openingVertex = 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 openingCircle = builder.AddEdge(openingVertex, openingVertex);++ var bottomLoops = new List<LoopId> { AddLoop(builder, [Forward(e1), Forward(e2), Forward(e3), Forward(e4)]) };+ var topLoops = new List<LoopId> { AddLoop(builder, [Forward(e5), Forward(e6), Forward(e7), Forward(e8)]) };+ if (hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop)+ {+ topLoops.Add(AddLoop(builder, [Forward(openingCircle)]));+ }+ else+ {+ bottomLoops.Add(AddLoop(builder, [Reversed(openingCircle)]));+ }++ 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 sphereFace = builder.AddFace([AddLoop(builder, [Forward(openingCircle)])]);++ var shell = builder.AddShell([bottomFace, topFace, xMinFace, xMaxFace, yMaxFace, yMinFace, sphereFace]);+ builder.AddBody([shell]);++ var geometry = new BrepGeometryStore();+ var p1 = new Point3D(outerBox.MinX, outerBox.MinY, outerBox.MinZ);+ var p2 = new Point3D(outerBox.MaxX, outerBox.MinY, outerBox.MinZ);+ var p3 = new Point3D(outerBox.MaxX, outerBox.MaxY, outerBox.MinZ);+ var p4 = new Point3D(outerBox.MinX, outerBox.MaxY, outerBox.MinZ);+ var p5 = new Point3D(outerBox.MinX, outerBox.MinY, outerBox.MaxZ);+ var p6 = new Point3D(outerBox.MaxX, outerBox.MinY, outerBox.MaxZ);+ var p7 = new Point3D(outerBox.MaxX, outerBox.MaxY, outerBox.MaxZ);+ var p8 = new Point3D(outerBox.MinX, outerBox.MaxY, outerBox.MaxZ);++ 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 downAxis = Direction3D.Create(new Vector3D(0d, 0d, -1d));+ var width = outerBox.MaxX - outerBox.MinX;+ var depth = outerBox.MaxY - outerBox.MinY;+ var height = outerBox.MaxZ - outerBox.MinZ;++ 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))));+ }++ geometry.AddCurve(new CurveGeometryId(13), CurveGeometry.FromCircle(new Circle3Curve(new Point3D(sphere.Center.X, sphere.Center.Y, openingPlaneZ), zAxis, openingRadius, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, outerBox.MinZ), downAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(2), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, outerBox.MaxZ), zAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(3), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, outerBox.MinY, 0d), Direction3D.Create(new Vector3D(0d, -1d, 0d)), xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(4), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(outerBox.MaxX, 0d, 0d), Direction3D.Create(new Vector3D(1d, 0d, 0d)), yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(5), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, outerBox.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(outerBox.MinX, 0d, 0d), Direction3D.Create(new Vector3D(-1d, 0d, 0d)), yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(7), SurfaceGeometry.FromSphere(new SphereSurface(sphere.Center, zAxis, sphere.Radius, 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(openingCircle, new CurveGeometryId(13), new ParameterInterval(0d, 2d * double.Pi)));+ 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(sphereFace, new SurfaceGeometryId(7)));++ var vertexPoints = new Dictionary<VertexId, Point3D>+ {+ [v1] = p1,+ [v2] = p2,+ [v3] = p3,+ [v4] = p4,+ [v5] = p5,+ [v6] = p6,+ [v7] = p7,+ [v8] = p8,+ [openingVertex] = new Point3D(sphere.Center.X + openingRadius, sphere.Center.Y, openingPlaneZ),+ };++ 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 KernelResult<BrepBody> CreateComposedContainedCylinderCavityBody(AxisAlignedBoxExtents outerBox,in RecognizedCylinder cylinder,@@ -1309,6 +1578,20 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn new BrepBody(body.Topology, translatedGeometry, body.Bindings, vertexPoints, body.SafeBooleanComposition, body.ShellRepresentation);}+ private static IReadOnlyDictionary<VertexId, Point3D> GetVertexPoints(BrepBody body)+ {+ var points = new Dictionary<VertexId, Point3D>();+ foreach (var vertex in body.Topology.Vertices)+ {+ if (body.TryGetVertexPoint(vertex.Id, out var point))+ {+ points[vertex.Id] = point;+ }+ }++ return points;+ }+private static LoopId AddLoop(TopologyBuilder builder, IReadOnlyList<EdgeUse> edgeUses){var loopId = builder.AllocateLoopId();diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 8ed9e398..1518c2a0 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -165,33 +165,70 @@ public static class BrepBooleanSafeCompositionGraphValidatorvar rootMaxZ = System.Math.Max(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);var toolMinZ = System.Math.Min(toolCylinder.MinCenter.Z, toolCylinder.MaxCenter.Z);var toolMaxZ = System.Math.Max(toolCylinder.MinCenter.Z, toolCylinder.MaxCenter.Z);+ var deltaX = toolCenter.X - rootCenter.X;+ var deltaY = toolCenter.Y - rootCenter.Y;+ var radialDistance = System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));+ var isCoaxialCenterBore = ToleranceMath.AlmostZero(radialDistance, tolerance);var spansRoot = toolMinZ <= (rootMinZ + tolerance.Linear) && toolMaxZ >= (rootMaxZ - tolerance.Linear);- if (!spansRoot)+ var entersFromTop = toolMaxZ >= (rootMaxZ - tolerance.Linear) && toolMinZ > (rootMinZ + tolerance.Linear);+ var entersFromBottom = toolMinZ <= (rootMinZ + tolerance.Linear) && toolMaxZ < (rootMaxZ - tolerance.Linear);+ var isBlind = entersFromTop || entersFromBottom;+ if (!spansRoot && !isBlind){diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(diagnosticContext,- "is outside the bounded cylinder-root safe subtract family; only through center bores that span both planar caps are supported.");+ "is outside the bounded cylinder-root safe subtract family; supported tools are either through bores or one-sided blind bores from top/bottom.");return false;}- var deltaX = toolCenter.X - rootCenter.X;- var deltaY = toolCenter.Y - rootCenter.Y;- var radialDistance = System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY));- var isCoaxialCenterBore = ToleranceMath.AlmostZero(radialDistance, tolerance);+ if (isBlind && !isCoaxialCenterBore)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ diagnosticContext,+ "bounded cylinder-root blind bores require coaxial centerline alignment with the root axis.");+ return false;+ }++ if (isBlind && composition.Holes.Count > 0)+ {+ diagnostic = new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ diagnosticContext.FormatMessage("bounded cylinder-root blind bores currently support only one bore; mixed/multi-bore cylinder-root chains remain deferred."),+ "BrepBoolean.AnalyticHole.HoleInterference");+ return false;+ }++ var spanKind = spansRoot+ ? SupportedBooleanHoleSpanKind.Through+ : entersFromTop+ ? SupportedBooleanHoleSpanKind.BlindFromTop+ : SupportedBooleanHoleSpanKind.BlindFromBottom;+ var startZ = spansRoot+ ? rootMinZ+ : entersFromTop+ ? rootMaxZ+ : rootMinZ;+ var endZ = spansRoot+ ? rootMaxZ+ : entersFromTop+ ? toolMinZ+ : toolMaxZ;+ var startCenter = new Point3D(toolCenter.X, toolCenter.Y, startZ);+ var endCenter = new Point3D(toolCenter.X, toolCenter.Y, endZ);var nextHole = new SupportedBooleanHole(nextFeatureId,surface,toolCenter.X,toolCenter.Y,- new Point3D(toolCenter.X, toolCenter.Y, rootMinZ),- new Point3D(toolCenter.X, toolCenter.Y, rootMaxZ),+ startCenter,+ endCenter,toolCylinder.Axis,Direction3D.Create(new Vector3D(1d, 0d, 0d)),toolCylinder.Radius,toolCylinder.Radius,- SupportedBooleanHoleSpanKind.Through,- rootMinZ,- rootMaxZ);+ spanKind,+ startZ,+ endZ);var ringOuterDistance = radialDistance + toolCylinder.Radius;if (ToleranceMath.AlmostEqual(ringOuterDistance, rootCylinder.Radius, tolerance)@@ -329,7 +366,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn true;case AnalyticSurfaceKind.Sphere when surface.Sphere is RecognizedSphere sphere:- if (!ValidateContainedSphereCavity(outerBox, sphere, tolerance, out diagnostic, featureId))+ if (!TryValidateBoundedSphereSubtract(outerBox, sphere, tolerance, out var spanKind, out var startCenter, out var endCenter, out diagnostic, featureId)){hole = default;return false;@@ -350,15 +387,15 @@ public static class BrepBooleanSafeCompositionGraphValidatorsurface,sphere.Center.X,sphere.Center.Y,- sphere.Center,- sphere.Center,+ startCenter,+ endCenter,Direction3D.Create(new Vector3D(0d, 0d, 1d)),Direction3D.Create(new Vector3D(1d, 0d, 0d)),sphere.Radius,sphere.Radius,- SupportedBooleanHoleSpanKind.Through,- outerBox.MinZ,- outerBox.MaxZ);+ spanKind,+ startCenter.Z,+ endCenter.Z);return true;case AnalyticSurfaceKind.Sphere:@@ -784,13 +821,19 @@ public static class BrepBooleanSafeCompositionGraphValidatorBooleanDiagnostic? SubtractStackDiagnostic,bool SupportsIndependentContinuationOnAdditiveRoot);- private static bool ValidateContainedSphereCavity(+ private static bool TryValidateBoundedSphereSubtract(AxisAlignedBoxExtents outerBox,in RecognizedSphere sphere,ToleranceContext tolerance,+ out SupportedBooleanHoleSpanKind spanKind,+ out Point3D startCenter,+ out Point3D endCenter,out BooleanDiagnostic? diagnostic,string? featureId){+ spanKind = SupportedBooleanHoleSpanKind.Contained;+ startCenter = sphere.Center;+ endCenter = sphere.Center;diagnostic = null;var minX = sphere.Center.X - sphere.Radius;@@ -800,6 +843,13 @@ public static class BrepBooleanSafeCompositionGraphValidatorvar minZ = sphere.Center.Z - sphere.Radius;var maxZ = sphere.Center.Z + sphere.Radius;+ var topCrosses = maxZ > (outerBox.MaxZ + tolerance.Linear);+ var bottomCrosses = minZ < (outerBox.MinZ - tolerance.Linear);+ var sideCrosses =+ minX < (outerBox.MinX - tolerance.Linear)+ || maxX > (outerBox.MaxX + tolerance.Linear)+ || minY < (outerBox.MinY - tolerance.Linear)+ || maxY > (outerBox.MaxY + tolerance.Linear);var tangentContact =ToleranceMath.AlmostEqual(minX, outerBox.MinX, tolerance)|| ToleranceMath.AlmostEqual(maxX, outerBox.MaxX, tolerance)@@ -816,12 +866,14 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn false;}- if (minX < (outerBox.MinX - tolerance.Linear)- || maxX > (outerBox.MaxX + tolerance.Linear)- || minY < (outerBox.MinY - tolerance.Linear)- || maxY > (outerBox.MaxY + tolerance.Linear)- || minZ < (outerBox.MinZ - tolerance.Linear)- || maxZ > (outerBox.MaxZ + tolerance.Linear))+ var crossesTopOrBottomCount = (topCrosses ? 1 : 0) + (bottomCrosses ? 1 : 0);+ if (!sideCrosses && !topCrosses && !bottomCrosses)+ {+ spanKind = SupportedBooleanHoleSpanKind.Contained;+ return true;+ }++ if (sideCrosses || crossesTopOrBottomCount != 1){diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(),@@ -830,6 +882,54 @@ public static class BrepBooleanSafeCompositionGraphValidatorreturn false;}- return true;+ if (topCrosses)+ {+ var planeZ = outerBox.MaxZ;+ var delta = planeZ - sphere.Center.Z;+ if (ToleranceMath.AlmostEqual(System.Math.Abs(delta), sphere.Radius, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "is tangent to the exterior top plane; degenerate spherical opening is unsupported.");+ return false;+ }++ var openingRadius = System.Math.Sqrt(System.Math.Max(0d, (sphere.Radius * sphere.Radius) - (delta * delta)));+ if (!ValidateCircleInsideBoxFootprint(outerBox, sphere.Center.X, sphere.Center.Y, openingRadius, tolerance, out diagnostic, "sphere opening section", featureId))+ {+ return false;+ }++ spanKind = SupportedBooleanHoleSpanKind.BlindFromTop;+ startCenter = new Point3D(sphere.Center.X, sphere.Center.Y, outerBox.MaxZ);+ endCenter = new Point3D(sphere.Center.X, sphere.Center.Y, sphere.Center.Z - sphere.Radius);+ return true;+ }++ {+ var planeZ = outerBox.MinZ;+ var delta = sphere.Center.Z - planeZ;+ if (ToleranceMath.AlmostEqual(System.Math.Abs(delta), sphere.Radius, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "is tangent to the exterior bottom plane; degenerate spherical opening is unsupported.");+ return false;+ }++ var openingRadius = System.Math.Sqrt(System.Math.Max(0d, (sphere.Radius * sphere.Radius) - (delta * delta)));+ if (!ValidateCircleInsideBoxFootprint(outerBox, sphere.Center.X, sphere.Center.Y, openingRadius, tolerance, out diagnostic, "sphere opening section", featureId))+ {+ return false;+ }++ spanKind = SupportedBooleanHoleSpanKind.BlindFromBottom;+ startCenter = new Point3D(sphere.Center.X, sphere.Center.Y, outerBox.MinZ);+ endCenter = new Point3D(sphere.Center.X, sphere.Center.Y, sphere.Center.Z + sphere.Radius);+ return true;+ }}+}diff --git a/docs/boolean-deferred.md b/docs/boolean-deferred.mdindex 7a315cf0..71e86ca8 100644--- a/docs/boolean-deferred.md+++ b/docs/boolean-deferred.md@@ -11,7 +11,9 @@ The current supported boolean subset is intentionally narrow and family-specific- box − cylinder blind hole- box − cone blind hole- box − box blind pocket and opposite-face through-slot (bounded orthogonal pocket family)-- box − sphere cavity+- box − sphere cavity (single-sphere only): fully enclosed cavity and one-sided top/bottom exterior-opening spherical pocket+- cylinder-root − coaxial center bore (through)+- cylinder-root − coaxial blind bore from top/bottom (single-bore bounded family)- rotated cylinder through-hole- safe-family composition for supported analytic-hole families, including independent world-Z multi-hole continuation on simple box roots- recognized safe box-root subtract with bounded prismatic through-cut tools (triangular/hexagonal/slot profiles) when the root has no prior subtract history@@ -30,6 +32,7 @@ The following items remain deferred:- general BRep booleans- bounded mixed analytic-hole + prismatic continuation rebuild path on safe box roots (recognition now exists; bounded reconstruction remains deferred)- safe-composition prismatic blind-pocket continuation (recognition-classification gap + bounded reconstruction path still deferred)+- multi-sphere and mixed sphere+prismatic continuation in one subtract chain## Known blocker: rotated cone through-hole