Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Implement bounded prism-family box-root subtract rebuild
Yuechen Lib1a305c07279
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex 521d3bea..7c7b0758 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -66,7 +66,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Intersect: empty intersection result is not representable in M13.", diagnostic.Message);+ Assert.Equal("Boolean Intersect: empty intersection result is not representable in the bounded boolean family.", diagnostic.Message);}[Fact]@@ -80,7 +80,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Intersect: touching-only intersection is non-solid and empty results are not representable in M13.", diagnostic.Message);+ Assert.Equal("Boolean Intersect: touching-only intersection is non-solid and empty results are not representable in the bounded boolean family.", diagnostic.Message);}[Fact]@@ -256,7 +256,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Union: disjoint box union is multi-body and not supported in M13.", diagnostic.Message);+ Assert.Equal("Boolean Union: disjoint box union is multi-body and not supported in the bounded boolean family.", diagnostic.Message);}[Fact]@@ -297,7 +297,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Subtract: subtraction fully removes the left box and empty results are not representable in M13.", diagnostic.Message);+ Assert.Equal("Boolean Subtract: subtraction fully removes the left box and empty results are not representable in the bounded boolean family.", diagnostic.Message);}[Fact]@@ -1320,7 +1320,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Union: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}[Fact]@@ -1334,7 +1334,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Intersect: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Intersect: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}@@ -1404,7 +1404,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Union: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}[Fact]@@ -1418,7 +1418,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Intersect: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Intersect: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}[Fact]@@ -1432,7 +1432,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Union: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}[Fact]@@ -1446,7 +1446,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Intersect: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Intersect: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}[Fact]@@ -1509,7 +1509,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);Assert.Equal(KernelDiagnosticCode.NotImplemented, diagnostic.Code);- Assert.Equal("Boolean Union: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal("Boolean Union: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}public static TheoryData<string, BooleanOperation, Transform3D> BoxTorusRepresentativeCases =>@@ -1549,7 +1549,7 @@ public sealed class BrepBooleanTests}else{- Assert.Equal($"Boolean {operation}: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);+ Assert.Equal($"Boolean {operation}: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", diagnostic.Message);}}diff --git a/Aetheris.Kernel.Core.Tests/Brep/Tessellation/BrepDisplayTessellatorTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/BrepDisplayTessellatorTests.csindex 6340cece..7272cf2f 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Tessellation/BrepDisplayTessellatorTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Tessellation/BrepDisplayTessellatorTests.cs@@ -165,7 +165,7 @@ public sealed class BrepDisplayTessellatorTests}[Fact]- public void Tessellate_M13BooleanBoxOutput_Succeeds()+ public void Tessellate_BoundedBooleanBoxOutput_Succeeds(){var left = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(0d, 4d, 0d, 4d, 0d, 4d)).Value;var right = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(2d, 6d, 1d, 3d, -1d, 2d)).Value;diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.csindex a010dd8d..a9350564 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs@@ -69,7 +69,7 @@ public sealed record BooleanRebuildData(IReadOnlyList<KernelDiagnostic> Diagnostics);/// <summary>-/// M13 boolean pipeline with narrow real support for axis-aligned box/box cases that resolve to a single box+/// bounded boolean pipeline with narrow real support for axis-aligned box/box cases that resolve to a single box/// plus the M10k box-minus-Z-aligned-through-cylinder subset that rebuilds to a single box-with-hole solid./// Unsupported and non-solid cases return deterministic NotImplemented diagnostics./// </summary>@@ -249,7 +249,7 @@ public static class BrepBooleanleftRecognized ? leftBox : null,rightRecognized ? rightBox : null,rightAnalyticRecognized ? analyticSurface : null,- $"Boolean {operation}: M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).");+ $"Boolean {operation}: bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).");}private static BooleanIntersectionData ComputeIntersections(BooleanRequest request, BooleanAnalysis analysis)@@ -372,12 +372,12 @@ public static class BrepBoolean{if (intersections.IsTouchingOnly){- return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: touching-only intersection is non-solid and empty results are not representable in M13.");+ return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: touching-only intersection is non-solid and empty results are not representable in the bounded boolean family.");}if (intersections.OverlapBox is null){- return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: empty intersection result is not representable in M13.");+ return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: empty intersection result is not representable in the bounded boolean family.");}return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 1, SingleBoxResult: intersections.OverlapBox, SafeCompositionResult: null, UnsupportedReason: null);@@ -434,7 +434,7 @@ public static class BrepBooleanif (AxisAlignedBoxExtents.Intersection(left, right) is null){- return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: disjoint box union is multi-body and not supported in M13.");+ return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: disjoint box union is multi-body and not supported in the bounded boolean family.");}if (TryClassifyBoundedOrthogonalUnion(left, right, tolerance, out var unionCells, out var unsupportedReason))@@ -469,7 +469,7 @@ public static class BrepBooleanif (right.Contains(left, tolerance)){- return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: subtraction fully removes the left box and empty results are not representable in M13.");+ return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: subtraction fully removes the left box and empty results are not representable in the bounded boolean family.");}if (TrySubtractToSingleBox(left, right, tolerance, out var singleBox))@@ -498,7 +498,7 @@ public static class BrepBooleanreturn new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: pocketUnsupportedReason);}- return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: box subtraction result is not representable as a single box in M13.");+ return new BooleanClassificationData(intersections, IsComputed: true, FragmentCount: 0, SingleBoxResult: null, SafeCompositionResult: null, UnsupportedReason: $"Boolean {operation}: box subtraction result is not representable as a single box in the bounded boolean family.");}private static BooleanRebuildData RebuildResult(BooleanRequest request, BooleanClassificationData classification)@@ -664,7 +664,7 @@ public static class BrepBooleanvar intersection = AxisAlignedBoxExtents.Intersection(left, right);if (intersection is null){- unsupportedReason = "Boolean Union: disjoint box union is multi-body and not supported in M13.";+ unsupportedReason = "Boolean Union: disjoint box union is multi-body and not supported in the bounded boolean family.";return false;}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.csnew file mode 100644index 00000000..31f88274--- /dev/null+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxPrismThroughCutBuilder.cs@@ -0,0 +1,215 @@+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;++public static class BrepBooleanBoxPrismThroughCutBuilder+{+ public static KernelResult<BrepBody> Build(+ AxisAlignedBoxExtents box,+ IReadOnlyList<(double X, double Y)> footprint,+ ToleranceContext _)+ {+ if (footprint.Count < 3)+ {+ 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])]),+ };++ 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);+ }+}diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxRecognition.csindex a014067e..05e0da39 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxRecognition.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxRecognition.cs@@ -185,7 +185,7 @@ public static class BrepBooleanBoxRecognition}else{- reason = "face normals are not axis-aligned as required for M13 boxes.";+ reason = "face normals are not axis-aligned as required for bounded boolean family boxes.";return false;}}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex 034e20dd..ed9b8bb9 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -388,7 +388,7 @@ public sealed class FirmamentBooleanCanonicalSuccessTests}private static bool HasExpectedMixedPrimitiveFailure(string message)- => message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)+ => message.Contains("bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)|| message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.csindex 47d6d5ab..d1da8247 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs@@ -340,7 +340,7 @@ public sealed class FirmamentBooleanRequiredFieldValidationTestsAssert.DoesNotContain(result.Compilation.Diagnostics, diagnostic => diagnostic.Message.Contains("[FIRM-STRUCT-", StringComparison.Ordinal));Assert.Contains(result.Compilation.Diagnostics, diagnostic =>diagnostic.Code == Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticCode.NotImplemented- && (diagnostic.Message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)+ && (diagnostic.Message.Contains("bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)|| diagnostic.Message.Contains("analytic tool surface kind", StringComparison.Ordinal)));}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex 7dbfab42..96317786 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -150,6 +150,42 @@ public sealed class FirmamentBuildAndExportTests"subtract");}+ [Fact]+ public void Run_PrismFamilyTriangularSubtractFixture_Writes_Default_Export_Artifact()+ {+ AssertExampleBuildAndExport(+ "testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament",+ "m3b-valid-box-subtract-triangular-prism.step",+ "tri_cut",+ 1,+ "boolean",+ "subtract");+ }++ [Fact]+ public void Run_PrismFamilyHexagonalSubtractFixture_Writes_Default_Export_Artifact()+ {+ AssertExampleBuildAndExport(+ "testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament",+ "m3b-valid-box-subtract-hexagonal-prism.step",+ "hex_cut",+ 1,+ "boolean",+ "subtract");+ }++ [Fact]+ public void Run_PrismFamilyStraightSlotSubtractFixture_Writes_Default_Export_Artifact()+ {+ AssertExampleBuildAndExport(+ "testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament",+ "m3b-valid-box-subtract-straight-slot.step",+ "slot_cut",+ 1,+ "boolean",+ "subtract");+ }+[Fact]public void Run_BooleanIntersectBasicExample_Writes_Default_Export_Artifact(){@@ -737,7 +773,7 @@ public sealed class FirmamentBuildAndExportTests}private static bool HasExpectedMixedPrimitiveFailure(string message)- => message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)+ => message.Contains("bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)|| message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.csindex 9bc280f6..3f93b7de 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs@@ -381,7 +381,7 @@ public sealed class FirmamentPrimitiveExecutionTests&& diagnostic.Message.Contains($"Requested boolean feature '{expectedFeatureId}' ({expectedKind}) could not be executed.", StringComparison.Ordinal));Assert.Contains(result.Compilation.Diagnostics, diagnostic =>diagnostic.Code == Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticCode.NotImplemented- && (diagnostic.Message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)+ && (diagnostic.Message.Contains("bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)|| diagnostic.Message.Contains("analytic hole surface kind", StringComparison.Ordinal)|| diagnostic.Message.Contains("Boolean feature", StringComparison.Ordinal)));}@@ -390,14 +390,16 @@ public sealed class FirmamentPrimitiveExecutionTests[InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-triangular-prism.firmament", "tri_cut")][InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-hexagonal-prism.firmament", "hex_cut")][InlineData("testdata/firmament/fixtures/m3b-valid-box-subtract-straight-slot.firmament", "slot_cut")]- public void Compile_BoxRoot_PrismSubtract_CanonicalCases_Hit_BoundedKernelLimit(string fixturePath, string featureId)+ public void Compile_BoxRoot_PrismSubtract_CanonicalCases_Succeed(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("core M13 boolean rebuild supports box/box and analytic-hole families only", StringComparison.Ordinal));+ Assert.True(result.Compilation.IsSuccess);+ Assert.NotNull(result.Compilation.Value.PrimitiveExecutionResult);+ var execution = result.Compilation.Value.PrimitiveExecutionResult!;+ Assert.Contains(execution.ExecutedBooleans, executed =>+ string.Equals(executed.FeatureId, featureId, StringComparison.Ordinal)+ && executed.Kind == FirmamentLoweredBooleanKind.Subtract);}[Theory]@@ -425,6 +427,19 @@ public sealed class FirmamentPrimitiveExecutionTestsstring.Equals(diagnostic.Source, "firmament.prism-bounded-subtract", 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") ]+ 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)+ && diagnostic.Message.Contains(expectedMessagePart, StringComparison.Ordinal));+ }+[Fact]public void Compile_ValidationFailure_Still_Fails_Before_Execution(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.csindex 70f78913..8a29e528 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentStepExporterTests.cs@@ -300,7 +300,7 @@ public sealed class FirmamentStepExporterTests}private static bool HasExpectedMixedPrimitiveFailure(string message)- => message.Contains("M13 only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)+ => message.Contains("bounded boolean family only supports recognized axis-aligned boxes from BrepPrimitives.CreateBox(...).", StringComparison.Ordinal)|| message.Contains("sequential safe composition only supports subtracting supported cylinder/cone analytic holes", StringComparison.Ordinal)|| message.Contains("safe subtract", StringComparison.Ordinal)|| message.Contains("unsupported follow-on tool kind", StringComparison.Ordinal)diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex 2f38da09..1bacb1cd 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -591,7 +591,7 @@ internal static class FirmamentPrimitiveExecutor]);}- if (!BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(baseBody, ToleranceContext.Default, out _, out var reason))+ if (!BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(baseBody, ToleranceContext.Default, out var rootBox, out var reason)){return KernelResult<BrepBody>.Failure([new KernelDiagnostic(@@ -601,14 +601,41 @@ internal static class FirmamentPrimitiveExecutorSource: "firmament.prism-bounded-subtract")]);}-- return KernelResult<BrepBody>.Failure([- new KernelDiagnostic(- KernelDiagnosticCode.NotImplemented,- KernelDiagnosticSeverity.Error,- $"Bounded prism-family subtract on box-root is validated, but execution is currently blocked: core M13 boolean rebuild supports box/box and analytic-hole families only; polyhedral prism tools ('{prismTool.OpName}') are not rebuildable yet.",- Source: "firmament.prism-bounded-subtract")- ]);++ var toolHeight = prismTool.ResolveHeight(boolean.Tool);+ var rootHeight = rootBox.MaxZ - rootBox.MinZ;+ if (toolHeight < rootHeight - ToleranceContext.Default.Linear)+ {+ return KernelResult<BrepBody>.Failure([+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ $"Bounded prism-family subtract on box-root requires a through-cut tool that spans the full root height ({rootHeight.ToString("G", CultureInfo.InvariantCulture)}). Got height '{toolHeight.ToString("G", CultureInfo.InvariantCulture)}' for tool op '{prismTool.OpName}'.",+ Source: "firmament.prism-bounded-subtract")+ ]);+ }++ var footprint = FirmamentPrismFamilyTools.ResolveFootprint(prismTool, boolean.Tool)+ .Select(point => (X: point.X, Y: point.Y))+ .ToArray();++ foreach (var point in footprint)+ {+ var insideX = point.X > rootBox.MinX + ToleranceContext.Default.Linear && point.X < rootBox.MaxX - ToleranceContext.Default.Linear;+ var insideY = point.Y > rootBox.MinY + ToleranceContext.Default.Linear && point.Y < rootBox.MaxY - ToleranceContext.Default.Linear;+ if (!insideX || !insideY)+ {+ return KernelResult<BrepBody>.Failure([+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ $"Bounded prism-family subtract on box-root requires the prism footprint to remain strictly inside the source box bounds; tool op '{prismTool.OpName}' is out of bounds.",+ Source: "firmament.prism-bounded-subtract")+ ]);+ }+ }++ return BrepBooleanBoxPrismThroughCutBuilder.Build(rootBox, footprint, ToleranceContext.Default);}private static KernelResult<BrepBody> ExecuteBoundedDraftOnRecognizedOrthogonalRoot(diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.csindex a9f15401..5539cb35 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrismFamilyTools.cs@@ -1,4 +1,5 @@using Aetheris.Kernel.Core.Brep;+using Aetheris.Kernel.Core.Brep.Features;using Aetheris.Kernel.Core.Diagnostics;using Aetheris.Kernel.Core.Math;using Aetheris.Kernel.Core.Results;@@ -18,7 +19,8 @@ internal sealed record FirmamentPrismToolDescriptor(string OpName,IReadOnlyList<string> RequiredFields,Func<FirmamentLoweredToolOp, KernelResult<BrepBody>> CreateBody,- Func<FirmamentLoweredToolOp, double> ResolveHeight);+ Func<FirmamentLoweredToolOp, double> ResolveHeight,+ Func<FirmamentLoweredToolOp, IReadOnlyList<ProfilePoint2D>> ResolveFootprint);internal static class FirmamentPrismFamilyTools{@@ -30,7 +32,13 @@ internal static class FirmamentPrismFamilyToolsFirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_width"]),FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_depth"]),FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),- static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]),+ static tool =>+ [+ new ProfilePoint2D(-FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_width"]) * 0.5d, -FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_depth"]) * 0.5d),+ new ProfilePoint2D(FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_width"]) * 0.5d, -FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_depth"]) * 0.5d),+ new ProfilePoint2D(0d, FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["base_depth"]) * 0.5d),+ ]);private static readonly FirmamentPrismToolDescriptor HexagonalPrismDescriptor = new(FirmamentPrismToolKind.HexagonalPrism,@@ -39,7 +47,19 @@ internal static class FirmamentPrismFamilyToolsstatic tool => BrepPrimitives.CreateHexagonalPrism(FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["across_flats"]),FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),- static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]),+ static tool =>+ {+ var acrossFlats = FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["across_flats"]);+ var circumradius = acrossFlats / double.Sqrt(3d);+ return Enumerable.Range(0, 6)+ .Select(index =>+ {+ var angle = (double.Pi / 3d) * index;+ return new ProfilePoint2D(circumradius * double.Cos(angle), circumradius * double.Sin(angle));+ })+ .ToArray();+ });private static readonly FirmamentPrismToolDescriptor StraightSlotDescriptor = new(FirmamentPrismToolKind.StraightSlot,@@ -49,7 +69,31 @@ internal static class FirmamentPrismFamilyToolsFirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["length"]),FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["width"]),FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"])),- static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]));+ static tool => FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["height"]),+ static tool =>+ {+ var length = FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["length"]);+ var width = FirmamentPrimitiveToolParsing.ParseScalar(tool.RawFields["width"]);+ const int semicircleSegments = 8;+ var halfLength = length * 0.5d;+ var radius = width * 0.5d;+ var centerOffset = halfLength - radius;+ var profileVertices = new List<ProfilePoint2D>(2 * (semicircleSegments + 1));++ for (var i = 0; i <= semicircleSegments; i++)+ {+ var t = double.Pi * (i / (double)semicircleSegments) - (double.Pi * 0.5d);+ profileVertices.Add(new ProfilePoint2D(centerOffset + (radius * double.Cos(t)), radius * double.Sin(t)));+ }++ for (var i = 0; i <= semicircleSegments; i++)+ {+ var t = double.Pi * (i / (double)semicircleSegments) + (double.Pi * 0.5d);+ profileVertices.Add(new ProfilePoint2D(-centerOffset + (radius * double.Cos(t)), radius * double.Sin(t)));+ }++ return profileVertices;+ });private static readonly IReadOnlyDictionary<string, FirmamentPrismToolDescriptor> DescriptorsByOpName =new Dictionary<string, FirmamentPrismToolDescriptor>(StringComparer.Ordinal)@@ -100,4 +144,7 @@ internal static class FirmamentPrismFamilyToolsvar height = descriptor.ResolveHeight(tool);return new Vector3D(0d, 0d, height * 0.5d);}++ public static IReadOnlyList<ProfilePoint2D> ResolveFootprint(FirmamentPrismToolDescriptor descriptor, FirmamentLoweredToolOp tool)+ => descriptor.ResolveFootprint(tool);}diff --git a/testdata/firmament/fixtures/m3b-invalid-box-subtract-hexagonal-prism-out-of-bounds.firmament b/testdata/firmament/fixtures/m3b-invalid-box-subtract-hexagonal-prism-out-of-bounds.firmamentnew file mode 100644index 00000000..9f0f6436--- /dev/null+++ b/testdata/firmament/fixtures/m3b-invalid-box-subtract-hexagonal-prism-out-of-bounds.firmament@@ -0,0 +1,17 @@+firmament:+ version: 1++model:+ name: m3b_invalid_box_subtract_hexagonal_prism_out_of_bounds+ units: mm++ops[2]:+ -+ op: box+ id: base+ size[3]: [40, 30, 20]+ -+ op: subtract+ id: hex_cut+ from: base+ with: { op: hexagonal_prism, across_flats: 60, height: 24 }diff --git a/testdata/firmament/fixtures/m3b-invalid-box-subtract-triangular-prism-short-height.firmament b/testdata/firmament/fixtures/m3b-invalid-box-subtract-triangular-prism-short-height.firmamentnew file mode 100644index 00000000..6a6f342e--- /dev/null+++ b/testdata/firmament/fixtures/m3b-invalid-box-subtract-triangular-prism-short-height.firmament@@ -0,0 +1,17 @@+firmament:+ version: 1++model:+ name: m3b_invalid_box_subtract_triangular_prism_short_height+ units: mm++ops[2]:+ -+ op: box+ id: base+ size[3]: [40, 30, 20]+ -+ op: subtract+ id: tri_cut+ from: base+ with: { op: triangular_prism, base_width: 18, base_depth: 10, height: 10 }