Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add bounded polygonal-extrusion safe roots for prismatic subtract

Yuechen Li058511f93cb2
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 0252bfe4..2ba13fa5 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -1662,6 +1662,63 @@ public sealed class BrepBooleanTests
Assert.Contains("through-cut tool", diagnostic.Message, StringComparison.Ordinal);
}
+ [Fact]
+ public void ClassifyBooleanCase_RoundedCornerRoot_PrismaticSubtract_RecognizesPolygonalSafeRoot()
+ {
+ var root = StandardLibraryPrimitives.CreateRoundedCornerBox(24d, 18d, 20d, 4d).Value;
+ var tool = StandardLibraryPrimitives.CreateSlotCut(10d, 4d, 24d, 2d).Value;
+
+ var classification = BrepBoolean.ClassifyBooleanCase(root, tool, BooleanOperation.Subtract);
+
+ Assert.Equal(BooleanExecutionClass.PlanarOnly, classification.ExecutionClass);
+ Assert.NotNull(classification.LeftSafeComposition);
+ Assert.Equal(SafeBooleanRootKind.PolygonalExtrusion, classification.LeftSafeComposition!.RootDescriptor.Kind);
+ Assert.NotNull(classification.RightPrismaticTool);
+ Assert.Null(classification.UnsupportedReason);
+ }
+
+ [Fact]
+ public void PolygonalRoot_PrismaticSubtract_Succeeds()
+ {
+ var root = StandardLibraryPrimitives.CreateRoundedCornerBox(24d, 18d, 20d, 4d).Value;
+ var tool = StandardLibraryPrimitives.CreateSlotCut(10d, 4d, 24d, 2d).Value;
+
+ var result = BrepBoolean.Subtract(root, tool);
+
+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));
+ Assert.NotNull(result.Value.SafeBooleanComposition?.ThroughVoids);
+ Assert.Equal(SafeBooleanRootKind.PolygonalExtrusion, result.Value.SafeBooleanComposition!.RootDescriptor.Kind);
+ Assert.Single(result.Value.SafeBooleanComposition.ThroughVoids!.PrismaticVoids);
+ }
+
+ [Fact]
+ public void PolygonalRoot_PrismaticSubtract_OutsidePolygonButInsideAabb_RemainsRejected()
+ {
+ var root = StandardLibraryPrimitives.CreateRoundedCornerBox(24d, 18d, 20d, 4d).Value;
+ var cornerBiasedTool = TransformBody(
+ StandardLibraryPrimitives.CreateSlotCut(3d, 3d, 24d, 1.5d).Value,
+ Transform3D.CreateTranslation(new Vector3D(10.2d, 7.2d, 0d)));
+
+ var result = BrepBoolean.Subtract(root, cornerBiasedTool);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Contains("polygonal root footprint", diagnostic.Message, StringComparison.Ordinal);
+ }
+
+ [Fact]
+ public void PolygonalRoot_PrismaticSubtract_ShortTool_RemainsRejected()
+ {
+ var root = StandardLibraryPrimitives.CreateRoundedCornerBox(24d, 18d, 20d, 4d).Value;
+ var shortTool = StandardLibraryPrimitives.CreateSlotCut(10d, 4d, 8d, 2d).Value;
+
+ var result = BrepBoolean.Subtract(root, shortTool);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Contains("through-cut tool", diagnostic.Message, StringComparison.Ordinal);
+ }
+
[Fact]
public void MixedThroughVoid_AnalyticPlusSlot_Succeeds()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
index e4a72f8f..764e5c1a 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
@@ -276,7 +276,7 @@ public static class BrepBoolean
{
var supportsBoxPrismaticContinuation = operation == BooleanOperation.Subtract
&& leftHasSafeComposition
- && leftSafeComposition is { RootDescriptor.Kind: SafeBooleanRootKind.Box }
+ && leftSafeComposition is { RootDescriptor.Kind: SafeBooleanRootKind.Box or SafeBooleanRootKind.PolygonalExtrusion }
&& (leftSafeComposition.Holes.Count > 0 || (leftSafeComposition.OpenSlots?.Count ?? 0) > 0);
if (!supportsBoxPrismaticContinuation)
{
@@ -367,7 +367,9 @@ public static class BrepBoolean
BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, BooleanOperation.Intersect, out _)
&& ((context.LeftHasSafeComposition
&& context.LeftSafeComposition is not null
- && context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Box)
+ && (context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Box
+ || (context.Operation == BooleanOperation.Subtract
+ && context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.PolygonalExtrusion)))
|| context.LeftRecognizedBox)
&& (context.RightRecognizedBox
|| (context.Operation == BooleanOperation.Subtract && context.RightPrismaticTool is not null)),
@@ -1010,7 +1012,12 @@ public static class BrepBoolean
: new BooleanRebuildData(classification, RebuiltBody: null, Diagnostics: rebuiltMixed.Diagnostics);
}
- var rebuiltPrismSubtract = BrepBooleanBoxPrismThroughCutBuilder.Build(leftComposition.RootDescriptor.Box, prismaticTool.Footprint, request.Tolerance ?? ToleranceContext.Default);
+ KernelResult<BrepBody> rebuiltPrismSubtract = leftComposition.RootDescriptor.Kind switch
+ {
+ SafeBooleanRootKind.PolygonalExtrusion when leftComposition.RootDescriptor.PolygonFootprint is { Count: > 2 } polygonFootprint
+ => BrepBooleanPolygonalPrismThroughCutBuilder.Build(polygonFootprint, leftComposition.RootDescriptor.Box, prismaticTool.Footprint),
+ _ => BrepBooleanBoxPrismThroughCutBuilder.Build(leftComposition.RootDescriptor.Box, prismaticTool.Footprint, request.Tolerance ?? ToleranceContext.Default),
+ };
if (!rebuiltPrismSubtract.IsSuccess)
{
return new BooleanRebuildData(classification, RebuiltBody: null, Diagnostics: rebuiltPrismSubtract.Diagnostics);
@@ -1789,9 +1796,10 @@ public static class BrepBoolean
out string? unsupportedReason)
{
unsupportedReason = null;
- if (leftComposition.RootDescriptor.Kind != SafeBooleanRootKind.Box)
+ var rootKind = leftComposition.RootDescriptor.Kind;
+ if (rootKind is not (SafeBooleanRootKind.Box or SafeBooleanRootKind.PolygonalExtrusion))
{
- unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires a recognized safe box root.";
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires a recognized safe box or polygonal-extrusion root.";
return false;
}
@@ -1815,17 +1823,66 @@ public static class BrepBoolean
if (!hasPriorSubtractHistory
&& (prismTool.Bounds.MinZ > root.MinZ + tolerance.Linear || prismTool.Bounds.MaxZ < root.MaxZ - tolerance.Linear))
{
- unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires a through-cut tool that spans the full box root height.";
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires a through-cut tool that spans the full root height.";
return false;
}
- foreach (var point in prismTool.Footprint)
+ if (rootKind == SafeBooleanRootKind.Box)
+ {
+ foreach (var point in prismTool.Footprint)
+ {
+ var insideX = point.X > root.MinX + tolerance.Linear && point.X < root.MaxX - tolerance.Linear;
+ var insideY = point.Y > root.MinY + tolerance.Linear && point.Y < root.MaxY - tolerance.Linear;
+ if (!insideX || !insideY)
+ {
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires footprint vertices strictly inside the box-root XY bounds.";
+ return false;
+ }
+ }
+ }
+ else if (leftComposition.RootDescriptor.PolygonFootprint is { Count: > 2 } rootFootprint)
+ {
+ if (!TryValidatePolygonalRootContainment(prismTool.Footprint, rootFootprint, tolerance, out unsupportedReason))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires polygonal roots to carry a valid footprint.";
+ return false;
+ }
+
+ return true;
+ }
+
+ private static bool TryValidatePolygonalRootContainment(
+ IReadOnlyList<(double X, double Y)> toolFootprint,
+ IReadOnlyList<(double X, double Y)> rootFootprint,
+ ToleranceContext tolerance,
+ out string unsupportedReason)
+ {
+ unsupportedReason = string.Empty;
+ foreach (var point in toolFootprint)
+ {
+ if (!BrepBooleanPrismaticFootprintContainment.TryComputeContainmentMargin(point, rootFootprint, tolerance, out var edgeDistance)
+ || edgeDistance <= tolerance.Linear)
+ {
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires footprint vertices strictly inside the polygonal root footprint.";
+ return false;
+ }
+ }
+
+ for (var i = 0; i < toolFootprint.Count; i++)
{
- var insideX = point.X > root.MinX + tolerance.Linear && point.X < root.MaxX - tolerance.Linear;
- var insideY = point.Y > root.MinY + tolerance.Linear && point.Y < root.MaxY - tolerance.Linear;
- if (!insideX || !insideY)
+ var next = (i + 1) % toolFootprint.Count;
+ var midpoint = (
+ X: 0.5d * (toolFootprint[i].X + toolFootprint[next].X),
+ Y: 0.5d * (toolFootprint[i].Y + toolFootprint[next].Y));
+ if (!BrepBooleanPrismaticFootprintContainment.TryComputeContainmentMargin(midpoint, rootFootprint, tolerance, out var edgeDistance)
+ || edgeDistance <= tolerance.Linear)
{
- unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires footprint vertices strictly inside the box-root XY bounds.";
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires tool edges to remain inside the polygonal root footprint.";
return false;
}
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs
index 31f88274..8848b725 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs
@@ -1,11 +1,6 @@
-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;
@@ -16,200 +11,14 @@ public static class BrepBooleanBoxPrismThroughCutBuilder
IReadOnlyList<(double X, double Y)> footprint,
ToleranceContext _)
{
- if (footprint.Count < 3)
+ var outerFootprint = new[]
{
- return KernelResult<BrepBody>.Failure([
- new KernelDiagnostic(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error,
- "Bounded prism-family subtract requires a valid prism footprint with at least three vertices.",
- "BrepBooleanBoxPrismThroughCutBuilder.Build")
- ]);
- }
-
- var zMin = box.MinZ;
- var zMax = box.MaxZ;
-
- var outerBottomPoints = new[]
- {
- new Point3D(box.MinX, box.MinY, zMin),
- new Point3D(box.MaxX, box.MinY, zMin),
- new Point3D(box.MaxX, box.MaxY, zMin),
- new Point3D(box.MinX, box.MaxY, zMin),
- };
- var outerTopPoints = outerBottomPoints.Select(point => new Point3D(point.X, point.Y, zMax)).ToArray();
-
- var n = footprint.Count;
- var innerBottomPoints = footprint.Select(point => new Point3D(point.X, point.Y, zMin)).ToArray();
- var innerTopPoints = footprint.Select(point => new Point3D(point.X, point.Y, zMax)).ToArray();
-
- var builder = new TopologyBuilder();
-
- var outerBottomVertices = outerBottomPoints.Select(_ => builder.AddVertex()).ToArray();
- var outerTopVertices = outerTopPoints.Select(_ => builder.AddVertex()).ToArray();
- var innerBottomVertices = innerBottomPoints.Select(_ => builder.AddVertex()).ToArray();
- var innerTopVertices = innerTopPoints.Select(_ => builder.AddVertex()).ToArray();
-
- var outerBottomEdges = new EdgeId[4];
- var outerTopEdges = new EdgeId[4];
- var outerVerticalEdges = new EdgeId[4];
- for (var i = 0; i < 4; i++)
- {
- var next = (i + 1) % 4;
- outerBottomEdges[i] = builder.AddEdge(outerBottomVertices[i], outerBottomVertices[next]);
- outerTopEdges[i] = builder.AddEdge(outerTopVertices[i], outerTopVertices[next]);
- outerVerticalEdges[i] = builder.AddEdge(outerBottomVertices[i], outerTopVertices[i]);
- }
-
- var innerBottomEdges = new EdgeId[n];
- var innerTopEdges = new EdgeId[n];
- var innerVerticalEdges = new EdgeId[n];
- for (var i = 0; i < n; i++)
- {
- var next = (i + 1) % n;
- innerBottomEdges[i] = builder.AddEdge(innerBottomVertices[i], innerBottomVertices[next]);
- innerTopEdges[i] = builder.AddEdge(innerTopVertices[i], innerTopVertices[next]);
- innerVerticalEdges[i] = builder.AddEdge(innerBottomVertices[i], innerTopVertices[i]);
- }
-
- var bottomFace = AddFaceWithLoops(builder,
- [EdgeUse.Forward(outerBottomEdges[0]), EdgeUse.Forward(outerBottomEdges[1]), EdgeUse.Forward(outerBottomEdges[2]), EdgeUse.Forward(outerBottomEdges[3])],
- [.. innerBottomEdges.Select(EdgeUse.Reversed)]);
-
- var topFace = AddFaceWithLoops(builder,
- [EdgeUse.Reversed(outerTopEdges[3]), EdgeUse.Reversed(outerTopEdges[2]), EdgeUse.Reversed(outerTopEdges[1]), EdgeUse.Reversed(outerTopEdges[0])],
- [.. innerTopEdges.Select(EdgeUse.Forward)]);
-
- var faces = new List<FaceId>(n + 6)
- {
- bottomFace,
- topFace,
- AddFaceWithLoop(builder, [EdgeUse.Forward(outerBottomEdges[0]), EdgeUse.Forward(outerVerticalEdges[1]), EdgeUse.Reversed(outerTopEdges[0]), EdgeUse.Reversed(outerVerticalEdges[0])]),
- AddFaceWithLoop(builder, [EdgeUse.Forward(outerBottomEdges[1]), EdgeUse.Forward(outerVerticalEdges[2]), EdgeUse.Reversed(outerTopEdges[1]), EdgeUse.Reversed(outerVerticalEdges[1])]),
- AddFaceWithLoop(builder, [EdgeUse.Forward(outerBottomEdges[2]), EdgeUse.Forward(outerVerticalEdges[3]), EdgeUse.Reversed(outerTopEdges[2]), EdgeUse.Reversed(outerVerticalEdges[2])]),
- AddFaceWithLoop(builder, [EdgeUse.Forward(outerBottomEdges[3]), EdgeUse.Forward(outerVerticalEdges[0]), EdgeUse.Reversed(outerTopEdges[3]), EdgeUse.Reversed(outerVerticalEdges[3])]),
+ (box.MinX, box.MinY),
+ (box.MaxX, box.MinY),
+ (box.MaxX, box.MaxY),
+ (box.MinX, box.MaxY),
};
- for (var i = 0; i < n; i++)
- {
- var next = (i + 1) % n;
- faces.Add(AddFaceWithLoop(builder,
- [
- EdgeUse.Reversed(innerBottomEdges[i]),
- EdgeUse.Forward(innerVerticalEdges[i]),
- EdgeUse.Forward(innerTopEdges[i]),
- EdgeUse.Reversed(innerVerticalEdges[next]),
- ]));
- }
-
- var shell = builder.AddShell(faces);
- builder.AddBody([shell]);
-
- var geometry = new BrepGeometryStore();
- var bindings = new BrepBindingModel();
-
- var curveId = 1;
- void AddLinearEdge(EdgeId edgeId, Point3D start, Point3D end)
- {
- var direction = end - start;
- geometry.AddCurve(new CurveGeometryId(curveId), CurveGeometry.FromLine(new Line3Curve(start, Direction3D.Create(direction))));
- bindings.AddEdgeBinding(new EdgeGeometryBinding(edgeId, new CurveGeometryId(curveId), new ParameterInterval(0d, direction.Length)));
- curveId++;
- }
-
- for (var i = 0; i < 4; i++)
- {
- AddLinearEdge(outerBottomEdges[i], outerBottomPoints[i], outerBottomPoints[(i + 1) % 4]);
- AddLinearEdge(outerTopEdges[i], outerTopPoints[i], outerTopPoints[(i + 1) % 4]);
- AddLinearEdge(outerVerticalEdges[i], outerBottomPoints[i], outerTopPoints[i]);
- }
-
- for (var i = 0; i < n; i++)
- {
- var next = (i + 1) % n;
- AddLinearEdge(innerBottomEdges[i], innerBottomPoints[i], innerBottomPoints[next]);
- AddLinearEdge(innerTopEdges[i], innerTopPoints[i], innerTopPoints[next]);
- AddLinearEdge(innerVerticalEdges[i], innerBottomPoints[i], innerTopPoints[i]);
- }
-
- var surfaceId = 1;
- void BindFaceToPlane(FaceId face, Point3D origin, Vector3D normal, Vector3D uAxis)
- {
- var sid = new SurfaceGeometryId(surfaceId++);
- geometry.AddSurface(sid, SurfaceGeometry.FromPlane(new PlaneSurface(origin, Direction3D.Create(normal), Direction3D.Create(uAxis))));
- bindings.AddFaceBinding(new FaceGeometryBinding(face, sid));
- }
-
- BindFaceToPlane(bottomFace, outerBottomPoints[0], new Vector3D(0d, 0d, -1d), new Vector3D(1d, 0d, 0d));
- BindFaceToPlane(topFace, outerTopPoints[0], new Vector3D(0d, 0d, 1d), new Vector3D(1d, 0d, 0d));
-
- BindFaceToPlane(faces[2], new Point3D(box.MinX, box.MinY, zMin), new Vector3D(0d, -1d, 0d), new Vector3D(1d, 0d, 0d));
- BindFaceToPlane(faces[3], new Point3D(box.MaxX, box.MinY, zMin), new Vector3D(1d, 0d, 0d), new Vector3D(0d, 1d, 0d));
- BindFaceToPlane(faces[4], new Point3D(box.MaxX, box.MaxY, zMin), new Vector3D(0d, 1d, 0d), new Vector3D(-1d, 0d, 0d));
- BindFaceToPlane(faces[5], new Point3D(box.MinX, box.MaxY, zMin), new Vector3D(-1d, 0d, 0d), new Vector3D(0d, -1d, 0d));
-
- for (var i = 0; i < n; i++)
- {
- var next = (i + 1) % n;
- var edgeDir = innerBottomPoints[next] - innerBottomPoints[i];
- var inwardNormal = Direction3D.Create(new Vector3D(edgeDir.Y, -edgeDir.X, 0d));
- BindFaceToPlane(faces[6 + i], innerBottomPoints[i], inwardNormal.ToVector(), new Vector3D(0d, 0d, 1d));
- }
-
- var vertexPoints = new Dictionary<VertexId, Point3D>();
- for (var i = 0; i < 4; i++)
- {
- vertexPoints[outerBottomVertices[i]] = outerBottomPoints[i];
- vertexPoints[outerTopVertices[i]] = outerTopPoints[i];
- }
-
- for (var i = 0; i < n; i++)
- {
- vertexPoints[innerBottomVertices[i]] = innerBottomPoints[i];
- vertexPoints[innerTopVertices[i]] = innerTopPoints[i];
- }
-
- var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints);
- var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);
- return validation.IsSuccess
- ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)
- : KernelResult<BrepBody>.Failure(validation.Diagnostics);
- }
-
- private static FaceId AddFaceWithLoops(TopologyBuilder builder, IReadOnlyList<EdgeUse> outerLoop, IReadOnlyList<EdgeUse> innerLoop)
- {
- var outerLoopId = AddLoop(builder, outerLoop);
- var innerLoopId = AddLoop(builder, innerLoop);
- return builder.AddFace([outerLoopId, innerLoopId]);
- }
-
- private static FaceId AddFaceWithLoop(TopologyBuilder builder, IReadOnlyList<EdgeUse> edgeUses)
- {
- var loopId = AddLoop(builder, edgeUses);
- return builder.AddFace([loopId]);
- }
-
- private static LoopId AddLoop(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 loopId;
- }
-
- 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);
+ return BrepBooleanPolygonalPrismThroughCutBuilder.Build(outerFootprint, box, footprint);
}
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPolygonalPrismThroughCutBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPolygonalPrismThroughCutBuilder.cs
new file mode 100644
index 00000000..5a197bdf
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPolygonalPrismThroughCutBuilder.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.Results;
+using Aetheris.Kernel.Core.Topology;
+
+namespace Aetheris.Kernel.Core.Brep.Boolean;
+
+internal static class BrepBooleanPolygonalPrismThroughCutBuilder
+{
+ public static KernelResult<BrepBody> Build(
+ IReadOnlyList<(double X, double Y)> outerFootprint,
+ AxisAlignedBoxExtents rootBounds,
+ IReadOnlyList<(double X, double Y)> innerFootprint)
+ {
+ if (outerFootprint.Count < 3 || innerFootprint.Count < 3)
+ {
+ return KernelResult<BrepBody>.Failure([
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ "Bounded prism-family subtract requires valid outer/inner footprints with at least three vertices.",
+ "BrepBooleanPolygonalPrismThroughCutBuilder.Build")
+ ]);
+ }
+
+ var zMin = rootBounds.MinZ;
+ var zMax = rootBounds.MaxZ;
+
+ var outerBottomPoints = outerFootprint.Select(point => new Point3D(point.X, point.Y, zMin)).ToArray();
+ var outerTopPoints = outerFootprint.Select(point => new Point3D(point.X, point.Y, zMax)).ToArray();
+ var innerBottomPoints = innerFootprint.Select(point => new Point3D(point.X, point.Y, zMin)).ToArray();
+ var innerTopPoints = innerFootprint.Select(point => new Point3D(point.X, point.Y, zMax)).ToArray();
+
+ var builder = new TopologyBuilder();
+
+ var outerBottomVertices = outerBottomPoints.Select(_ => builder.AddVertex()).ToArray();
+ var outerTopVertices = outerTopPoints.Select(_ => builder.AddVertex()).ToArray();
+ var innerBottomVertices = innerBottomPoints.Select(_ => builder.AddVertex()).ToArray();
+ var innerTopVertices = innerTopPoints.Select(_ => builder.AddVertex()).ToArray();
+
+ var outerBottomEdges = BuildEdgeLoop(builder, outerBottomVertices);
+ var outerTopEdges = BuildEdgeLoop(builder, outerTopVertices);
+ var innerBottomEdges = BuildEdgeLoop(builder, innerBottomVertices);
+ var innerTopEdges = BuildEdgeLoop(builder, innerTopVertices);
+ var outerVerticalEdges = BuildVerticalEdges(builder, outerBottomVertices, outerTopVertices);
+ var innerVerticalEdges = BuildVerticalEdges(builder, innerBottomVertices, innerTopVertices);
+
+ var bottomFace = AddFaceWithLoops(
+ builder,
+ [.. outerBottomEdges.Select(EdgeUse.Forward)],
+ [.. innerBottomEdges.Select(EdgeUse.Reversed)]);
+
+ var topFace = AddFaceWithLoops(
+ builder,
+ [.. outerTopEdges.Reverse().Select(EdgeUse.Reversed)],
+ [.. innerTopEdges.Select(EdgeUse.Forward)]);
+
+ var faces = new List<FaceId> { bottomFace, topFace };
+ faces.AddRange(AddSideFaces(builder, outerBottomEdges, outerTopEdges, outerVerticalEdges, reverseInnerOrientation: false));
+ faces.AddRange(AddSideFaces(builder, innerBottomEdges, innerTopEdges, innerVerticalEdges, reverseInnerOrientation: true));
+
+ var shell = builder.AddShell(faces);
+ builder.AddBody([shell]);
+
+ var geometry = new BrepGeometryStore();
+ var bindings = new BrepBindingModel();
+
+ var curveId = 1;
+ void AddLinearEdge(EdgeId edgeId, Point3D start, Point3D end)
+ {
+ var direction = end - start;
+ geometry.AddCurve(new CurveGeometryId(curveId), CurveGeometry.FromLine(new Line3Curve(start, Direction3D.Create(direction))));
+ bindings.AddEdgeBinding(new EdgeGeometryBinding(edgeId, new CurveGeometryId(curveId), new ParameterInterval(0d, direction.Length)));
+ curveId++;
+ }
+
+ BindLoopEdges(outerBottomEdges, outerBottomPoints, AddLinearEdge);
+ BindLoopEdges(outerTopEdges, outerTopPoints, AddLinearEdge);
+ BindLoopEdges(innerBottomEdges, innerBottomPoints, AddLinearEdge);
+ BindLoopEdges(innerTopEdges, innerTopPoints, AddLinearEdge);
+ BindVerticalEdges(outerVerticalEdges, outerBottomPoints, outerTopPoints, AddLinearEdge);
+ BindVerticalEdges(innerVerticalEdges, innerBottomPoints, innerTopPoints, AddLinearEdge);
+
+ var surfaceId = 1;
+ void BindFaceToPlane(FaceId face, Point3D origin, Vector3D normal, Vector3D uAxis)
+ {
+ var sid = new SurfaceGeometryId(surfaceId++);
+ geometry.AddSurface(sid, SurfaceGeometry.FromPlane(new PlaneSurface(origin, Direction3D.Create(normal), Direction3D.Create(uAxis))));
+ bindings.AddFaceBinding(new FaceGeometryBinding(face, sid));
+ }
+
+ BindFaceToPlane(bottomFace, outerBottomPoints[0], new Vector3D(0d, 0d, -1d), new Vector3D(1d, 0d, 0d));
+ BindFaceToPlane(topFace, outerTopPoints[0], new Vector3D(0d, 0d, 1d), new Vector3D(1d, 0d, 0d));
+
+ var faceIndex = 2;
+ for (var i = 0; i < outerBottomPoints.Length; i++)
+ {
+ var next = (i + 1) % outerBottomPoints.Length;
+ var edgeDir = outerBottomPoints[next] - outerBottomPoints[i];
+ var outwardNormal = Direction3D.Create(new Vector3D(edgeDir.Y, -edgeDir.X, 0d));
+ BindFaceToPlane(faces[faceIndex++], outerBottomPoints[i], outwardNormal.ToVector(), new Vector3D(0d, 0d, 1d));
+ }
+
+ for (var i = 0; i < innerBottomPoints.Length; i++)
+ {
+ var next = (i + 1) % innerBottomPoints.Length;
+ var edgeDir = innerBottomPoints[next] - innerBottomPoints[i];
+ var inwardNormal = Direction3D.Create(new Vector3D(-edgeDir.Y, edgeDir.X, 0d));
+ BindFaceToPlane(faces[faceIndex++], innerBottomPoints[i], inwardNormal.ToVector(), new Vector3D(0d, 0d, 1d));
+ }
+
+ var vertexPoints = new Dictionary<VertexId, Point3D>();
+ for (var i = 0; i < outerBottomVertices.Length; i++)
+ {
+ vertexPoints[outerBottomVertices[i]] = outerBottomPoints[i];
+ vertexPoints[outerTopVertices[i]] = outerTopPoints[i];
+ }
+
+ for (var i = 0; i < innerBottomVertices.Length; i++)
+ {
+ vertexPoints[innerBottomVertices[i]] = innerBottomPoints[i];
+ vertexPoints[innerTopVertices[i]] = innerTopPoints[i];
+ }
+
+ var body = new BrepBody(builder.Model, geometry, bindings, vertexPoints);
+ var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);
+ return validation.IsSuccess
+ ? KernelResult<BrepBody>.Success(body, validation.Diagnostics)
+ : KernelResult<BrepBody>.Failure(validation.Diagnostics);
+ }
+
+ private static EdgeId[] BuildEdgeLoop(TopologyBuilder builder, IReadOnlyList<VertexId> vertices)
+ {
+ var edges = new EdgeId[vertices.Count];
+ for (var i = 0; i < vertices.Count; i++)
+ {
+ edges[i] = builder.AddEdge(vertices[i], vertices[(i + 1) % vertices.Count]);
+ }
+
+ return edges;
+ }
+
+ private static EdgeId[] BuildVerticalEdges(TopologyBuilder builder, IReadOnlyList<VertexId> bottomVertices, IReadOnlyList<VertexId> topVertices)
+ {
+ var edges = new EdgeId[bottomVertices.Count];
+ for (var i = 0; i < bottomVertices.Count; i++)
+ {
+ edges[i] = builder.AddEdge(bottomVertices[i], topVertices[i]);
+ }
+
+ return edges;
+ }
+
+ private static IReadOnlyList<FaceId> AddSideFaces(TopologyBuilder builder, EdgeId[] bottom, EdgeId[] top, EdgeId[] vertical, bool reverseInnerOrientation)
+ {
+ var faces = new List<FaceId>(bottom.Length);
+ for (var i = 0; i < bottom.Length; i++)
+ {
+ var next = (i + 1) % bottom.Length;
+ var uses = reverseInnerOrientation
+ ? new[]
+ {
+ EdgeUse.Reversed(bottom[i]),
+ EdgeUse.Forward(vertical[i]),
+ EdgeUse.Forward(top[i]),
+ EdgeUse.Reversed(vertical[next]),
+ }
+ : new[]
+ {
+ EdgeUse.Forward(bottom[i]),
+ EdgeUse.Forward(vertical[next]),
+ EdgeUse.Reversed(top[i]),
+ EdgeUse.Reversed(vertical[i]),
+ };
+ faces.Add(AddFaceWithLoop(builder, uses));
+ }
+
+ return faces;
+ }
+
+ private static void BindLoopEdges(EdgeId[] edges, Point3D[] points, Action<EdgeId, Point3D, Point3D> bind)
+ {
+ for (var i = 0; i < edges.Length; i++)
+ {
+ bind(edges[i], points[i], points[(i + 1) % points.Length]);
+ }
+ }
+
+ private static void BindVerticalEdges(EdgeId[] edges, Point3D[] bottomPoints, Point3D[] topPoints, Action<EdgeId, Point3D, Point3D> bind)
+ {
+ for (var i = 0; i < edges.Length; i++)
+ {
+ bind(edges[i], bottomPoints[i], topPoints[i]);
+ }
+ }
+
+ private static FaceId AddFaceWithLoops(TopologyBuilder builder, IReadOnlyList<EdgeUse> outerLoop, IReadOnlyList<EdgeUse> innerLoop)
+ {
+ var outerLoopId = AddLoop(builder, outerLoop);
+ var innerLoopId = AddLoop(builder, innerLoop);
+ return builder.AddFace([outerLoopId, innerLoopId]);
+ }
+
+ private static FaceId AddFaceWithLoop(TopologyBuilder builder, IReadOnlyList<EdgeUse> edgeUses)
+ {
+ var loopId = AddLoop(builder, edgeUses);
+ return builder.AddFace([loopId]);
+ }
+
+ private static LoopId AddLoop(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 loopId;
+ }
+
+ 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/BrepBooleanPrismaticProfileRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticProfileRecognition.cs
new file mode 100644
index 00000000..848f37e2
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticProfileRecognition.cs
@@ -0,0 +1,142 @@
+using Aetheris.Kernel.Core.Geometry;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Numerics;
+
+namespace Aetheris.Kernel.Core.Brep.Boolean;
+
+public readonly record struct RecognizedPrismaticProfile(
+ AxisAlignedBoxExtents Bounds,
+ IReadOnlyList<(double X, double Y)> Footprint);
+
+internal static class BrepBooleanPrismaticProfileRecognition
+{
+ public static bool TryRecognize(BrepBody body, ToleranceContext tolerance, out RecognizedPrismaticProfile profile, out string reason)
+ {
+ profile = default;
+ reason = "uninitialized";
+
+ var points = new List<Point3D>();
+ foreach (var vertex in body.Topology.Vertices)
+ {
+ if (!body.TryGetVertexPoint(vertex.Id, out var point))
+ {
+ points.Clear();
+ break;
+ }
+
+ points.Add(point);
+ }
+
+ if (points.Count == 0)
+ {
+ foreach (var edge in body.Topology.Edges)
+ {
+ if (!body.TryGetEdgeCurveGeometry(edge.Id, out var curve) || curve?.Kind != Geometry.CurveGeometryKind.Line3)
+ {
+ continue;
+ }
+
+ if (!body.Bindings.TryGetEdgeBinding(edge.Id, out var edgeBinding))
+ {
+ continue;
+ }
+
+ var interval = edgeBinding.TrimInterval ?? new ParameterInterval(0d, 1d);
+ var start = curve.Line3!.Value.Evaluate(interval.Start);
+ var end = curve.Line3.Value.Evaluate(interval.End);
+ points.Add(start);
+ points.Add(end);
+ }
+ }
+
+ if (points.Count == 0)
+ {
+ reason = "prismatic profile recognition requires vertex points or line-edge bindings.";
+ return false;
+ }
+
+ if (points.Count < 6)
+ {
+ reason = "prismatic profile recognition requires at least six vertices.";
+ return false;
+ }
+
+ var minX = points.Min(p => p.X);
+ var maxX = points.Max(p => p.X);
+ var minY = points.Min(p => p.Y);
+ var maxY = points.Max(p => p.Y);
+ var minZ = points.Min(p => p.Z);
+ var maxZ = points.Max(p => p.Z);
+ if ((maxZ - minZ) <= tolerance.Linear)
+ {
+ reason = "prismatic profile recognition requires positive Z span.";
+ return false;
+ }
+
+ var bottom = points
+ .Where(p => ToleranceMath.AlmostEqual(p.Z, minZ, tolerance))
+ .Select(p => (p.X, p.Y))
+ .ToArray();
+ var top = points
+ .Where(p => ToleranceMath.AlmostEqual(p.Z, maxZ, tolerance))
+ .Select(p => (p.X, p.Y))
+ .ToArray();
+
+ if (bottom.Length < 3 || top.Length < 3)
+ {
+ reason = "prismatic profile recognition requires planar top and bottom loops with at least three vertices.";
+ return false;
+ }
+
+ var bottomUnique = UniqueXY(bottom, tolerance);
+ var topUnique = UniqueXY(top, tolerance);
+ if (bottomUnique.Count < 3 || topUnique.Count < 3 || bottomUnique.Count != topUnique.Count)
+ {
+ reason = "prismatic profile recognition requires matching top/bottom XY loop cardinality.";
+ return false;
+ }
+
+ foreach (var xy in bottomUnique)
+ {
+ if (!ContainsXY(topUnique, xy, tolerance))
+ {
+ reason = "prismatic profile recognition requires matching top/bottom XY vertices.";
+ return false;
+ }
+ }
+
+ profile = new RecognizedPrismaticProfile(
+ new AxisAlignedBoxExtents(minX, maxX, minY, maxY, minZ, maxZ),
+ OrderLoop(bottomUnique));
+ reason = string.Empty;
+ return true;
+ }
+
+ private static List<(double X, double Y)> UniqueXY(IEnumerable<(double X, double Y)> points, ToleranceContext tolerance)
+ {
+ var unique = new List<(double X, double Y)>();
+ foreach (var point in points)
+ {
+ if (!ContainsXY(unique, point, tolerance))
+ {
+ unique.Add(point);
+ }
+ }
+
+ return unique;
+ }
+
+ private static bool ContainsXY(IEnumerable<(double X, double Y)> points, (double X, double Y) candidate, ToleranceContext tolerance)
+ => points.Any(existing =>
+ ToleranceMath.AlmostEqual(existing.X, candidate.X, tolerance)
+ && ToleranceMath.AlmostEqual(existing.Y, candidate.Y, tolerance));
+
+ private static IReadOnlyList<(double X, double Y)> OrderLoop(IReadOnlyList<(double X, double Y)> points)
+ {
+ var centroidX = points.Average(p => p.X);
+ var centroidY = points.Average(p => p.Y);
+ return points
+ .OrderBy(point => double.Atan2(point.Y - centroidY, point.X - centroidX))
+ .ToArray();
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs
index 58566ab2..4687bf20 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs
@@ -1,6 +1,5 @@
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Numerics;
-using Aetheris.Kernel.Core.Geometry;
namespace Aetheris.Kernel.Core.Brep.Boolean;
@@ -13,131 +12,14 @@ internal static class BrepBooleanPrismaticToolRecognition
public static bool TryRecognize(BrepBody body, ToleranceContext tolerance, out SupportedPrismaticSubtractTool tool, out string reason)
{
tool = default!;
- reason = "uninitialized";
-
- var points = new List<Point3D>();
- foreach (var vertex in body.Topology.Vertices)
- {
- if (!body.TryGetVertexPoint(vertex.Id, out var point))
- {
- points.Clear();
- break;
- }
-
- points.Add(point);
- }
-
- if (points.Count == 0)
- {
- foreach (var edge in body.Topology.Edges)
- {
- if (!body.TryGetEdgeCurveGeometry(edge.Id, out var curve) || curve?.Kind != Geometry.CurveGeometryKind.Line3)
- {
- continue;
- }
-
- if (!body.Bindings.TryGetEdgeBinding(edge.Id, out var edgeBinding))
- {
- continue;
- }
-
- var interval = edgeBinding.TrimInterval ?? new ParameterInterval(0d, 1d);
- var start = curve.Line3!.Value.Evaluate(interval.Start);
- var end = curve.Line3.Value.Evaluate(interval.End);
- points.Add(start);
- points.Add(end);
- }
- }
-
- if (points.Count == 0)
- {
- reason = "prismatic tool recognition requires vertex points or line-edge bindings.";
- return false;
- }
-
- if (points.Count < 6)
- {
- reason = "prismatic tool recognition requires at least six vertices.";
- return false;
- }
-
- var minX = points.Min(p => p.X);
- var maxX = points.Max(p => p.X);
- var minY = points.Min(p => p.Y);
- var maxY = points.Max(p => p.Y);
- var minZ = points.Min(p => p.Z);
- var maxZ = points.Max(p => p.Z);
- if ((maxZ - minZ) <= tolerance.Linear)
- {
- reason = "prismatic tool recognition requires positive Z span.";
- return false;
- }
-
- var bottom = points
- .Where(p => ToleranceMath.AlmostEqual(p.Z, minZ, tolerance))
- .Select(p => (p.X, p.Y))
- .ToArray();
- var top = points
- .Where(p => ToleranceMath.AlmostEqual(p.Z, maxZ, tolerance))
- .Select(p => (p.X, p.Y))
- .ToArray();
-
- if (bottom.Length < 3 || top.Length < 3)
- {
- reason = "prismatic tool recognition requires planar top and bottom loops with at least three vertices.";
- return false;
- }
-
- var bottomUnique = UniqueXY(bottom, tolerance);
- var topUnique = UniqueXY(top, tolerance);
- if (bottomUnique.Count < 3 || topUnique.Count < 3 || bottomUnique.Count != topUnique.Count)
+ if (!BrepBooleanPrismaticProfileRecognition.TryRecognize(body, tolerance, out var profile, out var profileReason))
{
- reason = "prismatic tool recognition requires matching top/bottom XY loop cardinality.";
+ reason = profileReason.Replace("prismatic profile", "prismatic tool", StringComparison.Ordinal);
return false;
}
- foreach (var xy in bottomUnique)
- {
- if (!ContainsXY(topUnique, xy, tolerance))
- {
- reason = "prismatic tool recognition requires matching top/bottom XY vertices.";
- return false;
- }
- }
-
- var footprint = OrderLoop(bottomUnique);
- tool = new SupportedPrismaticSubtractTool(
- new AxisAlignedBoxExtents(minX, maxX, minY, maxY, minZ, maxZ),
- footprint);
+ tool = new SupportedPrismaticSubtractTool(profile.Bounds, profile.Footprint);
reason = string.Empty;
return true;
}
-
- private static List<(double X, double Y)> UniqueXY(IEnumerable<(double X, double Y)> points, ToleranceContext tolerance)
- {
- var unique = new List<(double X, double Y)>();
- foreach (var point in points)
- {
- if (!ContainsXY(unique, point, tolerance))
- {
- unique.Add(point);
- }
- }
-
- return unique;
- }
-
- private static bool ContainsXY(IEnumerable<(double X, double Y)> points, (double X, double Y) candidate, ToleranceContext tolerance)
- => points.Any(existing =>
- ToleranceMath.AlmostEqual(existing.X, candidate.X, tolerance)
- && ToleranceMath.AlmostEqual(existing.Y, candidate.Y, tolerance));
-
- private static IReadOnlyList<(double X, double Y)> OrderLoop(IReadOnlyList<(double X, double Y)> points)
- {
- var centroidX = points.Average(p => p.X);
- var centroidY = points.Average(p => p.Y);
- return points
- .OrderBy(point => double.Atan2(point.Y - centroidY, point.X - centroidX))
- .ToArray();
- }
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
index dc80c695..ca7c9b49 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeComposition.cs
@@ -70,12 +70,14 @@ public enum SafeBooleanRootKind
{
Box,
Cylinder,
+ PolygonalExtrusion,
}
public readonly record struct SafeBooleanRootDescriptor(
SafeBooleanRootKind Kind,
AxisAlignedBoxExtents Box,
- RecognizedCylinder? Cylinder = null)
+ RecognizedCylinder? Cylinder = null,
+ IReadOnlyList<(double X, double Y)>? PolygonFootprint = null)
{
public static SafeBooleanRootDescriptor FromBox(AxisAlignedBoxExtents box)
=> new(SafeBooleanRootKind.Box, box);
@@ -96,6 +98,9 @@ public readonly record struct SafeBooleanRootDescriptor(
cylinder);
}
+ public static SafeBooleanRootDescriptor FromPolygonalExtrusion(in RecognizedPrismaticProfile profile)
+ => new(SafeBooleanRootKind.PolygonalExtrusion, profile.Bounds, Cylinder: null, PolygonFootprint: profile.Footprint);
+
public SafeBooleanRootDescriptor Translate(Vector3D translation)
{
var translatedBox = new AxisAlignedBoxExtents(
@@ -114,7 +119,16 @@ public readonly record struct SafeBooleanRootDescriptor(
cylinder with { AxisOrigin = cylinder.AxisOrigin + translation });
}
- return new SafeBooleanRootDescriptor(Kind, translatedBox);
+ if (Kind == SafeBooleanRootKind.PolygonalExtrusion && PolygonFootprint is { Count: > 0 } footprint)
+ {
+ return new SafeBooleanRootDescriptor(
+ Kind,
+ translatedBox,
+ Cylinder: null,
+ PolygonFootprint: footprint.Select(point => (point.X + translation.X, point.Y + translation.Y)).ToArray());
+ }
+
+ return new SafeBooleanRootDescriptor(Kind, translatedBox, PolygonFootprint: PolygonFootprint);
}
}
@@ -195,6 +209,13 @@ public static class BrepBooleanSafeComposition
return true;
}
+ if (BrepBooleanPrismaticProfileRecognition.TryRecognize(body, tolerance, out var profile, out reason))
+ {
+ var root = SafeBooleanRootDescriptor.FromPolygonalExtrusion(profile);
+ composition = new SafeBooleanComposition(root.Box, [], root);
+ return true;
+ }
+
composition = default!;
return false;
}
diff --git a/testdata/firmament/examples/README.md b/testdata/firmament/examples/README.md
index 43eafe38..218b3b1d 100644
--- a/testdata/firmament/examples/README.md
+++ b/testdata/firmament/examples/README.md
@@ -35,4 +35,4 @@ Other combinations may fail and are intentionally not supported yet.
- `p2_mirror_hole_pair.firmament` — bounded `pattern_mirror` example for principal-plane mirrored hole placement.
- `schema_box_basic.firmament` — minimal schema-present export example showing schema presence without changing export body semantics; helper export path: `testdata/firmament/exports/schema_box_basic.step`.
-Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The supported safe subtract family remains narrow and explicit: `subtract(box, cylinder)` and `subtract(box, cone)` still require a Z-aligned tool, full span through the current box shell, non-degenerate boundary circles for cones, and strict in-bounds clearance with no tangent/grazing contact. Sequential composition is still bounded: analytic follow-on subtracts are pre-validated as safe-hole composition, while non-analytic follow-on tools are now passed through to kernel bounded-family routing for final admissibility/reconstruction diagnostics rather than being rejected by an upstream tool-kind gate. This is not general multi-feature boolean support. The composability probe `composed_part_with_slot.firmament` is now a successful routed case (`subtract(library_part, slot_cut)`) and remains useful as a regression check that follow-on prismatic routing reaches kernel execution. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, outside-footprint cuts, interfering multi-hole layouts, and unsupported subtract orderings remain unsupported. Box+cone `add`, box+cone `intersect`, tilted cones, partial-depth cone cuts, tangent/grazing cone cuts, apex-inside cases, outside-footprint cone cuts, and unsupported mixed-ordering requests remain unsupported. Box+sphere support is still narrow and truth-first: only `subtract(box, sphere)` with a strictly contained, non-tangent, fully enclosed cavity is supported, reconstructed via one outer shell plus one inner spherical shell. `add(box, sphere)`, `intersect(box, sphere)`, tangent cavity requests, and partially outside sphere requests remain unsupported. Box+torus booleans are currently unsupported in every audited form: `subtract(box, torus)`, `add(box, torus)`, and `intersect(box, torus)` all fail the real kernel boundary for centered, offset, fully contained, face-intersecting, and outside-footprint torus placements, so no box+torus example is included here. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.
+Unsupported boolean requests are tracked as fixtures/tests, not presented in this working example pack. The supported safe subtract family remains narrow and explicit: `subtract(box, cylinder)` and `subtract(box, cone)` still require a Z-aligned tool, full span through the current box shell, non-degenerate boundary circles for cones, and strict in-bounds clearance with no tangent/grazing contact. Forge-style polygonal extrusions (for example rounded-corner boxes / slot-cut solids) now also have a bounded safe-root path for prismatic through-cut subtract continuation, so these roots are no longer immediate left-operand dead ends; containment for that family uses the true polygon footprint, not only the root AABB. Sequential composition is still bounded: analytic follow-on subtracts are pre-validated as safe-hole composition, while non-analytic follow-on tools are now passed through to kernel bounded-family routing for final admissibility/reconstruction diagnostics rather than being rejected by an upstream tool-kind gate. This is not general multi-feature boolean support. The composability probe `composed_part_with_slot.firmament` is now a successful routed case (`subtract(library_part, slot_cut)`) and remains useful as a regression check that follow-on prismatic routing reaches kernel execution. Box+cylinder `add`, box+cylinder `intersect`, rotated cylinders, partial-depth cuts, tangent/grazing cases, outside-footprint cuts, interfering multi-hole layouts, and unsupported subtract orderings remain unsupported. Box+cone `add`, box+cone `intersect`, tilted cones, partial-depth cone cuts, tangent/grazing cone cuts, apex-inside cases, outside-footprint cone cuts, and unsupported mixed-ordering requests remain unsupported. Box+sphere support is still narrow and truth-first: only `subtract(box, sphere)` with a strictly contained, non-tangent, fully enclosed cavity is supported, reconstructed via one outer shell plus one inner spherical shell. `add(box, sphere)`, `intersect(box, sphere)`, tangent cavity requests, and partially outside sphere requests remain unsupported. Box+torus booleans are currently unsupported in every audited form: `subtract(box, torus)`, `add(box, torus)`, and `intersect(box, torus)` all fail the real kernel boundary for centered, offset, fully contained, face-intersecting, and outside-footprint torus placements, so no box+torus example is included here. These files are intended to stay minimal, readable, and aligned with the implemented language surface. Export artifacts are kept separately under `testdata/firmament/exports/` so examples remain source-only and demo outputs stay easy to find.