Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement F3 bounded cylinder-root bolt-hole composition
Yuechen Lid5f9abc7e190
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex f85121a8..a280e72d 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -308,16 +308,109 @@ public sealed class BrepBooleanTests}[Fact]- public void Subtract_CylinderRootOffsetHole_IsRejectedLoudly()+ public void Subtract_CylinderRootCenterBoreAndOffsetHole_Succeeds(){var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;var offsetHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));- var result = BrepBoolean.Subtract(root, offsetHole);+ var withCenterBore = BrepBoolean.Subtract(root, centerBore);+ Assert.True(withCenterBore.IsSuccess);++ var result = BrepBoolean.Subtract(withCenterBore.Value, offsetHole);++ Assert.True(result.IsSuccess);+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);+ Assert.Equal(9, result.Value.Topology.Faces.Count());+ Assert.NotNull(result.Value.ShellRepresentation);+ Assert.Equal(2, result.Value.ShellRepresentation!.InnerShellIds.Count);+ var export = Step242Exporter.ExportBody(result.Value);+ Assert.True(export.IsSuccess);+ Assert.Contains("BREP_WITH_VOIDS", export.Value, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_CylinderRootCenterBoreAndBoltCircle_SucceedsDeterministically()+ {+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;+ var hole0 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));+ var hole90 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 25d, 0d)));+ var hole180 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(-25d, 0d, 0d)));+ var hole270 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(0d, -25d, 0d)));++ var first = BrepBoolean.Subtract(root, centerBore).Value;+ first = BrepBoolean.Subtract(first, hole0).Value;+ first = BrepBoolean.Subtract(first, hole90).Value;+ first = BrepBoolean.Subtract(first, hole180).Value;+ var firstResult = BrepBoolean.Subtract(first, hole270);++ var second = BrepBoolean.Subtract(root, centerBore).Value;+ second = BrepBoolean.Subtract(second, hole0).Value;+ second = BrepBoolean.Subtract(second, hole90).Value;+ second = BrepBoolean.Subtract(second, hole180).Value;+ var secondResult = BrepBoolean.Subtract(second, hole270);++ Assert.True(firstResult.IsSuccess);+ Assert.True(secondResult.IsSuccess);+ Assert.True(BrepBindingValidator.Validate(firstResult.Value, true).IsSuccess);+ Assert.Equal(5, firstResult.Value.ShellRepresentation!.InnerShellIds.Count);+ var firstExport = Step242Exporter.ExportBody(firstResult.Value);+ var secondExport = Step242Exporter.ExportBody(secondResult.Value);+ Assert.True(firstExport.IsSuccess);+ Assert.True(secondExport.IsSuccess);+ Assert.Equal(firstExport.Value, secondExport.Value);+ }++ [Fact]+ public void Subtract_CylinderRootCenterBoreThenWallTouchingOffsetHole_IsRejectedLoudly()+ {+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;+ var touchingOuterWallHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(36d, 0d, 0d)));++ var withCenterBore = BrepBoolean.Subtract(root, centerBore);+ Assert.True(withCenterBore.IsSuccess);+ var result = BrepBoolean.Subtract(withCenterBore.Value, touchingOuterWallHole);++ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Contains("strictly inside the outer cylindrical wall", diagnostic.Message, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_CylinderRootCenterBoreThenOverlappingOffsetHole_IsRejectedLoudly()+ {+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;+ var overlappingCenterBoreHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(15d, 0d, 0d)));++ var withCenterBore = BrepBoolean.Subtract(root, centerBore);+ Assert.True(withCenterBore.IsSuccess);+ var result = BrepBoolean.Subtract(withCenterBore.Value, overlappingCenterBoreHole);++ Assert.False(result.IsSuccess);+ var diagnostic = Assert.Single(result.Diagnostics);+ Assert.Contains("strictly outside the center bore ring boundary", diagnostic.Message, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_CylinderRootBoltHoleTangentToBoltHole_IsRejectedLoudly()+ {+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;+ var holeA = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));+ var tangentHoleB = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(33d, 0d, 0d)));++ var withCenterBore = BrepBoolean.Subtract(root, centerBore);+ Assert.True(withCenterBore.IsSuccess);+ var withHoleA = BrepBoolean.Subtract(withCenterBore.Value, holeA);+ Assert.True(withHoleA.IsSuccess);+ var result = BrepBoolean.Subtract(withHoleA.Value, tangentHoleB);Assert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);- Assert.Contains("only coaxial center bores are supported", diagnostic.Message, StringComparison.Ordinal);+ Assert.Contains("tangent to previously accepted off-axis hole", diagnostic.Message, StringComparison.Ordinal);}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 24cd8c30..621ebf32 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -28,7 +28,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder_ = tolerance;if (composition.RootDescriptor.Kind == SafeBooleanRootKind.Cylinder){- return CreateBoundedCylinderRootCenterBoreBody(composition, tolerance);+ return CreateBoundedCylinderRootHoleChainBody(composition, tolerance);}if (composition.Holes.Count == 1@@ -54,12 +54,11 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn CreateComposedThroughHoleBody(composition);}- private static KernelResult<BrepBody> CreateBoundedCylinderRootCenterBoreBody(SafeBooleanComposition composition, ToleranceContext tolerance)+ private static KernelResult<BrepBody> CreateBoundedCylinderRootHoleChainBody(SafeBooleanComposition composition, ToleranceContext tolerance){if (composition.RootDescriptor.Cylinder is not RecognizedCylinder rootCylinder- || composition.Holes.Count != 1- || composition.Holes[0].Surface.Kind != AnalyticSurfaceKind.Cylinder- || composition.Holes[0].Surface.Cylinder is not RecognizedCylinder boreCylinder)+ || composition.Holes.Count < 1+ || composition.Holes.Any(hole => hole.Surface.Kind != AnalyticSurfaceKind.Cylinder)){return KernelResult<BrepBody>.Failure([new BooleanDiagnostic(@@ -67,7 +66,21 @@ public static class BrepBooleanBoxCylinderHoleBuilderBrepBooleanCylinderRecognition.CreateBooleanMessage(BooleanOperation.Subtract.ToString(),null,- "cylinder-root safe rebuild in F2 requires exactly one recognized through center-bore cylinder."),+ "cylinder-root safe rebuild in F3 requires a center-bore plus optional off-axis through-hole cylinder chain."),+ "BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),+ ]);+ }++ var centerBore = composition.Holes[0];+ if (centerBore.Surface.Cylinder is not RecognizedCylinder boreCylinder)+ {+ return KernelResult<BrepBody>.Failure([+ new BooleanDiagnostic(+ BooleanDiagnosticCode.NotFullySpanning,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),+ centerBore.FeatureId,+ "cylinder-root safe rebuild in F3 requires recognized cylindrical tool surfaces."),"BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),]);}@@ -101,13 +114,21 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn KernelResult<BrepBody>.Failure(outer.Diagnostics);}- var inner = BrepPrimitives.CreateCylinder(boreCylinder.Radius, rootCylinder.Height);- if (!inner.IsSuccess)+ var innerShells = new List<BrepBody>(composition.Holes.Count);+ foreach (var hole in composition.Holes){- return KernelResult<BrepBody>.Failure(inner.Diagnostics);+ var localCenter = new Point3D(hole.CenterX - rootCenter.X, hole.CenterY - rootCenter.Y, rootCylinder.Height * 0.5d);+ var holeShell = BrepPrimitives.CreateCylinder(hole.BottomRadius, rootCylinder.Height);+ if (!holeShell.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(holeShell.Diagnostics);+ }++ var transformedHoleShell = TranslateBody(holeShell.Value, new Vector3D(localCenter.X, localCenter.Y, localCenter.Z));+ innerShells.Add(transformedHoleShell);}- var merged = MergeOuterAndInnerShell(outer.Value, inner.Value);+ var merged = MergeOuterAndInnerShells(outer.Value, innerShells);var bodyWithComposition = TranslateMergedBody(merged, rootCenter, composition);var validation = BrepBindingValidator.Validate(bodyWithComposition, requireAllEdgeAndFaceBindings: true);return validation.IsSuccess@@ -137,8 +158,10 @@ public static class BrepBooleanBoxCylinderHoleBuilder}private static BrepBody MergeOuterAndInnerShell(BrepBody outer, BrepBody inner)+ => MergeOuterAndInnerShells(outer, [inner]);++ private static BrepBody MergeOuterAndInnerShells(BrepBody outer, IReadOnlyList<BrepBody> innerShells){- const int idOffset = 1000;var topology = new TopologyModel();foreach (var vertex in outer.Topology.Vertices.OrderBy(v => v.Id.Value))@@ -171,52 +194,59 @@ public static class BrepBooleanBoxCylinderHoleBuildertopology.AddShell(shell);}- var innerVertexMap = inner.Topology.Vertices.ToDictionary(v => v.Id, v => new VertexId(v.Id.Value + idOffset));- var innerEdgeMap = inner.Topology.Edges.ToDictionary(e => e.Id, e => new EdgeId(e.Id.Value + idOffset));- var innerLoopMap = inner.Topology.Loops.ToDictionary(l => l.Id, l => new LoopId(l.Id.Value + idOffset));- var innerCoedgeMap = inner.Topology.Coedges.ToDictionary(c => c.Id, c => new CoedgeId(c.Id.Value + idOffset));- var innerFaceMap = inner.Topology.Faces.ToDictionary(f => f.Id, f => new FaceId(f.Id.Value + idOffset));- var innerShellMap = inner.Topology.Shells.ToDictionary(s => s.Id, s => new ShellId(s.Id.Value + idOffset));-- foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value))+ var remappedInnerShellIds = new List<ShellId>(innerShells.Count);+ for (var innerIndex = 0; innerIndex < innerShells.Count; innerIndex++){- topology.AddVertex(new Vertex(innerVertexMap[vertex.Id]));- }+ var inner = innerShells[innerIndex];+ var idOffset = 1000 * (innerIndex + 1);+ var innerVertexMap = inner.Topology.Vertices.ToDictionary(v => v.Id, v => new VertexId(v.Id.Value + idOffset));+ var innerEdgeMap = inner.Topology.Edges.ToDictionary(e => e.Id, e => new EdgeId(e.Id.Value + idOffset));+ var innerLoopMap = inner.Topology.Loops.ToDictionary(l => l.Id, l => new LoopId(l.Id.Value + idOffset));+ var innerCoedgeMap = inner.Topology.Coedges.ToDictionary(c => c.Id, c => new CoedgeId(c.Id.Value + idOffset));+ var innerFaceMap = inner.Topology.Faces.ToDictionary(f => f.Id, f => new FaceId(f.Id.Value + idOffset));+ var innerShellMap = inner.Topology.Shells.ToDictionary(s => s.Id, s => new ShellId(s.Id.Value + idOffset));- foreach (var edge in inner.Topology.Edges.OrderBy(e => e.Id.Value))- {- topology.AddEdge(new Edge(innerEdgeMap[edge.Id], innerVertexMap[edge.StartVertexId], innerVertexMap[edge.EndVertexId]));- }+ foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value))+ {+ topology.AddVertex(new Vertex(innerVertexMap[vertex.Id]));+ }- foreach (var coedge in inner.Topology.Coedges.OrderBy(c => c.Id.Value))- {- topology.AddCoedge(new Coedge(- innerCoedgeMap[coedge.Id],- innerEdgeMap[coedge.EdgeId],- innerLoopMap[coedge.LoopId],- innerCoedgeMap[coedge.NextCoedgeId],- innerCoedgeMap[coedge.PrevCoedgeId],- coedge.IsReversed));- }+ foreach (var edge in inner.Topology.Edges.OrderBy(e => e.Id.Value))+ {+ topology.AddEdge(new Edge(innerEdgeMap[edge.Id], innerVertexMap[edge.StartVertexId], innerVertexMap[edge.EndVertexId]));+ }- foreach (var loop in inner.Topology.Loops.OrderBy(l => l.Id.Value))- {- topology.AddLoop(new Loop(innerLoopMap[loop.Id], loop.CoedgeIds.Select(id => innerCoedgeMap[id]).ToArray()));- }+ foreach (var coedge in inner.Topology.Coedges.OrderBy(c => c.Id.Value))+ {+ topology.AddCoedge(new Coedge(+ innerCoedgeMap[coedge.Id],+ innerEdgeMap[coedge.EdgeId],+ innerLoopMap[coedge.LoopId],+ innerCoedgeMap[coedge.NextCoedgeId],+ innerCoedgeMap[coedge.PrevCoedgeId],+ coedge.IsReversed));+ }- foreach (var face in inner.Topology.Faces.OrderBy(f => f.Id.Value))- {- topology.AddFace(new Face(innerFaceMap[face.Id], face.LoopIds.Select(id => innerLoopMap[id]).ToArray()));- }+ foreach (var loop in inner.Topology.Loops.OrderBy(l => l.Id.Value))+ {+ topology.AddLoop(new Loop(innerLoopMap[loop.Id], loop.CoedgeIds.Select(id => innerCoedgeMap[id]).ToArray()));+ }- foreach (var shell in inner.Topology.Shells.OrderBy(s => s.Id.Value))- {- topology.AddShell(new Shell(innerShellMap[shell.Id], shell.FaceIds.Select(id => innerFaceMap[id]).ToArray()));+ foreach (var face in inner.Topology.Faces.OrderBy(f => f.Id.Value))+ {+ topology.AddFace(new Face(innerFaceMap[face.Id], face.LoopIds.Select(id => innerLoopMap[id]).ToArray()));+ }++ foreach (var shell in inner.Topology.Shells.OrderBy(s => s.Id.Value))+ {+ topology.AddShell(new Shell(innerShellMap[shell.Id], shell.FaceIds.Select(id => innerFaceMap[id]).ToArray()));+ }++ remappedInnerShellIds.Add(innerShellMap[AssertSingleShellId(inner.Topology)]);}var outerShellId = AssertSingleShellId(outer.Topology);- var remappedInnerShellId = innerShellMap[AssertSingleShellId(inner.Topology)];- topology.AddBody(new Body(new BodyId(1), [outerShellId, remappedInnerShellId]));+ topology.AddBody(new Body(new BodyId(1), [outerShellId, .. remappedInnerShellIds]));var geometry = new BrepGeometryStore();foreach (var curve in outer.Geometry.Curves)@@ -229,14 +259,19 @@ public static class BrepBooleanBoxCylinderHoleBuildergeometry.AddSurface(surface.Key, surface.Value);}- foreach (var curve in inner.Geometry.Curves)+ for (var innerIndex = 0; innerIndex < innerShells.Count; innerIndex++){- geometry.AddCurve(new CurveGeometryId(curve.Key.Value + idOffset), curve.Value);- }+ var inner = innerShells[innerIndex];+ var idOffset = 1000 * (innerIndex + 1);+ foreach (var curve in inner.Geometry.Curves)+ {+ geometry.AddCurve(new CurveGeometryId(curve.Key.Value + idOffset), curve.Value);+ }- foreach (var surface in inner.Geometry.Surfaces)- {- geometry.AddSurface(new SurfaceGeometryId(surface.Key.Value + idOffset), surface.Value);+ foreach (var surface in inner.Geometry.Surfaces)+ {+ geometry.AddSurface(new SurfaceGeometryId(surface.Key.Value + idOffset), surface.Value);+ }}var bindings = new BrepBindingModel();@@ -250,22 +285,30 @@ public static class BrepBooleanBoxCylinderHoleBuilderbindings.AddFaceBinding(faceBinding);}- foreach (var edgeBinding in inner.Bindings.EdgeBindings.OrderBy(binding => binding.EdgeId.Value))+ for (var innerIndex = 0; innerIndex < innerShells.Count; innerIndex++){- bindings.AddEdgeBinding(edgeBinding with+ var inner = innerShells[innerIndex];+ var idOffset = 1000 * (innerIndex + 1);+ var innerEdgeMap = inner.Topology.Edges.ToDictionary(e => e.Id, e => new EdgeId(e.Id.Value + idOffset));+ var innerFaceMap = inner.Topology.Faces.ToDictionary(f => f.Id, f => new FaceId(f.Id.Value + idOffset));++ foreach (var edgeBinding in inner.Bindings.EdgeBindings.OrderBy(binding => binding.EdgeId.Value)){- EdgeId = innerEdgeMap[edgeBinding.EdgeId],- CurveGeometryId = new CurveGeometryId(edgeBinding.CurveGeometryId.Value + idOffset),- });- }+ bindings.AddEdgeBinding(edgeBinding with+ {+ EdgeId = innerEdgeMap[edgeBinding.EdgeId],+ CurveGeometryId = new CurveGeometryId(edgeBinding.CurveGeometryId.Value + idOffset),+ });+ }- foreach (var faceBinding in inner.Bindings.FaceBindings.OrderBy(binding => binding.FaceId.Value))- {- bindings.AddFaceBinding(faceBinding with+ foreach (var faceBinding in inner.Bindings.FaceBindings.OrderBy(binding => binding.FaceId.Value)){- FaceId = innerFaceMap[faceBinding.FaceId],- SurfaceGeometryId = new SurfaceGeometryId(faceBinding.SurfaceGeometryId.Value + idOffset),- });+ bindings.AddFaceBinding(faceBinding with+ {+ FaceId = innerFaceMap[faceBinding.FaceId],+ SurfaceGeometryId = new SurfaceGeometryId(faceBinding.SurfaceGeometryId.Value + idOffset),+ });+ }}var vertexPoints = new Dictionary<VertexId, Point3D>();@@ -277,11 +320,16 @@ public static class BrepBooleanBoxCylinderHoleBuilder}}- foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value))+ for (var innerIndex = 0; innerIndex < innerShells.Count; innerIndex++){- if (inner.TryGetVertexPoint(vertex.Id, out var point))+ var inner = innerShells[innerIndex];+ var idOffset = 1000 * (innerIndex + 1);+ foreach (var vertex in inner.Topology.Vertices.OrderBy(v => v.Id.Value)){- vertexPoints[innerVertexMap[vertex.Id]] = point;+ if (inner.TryGetVertexPoint(vertex.Id, out var point))+ {+ vertexPoints[new VertexId(vertex.Id.Value + idOffset)] = point;+ }}}@@ -291,7 +339,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderbindings,vertexPoints,safeBooleanComposition: null,- shellRepresentation: new BrepBodyShellRepresentation(outerShellId, [remappedInnerShellId]));+ shellRepresentation: new BrepBodyShellRepresentation(outerShellId, remappedInnerShellIds));}private static ShellId AssertSingleShellId(TopologyModel topology)@@ -686,6 +734,50 @@ public static class BrepBooleanBoxCylinderHoleBuilderreturn new BrepBody(body.Topology, translatedGeometry, body.Bindings, vertexPoints, composition, body.ShellRepresentation);}+ private static BrepBody TranslateBody(BrepBody body, Vector3D translation)+ {+ if (translation == Vector3D.Zero)+ {+ return body;+ }++ var translatedGeometry = new BrepGeometryStore();+ foreach (var curveEntry in body.Geometry.Curves)+ {+ translatedGeometry.AddCurve(curveEntry.Key, curveEntry.Value.Kind switch+ {+ CurveGeometryKind.Line3 => CurveGeometry.FromLine(new Line3Curve(curveEntry.Value.Line3!.Value.Origin + translation, curveEntry.Value.Line3.Value.Direction)),+ CurveGeometryKind.Circle3 => CurveGeometry.FromCircle(new Circle3Curve(curveEntry.Value.Circle3!.Value.Center + translation, curveEntry.Value.Circle3.Value.Normal, curveEntry.Value.Circle3.Value.Radius, curveEntry.Value.Circle3.Value.XAxis)),+ _ => curveEntry.Value+ });+ }++ foreach (var surfaceEntry in body.Geometry.Surfaces)+ {+ translatedGeometry.AddSurface(surfaceEntry.Key, surfaceEntry.Value.Kind switch+ {+ SurfaceGeometryKind.Plane => SurfaceGeometry.FromPlane(new PlaneSurface(surfaceEntry.Value.Plane!.Value.Origin + translation, surfaceEntry.Value.Plane.Value.Normal, surfaceEntry.Value.Plane.Value.UAxis)),+ SurfaceGeometryKind.Cylinder => SurfaceGeometry.FromCylinder(new CylinderSurface(surfaceEntry.Value.Cylinder!.Value.Origin + translation, surfaceEntry.Value.Cylinder.Value.Axis, surfaceEntry.Value.Cylinder.Value.Radius, surfaceEntry.Value.Cylinder.Value.XAxis)),+ _ => surfaceEntry.Value+ });+ }++ Dictionary<VertexId, Point3D>? vertexPoints = null;+ if (body.Topology.Vertices.Any())+ {+ vertexPoints = [];+ foreach (var vertex in body.Topology.Vertices)+ {+ if (body.TryGetVertexPoint(vertex.Id, out var point))+ {+ vertexPoints[vertex.Id] = point + translation;+ }+ }+ }++ return new BrepBody(body.Topology, translatedGeometry, body.Bindings, vertexPoints, body.SafeBooleanComposition, body.ShellRepresentation);+ }+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 7170f9d2..b6785e2c 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -105,15 +105,6 @@ public static class BrepBooleanSafeCompositionGraphValidatorupdatedComposition = composition;diagnostic = null;- if (composition.Holes.Count > 0)- {- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "supports only a single center-bore subtract on the bounded cylinder-root safe family in F2; follow-on cylinder-root subtract composition is deferred.");- return false;- }-if (surface.Kind != AnalyticSurfaceKind.Cylinder || surface.Cylinder is not RecognizedCylinder toolCylinder){diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(@@ -151,58 +142,150 @@ public static class BrepBooleanSafeCompositionGraphValidator(toolCylinder.MinCenter.Y + toolCylinder.MaxCenter.Y) * 0.5d,(toolCylinder.MinCenter.Z + toolCylinder.MaxCenter.Z) * 0.5d);- if (!ToleranceMath.AlmostEqual(rootCenter.X, toolCenter.X, tolerance)- || !ToleranceMath.AlmostEqual(rootCenter.Y, toolCenter.Y, tolerance))+ var rootMinZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);+ var 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 spansRoot = toolMinZ <= (rootMinZ + tolerance.Linear) && toolMaxZ >= (rootMaxZ - tolerance.Linear);+ if (!spansRoot){- diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(),nextFeatureId,- "is outside the bounded cylinder-root safe subtract family; only coaxial center bores are supported.");+ "is outside the bounded cylinder-root safe subtract family; only through center bores that span both planar caps are supported.");return false;}- if (toolCylinder.Radius >= (rootCylinder.Radius - tolerance.Linear))+ 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 nextHole = new SupportedBooleanHole(+ nextFeatureId,+ surface,+ toolCenter.X,+ toolCenter.Y,+ new Point3D(toolCenter.X, toolCenter.Y, rootMinZ),+ new Point3D(toolCenter.X, toolCenter.Y, rootMaxZ),+ toolCylinder.Axis,+ Direction3D.Create(new Vector3D(1d, 0d, 0d)),+ toolCylinder.Radius,+ toolCylinder.Radius,+ SupportedBooleanHoleSpanKind.Through,+ rootMinZ,+ rootMaxZ);++ if (composition.Holes.Count == 0)+ {+ if (!isCoaxialCenterBore)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ "is outside the bounded cylinder-root safe subtract family; the first subtract must be a coaxial center bore.");+ return false;+ }++ if (toolCylinder.Radius >= (rootCylinder.Radius - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ "must remain strictly smaller than the flange root radius in the bounded cylinder-root safe subtract family.");+ return false;+ }++ updatedComposition = composition with+ {+ Holes = [nextHole],+ };++ return true;+ }++ var centerBore = composition.Holes[0];+ var centerBoreDeltaX = centerBore.CenterX - rootCenter.X;+ var centerBoreDeltaY = centerBore.CenterY - rootCenter.Y;+ var centerBoreOffset = System.Math.Sqrt((centerBoreDeltaX * centerBoreDeltaX) + (centerBoreDeltaY * centerBoreDeltaY));+ if (!ToleranceMath.AlmostZero(centerBoreOffset, tolerance)){diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(),nextFeatureId,- "must remain strictly smaller than the flange root radius in the bounded cylinder-root safe subtract family.");+ "cannot continue cylinder-root safe subtract composition because the first accepted hole is not a coaxial center bore.");return false;}- var rootMinZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);- var 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 spansRoot = toolMinZ <= (rootMinZ + tolerance.Linear) && toolMaxZ >= (rootMaxZ - tolerance.Linear);- if (!spansRoot)+ if (isCoaxialCenterBore){- diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ diagnostic = new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ "cannot append another coaxial center bore in the bounded cylinder-root safe family."),+ "BrepBoolean.AnalyticHole.HoleInterference");+ return false;+ }++ var ringOuterDistance = radialDistance + toolCylinder.Radius;+ var ringInnerDistance = radialDistance - toolCylinder.Radius;+ if (ToleranceMath.AlmostEqual(ringOuterDistance, rootCylinder.Radius, tolerance)+ || ringOuterDistance > (rootCylinder.Radius - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(),nextFeatureId,- "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; off-axis through-holes must remain strictly inside the outer cylindrical wall.");return false;}- updatedComposition = composition with+ if (ToleranceMath.AlmostEqual(ringInnerDistance, centerBore.BottomRadius, tolerance)+ || ringInnerDistance < (centerBore.BottomRadius + tolerance.Linear)){- Holes =- [- new SupportedBooleanHole(+ diagnostic = new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),nextFeatureId,- surface,- rootCenter.X,- rootCenter.Y,- new Point3D(rootCenter.X, rootCenter.Y, rootMinZ),- new Point3D(rootCenter.X, rootCenter.Y, rootMaxZ),- toolCylinder.Axis,- Direction3D.Create(new Vector3D(1d, 0d, 0d)),- toolCylinder.Radius,- toolCylinder.Radius,- SupportedBooleanHoleSpanKind.Through,- rootMinZ,- rootMaxZ)- ],+ "is outside the bounded cylinder-root safe subtract family; off-axis through-holes must remain strictly outside the center bore ring boundary."),+ "BrepBoolean.AnalyticHole.HoleInterference");+ return false;+ }++ for (var i = 1; i < composition.Holes.Count; i++)+ {+ var existingHole = composition.Holes[i];+ var existingDeltaX = existingHole.CenterX - nextHole.CenterX;+ var existingDeltaY = existingHole.CenterY - nextHole.CenterY;+ var centerDistance = System.Math.Sqrt((existingDeltaX * existingDeltaX) + (existingDeltaY * existingDeltaY));+ var requiredDistance = existingHole.MaxBoundaryRadius + nextHole.MaxBoundaryRadius;++ if (ToleranceMath.AlmostEqual(centerDistance, requiredDistance, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ $"would be tangent to previously accepted off-axis hole {FormatFeatureRef(existingHole.FeatureId)}; tangent safe-hole composition is rejected.");+ return false;+ }++ if (centerDistance < (requiredDistance - tolerance.Linear))+ {+ diagnostic = new BooleanDiagnostic(+ BooleanDiagnosticCode.HoleInterference,+ BrepBooleanCylinderRecognition.CreateBooleanMessage(+ BooleanOperation.Subtract.ToString(),+ nextFeatureId,+ $"overlaps previously accepted off-axis hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping cylinder-root hole chains are not supported."),+ "BrepBoolean.AnalyticHole.HoleInterference");+ return false;+ }+ }++ updatedComposition = composition with+ {+ Holes = [.. composition.Holes, nextHole],};return true;