Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement bounded 2-edge chamfer execution path via JudgmentEngine

Yuechen Li1f7cfb5f8169
diff --git a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedChamferCornerJudgmentTests.cs b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedChamferCornerJudgmentTests.cs
index 4990884f..9978f524 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedChamferCornerJudgmentTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedChamferCornerJudgmentTests.cs
@@ -35,4 +35,40 @@ public sealed class BrepBoundedChamferCornerJudgmentTests
Assert.Equal(12, result.Value.Topology.Edges.Count());
Assert.Equal(8, result.Value.Topology.Vertices.Count());
}
+
+ [Fact]
+ public void ChamferTrustedPolyhedralIncidentEdgePair_Succeeds_For_Box_Corner_E6()
+ {
+ var box = BrepPrimitives.CreateBox(20d, 20d, 20d);
+ Assert.True(box.IsSuccess);
+
+ var result = BrepBoundedChamfer.ChamferTrustedPolyhedralIncidentEdgePair(
+ box.Value,
+ new BrepBoundedChamferIncidentEdgePairSelector(
+ BrepBoundedChamferCorner.XMaxYMaxZMax,
+ BrepBoundedChamferCornerIncidentEdge.XNegative,
+ BrepBoundedChamferCornerIncidentEdge.YNegative),
+ distance: 1d);
+
+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));
+ Assert.Equal(7, result.Value.Topology.Faces.Count());
+ }
+
+ [Fact]
+ public void ChamferTrustedPolyhedralIncidentEdgePair_Uses_JudgmentEngine_Rejection_Path()
+ {
+ var box = BrepPrimitives.CreateBox(20d, 20d, 20d);
+ Assert.True(box.IsSuccess);
+
+ var result = BrepBoundedChamfer.ChamferTrustedPolyhedralIncidentEdgePair(
+ box.Value,
+ new BrepBoundedChamferIncidentEdgePairSelector(
+ BrepBoundedChamferCorner.XMaxYMaxZMax,
+ BrepBoundedChamferCornerIncidentEdge.XNegative,
+ BrepBoundedChamferCornerIncidentEdge.YNegative),
+ distance: 20d);
+
+ Assert.False(result.IsSuccess);
+ Assert.Contains(result.Diagnostics, diagnostic => diagnostic.Message.Contains("two-edge corner resolution rejected", StringComparison.Ordinal));
+ }
}
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
index 78a85e3a..78777bbf 100644
--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
@@ -17,6 +17,7 @@ namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
public static class BrepBoundedChamfer
{
private const string PlanarCornerCutCandidate = "planar_corner_cut";
+ private const string PlanarEdgePairCutCandidate = "planar_edge_pair_cut";
private const string RejectCandidate = "reject";
public static KernelResult<BrepBody> ChamferAxisAlignedBoxSingleCorner(
@@ -206,6 +207,65 @@ public static class BrepBoundedChamfer
];
}
+ public static KernelResult<BrepBody> ChamferTrustedPolyhedralIncidentEdgePair(
+ BrepBody sourceBody,
+ BrepBoundedChamferIncidentEdgePairSelector selector,
+ double distance)
+ {
+ var contextResult = BrepBoundedChamferCornerContext.TryCreateFromTrustedBody(sourceBody, selector.Corner, distance);
+ if (!contextResult.IsSuccess)
+ {
+ return KernelResult<BrepBody>.Failure(contextResult.Diagnostics);
+ }
+
+ var context = contextResult.Value;
+ var engine = new JudgmentEngine<BrepBoundedChamferCornerContext>();
+ var candidates = BuildIncidentEdgePairCandidates();
+ var judgment = engine.Evaluate(context, candidates);
+ if (!judgment.IsSuccess || !judgment.Selection.HasValue || judgment.Selection.Value.Candidate.Name == RejectCandidate)
+ {
+ var reason = judgment.Rejections.Count == 0
+ ? "No bounded two-edge corner-resolution candidate was admissible."
+ : string.Join(" ", judgment.Rejections.Select(rejection => $"{rejection.CandidateName}: {rejection.Reason}."));
+ return KernelResult<BrepBody>.Failure([Failure($"Bounded chamfer two-edge corner resolution rejected: {reason}", "firmament.chamfer-bounded")]);
+ }
+
+ return judgment.Selection.Value.Candidate.Name switch
+ {
+ PlanarEdgePairCutCandidate => CreateTrustedPolyhedralSingleCornerPlanarChamferBody(sourceBody, context),
+ _ => KernelResult<BrepBody>.Failure([Failure($"Bounded chamfer two-edge corner resolution selected unsupported candidate '{judgment.Selection.Value.Candidate.Name}'.", "firmament.chamfer-bounded")])
+ };
+ }
+
+ private static IReadOnlyList<JudgmentCandidate<BrepBoundedChamferCornerContext>> BuildIncidentEdgePairCandidates()
+ {
+ var planarGuard = When.All<BrepBoundedChamferCornerContext>(
+ context => context.ParticipatingEdgeCount == 3,
+ context => context.IsConvexCorner,
+ context => context.AllFacesPlanar,
+ context => context.AreChamferDistancesEqual,
+ context => context.IsDistanceWithinLocalBounds,
+ context => context.HasCoherentBoundedPlanarCut,
+ context => context.PreservesManifoldTopology,
+ context => context.Corner == BrepBoundedChamferCorner.XMaxYMaxZMax);
+
+ return
+ [
+ new JudgmentCandidate<BrepBoundedChamferCornerContext>(
+ Name: PlanarEdgePairCutCandidate,
+ IsAdmissible: planarGuard,
+ Score: context => context.AllAdjacentFacesOrthogonal ? 180d : 140d,
+ RejectionReason: _ => "requires convex planar corner with coherent bounded planar cut and manifold safety",
+ TieBreakerPriority: 0),
+ new JudgmentCandidate<BrepBoundedChamferCornerContext>(
+ Name: RejectCandidate,
+ IsAdmissible: _ => true,
+ Score: _ => 0d,
+ RejectionReason: _ => "fallback reject candidate",
+ TieBreakerPriority: 99)
+ ];
+ }
+
private static KernelResult<BrepBody> CreateSingleCornerPlanarChamferBody(BrepBoundedChamferCornerContext context)
{
var box = context.Box;
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index fa8b83e9..8c8bbe9b 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -303,13 +303,25 @@ public sealed class FirmamentPrimitiveExecutionTests
}
[Fact]
- public void Compile_BoundedChamfer_CornerIncidentEdgeSelector_Reaches_Explicit_2EdgeGeometryBlocker()
+ public void Compile_Executes_BoundedChamfer_CornerIncidentEdgeSelector_On_BoxRoot_Into_Real_Body()
{
var result = CompileFixture("testdata/firmament/fixtures/m5a-valid-chamfer-corner-incident-edge-selector.firmament");
+ Assert.True(result.Compilation.IsSuccess);
+ var executedBoolean = Assert.Single(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedBooleans);
+ Assert.Equal("corner_pair_break", executedBoolean.FeatureId);
+ Assert.Equal(FirmamentLoweredBooleanKind.Chamfer, executedBoolean.Kind);
+ Assert.Equal(7, executedBoolean.Body.Topology.Faces.Count());
+ }
+
+ [Fact]
+ public void Compile_Rejects_BoundedChamfer_CornerIncidentEdgeSelector_When_Distance_TooLarge()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5a-invalid-chamfer-corner-incident-distance-too-large.firmament");
+
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
- diagnostic.Message.Contains("selector resolved to a valid local incident-edge pair", StringComparison.Ordinal));
+ diagnostic.Message.Contains("two-edge corner resolution rejected", StringComparison.Ordinal));
}
[Fact]
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index 51a10dc2..54c6e2ca 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -781,14 +781,7 @@ internal static class FirmamentPrimitiveExecutor
if (incidentEdgePair.HasValue)
{
- return KernelResult<BrepBody>.Failure(
- [
- new KernelDiagnostic(
- KernelDiagnosticCode.ValidationFailed,
- KernelDiagnosticSeverity.Error,
- "Bounded chamfer two-edge corner selector resolved to a valid local incident-edge pair; geometric 2-edge corner constructor is the next isolated blocker.",
- Source: "firmament.chamfer-bounded")
- ]);
+ return BrepBoundedChamfer.ChamferTrustedPolyhedralIncidentEdgePair(baseBody, incidentEdgePair.Value, distance);
}
if (corner.HasValue)
diff --git a/testdata/firmament/fixtures/m5a-invalid-chamfer-corner-incident-distance-too-large.firmament b/testdata/firmament/fixtures/m5a-invalid-chamfer-corner-incident-distance-too-large.firmament
new file mode 100644
index 00000000..1af5f3b8
--- /dev/null
+++ b/testdata/firmament/fixtures/m5a-invalid-chamfer-corner-incident-distance-too-large.firmament
@@ -0,0 +1,25 @@
+firmament:
+ version: 1
+
+model:
+ name: m5a_invalid_chamfer_corner_incident_distance_too_large
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 20
+ 20
+ 20
+ -
+ op: chamfer
+ id: corner_pair_break
+ from: base
+ corners[1]:
+ x_max_y_max_z_max
+ corner_edges[2]:
+ x_neg
+ y_neg
+ distance: 20