Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add bounded countersink hole family with cone+cylinder stack support
Yuechen Li7f6d726ea5da
diff --git a/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/expected.intent.md b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/expected.intent.mdnew file mode 100644index 00000000..4f685e9b--- /dev/null+++ b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/expected.intent.md@@ -0,0 +1,2 @@+A 70x40x16 mm plate with one top-entry countersunk through-hole centered at (0,0).+The entry is conical (4 mm top radius tapering to 2 mm at depth 6 mm), and the continuation is a 2 mm radius through bore.diff --git a/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/part.firmament b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/part.firmamentnew file mode 100644index 00000000..5c84daa6--- /dev/null+++ b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/part.firmament@@ -0,0 +1,46 @@+firmament:+ version: 1++model:+ name: fl_m1_countersink_hole+ units: mm++ops[3]:+ -+ op: box+ id: plate+ size[3]:+ 70+ 40+ 16+ place:+ on: origin+ offset[3]:+ 0+ 0+ -2++ -+ op: subtract+ id: countersink_entry+ from: plate+ with:+ op: cone+ bottom_radius: 1.75+ top_radius: 3.5+ height: 4+ place:+ on: origin+ offset[3]:+ 0+ 0+ 6++ -+ op: subtract+ id: countersink_through+ from: countersink_entry+ with:+ op: cylinder+ radius: 1.75+ height: 26diff --git a/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/prompt.md b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/prompt.mdnew file mode 100644index 00000000..6a90d3d2--- /dev/null+++ b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/prompt.md@@ -0,0 +1 @@+Author a rectangular plate with a single countersunk through-hole at the origin using a conical entry followed by a coaxial cylindrical continuation.diff --git a/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/review.toon b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/review.toonnew file mode 100644index 00000000..d9c08a51--- /dev/null+++ b/Aetheris.Firmament.FrictionLab/Cases/countersink-hole/review.toon@@ -0,0 +1,6 @@+case_id: countersink-hole+verdict: pass+review_notes:+ - "Bounded countersink family accepted: one world-Z conical entry plus one coaxial cylindrical continuation."+ - "STEP export includes both conical and cylindrical analytic faces for the hole."+reviewer_verdict: "M1 bounded countersink family works for the canonical through countersink case."diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 4e3ec9c2..521d3bea 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -226,7 +226,7 @@ public sealed class BrepBooleanTestsAssert.True(first.IsSuccess);var second = BrepBoolean.Union(first.Value, flange);- Assert.True(second.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));Assert.True(BrepBindingValidator.Validate(second.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);Assert.False(BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(second.Value, ToleranceContext.Default, out _, out _));Assert.NotNull(second.Value.SafeBooleanComposition);@@ -418,7 +418,7 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(left, right);Assert.True(first.IsSuccess);- Assert.True(second.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));var firstExport = Step242Exporter.ExportBody(first.Value);var secondExport = Step242Exporter.ExportBody(second.Value);@@ -480,7 +480,7 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(root, bore);Assert.True(first.IsSuccess);- Assert.True(second.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));Assert.True(BrepBindingValidator.Validate(first.Value, true).IsSuccess);var firstExport = Step242Exporter.ExportBody(first.Value);@@ -751,7 +751,7 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(left, right);Assert.True(first.IsSuccess);- Assert.True(second.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));Assert.Equal(7, first.Value.Topology.Faces.Count());Assert.Contains(first.Value.Topology.Faces, face =>first.Value.TryGetFaceSurfaceGeometry(face.Id, out var surface)@@ -958,8 +958,8 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(first.Value, secondHole);var repeated = BrepBoolean.Subtract(first.Value, secondHole);- Assert.True(second.IsSuccess);- Assert.True(repeated.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.True(repeated.IsSuccess, string.Join(Environment.NewLine, repeated.Diagnostics.Select(d => d.Message)));Assert.Equal(8, second.Value.Topology.Faces.Count());Assert.Equal(18, second.Value.Topology.Edges.Count());Assert.Equal(16, second.Value.Topology.Vertices.Count());@@ -989,8 +989,8 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(first.Value, coneHole);var repeated = BrepBoolean.Subtract(first.Value, coneHole);- Assert.True(second.IsSuccess);- Assert.True(repeated.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.True(repeated.IsSuccess, string.Join(Environment.NewLine, repeated.Diagnostics.Select(d => d.Message)));Assert.Equal(8, second.Value.Topology.Faces.Count());Assert.Equal(18, second.Value.Topology.Edges.Count());Assert.Equal(16, second.Value.Topology.Vertices.Count());@@ -1093,8 +1093,8 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(first.Value, through);var repeated = BrepBoolean.Subtract(first.Value, through);- Assert.True(second.IsSuccess);- Assert.True(repeated.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.True(repeated.IsSuccess, string.Join(Environment.NewLine, repeated.Diagnostics.Select(d => d.Message)));Assert.True(BrepBindingValidator.Validate(second.Value, true).IsSuccess);Assert.Equal(9, second.Value.Topology.Faces.Count());Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);@@ -1108,6 +1108,54 @@ public sealed class BrepBooleanTestsAssert.Contains("MANIFOLD_SOLID_BREP", export.Value, StringComparison.Ordinal);}++ [Fact]+ public void Subtract_ComposedBlindCountersinkThenCoaxialThrough_Succeeds_AsBoundedCountersinkHole()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;+ var countersink = TransformBody(CreateCone(bottomRadius: 1.75d, topRadius: 3.5d, height: 4d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 4d)));+ var through = BrepPrimitives.CreateCylinder(1.75d, 24d).Value;++ var first = BrepBoolean.Subtract(baseBox, countersink);+ Assert.True(first.IsSuccess);++ var second = BrepBoolean.Subtract(first.Value, through);+ var repeated = BrepBoolean.Subtract(first.Value, through);++ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.True(repeated.IsSuccess, string.Join(Environment.NewLine, repeated.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(second.Value, true).IsSuccess);+ Assert.Equal(8, second.Value.Topology.Faces.Count());+ Assert.Equal(2, second.Value.SafeBooleanComposition?.Holes.Count);++ var export = Step242Exporter.ExportBody(second.Value);+ var repeatedExport = Step242Exporter.ExportBody(repeated.Value);+ Assert.True(export.IsSuccess);+ Assert.True(repeatedExport.IsSuccess);+ Assert.Equal(export.Value, repeatedExport.Value);+ Assert.Contains("CONICAL_SURFACE", export.Value, StringComparison.Ordinal);+ Assert.Contains("CYLINDRICAL_SURFACE", export.Value, StringComparison.Ordinal);+ Assert.DoesNotContain("BREP_WITH_VOIDS", export.Value, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_ComposedBlindCountersinkThenLargerThrough_ReturnsInvalidCountersinkRadiusOrderingDiagnostic()+ {+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;+ var countersink = TransformBody(CreateCone(bottomRadius: 2.5d, topRadius: 3.5d, height: 4d), Transform3D.CreateTranslation(new Vector3D(0d, 0d, 4d)));+ var through = BrepPrimitives.CreateCylinder(3.0d, 24d).Value;++ var first = BrepBoolean.Subtract(baseBox, countersink);+ Assert.True(first.IsSuccess);++ var second = BrepBoolean.Subtract(first.Value, through);+ Assert.False(second.IsSuccess);++ var diagnostic = Assert.Single(second.Diagnostics);+ Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);+ Assert.Contains("requires cone transition radius to match continuation-cylinder radius", diagnostic.Message, StringComparison.Ordinal);+ }+[Fact]public void Subtract_ComposedBlindPocketThenOffsetThrough_ReturnsCoaxialSteppedDiagnostic(){@@ -1159,7 +1207,7 @@ public sealed class BrepBooleanTestsvar second = BrepBoolean.Subtract(baseBox, containedPocket);Assert.True(first.IsSuccess);- Assert.True(second.IsSuccess);+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));Assert.NotNull(first.Value.ShellRepresentation);Assert.Single(first.Value.ShellRepresentation!.InnerShellIds);Assert.True(BrepBindingValidator.Validate(first.Value, true).IsSuccess);@@ -1300,7 +1348,7 @@ public sealed class BrepBooleanTestsvar repeated = BrepBoolean.Subtract(left, right);Assert.True(result.IsSuccess);- Assert.True(repeated.IsSuccess);+ Assert.True(repeated.IsSuccess, string.Join(Environment.NewLine, repeated.Diagnostics.Select(d => d.Message)));Assert.NotNull(result.Value.ShellRepresentation);Assert.Single(result.Value.ShellRepresentation!.InnerShellIds);Assert.True(BrepBindingValidator.Validate(result.Value, requireAllEdgeAndFaceBindings: true).IsSuccess);diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 8131f1cb..0efffe18 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -68,6 +68,22 @@ public static class BrepBooleanBoxCylinderHoleBuilder&& composition.Holes.Any(h => h.IsBlind)&& IsCoaxialHolePair(composition.Holes[0], composition.Holes[1], tolerance)){+ if (BrepBooleanCoaxialCountersinkSubtractFamily.TryClassifyPair(+ composition.OuterBox,+ composition.Holes[0],+ composition.Holes[1],+ tolerance,+ out var countersinkProfile,+ out var countersinkDiagnostic))+ {+ return CreateSteppedCoaxialCountersinkBody(composition, countersinkProfile);+ }++ if (countersinkDiagnostic is not null)+ {+ return KernelResult<BrepBody>.Failure([countersinkDiagnostic.ToKernelDiagnostic()]);+ }+if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(composition.OuterBox,composition.Holes[0],@@ -646,6 +662,244 @@ public static class BrepBooleanBoxCylinderHoleBuilder: KernelResult<BrepBody>.Failure(validation.Diagnostics);}++ private static KernelResult<BrepBody> CreateSteppedCoaxialCountersinkBody(+ SafeBooleanComposition composition,+ in CoaxialCountersinkSubtractProfile countersinkProfile)+ {+ var box = composition.OuterBox;+ var builder = new TopologyBuilder();++ var v1 = builder.AddVertex();+ var v2 = builder.AddVertex();+ var v3 = builder.AddVertex();+ var v4 = builder.AddVertex();+ var v5 = builder.AddVertex();+ var v6 = builder.AddVertex();+ var v7 = builder.AddVertex();+ var v8 = builder.AddVertex();++ var e1 = builder.AddEdge(v1, v2);+ var e2 = builder.AddEdge(v2, v3);+ var e3 = builder.AddEdge(v3, v4);+ var e4 = builder.AddEdge(v4, v1);+ var e5 = builder.AddEdge(v5, v6);+ var e6 = builder.AddEdge(v6, v7);+ var e7 = builder.AddEdge(v7, v8);+ var e8 = builder.AddEdge(v8, v5);+ var e9 = builder.AddEdge(v1, v5);+ var e10 = builder.AddEdge(v2, v6);+ var e11 = builder.AddEdge(v3, v7);+ var e12 = builder.AddEdge(v4, v8);++ var entryVertex = builder.AddVertex();+ var transitionVertex = builder.AddVertex();+ var deepEndVertex = builder.AddVertex();+ var coneSeamStartVertex = builder.AddVertex();+ var coneSeamEndVertex = builder.AddVertex();+ var cylinderSeamStartVertex = builder.AddVertex();+ var cylinderSeamEndVertex = builder.AddVertex();++ var entryCircle = builder.AddEdge(entryVertex, entryVertex);+ var transitionCircle = builder.AddEdge(transitionVertex, transitionVertex);+ var deepEndCircle = builder.AddEdge(deepEndVertex, deepEndVertex);+ var coneSeam = builder.AddEdge(coneSeamStartVertex, coneSeamEndVertex);+ var cylinderSeam = builder.AddEdge(cylinderSeamStartVertex, cylinderSeamEndVertex);++ var bottomOuterLoop = AddLoop(builder, [Forward(e1), Forward(e2), Forward(e3), Forward(e4)]);+ var topOuterLoop = AddLoop(builder, [Forward(e5), Forward(e6), Forward(e7), Forward(e8)]);+ var bottomLoops = new List<LoopId>(2) { bottomOuterLoop };+ var topLoops = new List<LoopId>(2) { topOuterLoop };++ if (countersinkProfile.EntryFromTop)+ {+ topLoops.Add(AddLoop(builder, [Forward(entryCircle)]));+ if (countersinkProfile.ContinuationCylinder.SpanKind == SupportedBooleanHoleSpanKind.Through)+ {+ bottomLoops.Add(AddLoop(builder, [Reversed(deepEndCircle)]));+ }+ }+ else+ {+ bottomLoops.Add(AddLoop(builder, [Reversed(entryCircle)]));+ if (countersinkProfile.ContinuationCylinder.SpanKind == SupportedBooleanHoleSpanKind.Through)+ {+ topLoops.Add(AddLoop(builder, [Forward(deepEndCircle)]));+ }+ }++ var bottomFace = builder.AddFace(bottomLoops);+ var topFace = builder.AddFace(topLoops);+ var xMinFace = builder.AddFace([AddLoop(builder, [Forward(e1), Forward(e10), Reversed(e5), Reversed(e9)])]);+ var xMaxFace = builder.AddFace([AddLoop(builder, [Forward(e2), Forward(e11), Reversed(e6), Reversed(e10)])]);+ var yMaxFace = builder.AddFace([AddLoop(builder, [Forward(e3), Forward(e12), Reversed(e7), Reversed(e11)])]);+ var yMinFace = builder.AddFace([AddLoop(builder, [Forward(e4), Forward(e9), Reversed(e8), Reversed(e12)])]);++ var countersinkConeFace = builder.AddFace([+ AddLoop(builder, [Forward(coneSeam), Reversed(entryCircle), Reversed(coneSeam), Forward(transitionCircle)])+ ]);+ var continuationCylinderFace = builder.AddFace([+ AddLoop(builder, [Forward(cylinderSeam), Reversed(transitionCircle), Reversed(cylinderSeam), Forward(deepEndCircle)])+ ]);++ FaceId? deepBottomFace = null;+ if (countersinkProfile.ContinuationCylinder.IsBlind)+ {+ deepBottomFace = builder.AddFace([AddLoop(builder, [Forward(deepEndCircle)])]);+ }++ var shellFaces = new List<FaceId>+ {+ bottomFace,+ topFace,+ xMinFace,+ xMaxFace,+ yMaxFace,+ yMinFace,+ countersinkConeFace,+ continuationCylinderFace,+ };+ if (deepBottomFace is FaceId deepBottom)+ {+ shellFaces.Add(deepBottom);+ }++ var shell = builder.AddShell(shellFaces);+ builder.AddBody([shell]);++ var zAxis = Direction3D.Create(new Vector3D(0d, 0d, 1d));+ var xAxis = Direction3D.Create(new Vector3D(1d, 0d, 0d));+ var yAxis = Direction3D.Create(new Vector3D(0d, 1d, 0d));+ var width = box.MaxX - box.MinX;+ var depth = box.MaxY - box.MinY;+ var height = box.MaxZ - box.MinZ;+ var p1 = new Point3D(box.MinX, box.MinY, box.MinZ);+ var p2 = new Point3D(box.MaxX, box.MinY, box.MinZ);+ var p3 = new Point3D(box.MaxX, box.MaxY, box.MinZ);+ var p4 = new Point3D(box.MinX, box.MaxY, box.MinZ);+ var p5 = new Point3D(box.MinX, box.MinY, box.MaxZ);+ var p6 = new Point3D(box.MaxX, box.MinY, box.MaxZ);+ var p7 = new Point3D(box.MaxX, box.MaxY, box.MaxZ);+ var p8 = new Point3D(box.MinX, box.MaxY, box.MaxZ);++ var entryZ = countersinkProfile.EntryFromTop ? box.MaxZ : box.MinZ;+ var transitionZ = countersinkProfile.TransitionZ;+ var deepEndZ = countersinkProfile.ContinuationCylinder.SpanKind == SupportedBooleanHoleSpanKind.Through+ ? (countersinkProfile.EntryFromTop ? box.MinZ : box.MaxZ)+ : countersinkProfile.ContinuationEndZ;+ var center = new Point3D(countersinkProfile.EntryCone.CenterX, countersinkProfile.EntryCone.CenterY, 0d);+ var entryCenter = new Point3D(center.X, center.Y, entryZ);+ var transitionCenter = new Point3D(center.X, center.Y, transitionZ);+ var deepEndCenter = new Point3D(center.X, center.Y, deepEndZ);+ var seamAxis = countersinkProfile.EntryFromTop+ ? Direction3D.Create(new Vector3D(0d, 0d, -1d))+ : Direction3D.Create(new Vector3D(0d, 0d, 1d));+ var coneSeamStart = entryCenter + (xAxis.ToVector() * countersinkProfile.EntryRadius);+ var coneSeamEnd = transitionCenter + (xAxis.ToVector() * countersinkProfile.ContinuationRadius);+ var cylinderSeamStart = coneSeamEnd;+ var cylinderSeamEnd = deepEndCenter + (xAxis.ToVector() * countersinkProfile.ContinuationRadius);++ var geometry = new BrepGeometryStore();+ var lineCurves = new[]+ {+ (p1, new Vector3D(width, 0d, 0d)),+ (p2, new Vector3D(0d, depth, 0d)),+ (p3, new Vector3D(-width, 0d, 0d)),+ (p4, new Vector3D(0d, -depth, 0d)),+ (p5, new Vector3D(width, 0d, 0d)),+ (p6, new Vector3D(0d, depth, 0d)),+ (p7, new Vector3D(-width, 0d, 0d)),+ (p8, new Vector3D(0d, -depth, 0d)),+ (p1, new Vector3D(0d, 0d, height)),+ (p2, new Vector3D(0d, 0d, height)),+ (p3, new Vector3D(0d, 0d, height)),+ (p4, new Vector3D(0d, 0d, height)),+ };+ for (var i = 0; i < lineCurves.Length; i++)+ {+ geometry.AddCurve(new CurveGeometryId(i + 1), CurveGeometry.FromLine(new Line3Curve(lineCurves[i].Item1, Direction3D.Create(lineCurves[i].Item2))));+ }++ var entryCurveId = new CurveGeometryId(13);+ var transitionCurveId = new CurveGeometryId(14);+ var deepEndCurveId = new CurveGeometryId(15);+ var coneSeamCurveId = new CurveGeometryId(16);+ var cylinderSeamCurveId = new CurveGeometryId(17);+ geometry.AddCurve(entryCurveId, CurveGeometry.FromCircle(new Circle3Curve(entryCenter, zAxis, countersinkProfile.EntryRadius, xAxis)));+ geometry.AddCurve(transitionCurveId, CurveGeometry.FromCircle(new Circle3Curve(transitionCenter, zAxis, countersinkProfile.ContinuationRadius, xAxis)));+ geometry.AddCurve(deepEndCurveId, CurveGeometry.FromCircle(new Circle3Curve(deepEndCenter, zAxis, countersinkProfile.ContinuationRadius, xAxis)));+ geometry.AddCurve(coneSeamCurveId, CurveGeometry.FromLine(new Line3Curve(coneSeamStart, Direction3D.Create(coneSeamEnd - coneSeamStart))));+ geometry.AddCurve(cylinderSeamCurveId, CurveGeometry.FromLine(new Line3Curve(cylinderSeamStart, seamAxis)));++ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, box.MinZ), Direction3D.Create(new Vector3D(0d, 0d, -1d)), xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(2), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, 0d, box.MaxZ), zAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(3), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, box.MinY, 0d), Direction3D.Create(new Vector3D(0d, -1d, 0d)), xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(4), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(box.MaxX, 0d, 0d), Direction3D.Create(new Vector3D(1d, 0d, 0d)), yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(5), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(0d, box.MaxY, 0d), Direction3D.Create(new Vector3D(0d, 1d, 0d)), Direction3D.Create(new Vector3D(-1d, 0d, 0d)))));+ geometry.AddSurface(new SurfaceGeometryId(6), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(box.MinX, 0d, 0d), Direction3D.Create(new Vector3D(-1d, 0d, 0d)), yAxis)));++ var cone = countersinkProfile.EntryCone.Surface.Cone!.Value;+ var coneOriginParameter = System.Math.Min(cone.MinAxisParameter, cone.MaxAxisParameter);+ var coneOrigin = cone.PointAtAxisParameter(coneOriginParameter);+ var coneRadius = cone.RadiusAtAxisParameter(coneOriginParameter);+ geometry.AddSurface(new SurfaceGeometryId(7), SurfaceGeometry.FromCone(new ConeSurface(coneOrigin, cone.Axis, coneRadius, cone.SemiAngleRadians, countersinkProfile.EntryCone.ReferenceAxis)));+ geometry.AddSurface(new SurfaceGeometryId(8), SurfaceGeometry.FromCylinder(new CylinderSurface(deepEndCenter, zAxis, countersinkProfile.ContinuationRadius, xAxis)));+ if (deepBottomFace is not null)+ {+ geometry.AddSurface(new SurfaceGeometryId(9), SurfaceGeometry.FromPlane(new PlaneSurface(deepEndCenter, Direction3D.Create(new Vector3D(0d, 0d, countersinkProfile.EntryFromTop ? -1d : 1d)), xAxis)));+ }++ var bindings = new BrepBindingModel();+ for (var i = 0; i < 12; i++)+ {+ bindings.AddEdgeBinding(new EdgeGeometryBinding(new EdgeId(i + 1), new CurveGeometryId(i + 1), new ParameterInterval(0d, 1d)));+ }++ bindings.AddEdgeBinding(new EdgeGeometryBinding(entryCircle, entryCurveId, new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(transitionCircle, transitionCurveId, new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(deepEndCircle, deepEndCurveId, new ParameterInterval(0d, 2d * double.Pi)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(coneSeam, coneSeamCurveId, new ParameterInterval(0d, (coneSeamEnd - coneSeamStart).Length)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(cylinderSeam, cylinderSeamCurveId, new ParameterInterval(0d, (cylinderSeamEnd - cylinderSeamStart).Length)));++ bindings.AddFaceBinding(new FaceGeometryBinding(bottomFace, new SurfaceGeometryId(1)));+ bindings.AddFaceBinding(new FaceGeometryBinding(topFace, new SurfaceGeometryId(2)));+ bindings.AddFaceBinding(new FaceGeometryBinding(xMinFace, new SurfaceGeometryId(3)));+ bindings.AddFaceBinding(new FaceGeometryBinding(xMaxFace, new SurfaceGeometryId(4)));+ bindings.AddFaceBinding(new FaceGeometryBinding(yMaxFace, new SurfaceGeometryId(5)));+ bindings.AddFaceBinding(new FaceGeometryBinding(yMinFace, new SurfaceGeometryId(6)));+ bindings.AddFaceBinding(new FaceGeometryBinding(countersinkConeFace, new SurfaceGeometryId(7)));+ bindings.AddFaceBinding(new FaceGeometryBinding(continuationCylinderFace, new SurfaceGeometryId(8)));+ if (deepBottomFace is FaceId deepBottomBinding)+ {+ bindings.AddFaceBinding(new FaceGeometryBinding(deepBottomBinding, new SurfaceGeometryId(9)));+ }++ var vertexPoints = new Dictionary<VertexId, Point3D>+ {+ [v1] = p1,+ [v2] = p2,+ [v3] = p3,+ [v4] = p4,+ [v5] = p5,+ [v6] = p6,+ [v7] = p7,+ [v8] = p8,+ [entryVertex] = coneSeamStart,+ [transitionVertex] = coneSeamEnd,+ [deepEndVertex] = cylinderSeamEnd,+ [coneSeamStartVertex] = coneSeamStart,+ [coneSeamEndVertex] = coneSeamEnd,+ [cylinderSeamStartVertex] = cylinderSeamStart,+ [cylinderSeamEndVertex] = cylinderSeamEnd,+ };++ 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> CreateSteppedCoaxialCylinderBody(SafeBooleanComposition composition,in CoaxialCylinderSubtractStackProfile steppedProfile)diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialCountersinkSubtractFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialCountersinkSubtractFamily.csnew file mode 100644index 00000000..0b241509--- /dev/null+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialCountersinkSubtractFamily.cs@@ -0,0 +1,225 @@+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Numerics;++namespace Aetheris.Kernel.Core.Brep.Boolean;++internal readonly record struct CoaxialCountersinkSubtractProfile(+ SupportedBooleanHole EntryCone,+ SupportedBooleanHole ContinuationCylinder,+ bool EntryFromTop,+ double TransitionZ,+ double EntryRadius,+ double ContinuationRadius,+ double ContinuationEndZ);++internal static class BrepBooleanCoaxialCountersinkSubtractFamily+{+ // M1 bounded countersink family:+ // - exactly one cone + one cylinder subtract in a two-segment coaxial stack+ // - both world-Z aligned and centered on the same XY axis+ // - cone provides single-sided entry at box top or bottom (not through-cone)+ // - cone transition radius must match continuation cylinder radius+ // - continuation may be through or blind but must continue inward past transition+ // - larger/smaller ordering is enforced: entry radius > continuation radius++ public static bool TryClassifyPair(+ AxisAlignedBoxExtents outerBox,+ in SupportedBooleanHole first,+ in SupportedBooleanHole second,+ ToleranceContext tolerance,+ out CoaxialCountersinkSubtractProfile profile,+ out BooleanDiagnostic? diagnostic,+ string? featureId = null)+ {+ profile = default;+ diagnostic = null;++ var firstIsCone = first.Surface.Kind == AnalyticSurfaceKind.Cone;+ var secondIsCone = second.Surface.Kind == AnalyticSurfaceKind.Cone;+ var firstIsCylinder = first.Surface.Kind == AnalyticSurfaceKind.Cylinder;+ var secondIsCylinder = second.Surface.Kind == AnalyticSurfaceKind.Cylinder;+ if ((!firstIsCone && !secondIsCone) || (!firstIsCylinder && !secondIsCylinder))+ {+ return false;+ }++ var entryCone = firstIsCone ? first : second;+ var continuationCylinder = firstIsCylinder ? first : second;++ if (!IsWorldZAligned(entryCone.Axis, tolerance) || !IsWorldZAligned(continuationCylinder.Axis, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires world-Z aligned cone and cylinder tools.");+ return false;+ }++ var deltaX = entryCone.CenterX - continuationCylinder.CenterX;+ var deltaY = entryCone.CenterY - continuationCylinder.CenterY;+ if (System.Math.Sqrt((deltaX * deltaX) + (deltaY * deltaY)) > tolerance.Linear)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires coaxial cone and cylinder tools with matching XY axis centers.");+ return false;+ }++ var coneTopEntry = IsTopEntry(entryCone, outerBox, tolerance);+ var coneBottomEntry = IsBottomEntry(entryCone, outerBox, tolerance);+ if (coneTopEntry == coneBottomEntry)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires one-sided cone entry opening on exactly one box entry face.");+ return false;+ }++ var entryFromTop = coneTopEntry;+ var entryZ = entryFromTop ? ResolveTop(entryCone) : ResolveBottom(entryCone);+ var transitionZ = entryFromTop ? ResolveBottom(entryCone) : ResolveTop(entryCone);+ var continuationTop = ResolveTop(continuationCylinder);+ var continuationBottom = ResolveBottom(continuationCylinder);++ if (entryFromTop)+ {+ if (continuationTop < (transitionZ - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires the cylindrical continuation to reach the cone transition circle.");+ return false;+ }++ if (continuationBottom >= (transitionZ - tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires continuation below the cone transition plane.");+ return false;+ }+ }+ else+ {+ if (continuationBottom > (transitionZ + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires the cylindrical continuation to reach the cone transition circle.");+ return false;+ }++ if (continuationTop <= (transitionZ + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires continuation above the cone transition plane.");+ return false;+ }+ }++ var entryRadius = entryFromTop ? entryCone.BottomRadius : entryCone.TopRadius;+ var continuationRadius = continuationCylinder.BottomRadius;+ if (entryRadius <= (continuationRadius + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires cone entry radius strictly larger than continuation-cylinder radius at the transition plane.");+ return false;+ }++ var coneTransitionRadius = entryFromTop ? entryCone.TopRadius : entryCone.BottomRadius;+ if (!ToleranceMath.AlmostEqual(coneTransitionRadius, continuationRadius, tolerance))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ "bounded countersink subtract-stack support requires cone transition radius to match continuation-cylinder radius.");+ return false;+ }++ if (!ValidateCircleInsideBoxFootprint(outerBox, entryCone.CenterX, entryCone.CenterY, entryRadius, tolerance, out diagnostic, featureId, "countersink entry"))+ {+ return false;+ }++ var continuationEndZ = continuationCylinder.SpanKind == SupportedBooleanHoleSpanKind.Through+ ? (entryFromTop ? outerBox.MinZ : outerBox.MaxZ)+ : continuationCylinder.EndCenter.Z;++ profile = new CoaxialCountersinkSubtractProfile(+ entryCone,+ continuationCylinder,+ entryFromTop,+ transitionZ,+ entryRadius,+ continuationRadius,+ continuationEndZ);+ return true;+ }++ private static bool ValidateCircleInsideBoxFootprint(+ AxisAlignedBoxExtents box,+ double centerX,+ double centerY,+ double radius,+ ToleranceContext tolerance,+ out BooleanDiagnostic? diagnostic,+ string? featureId,+ string section)+ {+ diagnostic = null;+ var tangent = ToleranceMath.AlmostEqual(centerX - radius, box.MinX, tolerance)+ || ToleranceMath.AlmostEqual(centerX + radius, box.MaxX, tolerance)+ || ToleranceMath.AlmostEqual(centerY - radius, box.MinY, tolerance)+ || ToleranceMath.AlmostEqual(centerY + radius, box.MaxY, tolerance);+ if (tangent)+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ $"has tangent contact at the box side walls ({section}); tangent support is rejected to avoid zero-thickness boundary sections.");+ return false;+ }++ if (centerX - radius < (box.MinX - tolerance.Linear)+ || centerX + radius > (box.MaxX + tolerance.Linear)+ || centerY - radius < (box.MinY - tolerance.Linear)+ || centerY + radius > (box.MaxY + tolerance.Linear))+ {+ diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(+ BooleanOperation.Subtract.ToString(),+ featureId,+ $"extends outside the box side walls ({section}); supported subtract tools must remain inside the box footprint.");+ return false;+ }++ return true;+ }++ private static double ResolveTop(in SupportedBooleanHole hole) => System.Math.Max(hole.StartCenter.Z, hole.EndCenter.Z);++ private static double ResolveBottom(in SupportedBooleanHole hole) => System.Math.Min(hole.StartCenter.Z, hole.EndCenter.Z);++ private static bool IsTopEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => ResolveTop(hole) >= (outerBox.MaxZ - tolerance.Linear);++ private static bool IsBottomEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)+ => ResolveBottom(hole) <= (outerBox.MinZ + tolerance.Linear);++ private static bool IsWorldZAligned(Direction3D axis, ToleranceContext tolerance)+ {+ var axisVector = axis.ToVector();+ return ToleranceMath.AlmostZero(axisVector.X, tolerance)+ && ToleranceMath.AlmostZero(axisVector.Y, tolerance)+ && ToleranceMath.AlmostEqual(System.Math.Abs(axisVector.Z), 1d, tolerance);+ }+}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex 40355928..a7ffe34f 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -70,6 +70,24 @@ public static class BrepBooleanSafeCompositionGraphValidator{if (IsCoaxialHolePair(existingHole, nextHole, tolerance)){+ if (BrepBooleanCoaxialCountersinkSubtractFamily.TryClassifyPair(+ composition.OuterBox,+ existingHole,+ nextHole,+ tolerance,+ out _,+ out var countersinkDiagnostic,+ nextFeatureId))+ {+ continue;+ }++ if (countersinkDiagnostic is not null)+ {+ diagnostic = countersinkDiagnostic;+ return false;+ }+if (BrepBooleanCoaxialSubtractStackFamily.TryClassifyPair(composition.OuterBox,existingHole,diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex af9f2e82..dd58db67 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -266,8 +266,8 @@ public sealed class FirmamentBuildAndExportTestsvar first = FirmamentBuildAndExport.Run(fullSourcePath);var second = FirmamentBuildAndExport.Run(fullSourcePath);- Assert.True(first.IsSuccess);- Assert.True(second.IsSuccess);+ Assert.True(first.IsSuccess, string.Join(Environment.NewLine, first.Diagnostics.Select(d => d.Message)));+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));Assert.NotEmpty(first.Value.Export.StepText);Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);Assert.Contains("MANIFOLD_SOLID_BREP", first.Value.Export.StepText, StringComparison.Ordinal);@@ -301,6 +301,25 @@ public sealed class FirmamentBuildAndExportTestsAssert.Equal(2, topFace.face.LoopIds.Count);}++ [Fact]+ public void Run_FrictionLabCountersinkHole_NowBuildsAndExports()+ {+ var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/countersink-hole/part.firmament");++ var first = FirmamentBuildAndExport.Run(fullSourcePath);+ var second = FirmamentBuildAndExport.Run(fullSourcePath);++ Assert.True(first.IsSuccess, string.Join(Environment.NewLine, first.Diagnostics.Select(d => d.Message)));+ Assert.True(second.IsSuccess, string.Join(Environment.NewLine, second.Diagnostics.Select(d => d.Message)));+ Assert.NotEmpty(first.Value.Export.StepText);+ Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);+ Assert.Contains("MANIFOLD_SOLID_BREP", first.Value.Export.StepText, StringComparison.Ordinal);+ Assert.Contains("CONICAL_SURFACE", first.Value.Export.StepText, StringComparison.Ordinal);+ Assert.Contains("CYLINDRICAL_SURFACE", first.Value.Export.StepText, StringComparison.Ordinal);+ Assert.DoesNotContain("BREP_WITH_VOIDS", first.Value.Export.StepText, StringComparison.Ordinal);+ }+[Fact]public void Run_FrictionLabCounterboreHole_NowBuildsAndExports(){diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex 1d2bed4a..f9fd58bd 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -373,11 +373,20 @@ internal static class FirmamentPrimitiveExecutor&& BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(toolBody, ToleranceContext.Default, out _, out _);}- if (!string.Equals(boolean.Tool.OpName, "cylinder", StringComparison.Ordinal))+ var isCylinderTool = string.Equals(boolean.Tool.OpName, "cylinder", StringComparison.Ordinal);+ var isConeTool = string.Equals(boolean.Tool.OpName, "cone", StringComparison.Ordinal);+ if (!isCylinderTool && !isConeTool){return false;}+ if (isConeTool)+ {+ // Cone tools require real placed-body validation/execution for bounded blind-entry families+ // (e.g., countersink entry cones); validating unplaced cones collapses them into contained tools.+ return true;+ }+if (baseBody.SafeBooleanComposition is { Holes.Count: > 0 }){return true;