Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Add bounded prismatic subtract routing in boolean core

Yuechen Lifcbb9888ded5
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index c6ecff82..f298520e 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -9,6 +9,7 @@ using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Numerics;
using Aetheris.Kernel.Core.Step242;
using Aetheris.Kernel.Core.Topology;
+using Aetheris.Kernel.StandardLibrary;
namespace Aetheris.Kernel.Core.Tests.Brep.Boolean;
@@ -1633,6 +1634,36 @@ public sealed class BrepBooleanTests
Assert.Contains("Closest bounded union candidate rejected", diagnostic.Message, StringComparison.Ordinal);
}
+ [Fact]
+ public void RecognizedSafeRoot_PrismaticSubtract_Succeeds()
+ {
+ var boxA = BrepPrimitives.CreateBox(20d, 20d, 20d).Value;
+ var boxB = TransformBody(BrepPrimitives.CreateBox(20d, 20d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(10d, 10d, 0d)));
+ var union = BrepBoolean.Union(boxA, boxB);
+ Assert.True(union.IsSuccess);
+ Assert.True(union.Value.SafeBooleanComposition?.OccupiedCells?.Count > 0);
+
+ var tool = StandardLibraryPrimitives.CreateSlotCut(16d, 8d, 24d, 4d).Value;
+ var result = BrepBoolean.Subtract(union.Value, tool);
+
+ Assert.True(result.IsSuccess);
+ }
+
+ [Fact]
+ public void Unsupported_PrismaticSubtract_RemainsRejected()
+ {
+ var root = BrepPrimitives.CreateBox(20d, 20d, 20d).Value;
+ var safeRoot = BrepBoolean.Union(root, TransformBody(BrepPrimitives.CreateBox(20d, 20d, 20d).Value, Transform3D.CreateTranslation(new Vector3D(10d, 10d, 0d))));
+ Assert.True(safeRoot.IsSuccess);
+
+ var shortTool = StandardLibraryPrimitives.CreateSlotCut(16d, 8d, 10d, 4d).Value;
+ var result = BrepBoolean.Subtract(safeRoot.Value, shortTool);
+
+ Assert.False(result.IsSuccess);
+ var diagnostic = Assert.Single(result.Diagnostics);
+ Assert.Contains("through-cut tool", diagnostic.Message, StringComparison.Ordinal);
+ }
+
[Fact]
public void Execute_NonBoxInput_ReturnsDeterministicNotImplementedWithoutThrowing()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
index 3e63dd8e..49c16218 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
@@ -29,7 +29,8 @@ public sealed record BooleanAnalysis(
AxisAlignedBoxExtents? LeftBox,
AxisAlignedBoxExtents? RightBox,
AnalyticSurface? RightAnalyticSurface,
- string? UnsupportedReason);
+ string? UnsupportedReason,
+ SupportedPrismaticSubtractTool? RightPrismaticTool = null);
public enum BooleanExecutionClass
{
@@ -45,7 +46,8 @@ public sealed record BooleanCaseClassification(
AxisAlignedBoxExtents? RightBox,
AnalyticSurface? RightAnalyticSurface,
string? UnsupportedReason,
- BooleanDiagnostic? Diagnostic = null);
+ BooleanDiagnostic? Diagnostic = null,
+ SupportedPrismaticSubtractTool? RightPrismaticTool = null);
public sealed record BooleanIntersectionData(
BooleanAnalysis Analysis,
@@ -62,7 +64,8 @@ public sealed record BooleanClassificationData(
SafeBooleanComposition? SafeCompositionResult,
string? UnsupportedReason,
IReadOnlyList<AxisAlignedBoxExtents>? OrthogonalUnionCells = null,
- BooleanDiagnostic? Diagnostic = null);
+ BooleanDiagnostic? Diagnostic = null,
+ SupportedPrismaticSubtractTool? PrismaticThroughCutTool = null);
public sealed record BooleanRebuildData(
BooleanClassificationData Classification,
@@ -83,6 +86,7 @@ internal enum BooleanTopLevelCase
internal enum BooleanSubtractIntersectFamily
{
SubtractIntersectOrthogonalCellsExistingRoot,
+ SubtractPrismaticThroughCutOnRecognizedRoot,
SubtractBoxSingleBoxResult,
SubtractBoxPocketOnRecognizedRoot,
IntersectSupportedBoundedCase,
@@ -100,6 +104,7 @@ internal sealed record BooleanCaseContext(
SafeBooleanComposition? LeftSafeComposition,
AxisAlignedBoxExtents? LeftBox,
AxisAlignedBoxExtents? RightBox,
+ SupportedPrismaticSubtractTool? RightPrismaticTool,
AnalyticSurface? RightAnalyticSurface,
bool CanClassifyBoundedOrthogonalUnionWithExistingRoot,
SafeBooleanComposition? AdditiveComposition,
@@ -123,7 +128,8 @@ internal sealed record BooleanSubtractIntersectContext(
ToleranceContext Tolerance,
SafeBooleanComposition LeftSafeComposition,
AxisAlignedBoxExtents LeftRootBox,
- AxisAlignedBoxExtents RightBox,
+ AxisAlignedBoxExtents? RightBox,
+ SupportedPrismaticSubtractTool? RightPrismaticTool,
bool LeftHasOccupiedCells,
bool HasPositiveVolumeOverlap,
bool IsTouchingOnly,
@@ -228,7 +234,8 @@ public static class BrepBoolean
classification.LeftBox,
classification.RightBox,
classification.RightAnalyticSurface,
- classification.UnsupportedReason);
+ classification.UnsupportedReason,
+ classification.RightPrismaticTool);
}
public static BooleanCaseClassification ClassifyBooleanCase(BrepBody leftBody, BrepBody rightBody, BooleanOperation operation, ToleranceContext? tolerance = null)
@@ -248,6 +255,12 @@ public static class BrepBoolean
var resolvedTolerance = tolerance ?? ToleranceContext.Default;
var leftRecognized = BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(leftBody, resolvedTolerance, out var leftBox, out _);
var rightRecognized = BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(rightBody, resolvedTolerance, out var rightBox, out _);
+ var rightRecognizedPrismaticTool = BrepBooleanPrismaticToolRecognition.TryRecognize(rightBody, resolvedTolerance, out var rightPrismaticTool, out _);
+ if (rightRecognized)
+ {
+ rightRecognizedPrismaticTool = false;
+ rightPrismaticTool = null!;
+ }
var rightAnalyticRecognized = BrepBooleanAnalyticSurfaceRecognition.TryRecognizeAnalyticSurface(rightBody, resolvedTolerance, out var analyticSurface, out _);
var leftSafeCompositionRecognizedFromBody = leftBody.SafeBooleanComposition is not null;
@@ -307,6 +320,7 @@ public static class BrepBoolean
leftSafeComposition,
leftRecognized ? leftBox : null,
rightRecognized ? rightBox : null,
+ rightRecognizedPrismaticTool ? rightPrismaticTool : null,
rightAnalyticRecognized ? analyticSurface : null,
canClassifyBoundedOrthogonalUnionWithExistingRoot,
additiveComposition,
@@ -343,13 +357,15 @@ public static class BrepBoolean
Name: BooleanTopLevelCase.SubtractIntersectRecognizedSafeRoot.ToString(),
IsAdmissible: context =>
BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, BooleanOperation.Intersect, out _)
- && context.LeftHasSafeComposition
- && context.LeftSafeComposition is not null
- && context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Box
- && context.RightRecognizedBox,
+ && ((context.LeftHasSafeComposition
+ && context.LeftSafeComposition is not null
+ && context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Box)
+ || context.LeftRecognizedBox)
+ && (context.RightRecognizedBox
+ || (context.Operation == BooleanOperation.Subtract && context.RightPrismaticTool is not null)),
Score: _ => 250d,
RejectionReason: context =>
- $"Recognized-safe-root subtract/intersect shell requires subtract/intersect, a recognized safe box root, and a recognized box right operand (op={context.Operation}, hasSafe={context.LeftHasSafeComposition}, rightBox={context.RightRecognizedBox})."),
+ $"Recognized-safe-root subtract/intersect shell requires subtract/intersect, a recognized safe box root, and a recognized bounded right operand (box or subtract-prismatic tool) (op={context.Operation}, hasSafe={context.LeftHasSafeComposition}, rightBox={context.RightRecognizedBox}, rightPrismatic={(context.RightPrismaticTool is not null)})."),
new JudgmentCandidate<BooleanCaseContext>(
Name: BooleanTopLevelCase.SubtractCylinderRootKeyway.ToString(),
IsAdmissible: context => context.IsCylinderRootCandidate,
@@ -420,7 +436,8 @@ public static class BrepBoolean
context.LeftRecognizedBox ? context.LeftBox : context.LeftSafeComposition!.OuterBox,
context.RightBox,
context.RightAnalyticSurface,
- BuildUnsupportedSafeCompositionReason(context, candidateResult)),
+ BuildUnsupportedSafeCompositionReason(context, candidateResult),
+ RightPrismaticTool: context.RightPrismaticTool),
_ => CreateUnsupportedGeneralClassification(context),
};
}
@@ -437,55 +454,70 @@ public static class BrepBoolean
subtractIntersectContext.LeftRootBox,
subtractIntersectContext.RightBox,
null,
- BuildRecognizedSafeRootSubtractIntersectUnsupportedReason(subtractIntersectContext, selection));
+ BuildRecognizedSafeRootSubtractIntersectUnsupportedReason(subtractIntersectContext, selection),
+ RightPrismaticTool: subtractIntersectContext.RightPrismaticTool);
}
var family = Enum.Parse<BooleanSubtractIntersectFamily>(selection.Selection!.Value.Candidate.Name, ignoreCase: false);
return family switch
{
BooleanSubtractIntersectFamily.SubtractIntersectOrthogonalCellsExistingRoot
+ or BooleanSubtractIntersectFamily.SubtractPrismaticThroughCutOnRecognizedRoot
or BooleanSubtractIntersectFamily.SubtractBoxSingleBoxResult
or BooleanSubtractIntersectFamily.SubtractBoxPocketOnRecognizedRoot
or BooleanSubtractIntersectFamily.IntersectSupportedBoundedCase
=> new BooleanCaseClassification(
BooleanExecutionClass.PlanarOnly,
- context.LeftSafeComposition,
+ subtractIntersectContext.LeftSafeComposition,
subtractIntersectContext.LeftRootBox,
subtractIntersectContext.RightBox,
null,
- null),
+ null,
+ RightPrismaticTool: subtractIntersectContext.RightPrismaticTool),
_ => new BooleanCaseClassification(
BooleanExecutionClass.UnsupportedGeneralCase,
- context.LeftSafeComposition,
+ subtractIntersectContext.LeftSafeComposition,
subtractIntersectContext.LeftRootBox,
subtractIntersectContext.RightBox,
null,
- BuildRecognizedSafeRootSubtractIntersectUnsupportedReason(subtractIntersectContext, selection)),
+ BuildRecognizedSafeRootSubtractIntersectUnsupportedReason(subtractIntersectContext, selection),
+ RightPrismaticTool: subtractIntersectContext.RightPrismaticTool),
};
}
private static BooleanSubtractIntersectContext BuildBooleanSubtractIntersectContext(BooleanCaseContext context)
{
- var leftRootBox = context.LeftSafeComposition!.RootDescriptor.Box;
- var rightBox = context.RightBox!.Value;
- var overlap = AxisAlignedBoxExtents.Intersection(leftRootBox, rightBox);
+ var leftComposition = context.LeftSafeComposition
+ ?? new SafeBooleanComposition(context.LeftBox!.Value, [], SafeBooleanRootDescriptor.FromBox(context.LeftBox.Value));
+ var leftRootBox = leftComposition.RootDescriptor.Box;
+ var rightBox = context.RightBox;
+ var rightPrismaticTool = context.RightPrismaticTool;
+ var rightBounds = rightBox ?? rightPrismaticTool?.Bounds;
+ if (rightBounds is null)
+ {
+ rightBounds = leftComposition.RootDescriptor.Box;
+ }
+ var overlap = AxisAlignedBoxExtents.Intersection(leftRootBox, rightBounds.Value);
var hasPositiveVolumeOverlap = overlap is not null && overlap.Value.HasPositiveVolume(context.Tolerance);
var isTouchingOnly = overlap is not null && !hasPositiveVolumeOverlap;
- var rightContainsLeft = rightBox.Contains(leftRootBox, context.Tolerance);
+ var rightContainsLeft = rightBounds.Value.Contains(leftRootBox, context.Tolerance);
var canSubtractToSingleBox = context.Operation == BooleanOperation.Subtract
- && TrySubtractToSingleBox(leftRootBox, rightBox, context.Tolerance, out _);
+ && rightBox is not null
+ && TrySubtractToSingleBox(leftRootBox, rightBox.Value, context.Tolerance, out _);
string? subtractPocketUnsupportedReason = null;
var canSubtractToOrthogonalPocket = context.Operation == BooleanOperation.Subtract
- && TryClassifyBoundedOrthogonalPocketSubtract(leftRootBox, rightBox, context.Tolerance, out _, out subtractPocketUnsupportedReason);
+ && rightBox is not null
+ && TryClassifyBoundedOrthogonalPocketSubtract(leftRootBox, rightBox.Value, context.Tolerance, out _, out subtractPocketUnsupportedReason);
return new BooleanSubtractIntersectContext(
context.Operation,
context.Tolerance,
- context.LeftSafeComposition,
+ leftComposition,
leftRootBox,
rightBox,
- context.LeftSafeComposition.OccupiedCells is { Count: > 0 },
+ rightPrismaticTool,
+ leftComposition.OccupiedCells is { Count: > 0 },
hasPositiveVolumeOverlap,
isTouchingOnly,
rightContainsLeft,
@@ -507,6 +539,14 @@ public static class BrepBoolean
? $"Orthogonal occupied-cell subtract/intersect candidate {operationReason}"
: "Orthogonal occupied-cell subtract/intersect candidate requires subtract or intersect."
: "Orthogonal occupied-cell subtract/intersect candidate requires a recognized additive safe root with occupied cells."),
+ new JudgmentCandidate<BooleanSubtractIntersectContext>(
+ Name: BooleanSubtractIntersectFamily.SubtractPrismaticThroughCutOnRecognizedRoot.ToString(),
+ IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out _)
+ && context.RightPrismaticTool is not null,
+ Score: _ => 425d,
+ RejectionReason: context => !BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out var operationReason)
+ ? $"Prismatic subtract candidate {operationReason}"
+ : "Prismatic subtract candidate requires a recognized bounded prismatic subtract tool."),
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.SubtractBoxSingleBoxResult.ToString(),
IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out _)
@@ -601,17 +641,18 @@ public static class BrepBoolean
private static BooleanIntersectionData ComputeIntersections(BooleanRequest request, BooleanAnalysis analysis)
{
- if (analysis.LeftBox is null || (analysis.RightBox is null && analysis.RightAnalyticSurface is null))
+ var rightBounds = analysis.RightBox ?? analysis.RightPrismaticTool?.Bounds;
+ if (analysis.LeftBox is null || (rightBounds is null && analysis.RightAnalyticSurface is null))
{
return new BooleanIntersectionData(analysis, IsComputed: true, CandidatePairCount: 0, OverlapBox: null, IsTouchingOnly: false);
}
- if (analysis.RightBox is null)
+ if (rightBounds is null)
{
return new BooleanIntersectionData(analysis, IsComputed: true, CandidatePairCount: 1, OverlapBox: null, IsTouchingOnly: false);
}
- var overlap = AxisAlignedBoxExtents.Intersection(analysis.LeftBox.Value, analysis.RightBox.Value);
+ var overlap = AxisAlignedBoxExtents.Intersection(analysis.LeftBox.Value, rightBounds.Value);
var tolerance = request.Tolerance ?? ToleranceContext.Default;
var isTouchingOnly = overlap is not null && !overlap.Value.HasPositiveVolume(tolerance);
var overlapBox = overlap is not null && overlap.Value.HasPositiveVolume(tolerance)
@@ -713,6 +754,41 @@ public static class BrepBoolean
var left = intersections.Analysis.LeftBox!.Value;
var tolerance = request.Tolerance ?? ToleranceContext.Default;
var operation = request.Operation;
+ string? prismaticUnsupportedReason = null;
+ if (operation == BooleanOperation.Subtract
+ && intersections.Analysis.LeftSafeComposition is { } leftCompositionForPrismatic
+ && intersections.Analysis.RightPrismaticTool is { } prismaticTool
+ && TryClassifyBoundedPrismaticThroughCutSubtract(leftCompositionForPrismatic, prismaticTool, tolerance, out _))
+ {
+ return new BooleanClassificationData(
+ intersections,
+ IsComputed: true,
+ FragmentCount: 1,
+ SingleBoxResult: null,
+ SafeCompositionResult: null,
+ UnsupportedReason: null,
+ PrismaticThroughCutTool: prismaticTool);
+ }
+ else if (operation == BooleanOperation.Subtract
+ && intersections.Analysis.RightPrismaticTool is not null
+ && intersections.Analysis.LeftSafeComposition is not null)
+ {
+ TryClassifyBoundedPrismaticThroughCutSubtract(intersections.Analysis.LeftSafeComposition, intersections.Analysis.RightPrismaticTool, tolerance, out prismaticUnsupportedReason);
+ }
+
+ if (operation == BooleanOperation.Subtract
+ && intersections.Analysis.RightPrismaticTool is not null
+ && prismaticUnsupportedReason is not null)
+ {
+ return new BooleanClassificationData(
+ intersections,
+ IsComputed: true,
+ FragmentCount: 0,
+ SingleBoxResult: null,
+ SafeCompositionResult: null,
+ UnsupportedReason: prismaticUnsupportedReason);
+ }
+
var right = intersections.Analysis.RightBox!.Value;
string? occupiedUnsupportedReason = null;
@@ -911,6 +987,15 @@ public static class BrepBoolean
return new BooleanRebuildData(classification, rebuiltBody, rebuiltOrthogonalUnion.Diagnostics);
}
+ if (classification.PrismaticThroughCutTool is { } prismaticTool
+ && classification.Intersections.Analysis.LeftSafeComposition is { } leftComposition)
+ {
+ var rebuiltPrismSubtract = BrepBooleanBoxPrismThroughCutBuilder.Build(leftComposition.RootDescriptor.Box, prismaticTool.Footprint, request.Tolerance ?? ToleranceContext.Default);
+ return rebuiltPrismSubtract.IsSuccess
+ ? new BooleanRebuildData(classification, rebuiltPrismSubtract.Value, rebuiltPrismSubtract.Diagnostics)
+ : new BooleanRebuildData(classification, RebuiltBody: null, Diagnostics: rebuiltPrismSubtract.Diagnostics);
+ }
+
if (classification.SafeCompositionResult is not null)
{
var tolerance = request.Tolerance ?? ToleranceContext.Default;
@@ -1671,6 +1756,46 @@ public static class BrepBoolean
private static bool PositiveOverlap(double minA, double maxA, double minB, double maxB, ToleranceContext tolerance)
=> (System.Math.Min(maxA, maxB) - System.Math.Max(minA, minB)) > tolerance.Linear;
+ private static bool TryClassifyBoundedPrismaticThroughCutSubtract(
+ SafeBooleanComposition leftComposition,
+ SupportedPrismaticSubtractTool prismTool,
+ ToleranceContext tolerance,
+ out string? unsupportedReason)
+ {
+ unsupportedReason = null;
+ if (leftComposition.RootDescriptor.Kind != SafeBooleanRootKind.Box)
+ {
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract family requires a recognized safe box root.";
+ return false;
+ }
+
+ if (leftComposition.Holes.Count > 0 || (leftComposition.OpenSlots?.Count ?? 0) > 0)
+ {
+ unsupportedReason = "Boolean Subtract: bounded prismatic subtract continuation currently requires a recognized safe box root without existing analytic-hole/open-slot subtractions.";
+ return false;
+ }
+
+ var root = leftComposition.RootDescriptor.Box;
+ if (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.";
+ return false;
+ }
+
+ 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;
+ }
+ }
+
+ return true;
+ }
+
private static KernelResult<BrepBody> ValidateOutput(BrepBody body, IReadOnlyList<KernelDiagnostic> diagnostics)
{
var validation = BrepBindingValidator.Validate(body, requireAllEdgeAndFaceBindings: true);
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs
new file mode 100644
index 00000000..58566ab2
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanPrismaticToolRecognition.cs
@@ -0,0 +1,143 @@
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Numerics;
+using Aetheris.Kernel.Core.Geometry;
+
+namespace Aetheris.Kernel.Core.Brep.Boolean;
+
+public sealed record SupportedPrismaticSubtractTool(
+ AxisAlignedBoxExtents Bounds,
+ IReadOnlyList<(double X, double Y)> Footprint);
+
+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)
+ {
+ reason = "prismatic tool recognition requires matching top/bottom XY loop cardinality.";
+ 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);
+ 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.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs
index f1742845..8d4c42b1 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentConnectorLibraryPartTests.cs
@@ -46,7 +46,7 @@ public sealed class FirmamentConnectorLibraryPartTests
}
[Fact]
- public void ConnectorPart_Then_Op_Composition_Reveals_BoundedSubtract_Blocker()
+ public void ConnectorPart_With_SlotCut_Composition_Reveals_Next_Bounded_Blocker()
{
var source = FirmamentCorpusHarness.ReadFixtureText("testdata/firmament/examples/composed_part_with_slot.firmament");
@@ -59,7 +59,7 @@ public sealed class FirmamentConnectorLibraryPartTests
Assert.Contains(
compile.Compilation.Diagnostics,
diagnostic => diagnostic.Source == "BrepBoolean.RebuildResult"
- && diagnostic.Message.Contains("sequential safe composition only supports subtracting supported analytic holes", StringComparison.Ordinal));
+ && diagnostic.Message.Contains("bounded prismatic subtract continuation currently requires a recognized safe box root without existing analytic-hole/open-slot subtractions", StringComparison.Ordinal));
}
[Fact]
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index 2fad9329..4242b9b1 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -682,18 +682,17 @@ public sealed class FirmamentPrimitiveExecutionTests
}
[Theory]
- [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament", "tri_cut", "triangular_prism")]
- [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament", "hex_cut", "hexagonal_prism")]
- [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament", "slot_cut", "straight_slot")]
- public void Compile_PrismSubtract_Rejects_NonBoxRoot_Inputs(string fixturePath, string featureId, string toolOp)
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-triangular-prism.firmament", "tri_cut")]
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-hexagonal-prism.firmament", "hex_cut")]
+ [InlineData("testdata/firmament/fixtures/m3b-unsupported-cylinder-subtract-straight-slot.firmament", "slot_cut")]
+ public void Compile_PrismSubtract_Rejects_NonBoxRoot_Inputs(string fixturePath, string featureId)
{
var result = CompileFixture(fixturePath);
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
diagnostic.Message.Contains($"Boolean feature '{featureId}'", StringComparison.Ordinal)
- && diagnostic.Message.Contains("direct box-root source feature", StringComparison.Ordinal)
- && diagnostic.Message.Contains(toolOp, StringComparison.Ordinal));
+ && diagnostic.Message.Contains("sequential safe composition only supports subtracting supported analytic holes", StringComparison.Ordinal));
}
[Fact]
@@ -703,19 +702,19 @@ public sealed class FirmamentPrimitiveExecutionTests
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
- string.Equals(diagnostic.Source, "firmament.prism-bounded-subtract", StringComparison.Ordinal));
+ string.Equals(diagnostic.Source, "BrepBoolean.RebuildResult", StringComparison.Ordinal));
}
[Theory]
[InlineData("testdata/firmament/fixtures/m3b-invalid-box-subtract-triangular-prism-short-height.firmament", "through-cut tool") ]
- [InlineData("testdata/firmament/fixtures/m3b-invalid-box-subtract-hexagonal-prism-out-of-bounds.firmament", "out of bounds") ]
+ [InlineData("testdata/firmament/fixtures/m3b-invalid-box-subtract-hexagonal-prism-out-of-bounds.firmament", "strictly inside the box-root XY bounds") ]
public void Compile_PrismSubtract_Rejects_Invalid_BoundedConfigurations(string fixturePath, string expectedMessagePart)
{
var result = CompileFixture(fixturePath);
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
- string.Equals(diagnostic.Source, "firmament.prism-bounded-subtract", StringComparison.Ordinal)
+ string.Equals(diagnostic.Source, "BrepBoolean.RebuildResult", StringComparison.Ordinal)
&& diagnostic.Message.Contains(expectedMessagePart, StringComparison.Ordinal));
}
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index d0537797..dc48dab0 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -175,40 +175,6 @@ internal static class FirmamentPrimitiveExecutor
return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(toolResult.Diagnostics);
}
- if (FirmamentPrismFamilyTools.TryGetDescriptor(boolean.Tool.OpName, out var prismTool))
- {
- var canUseBoundedPrismPath =
- boolean.Kind == FirmamentLoweredBooleanKind.Subtract
- && boolean.Placement is null
- && featureGraphStates.TryGetValue(boolean.PrimaryReferenceFeatureId, out var sourceState)
- && sourceState == FirmamentSafeSubtractFeatureGraphState.BoxRoot;
-
- var allowGeneralBooleanFallback = prismTool.Kind == FirmamentPrismToolKind.SlotCut;
- if (canUseBoundedPrismPath || !allowGeneralBooleanFallback)
- {
- var prismResult = ExecuteBoundedPrismSubtractOnBoxRoot(
- boolean,
- prismTool,
- baseBody,
- featureGraphStates);
- if (!prismResult.IsSuccess)
- {
- return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(
- [
- CreateBooleanExecutionFailureDiagnostic(boolean),
- .. WithBooleanContext(boolean, prismResult.Diagnostics)
- ]);
- }
-
- var prismBooleanBody = prismResult.Value;
- executedBooleans.Add(new FirmamentExecutedBoolean(boolean.OpIndex, boolean.FeatureId, boolean.Kind, prismBooleanBody));
- publishedBodiesByFeatureId[boolean.FeatureId] = prismBooleanBody;
- booleanExecutionBodiesByFeatureId[boolean.FeatureId] = prismBooleanBody;
- featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;
- continue;
- }
- }
-
var featureGraphValidation = FirmamentSafeSubtractFeatureGraphValidator.ValidateNextBoolean(
boolean,
featureGraphStates,
diff --git a/docs/boolean-deferred.md b/docs/boolean-deferred.md
index d7dc52b4..92ca4d6c 100644
--- a/docs/boolean-deferred.md
+++ b/docs/boolean-deferred.md
@@ -13,6 +13,7 @@ The current supported boolean subset is intentionally narrow and family-specific
- box − sphere cavity
- rotated cylinder through-hole
- safe-family composition for the currently supported through-hole family
+- recognized safe box-root subtract with bounded prismatic through-cut tools (triangular/hexagonal/slot profiles) when the root has no prior analytic-hole/open-slot subtract history
## Current deferred boolean pile
@@ -25,6 +26,7 @@ The following items remain deferred:
- torus booleans
- broad add/intersect expansion outside the current narrow box-box subset
- general BRep booleans
+- prismatic continuation from safe roots that already contain analytic-hole/open-slot subtract history
## Known blocker: rotated cone through-hole