Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
chamfer: parse two-edge corner selectors and isolate incident-edge blocker
Yuechen Li46bad35c3704
diff --git a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParserTests.cs b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParserTests.csnew file mode 100644index 00000000..9714fde6--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParserTests.cs@@ -0,0 +1,22 @@+using Aetheris.Kernel.Core.Brep.EdgeFinishing;++namespace Aetheris.Kernel.Core.Tests.Brep.EdgeFinishing;++public sealed class BrepBoundedEdgeFinishingToolParserTests+{+ [Fact]+ public void TryParseChamferSelection_Allows_TwoEdgeCornerPair()+ {+ var fields = new Dictionary<string, string>+ {+ ["edges"] = "[\"x_max_y_max\", \"x_max_y_min\"]"+ };++ var ok = BrepBoundedEdgeFinishingToolParser.TryParseChamferSelection(fields, out var edge, out var edgePair, out var corner, out var error);++ Assert.True(ok, error);+ Assert.Null(edge);+ Assert.True(edgePair.HasValue);+ Assert.Null(corner);+ }+}diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.csindex 9dff6f04..7f152bb6 100644--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs@@ -9,10 +9,12 @@ public static class BrepBoundedEdgeFinishingToolParserpublic static bool TryParseChamferSelection(IReadOnlyDictionary<string, string> fields,out BrepBoundedChamferEdge? edge,+ out (BrepBoundedChamferEdge First, BrepBoundedChamferEdge Second)? edgePair,out BrepBoundedChamferCorner? corner,out string error){edge = null;+ edgePair = null;corner = null;error = string.Empty;@@ -26,12 +28,18 @@ public static class BrepBoundedEdgeFinishingToolParserif (hasEdges){- if (!TryParseChamferEdge(fields, out var parsedEdge, out error))+ if (!TryParseChamferEdges(fields, out var parsedEdges, out error)){return false;}- edge = parsedEdge;+ if (parsedEdges.Length == 1)+ {+ edge = parsedEdges[0];+ return true;+ }++ edgePair = (parsedEdges[0], parsedEdges[1]);return true;}@@ -62,7 +70,28 @@ public static class BrepBoundedEdgeFinishingToolParserout BrepBoundedChamferEdge edge,out string error){- edge = BrepBoundedChamferEdge.XMinYMin;+ edge = default;+ if (!TryParseChamferEdges(fields, out var edges, out error))+ {+ return false;+ }++ if (edges.Length != 1)+ {+ error = "bounded M5a supports exactly one explicit edge token";+ return false;+ }++ edge = edges[0];+ return true;+ }++ private static bool TryParseChamferEdges(+ IReadOnlyDictionary<string, string> fields,+ out BrepBoundedChamferEdge[] edges,+ out string error)+ {+ edges = [];error = string.Empty;if (!fields.TryGetValue("edges", out var edgesRaw) || string.IsNullOrWhiteSpace(edgesRaw))@@ -77,27 +106,38 @@ public static class BrepBoundedEdgeFinishingToolParserreturn false;}- if (tokens.Length != 1)+ if (tokens.Length is < 1 or > 2){- error = "bounded M5a supports exactly one explicit edge token";+ error = "bounded M5a supports either one edge token or a two-edge corner pair";return false;}- edge = tokens[0] switch+ var parsed = new BrepBoundedChamferEdge[tokens.Length];+ for (var i = 0; i < tokens.Length; i++){- "x_min_y_min" => BrepBoundedChamferEdge.XMinYMin,- "x_min_y_max" => BrepBoundedChamferEdge.XMinYMax,- "x_max_y_min" => BrepBoundedChamferEdge.XMaxYMin,- "x_max_y_max" => BrepBoundedChamferEdge.XMaxYMax,- _ => BrepBoundedChamferEdge.XMinYMin- };+ parsed[i] = tokens[i] switch+ {+ "x_min_y_min" => BrepBoundedChamferEdge.XMinYMin,+ "x_min_y_max" => BrepBoundedChamferEdge.XMinYMax,+ "x_max_y_min" => BrepBoundedChamferEdge.XMaxYMin,+ "x_max_y_max" => BrepBoundedChamferEdge.XMaxYMax,+ _ => default+ };++ if (tokens[i] is not ("x_min_y_min" or "x_min_y_max" or "x_max_y_min" or "x_max_y_max"))+ {+ error = "supported tokens are x_min_y_min, x_min_y_max, x_max_y_min, x_max_y_max";+ return false;+ }+ }- if (tokens[0] is not ("x_min_y_min" or "x_min_y_max" or "x_max_y_min" or "x_max_y_max"))+ if (parsed.Length == 2 && parsed[0] == parsed[1]){- error = "supported tokens are x_min_y_min, x_min_y_max, x_max_y_min, x_max_y_max";+ error = "two-edge corner pair requires two distinct edge tokens";return false;}+ edges = parsed;return true;}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.csindex 9a886e7a..bcabda57 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs@@ -302,6 +302,16 @@ public sealed class FirmamentPrimitiveExecutionTestsdiagnostic.Message.Contains("distance is too large", StringComparison.Ordinal));}+ [Fact]+ public void Compile_Rejects_BoundedChamfer_TwoEdgeCornerPair_When_Tokens_Do_Not_Name_Incident_VertexEdges()+ {+ var result = CompileFixture("testdata/firmament/fixtures/m5a-invalid-chamfer-two-edge-corner-selector.firmament");++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Message.Contains("requires a selector family that names two incident edges at one vertex", StringComparison.Ordinal));+ }+[Fact]public void Compile_Executes_BoundedChamfer_SingleCorner_E2_On_BoxRoot_Into_Real_Body(){diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex 594c2921..1180173b 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -738,7 +738,7 @@ internal static class FirmamentPrimitiveExecutor]);}- if (!BrepBoundedEdgeFinishingToolParser.TryParseChamferSelection(boolean.Tool.RawFields, out var edge, out var corner, out var edgeError))+ if (!BrepBoundedEdgeFinishingToolParser.TryParseChamferSelection(boolean.Tool.RawFields, out var edge, out var edgePair, out var corner, out var edgeError)){return KernelResult<BrepBody>.Failure([@@ -779,6 +779,18 @@ internal static class FirmamentPrimitiveExecutorreturn BrepBoundedChamfer.ChamferAxisAlignedBoxVerticalEdge(box, edge.Value, distance);}+ if (edgePair.HasValue)+ {+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ "Bounded chamfer two-edge corner resolution requires a selector family that names two incident edges at one vertex; current bounded edge tokens identify disjoint vertical edges only.",+ Source: "firmament.chamfer-bounded")+ ]);+ }+if (corner.HasValue){if (BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(baseBody, ToleranceContext.Default, out var box, out _))diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.csindex 2cf90241..88e87330 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs@@ -170,15 +170,20 @@ internal static class FirmamentBooleanRequiredFieldValidatorif (hasEdges){- if (!TryParseFaceTokens(edgesRaw!, out var edgeTokens) || edgeTokens.Count != 1)+ if (!TryParseFaceTokens(edgesRaw!, out var edgeTokens) || edgeTokens.Count is < 1 or > 2){- return InvalidFieldTypeOrShape("edges", opIndex, entry.OpName, "expected a single-item string array with one explicit edge token");+ return InvalidFieldTypeOrShape("edges", opIndex, entry.OpName, "expected a string array with one explicit edge token or one two-edge corner pair");}- if (edgeTokens[0] is not ("x_min_y_min" or "x_min_y_max" or "x_max_y_min" or "x_max_y_max"))+ if (edgeTokens.Any(token => token is not ("x_min_y_min" or "x_min_y_max" or "x_max_y_min" or "x_max_y_max"))){return InvalidFieldValue("edges", opIndex, entry.OpName, "supported bounded M5a edge tokens are x_min_y_min, x_min_y_max, x_max_y_min, x_max_y_max");}++ if (edgeTokens.Count == 2 && string.Equals(edgeTokens[0], edgeTokens[1], StringComparison.Ordinal))+ {+ return InvalidFieldValue("edges", opIndex, entry.OpName, "bounded M5a two-edge corner pair requires two distinct edge tokens");+ }}else{diff --git a/testdata/firmament/fixtures/m5a-invalid-chamfer-two-edge-corner-selector.firmament b/testdata/firmament/fixtures/m5a-invalid-chamfer-two-edge-corner-selector.firmamentnew file mode 100644index 00000000..2fcddd96--- /dev/null+++ b/testdata/firmament/fixtures/m5a-invalid-chamfer-two-edge-corner-selector.firmament@@ -0,0 +1,23 @@+firmament:+ version: 1++model:+ name: m5a_invalid_chamfer_two_edge_corner_selector+ units: mm++ops[2]:+ -+ op: box+ id: base+ size[3]:+ 20+ 20+ 20+ -+ op: chamfer+ id: edge_break+ from: base+ edges[1]:+ x_max_y_max+ x_max_y_min+ distance: 1