Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement M5a bounded convex planar edge chamfer

Yuechen Licf8cf9b3911a
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs
new file mode 100644
index 00000000..294e776f
--- /dev/null
+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs
@@ -0,0 +1,36 @@
+using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Brep.Features;
+
+namespace Aetheris.Kernel.Core.Tests.Brep.Features;
+
+public sealed class BrepBoundedChamferTests
+{
+ [Fact]
+ public void ChamferAxisAlignedBoxVerticalEdge_Succeeds_ForSingleExplicitConvexEdge()
+ {
+ var box = new AxisAlignedBoxExtents(0d, 40d, 0d, 20d, 0d, 10d);
+
+ var result = BrepBoundedChamfer.ChamferAxisAlignedBoxVerticalEdge(
+ box,
+ BrepBoundedChamferEdge.XMaxYMax,
+ distance: 1.5d);
+
+ Assert.True(result.IsSuccess);
+ Assert.Equal(7, result.Value.Topology.Faces.Count());
+ Assert.True(result.Value.Topology.Edges.Count() > 12);
+ }
+
+ [Fact]
+ public void ChamferAxisAlignedBoxVerticalEdge_Rejects_OverlargeDistance()
+ {
+ var box = new AxisAlignedBoxExtents(0d, 8d, 0d, 5d, 0d, 10d);
+
+ var result = BrepBoundedChamfer.ChamferAxisAlignedBoxVerticalEdge(
+ box,
+ BrepBoundedChamferEdge.XMinYMin,
+ distance: 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/BrepBoundedChamfer.cs b/Aetheris.Kernel.Core/Brep/Features/BrepBoundedChamfer.cs
new file mode 100644
index 00000000..a4f827a7
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Features/BrepBoundedChamfer.cs
@@ -0,0 +1,110 @@
+using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Diagnostics;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Results;
+
+namespace Aetheris.Kernel.Core.Brep.Features;
+
+/// <summary>
+/// M5a bounded functional chamfer for convex planar-planar external edges on axis-aligned box-like bodies.
+/// This intentionally supports only a single explicit vertical box edge token with one uniform distance.
+/// </summary>
+public static class BrepBoundedChamfer
+{
+ public static KernelResult<BrepBody> ChamferAxisAlignedBoxVerticalEdge(
+ AxisAlignedBoxExtents box,
+ BrepBoundedChamferEdge edge,
+ double distance)
+ {
+ if (!double.IsFinite(distance) || distance <= 0d)
+ {
+ return KernelResult<BrepBody>.Failure([Failure("Bounded chamfer distance must be finite and greater than 0.", "firmament.chamfer-bounded")]);
+ }
+
+ var sizeX = box.MaxX - box.MinX;
+ var sizeY = box.MaxY - box.MinY;
+ var sizeZ = box.MaxZ - box.MinZ;
+ if (sizeX <= 0d || sizeY <= 0d || sizeZ <= 0d)
+ {
+ return KernelResult<BrepBody>.Failure([Failure("Bounded chamfer requires a source box with strictly positive extents.", "firmament.chamfer-bounded")]);
+ }
+
+ var maxDistance = System.Math.Min(sizeX, sizeY);
+ if (distance >= maxDistance)
+ {
+ return KernelResult<BrepBody>.Failure(
+ [
+ Failure(
+ "Bounded chamfer distance is too large for the selected edge; it must be strictly less than the local adjacent face extents to preserve manifoldness.",
+ "firmament.chamfer-bounded")
+ ]);
+ }
+
+ var profile = BuildProfile(box, edge, distance);
+ var frame = new ExtrudeFrame3D(
+ origin: new Point3D(0d, 0d, box.MinZ),
+ normal: Direction3D.Create(new Vector3D(0d, 0d, 1d)),
+ uAxis: Direction3D.Create(new Vector3D(1d, 0d, 0d)));
+ return BrepExtrude.Create(profile, frame, sizeZ);
+ }
+
+ private static PolylineProfile2D BuildProfile(AxisAlignedBoxExtents box, BrepBoundedChamferEdge edge, double d)
+ => CreateProfile(edge switch
+ {
+ BrepBoundedChamferEdge.XMaxYMax =>
+ [
+ new ProfilePoint2D(box.MinX, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MaxY - d),
+ new ProfilePoint2D(box.MaxX - d, box.MaxY),
+ new ProfilePoint2D(box.MinX, box.MaxY)
+ ],
+ BrepBoundedChamferEdge.XMaxYMin =>
+ [
+ new ProfilePoint2D(box.MinX, box.MinY),
+ new ProfilePoint2D(box.MaxX - d, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MinY + d),
+ new ProfilePoint2D(box.MaxX, box.MaxY),
+ new ProfilePoint2D(box.MinX, box.MaxY)
+ ],
+ BrepBoundedChamferEdge.XMinYMax =>
+ [
+ new ProfilePoint2D(box.MinX, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MaxY),
+ new ProfilePoint2D(box.MinX + d, box.MaxY),
+ new ProfilePoint2D(box.MinX, box.MaxY - d)
+ ],
+ BrepBoundedChamferEdge.XMinYMin =>
+ [
+ new ProfilePoint2D(box.MinX, box.MinY + d),
+ new ProfilePoint2D(box.MinX + d, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MinY),
+ new ProfilePoint2D(box.MaxX, box.MaxY),
+ new ProfilePoint2D(box.MinX, box.MaxY)
+ ],
+ _ => throw new ArgumentOutOfRangeException(nameof(edge), edge, null)
+ });
+
+ private static PolylineProfile2D CreateProfile(IReadOnlyList<ProfilePoint2D> vertices)
+ {
+ var profileResult = PolylineProfile2D.Create(vertices);
+ if (!profileResult.IsSuccess)
+ {
+ throw new InvalidOperationException("Bounded chamfer profile generation produced an invalid profile.");
+ }
+
+ return profileResult.Value;
+ }
+
+ private static KernelDiagnostic Failure(string message, string source)
+ => new(KernelDiagnosticCode.ValidationFailed, KernelDiagnosticSeverity.Error, message, Source: source);
+}
+
+public enum BrepBoundedChamferEdge
+{
+ XMinYMin,
+ XMinYMax,
+ XMaxYMin,
+ XMaxYMax
+}
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
index fc52a38d..dadb16c8 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
@@ -170,6 +170,63 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
FirmamentDiagnosticCodes.BooleanInvalidFieldValue,
"Boolean op 'draft' at index 1 has invalid field 'pull'; expected '+z' for bounded M4 draft pull direction.");
+ [Fact]
+ public void Compiler_Accepts_ValidBoundedChamferShape() =>
+ AssertValidBooleanOp("""
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 20
+ 10
+ -
+ op: chamfer
+ id: edge_break
+ from: base
+ edges[1]:
+ x_max_y_max
+ distance: 1.5
+ """);
+
+ [Fact]
+ public void Compiler_Rejects_Chamfer_UnsupportedEdgeToken() =>
+ AssertBooleanFailure(
+ """
+ firmament:
+ version: 1
+
+ model:
+ name: demo
+ units: mm
+
+ ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 20
+ 20
+ 20
+ -
+ op: chamfer
+ id: edge_break
+ from: base
+ edges[1]:
+ curved_edge
+ distance: 1
+ """,
+ FirmamentDiagnosticCodes.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_ValidTorusBooleanToolShape_Past_FieldValidation()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index 81a2375d..7dbfab42 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -174,6 +174,18 @@ public sealed class FirmamentBuildAndExportTests
"draft");
}
+ [Fact]
+ public void Run_M5aChamferBoxEdgeExample_Writes_Default_Export_Artifact()
+ {
+ AssertExampleBuildAndExport(
+ "testdata/firmament/examples/m5a_chamfer_box_edge_basic.firmament",
+ "m5a_chamfer_box_edge_basic.step",
+ "edge_break",
+ 1,
+ "boolean",
+ "chamfer");
+ }
+
[Fact]
public void Run_BooleanBoxCylinderHoleExample_Writes_Default_Export_Artifact()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index ba227e32..4917ba42 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -279,6 +279,29 @@ public sealed class FirmamentPrimitiveExecutionTests
diagnostic.Message.Contains("Bounded draft requires a box-root or recognized orthogonal additive root input", StringComparison.Ordinal));
}
+ [Fact]
+ public void Compile_Executes_BoundedChamfer_On_BoxRoot_Into_Real_Body()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5a-valid-chamfer-box-edge-exec.firmament");
+
+ Assert.True(result.Compilation.IsSuccess);
+ var executedBoolean = Assert.Single(result.Compilation.Value.PrimitiveExecutionResult!.ExecutedBooleans);
+ Assert.Equal("edge_break", executedBoolean.FeatureId);
+ Assert.Equal(FirmamentLoweredBooleanKind.Chamfer, executedBoolean.Kind);
+ Assert.Equal(7, executedBoolean.Body.Topology.Faces.Count());
+ Assert.NotEmpty(executedBoolean.Body.Topology.Bodies);
+ }
+
+ [Fact]
+ public void Compile_Rejects_BoundedChamfer_When_Distance_TooLarge()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5a-invalid-chamfer-distance-too-large.firmament");
+
+ Assert.False(result.Compilation.IsSuccess);
+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
+ diagnostic.Message.Contains("distance is too large", 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.cs
index d86c9d25..272177e2 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -1,3 +1,4 @@
+using System.Globalization;
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Boolean;
using Aetheris.Kernel.Core.Brep.Features;
@@ -74,6 +75,26 @@ internal static class FirmamentPrimitiveExecutor
continue;
}
+ if (boolean.Kind == FirmamentLoweredBooleanKind.Chamfer)
+ {
+ var chamferResult = ExecuteBoundedChamferOnRecognizedOrthogonalRoot(boolean, baseBody, featureGraphStates);
+ if (!chamferResult.IsSuccess)
+ {
+ return KernelResult<FirmamentPrimitiveExecutionResult>.Failure(
+ [
+ CreateBooleanExecutionFailureDiagnostic(boolean),
+ .. WithBooleanContext(boolean, chamferResult.Diagnostics)
+ ]);
+ }
+
+ var chamferedBody = chamferResult.Value;
+ executedBooleans.Add(new FirmamentExecutedBoolean(boolean.OpIndex, boolean.FeatureId, boolean.Kind, chamferedBody));
+ publishedBodiesByFeatureId[boolean.FeatureId] = chamferedBody;
+ booleanExecutionBodiesByFeatureId[boolean.FeatureId] = chamferedBody;
+ featureGraphStates[boolean.FeatureId] = FirmamentSafeSubtractFeatureGraphState.Other;
+ continue;
+ }
+
if (IsPatternGeneratedFeature(boolean.FeatureId))
{
var patternToolResult = FirmamentBooleanToolBodyFactory.CreateBody(boolean.Tool);
@@ -638,6 +659,114 @@ internal static class FirmamentPrimitiveExecutor
return BrepBoundedDraft.DraftAxisAlignedBoxSideFaces(box, angleDegrees, faces);
}
+ private static KernelResult<BrepBody> ExecuteBoundedChamferOnRecognizedOrthogonalRoot(
+ FirmamentLoweredBoolean boolean,
+ BrepBody baseBody,
+ IReadOnlyDictionary<string, FirmamentSafeSubtractFeatureGraphState> featureGraphStates)
+ {
+ if (!featureGraphStates.TryGetValue(boolean.PrimaryReferenceFeatureId, out var sourceState)
+ || sourceState is not (FirmamentSafeSubtractFeatureGraphState.BoxRoot or FirmamentSafeSubtractFeatureGraphState.BoundedOrthogonalAdditiveSafeRoot))
+ {
+ return KernelResult<BrepBody>.Failure(
+ [
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded chamfer requires a box-root or recognized orthogonal additive root input; '{boolean.PrimaryReferenceFeatureId}' is not eligible.",
+ Source: "firmament.chamfer-bounded")
+ ]);
+ }
+
+ if (!BrepBooleanBoxRecognition.TryRecognizeAxisAlignedBox(baseBody, ToleranceContext.Default, out var box, out var reason))
+ {
+ return KernelResult<BrepBody>.Failure(
+ [
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded chamfer requires an axis-aligned box-like source body; failed to recognize source body ({reason}).",
+ Source: "firmament.chamfer-bounded")
+ ]);
+ }
+
+ if (!boolean.Tool.RawFields.TryGetValue("distance", out var distanceRaw)
+ || !double.TryParse(distanceRaw, NumberStyles.Float, CultureInfo.InvariantCulture, out var distance)
+ || !double.IsFinite(distance))
+ {
+ return KernelResult<BrepBody>.Failure(
+ [
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ "Bounded chamfer execution expected validated 'distance' scalar.",
+ Source: "firmament.chamfer-bounded")
+ ]);
+ }
+
+ if (!TryParseChamferEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
+ {
+ return KernelResult<BrepBody>.Failure(
+ [
+ new KernelDiagnostic(
+ KernelDiagnosticCode.ValidationFailed,
+ KernelDiagnosticSeverity.Error,
+ $"Bounded chamfer edges are invalid: {edgeError}.",
+ Source: "firmament.chamfer-bounded")
+ ]);
+ }
+
+ return BrepBoundedChamfer.ChamferAxisAlignedBoxVerticalEdge(box, edge, distance);
+ }
+
+ private static bool TryParseChamferEdge(
+ IReadOnlyDictionary<string, string> fields,
+ out BrepBoundedChamferEdge edge,
+ out string error)
+ {
+ edge = BrepBoundedChamferEdge.XMinYMin;
+ 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 content = trimmed[1..^1];
+ var tokens = content.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
+ .Select(token => token.Trim().Trim('"'))
+ .Where(token => !string.IsNullOrWhiteSpace(token))
+ .ToArray();
+ if (tokens.Length != 1)
+ {
+ error = "bounded M5a supports exactly one explicit edge token";
+ return false;
+ }
+
+ edge = tokens[0] 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,
+ _ => BrepBoundedChamferEdge.XMinYMin
+ };
+ if (tokens[0] 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;
+ }
+
+ 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.cs
index 878351bf..758d2872 100644
--- a/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
+++ b/Aetheris.Kernel.Firmament/Formatting/FirmamentCanonicalFormatter.cs
@@ -164,6 +164,11 @@ internal static class FirmamentCanonicalFormatter
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "faces");
EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "direction");
break;
+ case FirmamentKnownOpKind.Chamfer:
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "from");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "edges");
+ EmitIfPresent(builder, entry.RawFields, emitted, indentLevel, "distance");
+ 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.cs
index ef546dcb..c7711528 100644
--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs
+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLowerer.cs
@@ -123,6 +123,9 @@ internal static class FirmamentPrimitiveLowerer
case FirmamentKnownOpKind.Draft:
loweredBooleans.Add(LowerDraft(index, entry));
break;
+ case FirmamentKnownOpKind.Chamfer:
+ loweredBooleans.Add(LowerChamfer(index, entry));
+ break;
default:
skippedOps.Add(new FirmamentLoweringSkippedOp(
@@ -193,6 +196,18 @@ internal static class FirmamentPrimitiveLowerer
Placement: null);
}
+ private static FirmamentLoweredBoolean LowerChamfer(int opIndex, FirmamentParsedOpEntry entry)
+ {
+ return new FirmamentLoweredBoolean(
+ OpIndex: opIndex,
+ FeatureId: entry.RawFields["id"],
+ Kind: FirmamentLoweredBooleanKind.Chamfer,
+ PrimaryReferenceField: "from",
+ PrimaryReferenceFeatureId: entry.RawFields["from"],
+ Tool: new FirmamentLoweredToolOp("chamfer", 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.cs
index 3cb267d9..ba82c605 100644
--- a/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs
+++ b/Aetheris.Kernel.Firmament/Lowering/FirmamentPrimitiveLoweringPlan.cs
@@ -44,7 +44,8 @@ public enum FirmamentLoweredBooleanKind
Add,
Subtract,
Intersect,
- Draft
+ Draft,
+ Chamfer
}
public enum FirmamentLoweredPrimitiveKind
diff --git a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
index 618cd666..7bc4fbb6 100644
--- a/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
+++ b/Aetheris.Kernel.Firmament/ParsedModel/FirmamentKnownOpKind.cs
@@ -14,6 +14,7 @@ public enum FirmamentKnownOpKind
Subtract,
Intersect,
Draft,
+ Chamfer,
ExpectExists,
ExpectSelectable,
ExpectManifold,
@@ -39,6 +40,7 @@ internal static class FirmamentKnownOpKinds
["subtract"] = FirmamentKnownOpKind.Subtract,
["intersect"] = FirmamentKnownOpKind.Intersect,
["draft"] = FirmamentKnownOpKind.Draft,
+ ["chamfer"] = FirmamentKnownOpKind.Chamfer,
["expect_exists"] = FirmamentKnownOpKind.ExpectExists,
["expect_selectable"] = FirmamentKnownOpKind.ExpectSelectable,
["expect_manifold"] = FirmamentKnownOpKind.ExpectManifold,
@@ -65,6 +67,7 @@ internal static class FirmamentKnownOpKinds
FirmamentKnownOpKind.Subtract => FirmamentOpFamily.Boolean,
FirmamentKnownOpKind.Intersect => FirmamentOpFamily.Boolean,
FirmamentKnownOpKind.Draft => FirmamentOpFamily.Boolean,
+ FirmamentKnownOpKind.Chamfer => 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.cs
index 8dee0765..98a2d98c 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
@@ -29,6 +29,7 @@ internal static class FirmamentBooleanRequiredFieldValidator
FirmamentKnownOpKind.Subtract => ValidateBooleanEntry(entry, index, targetFieldName: "from"),
FirmamentKnownOpKind.Intersect => ValidateBooleanEntry(entry, index, targetFieldName: "left"),
FirmamentKnownOpKind.Draft => ValidateDraftEntry(entry, index),
+ FirmamentKnownOpKind.Chamfer => ValidateChamferEntry(entry, index),
_ => KernelResult<bool>.Success(true)
};
@@ -137,6 +138,46 @@ internal static class FirmamentBooleanRequiredFieldValidator
return KernelResult<bool>.Success(true);
}
+ private static KernelResult<bool> ValidateChamferEntry(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("distance", out var distanceRaw) || string.IsNullOrWhiteSpace(distanceRaw))
+ {
+ return MissingField("distance", opIndex, entry.OpName);
+ }
+
+ if (!TryParseNumeric(distanceRaw, out var distance) || distance <= 0d)
+ {
+ return InvalidFieldValue("distance", opIndex, entry.OpName, "expected a numeric value greater than 0 for bounded M5a chamfer");
+ }
+
+ 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 edge token");
+ }
+
+ if (tokens[0] 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");
+ }
+
+ 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.cs
index 2f505857..867be7ed 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentDocumentCoherenceValidator.cs
@@ -686,6 +686,7 @@ internal static class FirmamentDocumentCoherenceValidator
FirmamentKnownOpKind.Subtract => "from",
FirmamentKnownOpKind.Intersect => "left",
FirmamentKnownOpKind.Draft => "from",
+ FirmamentKnownOpKind.Chamfer => "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.cs
index b5fec60f..a7bf34a1 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentSelectorContracts.cs
@@ -88,6 +88,7 @@ internal static class FirmamentSelectorContracts
case FirmamentKnownOpKind.Subtract:
case FirmamentKnownOpKind.Intersect:
case FirmamentKnownOpKind.Draft:
+ case FirmamentKnownOpKind.Chamfer:
allowedPorts = BooleanAllowedPorts;
return true;
default:
@@ -136,6 +137,7 @@ internal static class FirmamentSelectorContracts
case FirmamentKnownOpKind.Subtract:
case FirmamentKnownOpKind.Intersect:
case FirmamentKnownOpKind.Draft:
+ case FirmamentKnownOpKind.Chamfer:
contracts = BooleanPorts;
return true;
default:
diff --git a/testdata/firmament/examples/m5a_chamfer_box_edge_basic.firmament b/testdata/firmament/examples/m5a_chamfer_box_edge_basic.firmament
new file mode 100644
index 00000000..2eae12b1
--- /dev/null
+++ b/testdata/firmament/examples/m5a_chamfer_box_edge_basic.firmament
@@ -0,0 +1,22 @@
+firmament:
+ version: 1
+
+model:
+ name: m5a_chamfer_box_edge_basic
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 20
+ 10
+ -
+ op: chamfer
+ id: edge_break
+ from: base
+ edges[1]:
+ x_max_y_max
+ distance: 1.5
diff --git a/testdata/firmament/fixtures/m5a-invalid-chamfer-distance-too-large.firmament b/testdata/firmament/fixtures/m5a-invalid-chamfer-distance-too-large.firmament
new file mode 100644
index 00000000..8efde191
--- /dev/null
+++ b/testdata/firmament/fixtures/m5a-invalid-chamfer-distance-too-large.firmament
@@ -0,0 +1,22 @@
+firmament:
+ version: 1
+
+model:
+ name: m5a_invalid_chamfer_distance
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 8
+ 5
+ 10
+ -
+ op: chamfer
+ id: edge_break
+ from: base
+ edges[1]:
+ x_min_y_min
+ distance: 5
diff --git a/testdata/firmament/fixtures/m5a-valid-chamfer-box-edge-exec.firmament b/testdata/firmament/fixtures/m5a-valid-chamfer-box-edge-exec.firmament
new file mode 100644
index 00000000..7be85c11
--- /dev/null
+++ b/testdata/firmament/fixtures/m5a-valid-chamfer-box-edge-exec.firmament
@@ -0,0 +1,22 @@
+firmament:
+ version: 1
+
+model:
+ name: m5a_chamfer_box_edge_exec
+ units: mm
+
+ops[2]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 40
+ 20
+ 10
+ -
+ op: chamfer
+ id: edge_break
+ from: base
+ edges[1]:
+ x_max_y_max
+ distance: 1.5