Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement bounded cylinder-root keyway open-slot rebuild
Yuechen Li73dca9b10e83
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex a98c870f..7fd0114b 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -439,19 +439,35 @@ public sealed class BrepBooleanTests}[Fact]- public void Subtract_CylinderRootCenterlineKeyway_ProgressesToExplicitOpenSlotRebuildBlocker()+ public void Subtract_CylinderRootCenterlineKeyway_RebuildsAndExportsTruthfully(){var shaft = BrepPrimitives.CreateCylinder(15d, 80d).Value;var keywayTool = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(5d, 15d, -3d, 3d, -45d, 45d)).Value;var result = BrepBoolean.Subtract(shaft, keywayTool);+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);+ Assert.Equal(6, result.Value.Topology.Faces.Count());++ var export = Step242Exporter.ExportBody(result.Value);+ Assert.True(export.IsSuccess);+ Assert.Contains("CYLINDRICAL_SURFACE", export.Value, StringComparison.Ordinal);+ Assert.Contains("PLANE", export.Value, StringComparison.Ordinal);+ }++ [Fact]+ public void Subtract_CylinderRootKeywayRejectsTangentSideWalls()+ {+ var shaft = BrepPrimitives.CreateCylinder(15d, 80d).Value;+ var tangentTool = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(5d, 15d, -15d, 15d, -45d, 45d)).Value;++ var result = BrepBoolean.Subtract(shaft, tangentTool);+Assert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal(- "Boolean Subtract: bounded cylinder-root keyway family is recognized (single world-Z through rectangular slot), but rebuild/export for open-slot topology is not implemented yet.",- diagnostic.Message);+ Assert.Contains("tangent side walls are unsupported", diagnostic.Message, StringComparison.Ordinal);}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.csindex e2a6e947..a010dd8d 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs@@ -220,13 +220,7 @@ public static class BrepBooleanresolvedTolerance,out var keywayUnsupportedReason)){- return new BooleanCaseClassification(- BooleanExecutionClass.UnsupportedGeneralCase,- leftSafeComposition,- leftSafeComposition.OuterBox,- rightBox,- null,- "Boolean Subtract: bounded cylinder-root keyway family is recognized (single world-Z through rectangular slot), but rebuild/export for open-slot topology is not implemented yet.");+ return new BooleanCaseClassification(BooleanExecutionClass.UnsupportedGeneralCase, leftSafeComposition, leftSafeComposition.OuterBox, rightBox, null, null);}return new BooleanCaseClassification(@@ -289,10 +283,45 @@ public static class BrepBooleancase BooleanExecutionClass.PlanarWithAnalyticHole:return ClassifyPlanarWithAnalyticHole(request, intersections);default:+ if (TryClassifyBoundedCylinderRootOpenSlot(request, intersections, out var openSlotClassification))+ {+ return openSlotClassification;+ }+return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: intersections.Analysis.UnsupportedReason);}}+ private static bool TryClassifyBoundedCylinderRootOpenSlot(BooleanRequest request, BooleanIntersectionData intersections, out BooleanClassificationData classification)+ {+ classification = default!;+ if (request.Operation != BooleanOperation.Subtract+ || intersections.Analysis.LeftSafeComposition is not SafeBooleanComposition leftComposition+ || intersections.Analysis.RightBox is not AxisAlignedBoxExtents toolBox+ || leftComposition.RootDescriptor.Kind != SafeBooleanRootKind.Cylinder)+ {+ return false;+ }++ var tolerance = request.Tolerance ?? ToleranceContext.Default;+ if (!TryClassifyBoundedCylinderRootKeyway(leftComposition.RootDescriptor, toolBox, tolerance, out _))+ {+ return false;+ }++ classification = new BooleanClassificationData(+ intersections,+ IsComputed: true,+ FragmentCount: 1,+ SingleBoxResult: null,+ SafeCompositionResult: leftComposition with+ {+ OpenSlots = [new SupportedCylinderOpenSlot(toolBox)],+ },+ UnsupportedReason: null);+ return true;+ }+private static BooleanClassificationData ClassifyPlanarWithAnalyticHole(BooleanRequest request, BooleanIntersectionData intersections){var leftComposition = intersections.Analysis.LeftSafeComposition@@ -826,6 +855,21 @@ public static class BrepBooleanreturn false;}+ if ((toolBox.MaxY - toolBox.MinY) <= (2d * tolerance.Linear))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires strictly positive keyway side-wall span (non-degenerate slot width).";+ return false;+ }++ var dyMin = toolBox.MinY - rootCenterY;+ var dyMax = toolBox.MaxY - rootCenterY;+ if (System.Math.Abs(dyMin) >= (rootCylinder.Radius - tolerance.Linear)+ || System.Math.Abs(dyMax) >= (rootCylinder.Radius - tolerance.Linear))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires side walls to intersect the cylindrical wall with positive span (tangent side walls are unsupported).";+ return false;+ }+var reachesFarSideWall = ContainsPoint(toolBox.MinX, toolBox.MaxX, rootCenterX - rootCylinder.Radius, tolerance)&& ContainsPoint(toolBox.MinY, toolBox.MaxY, rootCenterY, tolerance);if (reachesFarSideWall)@@ -834,6 +878,14 @@ public static class BrepBooleanreturn false;}+ var positiveWallAtMinY = (rootCenterX + System.Math.Sqrt((rootCylinder.Radius * rootCylinder.Radius) - (dyMin * dyMin))) - toolBox.MinX;+ var positiveWallAtMaxY = (rootCenterX + System.Math.Sqrt((rootCylinder.Radius * rootCylinder.Radius) - (dyMax * dyMax))) - toolBox.MinX;+ if (positiveWallAtMinY <= (2d * tolerance.Linear) || positiveWallAtMaxY <= (2d * tolerance.Linear))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires strictly positive wall thickness between the slot floor and cylindrical wall.";+ return false;+ }+return true;}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 97cecb32..8131f1cb 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -28,6 +28,11 @@ public static class BrepBooleanBoxCylinderHoleBuilder_ = tolerance;if (composition.RootDescriptor.Kind == SafeBooleanRootKind.Cylinder){+ if (composition.OpenSlots is { Count: > 0 })+ {+ return BrepBooleanCylinderOpenSlotBuilder.Build(composition, tolerance);+ }+return CreateBoundedCylinderRootHoleChainBody(composition, tolerance);}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderOpenSlotBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderOpenSlotBuilder.csnew file mode 100644index 00000000..80a46361--- /dev/null+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderOpenSlotBuilder.cs@@ -0,0 +1,238 @@+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Geometry;+using Aetheris.Kernel.Core.Geometry.Curves;+using Aetheris.Kernel.Core.Geometry.Surfaces;+using Aetheris.Kernel.Core.Math;+using Aetheris.Kernel.Core.Numerics;+using Aetheris.Kernel.Core.Results;+using Aetheris.Kernel.Core.Topology;++namespace Aetheris.Kernel.Core.Brep.Boolean;++internal static class BrepBooleanCylinderOpenSlotBuilder+{+ public static KernelResult<BrepBody> Build(SafeBooleanComposition composition, ToleranceContext tolerance)+ {+ if (composition.RootDescriptor.Cylinder is not RecognizedCylinder rootCylinder+ || composition.OpenSlots is not { Count: 1 }+ || composition.Holes.Count != 0)+ {+ return KernelResult<BrepBody>.Failure([+ new KernelDiagnostic(+ KernelDiagnosticCode.NotImplemented,+ KernelDiagnosticSeverity.Error,+ "Boolean Subtract: bounded cylinder-root open-slot rebuild requires one recognized root cylinder and one supported rectangular through-slot tool.",+ "BrepBooleanCylinderOpenSlotBuilder.Build"),+ ]);+ }++ var slot = composition.OpenSlots[0].ToolExtents;+ var centerX = (rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d;+ var centerY = (rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d;+ var minZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);+ var maxZ = System.Math.Max(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);++ var yMin = slot.MinY;+ var yMax = slot.MaxY;+ var floorX = slot.MinX;+ var radius = rootCylinder.Radius;++ var dyMin = yMin - centerY;+ var dyMax = yMax - centerY;+ var xOnCylinderAtMinY = centerX + System.Math.Sqrt(System.Math.Max(0d, (radius * radius) - (dyMin * dyMin)));+ var xOnCylinderAtMaxY = centerX + System.Math.Sqrt(System.Math.Max(0d, (radius * radius) - (dyMax * dyMax)));++ if (xOnCylinderAtMinY <= floorX + tolerance.Linear || xOnCylinderAtMaxY <= floorX + tolerance.Linear)+ {+ return KernelResult<BrepBody>.Failure([+ new KernelDiagnostic(+ KernelDiagnosticCode.NotImplemented,+ KernelDiagnosticSeverity.Error,+ "Boolean Subtract: bounded cylinder-root open-slot rebuild requires strictly positive slot side-wall span between the floor plane and cylindrical wall.",+ "BrepBooleanCylinderOpenSlotBuilder.Build"),+ ]);+ }++ var topArcMax = new Point3D(xOnCylinderAtMaxY, yMax, maxZ);+ var topArcMin = new Point3D(xOnCylinderAtMinY, yMin, maxZ);+ var bottomArcMax = new Point3D(xOnCylinderAtMaxY, yMax, minZ);+ var bottomArcMin = new Point3D(xOnCylinderAtMinY, yMin, minZ);++ var topFloorMax = new Point3D(floorX, yMax, maxZ);+ var topFloorMin = new Point3D(floorX, yMin, maxZ);+ var bottomFloorMax = new Point3D(floorX, yMax, minZ);+ var bottomFloorMin = new Point3D(floorX, yMin, minZ);++ var builder = new TopologyBuilder();+ var vTopArcMax = builder.AddVertex();+ var vTopArcMin = builder.AddVertex();+ var vBottomArcMax = builder.AddVertex();+ var vBottomArcMin = builder.AddVertex();+ var vTopFloorMax = builder.AddVertex();+ var vTopFloorMin = builder.AddVertex();+ var vBottomFloorMax = builder.AddVertex();+ var vBottomFloorMin = builder.AddVertex();++ var eTopArc = builder.AddEdge(vTopArcMax, vTopArcMin);+ var eBottomArc = builder.AddEdge(vBottomArcMin, vBottomArcMax);+ var eCylMax = builder.AddEdge(vBottomArcMax, vTopArcMax);+ var eCylMin = builder.AddEdge(vTopArcMin, vBottomArcMin);+ var eTopFloor = builder.AddEdge(vTopFloorMax, vTopFloorMin);+ var eBottomFloor = builder.AddEdge(vBottomFloorMin, vBottomFloorMax);+ var eFloorMax = builder.AddEdge(vBottomFloorMax, vTopFloorMax);+ var eFloorMin = builder.AddEdge(vTopFloorMin, vBottomFloorMin);+ var eTopRadialMax = builder.AddEdge(vTopArcMax, vTopFloorMax);+ var eTopRadialMin = builder.AddEdge(vTopFloorMin, vTopArcMin);+ var eBottomRadialMax = builder.AddEdge(vBottomFloorMax, vBottomArcMax);+ var eBottomRadialMin = builder.AddEdge(vBottomArcMin, vBottomFloorMin);++ var sideCylinderFace = AddFaceWithLoop(builder, [+ EdgeUse.Forward(eCylMax),+ EdgeUse.Forward(eTopArc),+ EdgeUse.Forward(eCylMin),+ EdgeUse.Forward(eBottomArc),+ ]);++ var topCapFace = AddFaceWithLoop(builder, [+ EdgeUse.Reversed(eTopArc),+ EdgeUse.Forward(eTopRadialMax),+ EdgeUse.Forward(eTopFloor),+ EdgeUse.Forward(eTopRadialMin),+ ]);++ var bottomCapFace = AddFaceWithLoop(builder, [+ EdgeUse.Reversed(eBottomArc),+ EdgeUse.Reversed(eBottomRadialMin),+ EdgeUse.Forward(eBottomFloor),+ EdgeUse.Forward(eBottomRadialMax),+ ]);++ var floorFace = AddFaceWithLoop(builder, [+ EdgeUse.Reversed(eTopFloor),+ EdgeUse.Forward(eFloorMax),+ EdgeUse.Forward(eBottomFloor),+ EdgeUse.Reversed(eFloorMin),+ ]);++ var sideMaxFace = AddFaceWithLoop(builder, [+ EdgeUse.Reversed(eTopRadialMax),+ EdgeUse.Reversed(eCylMax),+ EdgeUse.Reversed(eBottomRadialMax),+ EdgeUse.Forward(eFloorMax),+ ]);++ var sideMinFace = AddFaceWithLoop(builder, [+ EdgeUse.Reversed(eTopRadialMin),+ EdgeUse.Forward(eCylMin),+ EdgeUse.Reversed(eBottomRadialMin),+ EdgeUse.Reversed(eFloorMin),+ ]);++ var shell = builder.AddShell([sideCylinderFace, topCapFace, bottomCapFace, floorFace, sideMaxFace, sideMinFace]);+ 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 topCenter = new Point3D(centerX, centerY, maxZ);+ var bottomCenter = new Point3D(centerX, centerY, minZ);++ var thetaMax = NormalizeAngle(System.Math.Atan2(yMax - centerY, xOnCylinderAtMaxY - centerX));+ var thetaMin = NormalizeAngle(System.Math.Atan2(yMin - centerY, xOnCylinderAtMinY - centerX));+ var topArcEnd = thetaMin < thetaMax ? thetaMin + (2d * double.Pi) : thetaMin;+ var bottomArcEnd = thetaMax < thetaMin ? thetaMax + (2d * double.Pi) : thetaMax;++ geometry.AddCurve(new CurveGeometryId(1), CurveGeometry.FromCircle(new Circle3Curve(topCenter, zAxis, radius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(2), CurveGeometry.FromCircle(new Circle3Curve(bottomCenter, zAxis, radius, xAxis)));+ geometry.AddCurve(new CurveGeometryId(3), CurveGeometry.FromLine(new Line3Curve(bottomArcMax, zAxis)));+ geometry.AddCurve(new CurveGeometryId(4), CurveGeometry.FromLine(new Line3Curve(topArcMin, Direction3D.Create(new Vector3D(0d, 0d, -1d)))));+ geometry.AddCurve(new CurveGeometryId(5), CurveGeometry.FromLine(new Line3Curve(topFloorMax, Direction3D.Create(new Vector3D(0d, -1d, 0d)))));+ geometry.AddCurve(new CurveGeometryId(6), CurveGeometry.FromLine(new Line3Curve(bottomFloorMin, yAxis)));+ geometry.AddCurve(new CurveGeometryId(7), CurveGeometry.FromLine(new Line3Curve(bottomFloorMax, zAxis)));+ geometry.AddCurve(new CurveGeometryId(8), CurveGeometry.FromLine(new Line3Curve(topFloorMin, Direction3D.Create(new Vector3D(0d, 0d, -1d)))));+ geometry.AddCurve(new CurveGeometryId(9), CurveGeometry.FromLine(new Line3Curve(topArcMax, Direction3D.Create(new Vector3D(floorX - xOnCylinderAtMaxY, 0d, 0d)))));+ geometry.AddCurve(new CurveGeometryId(10), CurveGeometry.FromLine(new Line3Curve(topFloorMin, Direction3D.Create(new Vector3D(xOnCylinderAtMinY - floorX, 0d, 0d)))));+ geometry.AddCurve(new CurveGeometryId(11), CurveGeometry.FromLine(new Line3Curve(bottomFloorMax, Direction3D.Create(new Vector3D(xOnCylinderAtMaxY - floorX, 0d, 0d)))));+ geometry.AddCurve(new CurveGeometryId(12), CurveGeometry.FromLine(new Line3Curve(bottomArcMin, Direction3D.Create(new Vector3D(floorX - xOnCylinderAtMinY, 0d, 0d)))));++ geometry.AddSurface(new SurfaceGeometryId(1), SurfaceGeometry.FromCylinder(new CylinderSurface(new Point3D(centerX, centerY, minZ), zAxis, radius, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(2), SurfaceGeometry.FromPlane(new PlaneSurface(topCenter, zAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(3), SurfaceGeometry.FromPlane(new PlaneSurface(bottomCenter, Direction3D.Create(new Vector3D(0d, 0d, -1d)), yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(4), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(floorX, centerY, 0d), Direction3D.Create(new Vector3D(1d, 0d, 0d)), yAxis)));+ geometry.AddSurface(new SurfaceGeometryId(5), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(centerX, yMax, 0d), yAxis, xAxis)));+ geometry.AddSurface(new SurfaceGeometryId(6), SurfaceGeometry.FromPlane(new PlaneSurface(new Point3D(centerX, yMin, 0d), Direction3D.Create(new Vector3D(0d, -1d, 0d)), Direction3D.Create(new Vector3D(-1d, 0d, 0d)))));++ var bindings = new BrepBindingModel();+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eTopArc, new CurveGeometryId(1), new ParameterInterval(thetaMax, topArcEnd)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eBottomArc, new CurveGeometryId(2), new ParameterInterval(thetaMin, bottomArcEnd)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eCylMax, new CurveGeometryId(3), new ParameterInterval(0d, maxZ - minZ)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eCylMin, new CurveGeometryId(4), new ParameterInterval(0d, maxZ - minZ)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eTopFloor, new CurveGeometryId(5), new ParameterInterval(0d, yMax - yMin)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eBottomFloor, new CurveGeometryId(6), new ParameterInterval(0d, yMax - yMin)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eFloorMax, new CurveGeometryId(7), new ParameterInterval(0d, maxZ - minZ)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eFloorMin, new CurveGeometryId(8), new ParameterInterval(0d, maxZ - minZ)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eTopRadialMax, new CurveGeometryId(9), new ParameterInterval(0d, xOnCylinderAtMaxY - floorX)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eTopRadialMin, new CurveGeometryId(10), new ParameterInterval(0d, xOnCylinderAtMinY - floorX)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eBottomRadialMax, new CurveGeometryId(11), new ParameterInterval(0d, xOnCylinderAtMaxY - floorX)));+ bindings.AddEdgeBinding(new EdgeGeometryBinding(eBottomRadialMin, new CurveGeometryId(12), new ParameterInterval(0d, xOnCylinderAtMinY - floorX)));++ bindings.AddFaceBinding(new FaceGeometryBinding(sideCylinderFace, new SurfaceGeometryId(1)));+ bindings.AddFaceBinding(new FaceGeometryBinding(topCapFace, new SurfaceGeometryId(2)));+ bindings.AddFaceBinding(new FaceGeometryBinding(bottomCapFace, new SurfaceGeometryId(3)));+ bindings.AddFaceBinding(new FaceGeometryBinding(floorFace, new SurfaceGeometryId(4)));+ bindings.AddFaceBinding(new FaceGeometryBinding(sideMaxFace, new SurfaceGeometryId(5)));+ bindings.AddFaceBinding(new FaceGeometryBinding(sideMinFace, new SurfaceGeometryId(6)));++ var points = new Dictionary<VertexId, Point3D>+ {+ [vTopArcMax] = topArcMax,+ [vTopArcMin] = topArcMin,+ [vBottomArcMax] = bottomArcMax,+ [vBottomArcMin] = bottomArcMin,+ [vTopFloorMax] = topFloorMax,+ [vTopFloorMin] = topFloorMin,+ [vBottomFloorMax] = bottomFloorMax,+ [vBottomFloorMin] = bottomFloorMin,+ };++ var body = new BrepBody(builder.Model, geometry, bindings, points, composition);+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);+ return validation.IsSuccess+ ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);+ }++ private static FaceId AddFaceWithLoop(TopologyBuilder builder, IReadOnlyList<EdgeUse> edgeUses)+ {+ var loopId = builder.AllocateLoopId();+ var coedgeIds = new CoedgeId[edgeUses.Count];+ for (var i = 0; i < edgeUses.Count; i++)+ {+ coedgeIds[i] = builder.AllocateCoedgeId();+ }++ for (var i = 0; i < edgeUses.Count; i++)+ {+ var next = coedgeIds[(i + 1) % edgeUses.Count];+ var prev = coedgeIds[(i + edgeUses.Count - 1) % edgeUses.Count];+ builder.AddCoedge(new Coedge(coedgeIds[i], edgeUses[i].EdgeId, loopId, next, prev, edgeUses[i].IsReversed));+ }++ builder.AddLoop(new Loop(loopId, coedgeIds));+ return builder.AddFace([loopId]);+ }++ private static double NormalizeAngle(double value)+ {+ var angle = value % (2d * double.Pi);+ return angle < 0d ? angle + (2d * double.Pi) : angle;+ }++ private readonly record struct EdgeUse(EdgeId EdgeId, bool IsReversed)+ {+ public static EdgeUse Forward(EdgeId edgeId) => new(edgeId, false);+ public static EdgeUse Reversed(EdgeId edgeId) => new(edgeId, true);+ }+}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.csindex f9a3fe83..5daf3521 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs@@ -8,7 +8,8 @@ public sealed record SafeBooleanComposition(AxisAlignedBoxExtents OuterBox,IReadOnlyList<SupportedBooleanHole> Holes,SafeBooleanRootDescriptor? Root = null,- IReadOnlyList<AxisAlignedBoxExtents>? OccupiedCells = null)+ IReadOnlyList<AxisAlignedBoxExtents>? OccupiedCells = null,+ IReadOnlyList<SupportedCylinderOpenSlot>? OpenSlots = null){public SafeBooleanRootDescriptor RootDescriptor => Root ?? SafeBooleanRootDescriptor.FromBox(OuterBox);@@ -32,7 +33,8 @@ public sealed record SafeBooleanComposition(cell.MinY + translation.Y,cell.MaxY + translation.Y,cell.MinZ + translation.Z,- cell.MaxZ + translation.Z)).ToArray());+ cell.MaxZ + translation.Z)).ToArray(),+ OpenSlots?.Select(slot => slot.Translate(translation)).ToArray());}}@@ -127,6 +129,19 @@ public readonly record struct SupportedBooleanHole(};}+public readonly record struct SupportedCylinderOpenSlot(+ AxisAlignedBoxExtents ToolExtents)+{+ public SupportedCylinderOpenSlot Translate(Vector3D translation)+ => new(new AxisAlignedBoxExtents(+ ToolExtents.MinX + translation.X,+ ToolExtents.MaxX + translation.X,+ ToolExtents.MinY + translation.Y,+ ToolExtents.MaxY + translation.Y,+ ToolExtents.MinZ + translation.Z,+ ToolExtents.MaxZ + translation.Z));+}+public static class BrepBooleanSafeComposition{public static bool TryRecognize(BrepBody body, ToleranceContext tolerance, out SafeBooleanComposition composition, out string reason)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex a8f26f01..034e20dd 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -211,16 +211,12 @@ public sealed class FirmamentBooleanCanonicalSuccessTests}[Fact]- public void CylinderRootKeywayPressureCase_Fails_WithExplicitOpenSlotRebuildDiagnostic()+ public void CylinderRootKeywayPressureCase_Succeeds(){- var source = FirmamentCorpusHarness.ReadFixtureText("Aetheris.Firmament.FrictionLab/Cases/shaft-keyway/part.firmament");- var result = FirmamentCorpusHarness.Compile(source);+ var result = ExportFixture("Aetheris.Firmament.FrictionLab/Cases/shaft-keyway/part.firmament");- Assert.False(result.Compilation.IsSuccess);- Assert.Contains(result.Compilation.Diagnostics, diagnostic =>- diagnostic.Code == KernelDiagnosticCode.NotImplemented- && diagnostic.Source == "BrepBoolean.RebuildResult"- && diagnostic.Message.Contains("bounded cylinder-root keyway family is recognized", StringComparison.Ordinal));+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.Contains("CYLINDRICAL_SURFACE", result.Value.StepText, StringComparison.Ordinal);}[Fact]@@ -313,6 +309,51 @@ public sealed class FirmamentBooleanCanonicalSuccessTests&& diagnostic.Message.Contains("requires a single exterior mouth and cannot cut through the far-side cylindrical wall", StringComparison.Ordinal));}+ [Fact]+ public void CylinderRootKeywayOutsideBoundedSubset_Fails_WhenSideWallsAreTangent()+ {+ const string source = """+ firmament:+ version: 1++ model:+ name: keyway_tangent_side_walls+ units: mm++ ops[2]:+ -+ op: cylinder+ id: shaft+ radius: 15+ height: 80++ -+ op: subtract+ id: tangent_keyway+ from: shaft+ with:+ op: box+ size[3]:+ 10+ 30+ 90+ place:+ on: origin+ offset[3]:+ 10+ 0+ 0+ """;++ var result = FirmamentCorpusHarness.Compile(source);++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Code == KernelDiagnosticCode.NotImplemented+ && diagnostic.Source == "BrepBoolean.RebuildResult"+ && diagnostic.Message.Contains("tangent side walls are unsupported", StringComparison.Ordinal));+ }+public static TheoryData<string, string, string> UnsupportedBoxTorusVariantSources =>new(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex 4e55a3d0..d53ee611 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -531,17 +531,16 @@ public sealed class FirmamentBuildAndExportTests}[Fact]- public void Run_FrictionLabShaftKeyway_RemainsExplicitlyUnsupported()+ public void Run_FrictionLabShaftKeyway_SucceedsAndExports(){var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/shaft-keyway/part.firmament");var result = FirmamentBuildAndExport.Run(fullSourcePath);- Assert.False(result.IsSuccess);- Assert.Contains(result.Diagnostics, diagnostic =>- diagnostic.Message.Contains("Requested boolean feature 'keyway' (subtract) could not be executed.", StringComparison.Ordinal));- Assert.Contains(result.Diagnostics, diagnostic =>- diagnostic.Source == "BrepBoolean.RebuildResult"- && diagnostic.Message.Contains("bounded cylinder-root keyway family is recognized", StringComparison.Ordinal));+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));+ Assert.Equal("keyway", result.Value.Export.ExportedFeatureId);+ Assert.Equal("boolean", result.Value.Export.ExportedBodyCategory);+ Assert.Equal("subtract", result.Value.Export.ExportedFeatureKind);+ Assert.Contains("CYLINDRICAL_SURFACE", result.Value.Export.StepText, StringComparison.Ordinal);}[Fact]