Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
M5b: add bounded manufacturing fillet preflight and diagnostics
Yuechen Li04e12acf450e
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.csnew file mode 100644index 00000000..213a63c1--- /dev/null+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs@@ -0,0 +1,50 @@+using Aetheris.Kernel.Core.Brep.Boolean;+using Aetheris.Kernel.Core.Brep.Features;++namespace Aetheris.Kernel.Core.Tests.Brep.Features;++public sealed class BrepBoundedManufacturingFilletPreflightTests+{+ [Fact]+ public void ResolveInternalConcaveVerticalEdge_Succeeds_ForOrthogonalLRoot_WithBoundedRadius()+ {+ var composition = new SafeBooleanComposition(+ new AxisAlignedBoxExtents(0d, 30d, 0d, 20d, 0d, 10d),+ [],+ OccupiedCells:+ [+ new AxisAlignedBoxExtents(0d, 30d, 0d, 10d, 0d, 10d),+ new AxisAlignedBoxExtents(0d, 10d, 10d, 20d, 0d, 10d)+ ]);++ var result = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdge(+ composition,+ BrepBoundedManufacturingFilletEdge.InnerXMaxYMax,+ radius: 2d);++ Assert.True(result.IsSuccess);+ Assert.Equal(10d, result.Value.EdgeX);+ Assert.Equal(10d, result.Value.EdgeY);+ }++ [Fact]+ public void ResolveInternalConcaveVerticalEdge_Rejects_OverlargeRadius()+ {+ var composition = new SafeBooleanComposition(+ new AxisAlignedBoxExtents(0d, 30d, 0d, 20d, 0d, 10d),+ [],+ OccupiedCells:+ [+ new AxisAlignedBoxExtents(0d, 30d, 0d, 10d, 0d, 10d),+ new AxisAlignedBoxExtents(0d, 10d, 10d, 20d, 0d, 10d)+ ]);++ var result = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdge(+ composition,+ BrepBoundedManufacturingFilletEdge.InnerXMaxYMax,+ radius: 5d);++ Assert.False(result.IsSuccess);+ Assert.Contains(result.Diagnostics, diagnostic => diagnostic.Message.Contains("too large", StringComparison.Ordinal));+ }+}diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.cs b/Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.csnew file mode 100644index 00000000..879dc556--- /dev/null+++ b/Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.cs@@ -0,0 +1,156 @@+using Aetheris.Kernel.Core.Brep.Boolean;+using Aetheris.Kernel.Core.Diagnostics;+using Aetheris.Kernel.Core.Results;++namespace Aetheris.Kernel.Core.Brep.Features;++/// <summary>+/// M5b bounded manufacturing-fillet preflight for explicit internal concave planar vertical edges on+/// orthogonal full-height additive-root footprints represented by occupied cells.+/// This is intentionally a bounded selector/radius gate and not a general blend/corner-resolution system.+/// </summary>+public static class BrepBoundedManufacturingFilletPreflight+{+ public static KernelResult<BoundedManufacturingFilletSelection> ResolveInternalConcaveVerticalEdge(+ SafeBooleanComposition composition,+ BrepBoundedManufacturingFilletEdge edge,+ double radius)+ {+ if (!double.IsFinite(radius) || radius <= 0d)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure("Bounded fillet radius must be finite and greater than 0.", "firmament.fillet-bounded")]);+ }++ var cells = composition.OccupiedCells;+ if (cells is null || cells.Count == 0)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(+ "Bounded M5b fillet requires an occupied-cell orthogonal additive-root source so internal concave edge candidates can be identified explicitly.",+ "firmament.fillet-bounded")]);+ }++ var minZ = cells[0].MinZ;+ var maxZ = cells[0].MaxZ;+ for (var i = 1; i < cells.Count; i++)+ {+ if (!NearlyEqual(cells[i].MinZ, minZ) || !NearlyEqual(cells[i].MaxZ, maxZ))+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(+ "Bounded M5b fillet currently supports full-height prismatic occupied-cell roots only; mixed-Z occupied cells are outside this milestone.",+ "firmament.fillet-bounded")]);+ }+ }++ var xCoords = cells.SelectMany(cell => new[] { cell.MinX, cell.MaxX }).Distinct().OrderBy(v => v).ToArray();+ var yCoords = cells.SelectMany(cell => new[] { cell.MinY, cell.MaxY }).Distinct().OrderBy(v => v).ToArray();+ if (xCoords.Length < 2 || yCoords.Length < 2)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure("Bounded fillet preflight could not recover a usable XY cell grid.", "firmament.fillet-bounded")]);+ }++ var occupied = new bool[xCoords.Length - 1, yCoords.Length - 1];+ for (var xi = 0; xi < xCoords.Length - 1; xi++)+ {+ for (var yi = 0; yi < yCoords.Length - 1; yi++)+ {+ var cx = 0.5d * (xCoords[xi] + xCoords[xi + 1]);+ var cy = 0.5d * (yCoords[yi] + yCoords[yi + 1]);+ occupied[xi, yi] = cells.Any(cell =>+ cx > cell.MinX && cx < cell.MaxX &&+ cy > cell.MinY && cy < cell.MaxY);+ }+ }++ var corners = new List<BoundedManufacturingFilletCornerCandidate>();+ for (var xi = 1; xi < xCoords.Length - 1; xi++)+ {+ for (var yi = 1; yi < yCoords.Length - 1; yi++)+ {+ var sw = occupied[xi - 1, yi - 1];+ var se = occupied[xi, yi - 1];+ var nw = occupied[xi - 1, yi];+ var ne = occupied[xi, yi];+ var occupiedCount = (sw ? 1 : 0) + (se ? 1 : 0) + (nw ? 1 : 0) + (ne ? 1 : 0);+ if (occupiedCount != 3)+ {+ continue;+ }++ var dx = System.Math.Min(xCoords[xi] - xCoords[xi - 1], xCoords[xi + 1] - xCoords[xi]);+ var dy = System.Math.Min(yCoords[yi] - yCoords[yi - 1], yCoords[yi + 1] - yCoords[yi]);+ var maxRadius = 0.5d * System.Math.Min(dx, dy);+ if (maxRadius <= 0d || !double.IsFinite(maxRadius))+ {+ continue;+ }++ corners.Add(new BoundedManufacturingFilletCornerCandidate(xCoords[xi], yCoords[yi], maxRadius));+ }+ }++ if (corners.Count == 0)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(+ "Bounded M5b fillet only supports explicit internal concave planar-planar vertical edges; no qualifying internal concave edge was found on the source body.",+ "firmament.fillet-bounded")]);+ }++ var selected = SelectCorner(edge, corners);+ if (selected is null)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(+ "Bounded fillet edge token did not resolve to a unique internal concave edge candidate on this source body.",+ "firmament.fillet-bounded")]);+ }++ if (radius >= selected.Value.MaxAllowedRadius)+ {+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(+ "Bounded fillet radius is too large for the selected internal concave edge; radius must be strictly less than the local bounded neighborhood extent.",+ "firmament.fillet-bounded")]);+ }++ return KernelResult<BoundedManufacturingFilletSelection>.Success(+ new BoundedManufacturingFilletSelection(selected.Value.X, selected.Value.Y, minZ, maxZ, selected.Value.MaxAllowedRadius));+ }++ private static BoundedManufacturingFilletCornerCandidate? SelectCorner(+ BrepBoundedManufacturingFilletEdge edge,+ IReadOnlyList<BoundedManufacturingFilletCornerCandidate> corners)+ {+ var orderedByXThenY = corners.OrderBy(c => c.X).ThenBy(c => c.Y).ToArray();+ var orderedByXThenYDesc = corners.OrderByDescending(c => c.X).ThenBy(c => c.Y).ToArray();++ return edge switch+ {+ BrepBoundedManufacturingFilletEdge.InnerXMinYMin => orderedByXThenY.First(),+ BrepBoundedManufacturingFilletEdge.InnerXMinYMax => orderedByXThenY.OrderByDescending(c => c.Y).First(),+ BrepBoundedManufacturingFilletEdge.InnerXMaxYMin => orderedByXThenYDesc.First(),+ BrepBoundedManufacturingFilletEdge.InnerXMaxYMax => orderedByXThenYDesc.OrderByDescending(c => c.Y).First(),+ _ => null+ };+ }++ private static bool NearlyEqual(double a, double b)+ => System.Math.Abs(a - b) <= 1e-9;++ private static KernelDiagnostic Failure(string message, string source)+ => new(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, message, Source: source);++ private readonly record struct BoundedManufacturingFilletCornerCandidate(double X, double Y, double MaxAllowedRadius);+}++public readonly record struct BoundedManufacturingFilletSelection(+ double EdgeX,+ double EdgeY,+ double MinZ,+ double MaxZ,+ double MaxAllowedRadius);++public enum BrepBoundedManufacturingFilletEdge+{+ InnerXMinYMin,+ InnerXMinYMax,+ InnerXMaxYMin,+ InnerXMaxYMax+}diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.csindex dadb16c8..47d6d5ab 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs@@ -227,6 +227,83 @@ public sealed class FirmamentBooleanRequiredFieldValidationTestsFirmamentDiagnosticCodes.BooleanInvalidFieldValue,"Boolean op 'chamfer' at index 1 has invalid field 'edges'; supported bounded M5a edge tokens are x_min_y_min, x_min_y_max, x_max_y_min, x_max_y_max.");+ [Fact]+ public void Compiler_Allows_ValidBoundedFilletShape_Past_FieldValidation()+ {+ const string source = """+ firmament:+ version: 1++ model:+ name: demo+ units: mm++ ops[3]:+ -+ op: box+ id: base+ size[3]:+ 30+ 20+ 10+ -+ op: add+ id: rib+ to: base+ with:+ op: box+ size[3]:+ 10+ 10+ 10+ -+ op: fillet+ id: corner_relief+ from: rib+ edges[1]:+ inner_x_max_y_max+ radius: 1.25+ """;++ var compiler = new FirmamentCompiler();+ var result = compiler.Compile(new FirmamentCompileRequest(new FirmamentSourceDocument(source)));++ Assert.False(result.Compilation.IsSuccess);+ Assert.DoesNotContain(result.Compilation.Diagnostics, diagnostic => diagnostic.Message.Contains("[FIRM-STRUCT-", StringComparison.Ordinal));+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Source == "firmament.fillet-bounded");+ }++ [Fact]+ public void Compiler_Rejects_Fillet_UnsupportedEdgeToken() =>+ AssertBooleanFailure(+ """+ firmament:+ version: 1++ model:+ name: demo+ units: mm++ ops[2]:+ -+ op: box+ id: base+ size[3]:+ 20+ 20+ 20+ -+ op: fillet+ id: edge_break+ from: base+ edges[1]:+ x_max_y_max+ radius: 1+ """,+ FirmamentDiagnosticCodes.BooleanInvalidFieldValue,+ "Boolean op 'fillet' at index 1 has invalid field 'edges'; supported bounded M5b edge tokens are inner_x_min_y_min, inner_x_min_y_max, inner_x_max_y_min, inner_x_max_y_max.");+[Fact]public void Compiler_Allows_ValidTorusBooleanToolShape_Past_FieldValidation(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.csindex 4917ba42..9bc280f6 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs@@ -302,6 +302,29 @@ public sealed class FirmamentPrimitiveExecutionTestsdiagnostic.Message.Contains("distance is too large", StringComparison.Ordinal));}+ [Fact]+ public void Compile_BoundedFilletCanonicalInternalCase_Reaches_Narrow_TruthfulRebuildBlocker()+ {+ var result = CompileFixture("testdata/firmament/fixtures/m5b-canonical-internal-fillet-lroot.firmament");++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Source == "firmament.fillet-bounded"+ && diagnostic.Code == Aetheris.Kernel.Core.Diagnostics.KernelDiagnosticCode.ValidationFailed+ && diagnostic.Message.Contains("safe-composition metadata", StringComparison.Ordinal));+ }++ [Fact]+ public void Compile_Rejects_BoundedFillet_On_BoxRoot()+ {+ var result = CompileFixture("testdata/firmament/fixtures/m5b-invalid-fillet-radius-too-large.firmament");++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Source == "firmament.fillet-bounded"+ && diagnostic.Message.Contains("not eligible", StringComparison.Ordinal));+ }+[Fact]public void Compile_Mixed_Document_With_Unsupported_Boolean_Fails_Before_Publishing_Success_Artifact(){diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.csindex 272177e2..2f38da09 100644--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs@@ -95,6 +95,26 @@ internal static class FirmamentPrimitiveExecutorcontinue;}+ if (boolean.Kind == FirmamentLoweredBooleanKind.Fillet)+ {+ var filletResult = ExecuteBoundedManufacturingFilletOnRecognizedOrthogonalRoot(boolean, baseBody, featureGraphStates);+ if (!filletResult.IsSuccess)+ {+ return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(+ [+ CreateBooleanExecutionFailureDiagnostic(boolean),+ .. WithBooleanContext(boolean, filletResult.Diagnostics)+ ]);+ }++ var filletedBody = filletResult.Value;+ executedBooleans.Add(new FirmamentExecutedBoolean(boolean.OpIndex, boolean.FeatureId, boolean.Kind, filletedBody));+ publishedBodiesByFeatureId[boolean.FeatureId] = filletedBody;+ booleanExecutionBodiesByFeatureId[boolean.FeatureId] = filletedBody;+ featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;+ continue;+ }+if (IsPatternGeneratedFeature(boolean.FeatureId)){var patternToolResult = FirmamentBooleanToolBodyFactory.CreateBody(boolean.Tool);@@ -767,6 +787,133 @@ internal static class FirmamentPrimitiveExecutorreturn true;}+ private static KernelResult<BrepBody> ExecuteBoundedManufacturingFilletOnRecognizedOrthogonalRoot(+ FirmamentLoweredBoolean boolean,+ BrepBody baseBody,+ IReadOnlyDictionary<string, FirmamentSafeSubtractFeatureGraphState> featureGraphStates)+ {+ if (!featureGraphStates.TryGetValue(boolean.PrimaryReferenceFeatureId, out var sourceState)+ || sourceState is not (FirmamentSafeSubtractFeatureGraphState.BoundedOrthogonalAdditiveSafeRoot+ or FirmamentSafeSubtractFeatureGraphState.BoundedOrthogonalAdditiveOutsideSafeRoot+ or FirmamentSafeSubtractFeatureGraphState.SafeSubtractComposition))+ {+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ $"Bounded M5b fillet requires a recognized orthogonal additive or safe subtract root input; '{boolean.PrimaryReferenceFeatureId}' is not eligible.",+ Source: "firmament.fillet-bounded")+ ]);+ }++ if (!boolean.Tool.RawFields.TryGetValue("radius", out var radiusRaw)+ || !double.TryParse(radiusRaw, NumberStyles.Float, CultureInfo.InvariantCulture, out var radius)+ || !double.IsFinite(radius))+ {+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ "Bounded M5b fillet execution expected validated 'radius' scalar.",+ Source: "firmament.fillet-bounded")+ ]);+ }++ if (!TryParseFilletEdge(boolean.Tool.RawFields, out var edge, out var edgeError))+ {+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ $"Bounded fillet edges are invalid: {edgeError}.",+ Source: "firmament.fillet-bounded")+ ]);+ }++ if (baseBody.SafeBooleanComposition is null)+ {+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.ValidationFailed,+ KernelDiagnosticSeverity.Error,+ "Bounded M5b fillet requires a source body with safe-composition metadata for explicit internal concave edge preflight.",+ Source: "firmament.fillet-bounded")+ ]);+ }++ var preflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdge(+ baseBody.SafeBooleanComposition,+ edge,+ radius);+ if (!preflight.IsSuccess)+ {+ return KernelResult<BrepBody>.Failure(preflight.Diagnostics);+ }++ var selection = preflight.Value;+ return KernelResult<BrepBody>.Failure(+ [+ new KernelDiagnostic(+ KernelDiagnosticCode.NotImplemented,+ KernelDiagnosticSeverity.Error,+ $"Bounded M5b fillet preflight resolved internal edge at ({selection.EdgeX.ToString("0.###", CultureInfo.InvariantCulture)}, {selection.EdgeY.ToString("0.###", CultureInfo.InvariantCulture)}) with max radius {selection.MaxAllowedRadius.ToString("0.###", CultureInfo.InvariantCulture)}, but truthful cylindrical edge rebuild/export for this bounded family is not implemented yet.",+ Source: "firmament.fillet-bounded")+ ]);+ }++ private static bool TryParseFilletEdge(+ IReadOnlyDictionary<string, string> fields,+ out BrepBoundedManufacturingFilletEdge edge,+ out string error)+ {+ edge = BrepBoundedManufacturingFilletEdge.InnerXMinYMin;+ error = string.Empty;++ if (!fields.TryGetValue("edges", out var edgesRaw) || string.IsNullOrWhiteSpace(edgesRaw))+ {+ error = "missing required edges list";+ return false;+ }++ var trimmed = edgesRaw.Trim();+ if (!trimmed.StartsWith("[", StringComparison.Ordinal) || !trimmed.EndsWith("]", StringComparison.Ordinal))+ {+ error = "expected array-like edges value";+ return false;+ }++ var tokens = trimmed[1..^1]+ .Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)+ .Select(token => token.Trim().Trim('"'))+ .Where(token => !string.IsNullOrWhiteSpace(token))+ .ToArray();+ if (tokens.Length != 1)+ {+ error = "bounded M5b supports exactly one explicit internal edge token";+ return false;+ }++ edge = tokens[0] switch+ {+ "inner_x_min_y_min" => BrepBoundedManufacturingFilletEdge.InnerXMinYMin,+ "inner_x_min_y_max" => BrepBoundedManufacturingFilletEdge.InnerXMinYMax,+ "inner_x_max_y_min" => BrepBoundedManufacturingFilletEdge.InnerXMaxYMin,+ "inner_x_max_y_max" => BrepBoundedManufacturingFilletEdge.InnerXMaxYMax,+ _ => BrepBoundedManufacturingFilletEdge.InnerXMinYMin+ };+ if (tokens[0] is not ("inner_x_min_y_min" or "inner_x_min_y_max" or "inner_x_max_y_min" or "inner_x_max_y_max"))+ {+ error = "supported tokens are inner_x_min_y_min, inner_x_min_y_max, inner_x_max_y_min, inner_x_max_y_max";+ return false;+ }++ return true;+ }+private static bool TryParseDraftFaces(IReadOnlyDictionary<string, string> fields,out BrepBoundedDraftFaces faces,diff --git a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.csindex 758d2872..e620dd53 100644--- a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs+++ b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs@@ -169,6 +169,11 @@ internal static class FirmamentCanonicalFormatterEmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "edges");EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "distance");break;+ case FirmamentKnownOpKind.Fillet:+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "from");+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "edges");+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "radius");+ break;case FirmamentKnownOpKind.ExpectExists:EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "target");break;diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.csindex c7711528..ed5ca05c 100644--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs@@ -126,6 +126,9 @@ internal static class FirmamentPrimitiveLowerercase FirmamentKnownOpKind.Chamfer:loweredBooleans.Add(LowerChamfer(index, entry));break;+ case FirmamentKnownOpKind.Fillet:+ loweredBooleans.Add(LowerFillet(index, entry));+ break;default:skippedOps.Add(new FirmamentLoweringSkippedOp(@@ -208,6 +211,18 @@ internal static class FirmamentPrimitiveLowererPlacement: null);}+ private static FirmamentLoweredBoolean LowerFillet(int opIndex, FirmamentParsedOpEntry entry)+ {+ return new FirmamentLoweredBoolean(+ OpIndex: opIndex,+ FeatureId: entry.RawFields["id"],+ Kind: FirmamentLoweredBooleanKind.Fillet,+ PrimaryReferenceField: "from",+ PrimaryReferenceFeatureId: entry.RawFields["from"],+ Tool: new FirmamentLoweredToolOp("fillet", entry.RawFields, string.Empty),+ Placement: null);+ }+private static FirmamentLoweredToolOp ParseTool(string rawWith){var trimmed = rawWith.Trim();diff --git a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.csindex ba82c605..c7a221d9 100644--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs@@ -45,7 +45,8 @@ public enum FirmamentLoweredBooleanKindSubtract,Intersect,Draft,- Chamfer+ Chamfer,+ Fillet}public enum FirmamentLoweredPrimitiveKinddiff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.csindex 7bc4fbb6..23571985 100644--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs@@ -15,6 +15,7 @@ public enum FirmamentKnownOpKindIntersect,Draft,Chamfer,+ Fillet,ExpectExists,ExpectSelectable,ExpectManifold,@@ -41,6 +42,7 @@ internal static class FirmamentKnownOpKinds["intersect"] = FirmamentKnownOpKind.Intersect,["draft"] = FirmamentKnownOpKind.Draft,["chamfer"] = FirmamentKnownOpKind.Chamfer,+ ["fillet"] = FirmamentKnownOpKind.Fillet,["expect_exists"] = FirmamentKnownOpKind.ExpectExists,["expect_selectable"] = FirmamentKnownOpKind.ExpectSelectable,["expect_manifold"] = FirmamentKnownOpKind.ExpectManifold,@@ -68,6 +70,7 @@ internal static class FirmamentKnownOpKindsFirmamentKnownOpKind.Intersect => FirmamentOpFamily.Boolean,FirmamentKnownOpKind.Draft => FirmamentOpFamily.Boolean,FirmamentKnownOpKind.Chamfer => FirmamentOpFamily.Boolean,+ FirmamentKnownOpKind.Fillet => FirmamentOpFamily.Boolean,FirmamentKnownOpKind.ExpectExists => FirmamentOpFamily.Validation,FirmamentKnownOpKind.ExpectSelectable => FirmamentOpFamily.Validation,FirmamentKnownOpKind.ExpectManifold => FirmamentOpFamily.Validation,diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.csindex 98a2d98c..07ea8ea4 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs@@ -30,6 +30,7 @@ internal static class FirmamentBooleanRequiredFieldValidatorFirmamentKnownOpKind.Intersect => ValidateBooleanEntry(entry, index, targetFieldName: "left"),FirmamentKnownOpKind.Draft => ValidateDraftEntry(entry, index),FirmamentKnownOpKind.Chamfer => ValidateChamferEntry(entry, index),+ FirmamentKnownOpKind.Fillet => ValidateFilletEntry(entry, index),_ => KernelResult<bool>.Success(true)};@@ -178,6 +179,46 @@ internal static class FirmamentBooleanRequiredFieldValidatorreturn KernelResult<bool>.Success(true);}+ private static KernelResult<bool> ValidateFilletEntry(FirmamentParsedOpEntry entry, int opIndex)+ {+ if (!TryGetRequiredNonEmptyScalar(entry, "id", opIndex, out var missingOrTypeDiagnostic))+ {+ return KernelResult<bool>.Failure([missingOrTypeDiagnostic!]);+ }++ if (!TryGetRequiredNonEmptyScalar(entry, "from", opIndex, out missingOrTypeDiagnostic))+ {+ return KernelResult<bool>.Failure([missingOrTypeDiagnostic!]);+ }++ if (!entry.RawFields.TryGetValue("radius", out var radiusRaw) || string.IsNullOrWhiteSpace(radiusRaw))+ {+ return MissingField("radius", opIndex, entry.OpName);+ }++ if (!TryParseNumeric(radiusRaw, out var radius) || radius <= 0d)+ {+ return InvalidFieldValue("radius", opIndex, entry.OpName, "expected a numeric value greater than 0 for bounded M5b fillet");+ }++ if (!entry.RawFields.TryGetValue("edges", out var edgesRaw) || string.IsNullOrWhiteSpace(edgesRaw))+ {+ return MissingField("edges", opIndex, entry.OpName);+ }++ if (!TryParseFaceTokens(edgesRaw, out var tokens) || tokens.Count != 1)+ {+ return InvalidFieldTypeOrShape("edges", opIndex, entry.OpName, "expected a single-item string array with one explicit internal edge token");+ }++ if (tokens[0] is not ("inner_x_min_y_min" or "inner_x_min_y_max" or "inner_x_max_y_min" or "inner_x_max_y_max"))+ {+ return InvalidFieldValue("edges", opIndex, entry.OpName, "supported bounded M5b edge tokens are inner_x_min_y_min, inner_x_min_y_max, inner_x_max_y_min, inner_x_max_y_max");+ }++ return KernelResult<bool>.Success(true);+ }+private static KernelResult<bool> ValidateNestedPrimitiveToolFields(FirmamentParsedOpEntry entry, int opIndex, string withOpRaw, IReadOnlyDictionary<string, string> withFields){if (string.Equals(withOpRaw, "box", StringComparison.Ordinal))diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.csindex 867be7ed..f77d4f7e 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs@@ -687,6 +687,7 @@ internal static class FirmamentDocumentCoherenceValidatorFirmamentKnownOpKind.Intersect => "left",FirmamentKnownOpKind.Draft => "from",FirmamentKnownOpKind.Chamfer => "from",+ FirmamentKnownOpKind.Fillet => "from",_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, "Boolean op kind must map to a feature reference field.")};diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.csindex a7bf34a1..e8343874 100644--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs@@ -89,6 +89,7 @@ internal static class FirmamentSelectorContractscase FirmamentKnownOpKind.Intersect:case FirmamentKnownOpKind.Draft:case FirmamentKnownOpKind.Chamfer:+ case FirmamentKnownOpKind.Fillet:allowedPorts = BooleanAllowedPorts;return true;default:@@ -138,6 +139,7 @@ internal static class FirmamentSelectorContractscase FirmamentKnownOpKind.Intersect:case FirmamentKnownOpKind.Draft:case FirmamentKnownOpKind.Chamfer:+ case FirmamentKnownOpKind.Fillet:contracts = BooleanPorts;return true;default:diff --git a/testdata/firmament/fixtures/m5b-canonical-internal-fillet-lroot.firmament b/testdata/firmament/fixtures/m5b-canonical-internal-fillet-lroot.firmamentnew file mode 100644index 00000000..ed75c46a--- /dev/null+++ b/testdata/firmament/fixtures/m5b-canonical-internal-fillet-lroot.firmament@@ -0,0 +1,38 @@+firmament:+ version: 1++model:+ name: m5b_internal_fillet_lroot+ units: mm++ops[3]:+ -+ op: box+ id: base+ size[3]:+ 30+ 20+ 10+ -+ op: add+ id: lroot+ to: base+ with:+ op: box+ size[3]:+ 10+ 10+ 10+ place:+ on: origin+ offset[3]:+ -10+ 0+ 0+ -+ op: fillet+ id: corner_relief+ from: lroot+ edges[1]:+ inner_x_max_y_max+ radius: 1.5diff --git a/testdata/firmament/fixtures/m5b-invalid-fillet-radius-too-large.firmament b/testdata/firmament/fixtures/m5b-invalid-fillet-radius-too-large.firmamentnew file mode 100644index 00000000..0fa7f951--- /dev/null+++ b/testdata/firmament/fixtures/m5b-invalid-fillet-radius-too-large.firmament@@ -0,0 +1,22 @@+firmament:+ version: 1++model:+ name: m5b_invalid_fillet_box_root+ units: mm++ops[2]:+ -+ op: box+ id: base+ size[3]:+ 30+ 20+ 10+ -+ op: fillet+ id: corner_relief+ from: base+ edges[1]:+ inner_x_max_y_max+ radius: 5