Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

F1 bounded chained same-radius concave fillet support

Yuechen Li6e5eaba52d34
diff --git a/Aetheris.CLI.Tests/CliBaselineTests.cs b/Aetheris.CLI.Tests/CliBaselineTests.cs
index b067d2ff..5a26586c 100644
--- a/Aetheris.CLI.Tests/CliBaselineTests.cs
+++ b/Aetheris.CLI.Tests/CliBaselineTests.cs
@@ -219,6 +219,44 @@ public sealed class CliBaselineTests
File.Delete(outputPath);
}
+ [Fact]
+ public void Build_And_Analyze_BoundedChainedSameRadiusFillet_Reports_MultipleCylindricalSurfaces_And_Manifoldness()
+ {
+ var outputPath = Path.Combine(RepoRoot, "testdata", "firmament", "exports", "cli-m5b-bounded-chained-fillet.step");
+ if (File.Exists(outputPath))
+ {
+ File.Delete(outputPath);
+ }
+
+ var buildStdout = new StringWriter();
+ var buildStderr = new StringWriter();
+ var buildExitCode = Aetheris.CLI.CliRunner.Run(
+ ["build", Path.Combine(RepoRoot, "testdata/firmament/fixtures/m5b-valid-fillet-concave-chained-adjacent-pair.firmament"), "--out", outputPath],
+ buildStdout,
+ buildStderr);
+ Assert.Equal(0, buildExitCode);
+ Assert.True(File.Exists(outputPath), buildStderr.ToString());
+
+ var summary = AnalyzeSummary(outputPath);
+ Assert.Equal("enclosed-manifold", summary.GetProperty("structuralAssessment").GetString());
+ Assert.True(summary.GetProperty("surfaceFamilies").GetProperty("cylinder").GetInt32() >= 2);
+
+ var maxFaceId = summary.GetProperty("faceIds").GetProperty("max").GetInt32();
+ var cylinderCountAtRadius = 0;
+ for (var faceId = 1; faceId <= maxFaceId; faceId++)
+ {
+ var face = AnalyzeFace(outputPath, faceId);
+ if (face.GetProperty("surfaceType").GetString() is "Cylinder"
+ && Math.Abs(face.GetProperty("radius").GetDouble() - 0.4d) <= 1e-8)
+ {
+ cylinderCountAtRadius++;
+ }
+ }
+
+ Assert.True(cylinderCountAtRadius >= 2, "Expected at least two radius-0.4 cylindrical faces in bounded chained fillet export.");
+ File.Delete(outputPath);
+ }
+
[Fact]
public void Build_And_Analyze_TriangularPrism_Example_Reports_IsoscelesContractBounds()
{
diff --git a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
index 0c7a54ec..6903b0e9 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
@@ -46,7 +46,23 @@ public sealed class BrepBoundedFilletTests
var result = BrepBoundedFillet.FilletTrustedPolyhedralSingleInternalConcaveEdge(source, preflight.Value, 1.5d);
Assert.False(result.IsSuccess);
- Assert.Contains(result.Diagnostics, d => d.Message.Contains("No bounded single-edge fillet candidate", StringComparison.Ordinal));
+ Assert.Contains(result.Diagnostics, d => d.Message.Contains("No bounded single-edge/chained fillet candidate", StringComparison.Ordinal));
+ }
+
+ [Fact]
+ public void FilletTrustedPolyhedralSingleInternalConcaveEdge_Builds_ChainedSameRadiusCylindricalFillets_ForAdjacentPair()
+ {
+ var source = CreatePlanarSourceWithNotchComposition();
+ var preflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdges(
+ source.SafeBooleanComposition!,
+ [BrepBoundedManufacturingFilletEdge.InnerXMaxYMin, BrepBoundedManufacturingFilletEdge.InnerXMaxYMax],
+ radius: 1d);
+ Assert.True(preflight.IsSuccess, string.Join(Environment.NewLine, preflight.Diagnostics.Select(d => d.Message)));
+
+ var result = BrepBoundedFillet.FilletTrustedPolyhedralSingleInternalConcaveEdge(source, preflight.Value, 1d);
+
+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));
+ Assert.True(result.Value.Bindings.FaceBindings.Count(binding => result.Value.Geometry.GetSurface(binding.SurfaceGeometryId).Kind == SurfaceGeometryKind.Cylinder) >= 2);
}
private static BrepBody CreatePlanarSourceWithLRootComposition()
@@ -70,4 +86,24 @@ public sealed class BrepBoundedFilletTests
new AxisAlignedBoxExtents(0d, 30d, 0d, 10d, 0d, 10d),
new AxisAlignedBoxExtents(0d, 10d, 10d, 20d, 0d, 10d)
]);
+
+ private static BrepBody CreatePlanarSourceWithNotchComposition()
+ {
+ var box = BrepPrimitives.CreateBox(40d, 30d, 10d);
+ Assert.True(box.IsSuccess);
+ return new BrepBody(
+ box.Value.Topology,
+ box.Value.Geometry,
+ box.Value.Bindings,
+ vertexPoints: null,
+ safeBooleanComposition: new SafeBooleanComposition(
+ new AxisAlignedBoxExtents(0d, 40d, 0d, 30d, 0d, 10d),
+ [],
+ OccupiedCells:
+ [
+ new AxisAlignedBoxExtents(0d, 30d, 0d, 30d, 0d, 10d),
+ new AxisAlignedBoxExtents(30d, 40d, 0d, 10d, 0d, 10d),
+ new AxisAlignedBoxExtents(30d, 40d, 20d, 30d, 0d, 10d)
+ ]));
+ }
}
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
index a3fca1c6..9d14aeb9 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
@@ -23,8 +23,9 @@ public sealed class BrepBoundedManufacturingFilletPreflightTests
radius: 2d);
Assert.True(result.IsSuccess);
- Assert.Equal(10d, result.Value.EdgeX);
- Assert.Equal(10d, result.Value.EdgeY);
+ var corner = Assert.Single(result.Value.Corners);
+ Assert.Equal(10d, corner.EdgeX);
+ Assert.Equal(10d, corner.EdgeY);
}
[Fact]
@@ -47,4 +48,27 @@ public sealed class BrepBoundedManufacturingFilletPreflightTests
Assert.False(result.IsSuccess);
Assert.Contains(result.Diagnostics, diagnostic => diagnostic.Message.Contains("too large", StringComparison.Ordinal));
}
+
+ [Fact]
+ public void ResolveInternalConcaveVerticalEdges_Succeeds_ForAdjacentPair_OnNotchedRoot()
+ {
+ var composition = new SafeBooleanComposition(
+ new AxisAlignedBoxExtents(0d, 40d, 0d, 30d, 0d, 10d),
+ [],
+ OccupiedCells:
+ [
+ new AxisAlignedBoxExtents(0d, 30d, 0d, 30d, 0d, 10d),
+ new AxisAlignedBoxExtents(30d, 40d, 0d, 10d, 0d, 10d),
+ new AxisAlignedBoxExtents(30d, 40d, 20d, 30d, 0d, 10d)
+ ]);
+
+ var result = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdges(
+ composition,
+ [BrepBoundedManufacturingFilletEdge.InnerXMaxYMin, BrepBoundedManufacturingFilletEdge.InnerXMaxYMax],
+ radius: 2d);
+
+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));
+ Assert.Equal(2, result.Value.Corners.Count);
+ Assert.True(result.Value.HasLocalInteraction);
+ }
}
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs
index b6445336..a6adfc1c 100644
--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs
@@ -198,12 +198,12 @@ public static class BrepBoundedEdgeFinishingToolParser
return true;
}
- public static bool TryParseFilletEdge(
+ public static bool TryParseFilletEdges(
IReadOnlyDictionary<string, string> fields,
- out BrepBoundedManufacturingFilletEdge edge,
+ out BrepBoundedManufacturingFilletEdge[] edges,
out string error)
{
- edge = BrepBoundedManufacturingFilletEdge.InnerXMinYMin;
+ edges = [];
error = string.Empty;
if (!fields.TryGetValue("edges", out var edgesRaw) || string.IsNullOrWhiteSpace(edgesRaw))
@@ -218,27 +218,38 @@ public static class BrepBoundedEdgeFinishingToolParser
return false;
}
- if (tokens.Length != 1)
+ if (tokens.Length is < 1 or > 2)
{
- error = "bounded M5b supports exactly one explicit internal edge token";
+ error = "bounded M5b/F1 supports either one explicit internal edge token or two explicitly chained internal edge tokens";
return false;
}
- edge = tokens[0] switch
+ var parsed = new BrepBoundedManufacturingFilletEdge[tokens.Length];
+ for (var i = 0; i < tokens.Length; i++)
{
- "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
- };
+ parsed[i] = tokens[i] 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"))
+ if (tokens[i] 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;
+ }
+ }
+
+ if (parsed.Distinct().Count() != parsed.Length)
{
- error = "supported tokens are inner_x_min_y_min, inner_x_min_y_max, inner_x_max_y_min, inner_x_max_y_max";
+ error = "bounded M5b/F1 chained edge selection requires distinct edge tokens";
return false;
}
+ edges = parsed;
return true;
}
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
index 53f39ccd..46cf3fba 100644
--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
@@ -11,11 +11,12 @@ using Aetheris.Kernel.Core.Topology;
namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
/// <summary>
-/// F0 bounded single-edge constant-radius fillet builder for one explicit internal concave planar-planar vertical edge.
+/// F0/F1 bounded constant-radius cylindrical fillet builder for explicit internal concave planar-planar vertical edges.
/// </summary>
public static class BrepBoundedFillet
{
private const string SingleEdgeCylindricalFilletCandidate = "single_edge_cylindrical_fillet";
+ private const string ChainedSameRadiusCylindricalFilletCandidate = "chained_same_radius_cylindrical_fillets";
private const string RejectCandidate = "reject";
public static KernelResult<BrepBody> FilletTrustedPolyhedralSingleInternalConcaveEdge(
@@ -35,12 +36,17 @@ public static class BrepBoundedFillet
if (!judgment.IsSuccess || !judgment.Selection.HasValue || judgment.Selection.Value.Candidate.Name == RejectCandidate)
{
var reason = judgment.Rejections.Count == 0
- ? "No bounded single-edge fillet candidate was admissible."
+ ? "No bounded single-edge/chained fillet candidate was admissible."
: string.Join(" ", judgment.Rejections.Select(rejection => $"{rejection.CandidateName}: {rejection.Reason}."));
return KernelResult<BrepBody>.Failure([Failure($"Bounded fillet edge resolution rejected: {reason}", "firmament.fillet-bounded")]);
}
- return BuildSingleEdgeConcaveFilletBody(sourceBody, context);
+ return judgment.Selection.Value.Candidate.Name switch
+ {
+ SingleEdgeCylindricalFilletCandidate => BuildConcaveFilletBody(sourceBody, context),
+ ChainedSameRadiusCylindricalFilletCandidate => BuildConcaveFilletBody(sourceBody, context),
+ _ => KernelResult<BrepBody>.Failure([Failure($"Bounded fillet selected unsupported candidate '{judgment.Selection.Value.Candidate.Name}'.", "firmament.fillet-bounded")])
+ };
}
private static IReadOnlyList<JudgmentCandidate<BrepBoundedFilletContext>> BuildCandidates()
@@ -50,22 +56,34 @@ public static class BrepBoundedFillet
Name: SingleEdgeCylindricalFilletCandidate,
IsAdmissible: When.All<BrepBoundedFilletContext>(
context => context.IsTrustedSource,
- context => context.IsSingleEdgeSelection,
+ context => context.SelectionCount == 1,
context => context.IsPlanarPlanar,
context => context.IsInternalConcave,
context => context.IsBoundedRadius),
Score: context => context.IsInternalConcave ? 100d : 0d,
- RejectionReason: context => $"requires trusted single-edge internal concave planar-planar bounded-radius context (trusted={context.IsTrustedSource}, single={context.IsSingleEdgeSelection}, planar={context.IsPlanarPlanar}, concave={context.IsInternalConcave}, bounded={context.IsBoundedRadius})",
+ RejectionReason: context => $"requires trusted single-edge internal concave planar-planar bounded-radius context (trusted={context.IsTrustedSource}, count={context.SelectionCount}, planar={context.IsPlanarPlanar}, concave={context.IsInternalConcave}, bounded={context.IsBoundedRadius})",
TieBreakerPriority: 0),
+ new JudgmentCandidate<BrepBoundedFilletContext>(
+ Name: ChainedSameRadiusCylindricalFilletCandidate,
+ IsAdmissible: When.All<BrepBoundedFilletContext>(
+ context => context.IsTrustedSource,
+ context => context.SelectionCount == 2,
+ context => context.IsPlanarPlanar,
+ context => context.IsInternalConcave,
+ context => context.IsBoundedRadius,
+ context => context.HasLocalChainedInteraction),
+ Score: context => context.HasLocalChainedInteraction ? 150d : 0d,
+ RejectionReason: context => $"requires trusted two-edge same-radius chained internal concave planar-planar bounded-radius context (trusted={context.IsTrustedSource}, count={context.SelectionCount}, planar={context.IsPlanarPlanar}, concave={context.IsInternalConcave}, bounded={context.IsBoundedRadius}, interacting={context.HasLocalChainedInteraction})",
+ TieBreakerPriority: 1),
new JudgmentCandidate<BrepBoundedFilletContext>(
Name: RejectCandidate,
IsAdmissible: _ => true,
Score: _ => -1d,
RejectionReason: _ => "bounded single-edge cylindrical fillet candidate is not admissible",
- TieBreakerPriority: 1)
+ TieBreakerPriority: 2)
];
- private static KernelResult<BrepBody> BuildSingleEdgeConcaveFilletBody(BrepBody sourceBody, BrepBoundedFilletContext context)
+ private static KernelResult<BrepBody> BuildConcaveFilletBody(BrepBody sourceBody, BrepBoundedFilletContext context)
{
if (!TryBuildOrthogonalFootprintLoop(context.OccupiedCells, out var loop, out var loopFailure))
{
@@ -74,17 +92,17 @@ public static class BrepBoundedFillet
"firmament.fillet-bounded")]);
}
- if (!TryApplySingleCornerFillet(loop, context.Selection.EdgeX, context.Selection.EdgeY, context.Radius, out var filletedLoop, out var filletFailure))
+ if (!TryApplyCornerFillets(loop, context.Selection.Corners, context.Radius, out var filletedLoop, out var filletFailure))
{
return KernelResult<BrepBody>.Failure([Failure(
- $"Bounded fillet local builder could not construct the selected internal-edge cylindrical cut: {filletFailure}",
+ $"Bounded fillet local builder could not construct the selected internal-edge cylindrical cut chain: {filletFailure}",
"firmament.fillet-bounded")]);
}
- return BuildExtrudedBodyWithSingleArc(filletedLoop, context.Selection.MinZ, context.Selection.MaxZ, context.Radius);
+ return BuildExtrudedBodyWithArcs(filletedLoop, context.Selection.MinZ, context.Selection.MaxZ, context.Radius);
}
- private static KernelResult<BrepBody> BuildExtrudedBodyWithSingleArc(
+ private static KernelResult<BrepBody> BuildExtrudedBodyWithArcs(
IReadOnlyList<LoopSegment2D> segments,
double minZ,
double maxZ,
@@ -262,10 +280,9 @@ public static class BrepBoundedFillet
return (startAngle, endAngle);
}
- private static bool TryApplySingleCornerFillet(
+ private static bool TryApplyCornerFillets(
IReadOnlyList<(double X, double Y)> loop,
- double cornerX,
- double cornerY,
+ IReadOnlyList<BoundedManufacturingFilletCornerSelection> corners,
double radius,
out List<LoopSegment2D> filletedLoop,
out string failure)
@@ -273,58 +290,90 @@ public static class BrepBoundedFillet
filletedLoop = [];
failure = string.Empty;
- var cornerIndices = Enumerable.Range(0, loop.Count)
- .Where(index => NearlyEqual(loop[index].X, cornerX) && NearlyEqual(loop[index].Y, cornerY))
- .ToArray();
- if (cornerIndices.Length != 1)
+ if (corners.Count is < 1 or > 2)
{
- failure = "selected internal corner was not uniquely present on the boundary loop";
+ failure = "selected bounded fillet corner set must contain one or two corners";
return false;
}
var signedArea = ComputeSignedArea(loop);
var isCounterClockwise = signedArea > 0d;
- var indexToFillet = cornerIndices[0];
- if (!IsConcaveCorner(loop, indexToFillet, isCounterClockwise))
+ var cornerDataByIndex = new Dictionary<int, ((double X, double Y) CutA, (double X, double Y) CutB, (double X, double Y) Center)>();
+ foreach (var cornerSelection in corners)
{
- failure = "selected corner is not a local concave corner on this footprint";
- return false;
- }
+ var cornerIndices = Enumerable.Range(0, loop.Count)
+ .Where(index => NearlyEqual(loop[index].X, cornerSelection.EdgeX) && NearlyEqual(loop[index].Y, cornerSelection.EdgeY))
+ .ToArray();
+ if (cornerIndices.Length != 1)
+ {
+ failure = "selected internal corner was not uniquely present on the boundary loop";
+ return false;
+ }
+
+ var indexToFillet = cornerIndices[0];
+ if (!IsConcaveCorner(loop, indexToFillet, isCounterClockwise))
+ {
+ failure = "selected corner is not a local concave corner on this footprint";
+ return false;
+ }
- var prevIndex = (indexToFillet + loop.Count - 1) % loop.Count;
- var nextIndex = (indexToFillet + 1) % loop.Count;
- var corner = loop[indexToFillet];
- var prev = loop[prevIndex];
- var next = loop[nextIndex];
+ var prevIndex = (indexToFillet + loop.Count - 1) % loop.Count;
+ var nextIndex = (indexToFillet + 1) % loop.Count;
+ var corner = loop[indexToFillet];
+ var prev = loop[prevIndex];
+ var next = loop[nextIndex];
- var incoming = (X: prev.X - corner.X, Y: prev.Y - corner.Y);
- var outgoing = (X: next.X - corner.X, Y: next.Y - corner.Y);
- if (!IsAxisAligned(incoming) || !IsAxisAligned(outgoing))
- {
- failure = "selected corner neighborhood is not axis-aligned";
- return false;
+ var incoming = (X: prev.X - corner.X, Y: prev.Y - corner.Y);
+ var outgoing = (X: next.X - corner.X, Y: next.Y - corner.Y);
+ if (!IsAxisAligned(incoming) || !IsAxisAligned(outgoing))
+ {
+ failure = "selected corner neighborhood is not axis-aligned";
+ return false;
+ }
+
+ var incomingLength = System.Math.Sqrt(incoming.X * incoming.X + incoming.Y * incoming.Y);
+ var outgoingLength = System.Math.Sqrt(outgoing.X * outgoing.X + outgoing.Y * outgoing.Y);
+ if (radius >= incomingLength || radius >= outgoingLength)
+ {
+ failure = "radius exceeds one of the local orthogonal edge spans";
+ return false;
+ }
+
+ var cutA = (corner.X + incoming.X / incomingLength * radius, corner.Y + incoming.Y / incomingLength * radius);
+ var cutB = (corner.X + outgoing.X / outgoingLength * radius, corner.Y + outgoing.Y / outgoingLength * radius);
+ var center = (corner.X + incoming.X / incomingLength * radius + outgoing.X / outgoingLength * radius,
+ corner.Y + incoming.Y / incomingLength * radius + outgoing.Y / outgoingLength * radius);
+ cornerDataByIndex[indexToFillet] = (cutA, cutB, center);
}
- var incomingLength = System.Math.Sqrt(incoming.X * incoming.X + incoming.Y * incoming.Y);
- var outgoingLength = System.Math.Sqrt(outgoing.X * outgoing.X + outgoing.Y * outgoing.Y);
- if (radius >= incomingLength || radius >= outgoingLength)
+ foreach (var index in cornerDataByIndex.Keys)
{
- failure = "radius exceeds one of the local orthogonal edge spans";
- return false;
+ var nextIndex = (index + 1) % loop.Count;
+ if (!cornerDataByIndex.ContainsKey(nextIndex))
+ {
+ continue;
+ }
+
+ var first = cornerDataByIndex[index].CutB;
+ var second = cornerDataByIndex[nextIndex].CutA;
+ if (LoopSegment2D.Line(first, second).Length <= 1e-8)
+ {
+ failure = "chained corner interaction collapsed an inter-fillet span";
+ return false;
+ }
}
- var cutA = (corner.X + incoming.X / incomingLength * radius, corner.Y + incoming.Y / incomingLength * radius);
- var cutB = (corner.X + outgoing.X / outgoingLength * radius, corner.Y + outgoing.Y / outgoingLength * radius);
- var center = (corner.X + incoming.X / incomingLength * radius + outgoing.X / outgoingLength * radius,
- corner.Y + incoming.Y / incomingLength * radius + outgoing.Y / outgoingLength * radius);
+ var arcCenters = cornerDataByIndex.Values.ToDictionary(
+ data => (data.CutA, data.CutB),
+ data => data.Center);
var transformed = new List<(double X, double Y)>();
for (var i = 0; i < loop.Count; i++)
{
- if (i == indexToFillet)
+ if (cornerDataByIndex.TryGetValue(i, out var data))
{
- transformed.Add(cutA);
- transformed.Add(cutB);
+ transformed.Add(data.CutA);
+ transformed.Add(data.CutB);
continue;
}
@@ -335,8 +384,7 @@ public static class BrepBoundedFillet
{
var start = transformed[i];
var end = transformed[(i + 1) % transformed.Count];
- if (NearlyEqual(start.X, cutA.Item1) && NearlyEqual(start.Y, cutA.Item2)
- && NearlyEqual(end.X, cutB.Item1) && NearlyEqual(end.Y, cutB.Item2))
+ if (arcCenters.TryGetValue((start, end), out var center))
{
filletedLoop.Add(LoopSegment2D.Arc(start, end, center, isClockwise: false));
}
@@ -575,7 +623,8 @@ public static class BrepBoundedFillet
internal readonly record struct BrepBoundedFilletContext(
bool IsTrustedSource,
- bool IsSingleEdgeSelection,
+ int SelectionCount,
+ bool HasLocalChainedInteraction,
bool IsPlanarPlanar,
bool IsInternalConcave,
bool IsBoundedRadius,
@@ -603,7 +652,8 @@ internal readonly record struct BrepBoundedFilletContext(
var bounded = radius < selection.MaxAllowedRadius;
return KernelResult<BrepBoundedFilletContext>.Success(new BrepBoundedFilletContext(
IsTrustedSource: true,
- IsSingleEdgeSelection: true,
+ SelectionCount: selection.Corners.Count,
+ HasLocalChainedInteraction: selection.HasLocalInteraction,
IsPlanarPlanar: planar,
IsInternalConcave: true,
IsBoundedRadius: bounded,
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
index 1bdfe738..62cea6fc 100644
--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
@@ -11,9 +11,9 @@ namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
/// </summary>
public static class BrepBoundedManufacturingFilletPreflight
{
- public static KernelResult<BoundedManufacturingFilletSelection> ResolveInternalConcaveVerticalEdge(
+ public static KernelResult<BoundedManufacturingFilletSelection> ResolveInternalConcaveVerticalEdges(
SafeBooleanComposition composition,
- BrepBoundedManufacturingFilletEdge edge,
+ IReadOnlyList<BrepBoundedManufacturingFilletEdge> edges,
double radius)
{
if (!double.IsFinite(radius) || radius <= 0d)
@@ -21,6 +21,13 @@ public static class BrepBoundedManufacturingFilletPreflight
return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure("Bounded fillet radius must be finite and greater than 0.", "firmament.fillet-bounded")]);
}
+ if (edges.Count is < 1 or > 2)
+ {
+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(
+ "Bounded M5b/F1 fillet supports one edge token or one two-edge chained token pair only.",
+ "firmament.fillet-bounded")]);
+ }
+
var cells = composition.OccupiedCells;
if (cells is null || cells.Count == 0)
{
@@ -95,25 +102,62 @@ public static class BrepBoundedManufacturingFilletPreflight
"firmament.fillet-bounded")]);
}
- var selected = SelectCorner(edge, corners);
- if (selected is null)
+ var selected = new List<BoundedManufacturingFilletCornerCandidate>(edges.Count);
+ foreach (var edge in edges)
+ {
+ var corner = SelectCorner(edge, corners);
+ if (corner 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")]);
+ }
+
+ selected.Add(corner.Value);
+ }
+
+ if (selected.Select(c => (c.X, c.Y)).Distinct().Count() != selected.Count)
{
return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(
- "Bounded fillet edge token did not resolve to a unique internal concave edge candidate on this source body.",
+ "Bounded M5b/F1 chained fillet requires edge tokens resolving to distinct local concave corners.",
"firmament.fillet-bounded")]);
}
- if (radius >= selected.Value.MaxAllowedRadius)
+ var maxAllowedRadius = selected.Min(corner => corner.MaxAllowedRadius);
+ if (radius >= 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")]);
}
+ var hasLocalInteraction = false;
+ if (selected.Count == 2)
+ {
+ hasLocalInteraction = AreAdjacentCorners(selected[0], selected[1], corners);
+ if (!hasLocalInteraction)
+ {
+ return KernelResult<BoundedManufacturingFilletSelection>.Failure([Failure(
+ "Bounded M5b/F1 chained fillet currently supports only locally adjacent concave edge pairs.",
+ "firmament.fillet-bounded")]);
+ }
+ }
+
return KernelResult<BoundedManufacturingFilletSelection>.Success(
- new BoundedManufacturingFilletSelection(selected.Value.X, selected.Value.Y, minZ, maxZ, selected.Value.MaxAllowedRadius));
+ new BoundedManufacturingFilletSelection(
+ selected.Select(corner => new BoundedManufacturingFilletCornerSelection(corner.X, corner.Y, corner.MaxAllowedRadius)).ToArray(),
+ minZ,
+ maxZ,
+ maxAllowedRadius,
+ hasLocalInteraction));
}
+ public static KernelResult<BoundedManufacturingFilletSelection> ResolveInternalConcaveVerticalEdge(
+ SafeBooleanComposition composition,
+ BrepBoundedManufacturingFilletEdge edge,
+ double radius)
+ => ResolveInternalConcaveVerticalEdges(composition, [edge], radius);
+
private static BoundedManufacturingFilletCornerCandidate? SelectCorner(
BrepBoundedManufacturingFilletEdge edge,
IReadOnlyList<BoundedManufacturingFilletCornerCandidate> corners)
@@ -131,6 +175,36 @@ public static class BrepBoundedManufacturingFilletPreflight
};
}
+ private static bool AreAdjacentCorners(
+ BoundedManufacturingFilletCornerCandidate first,
+ BoundedManufacturingFilletCornerCandidate second,
+ IReadOnlyList<BoundedManufacturingFilletCornerCandidate> allCorners)
+ {
+ var alignedX = NearlyEqual(first.X, second.X);
+ var alignedY = NearlyEqual(first.Y, second.Y);
+ if (alignedX == alignedY)
+ {
+ return false;
+ }
+
+ if (alignedX)
+ {
+ var low = System.Math.Min(first.Y, second.Y);
+ var high = System.Math.Max(first.Y, second.Y);
+ return !allCorners.Any(corner =>
+ NearlyEqual(corner.X, first.X)
+ && corner.Y > low
+ && corner.Y < high);
+ }
+
+ var minX = System.Math.Min(first.X, second.X);
+ var maxX = System.Math.Max(first.X, second.X);
+ return !allCorners.Any(corner =>
+ NearlyEqual(corner.Y, first.Y)
+ && corner.X > minX
+ && corner.X < maxX);
+ }
+
private static bool NearlyEqual(double a, double b)
=> System.Math.Abs(a - b) <= 1e-9;
@@ -141,10 +215,15 @@ public static class BrepBoundedManufacturingFilletPreflight
}
public readonly record struct BoundedManufacturingFilletSelection(
- double EdgeX,
- double EdgeY,
+ IReadOnlyList<BoundedManufacturingFilletCornerSelection> Corners,
double MinZ,
double MaxZ,
+ double MaxAllowedRadius,
+ bool HasLocalInteraction);
+
+public readonly record struct BoundedManufacturingFilletCornerSelection(
+ double EdgeX,
+ double EdgeY,
double MaxAllowedRadius);
public enum BrepBoundedManufacturingFilletEdge
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
index ac41f877..7dfde46b 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanRequiredFieldValidationTests.cs
@@ -425,6 +425,38 @@ public sealed class FirmamentBooleanRequiredFieldValidationTests
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_Rejects_Fillet_ThreeEdgeChainShape() =>
+ 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[3]:
+ inner_x_min_y_min
+ inner_x_max_y_min
+ inner_x_max_y_max
+ radius: 1
+ """,
+ FirmamentDiagnosticCodes.BooleanInvalidFieldTypeOrShape,
+ "Boolean op 'fillet' at index 1 has invalid field 'edges'; expected a one- or two-item string array with explicit internal edge tokens.");
+
[Fact]
public void Compiler_Allows_ValidTorusBooleanToolShape_Past_FieldValidation()
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index 72625336..ace8aed0 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -464,6 +464,21 @@ public sealed class FirmamentPrimitiveExecutionTests
face => fillet.Body.Geometry.GetSurface(face.SurfaceGeometryId).Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cylinder);
}
+ [Fact]
+ public void Compile_BoundedFilletChainedAdjacentPair_Executes_With_MultipleCylindricalFaces()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5b-valid-fillet-concave-chained-adjacent-pair.firmament");
+
+ Assert.True(result.Compilation.IsSuccess, string.Join(Environment.NewLine, result.Compilation.Diagnostics.Select(d => d.Message)));
+ var execution = result.Compilation.Value.PrimitiveExecutionResult!;
+ var root = Assert.Single(execution.ExecutedBooleans, executed => executed.FeatureId == "croot");
+ var fillet = Assert.Single(execution.ExecutedBooleans, executed => executed.FeatureId == "chained_inner_fillet");
+ Assert.Equal(FirmamentLoweredBooleanKind.Fillet, fillet.Kind);
+ Assert.NotEqual(root.Body.Topology.Faces.Count(), fillet.Body.Topology.Faces.Count());
+ Assert.True(
+ fillet.Body.Bindings.FaceBindings.Count(face => fillet.Body.Geometry.GetSurface(face.SurfaceGeometryId).Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cylinder) >= 2);
+ }
+
[Fact]
public void Compile_Rejects_BoundedFillet_When_Source_Has_NoOccupiedCellMetadata()
@@ -487,6 +502,17 @@ public sealed class FirmamentPrimitiveExecutionTests
&& diagnostic.Message.Contains("not eligible", StringComparison.Ordinal));
}
+ [Fact]
+ public void Compile_Rejects_BoundedFillet_ThreeEdgeChain_Request()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5b-invalid-fillet-three-edge-chain.firmament");
+
+ Assert.False(result.Compilation.IsSuccess);
+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
+ diagnostic.Source == "firmament"
+ && diagnostic.Message.Contains("one- or two-item string array", 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 e5fb16bd..28867e6e 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -857,7 +857,7 @@ internal static class FirmamentPrimitiveExecutor
]);
}
- if (!BrepBoundedEdgeFinishingToolParser.TryParseFilletEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
+ if (!BrepBoundedEdgeFinishingToolParser.TryParseFilletEdges(boolean.Tool.RawFields, out var edges, out var edgeError))
{
return KernelResult<BrepBody>.Failure(
[
@@ -887,9 +887,9 @@ internal static class FirmamentPrimitiveExecutor
composition = recognized;
}
- var preflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdge(
+ var preflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdges(
composition,
- edge,
+ edges,
radius);
if (!preflight.IsSuccess)
{
diff --git a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
index a6669c8d..8718d36b 100644
--- a/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
+++ b/Aetheris.Kernel.Firmament/Validation/FirmamentBooleanRequiredFieldValidator.cs
@@ -266,16 +266,21 @@ internal static class FirmamentBooleanRequiredFieldValidator
return MissingField("edges", opIndex, entry.OpName);
}
- if (!TryParseFaceTokens(edgesRaw, out var tokens) || tokens.Count != 1)
+ if (!TryParseFaceTokens(edgesRaw, out var tokens) || tokens.Count is < 1 or > 2)
{
- return InvalidFieldTypeOrShape("edges", opIndex, entry.OpName, "expected a single-item string array with one explicit internal edge token");
+ return InvalidFieldTypeOrShape("edges", opIndex, entry.OpName, "expected a one- or two-item string array with explicit internal edge tokens");
}
- 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"))
+ if (tokens.Any(token => token 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");
}
+ if (tokens.Distinct(StringComparer.Ordinal).Count() != tokens.Count)
+ {
+ return InvalidFieldValue("edges", opIndex, entry.OpName, "bounded M5b/F1 chained fillet requires distinct internal edge tokens");
+ }
+
return KernelResult<bool>.Success(true);
}
diff --git a/testdata/firmament/fixtures/m5b-invalid-fillet-three-edge-chain.firmament b/testdata/firmament/fixtures/m5b-invalid-fillet-three-edge-chain.firmament
new file mode 100644
index 00000000..0c9d049b
--- /dev/null
+++ b/testdata/firmament/fixtures/m5b-invalid-fillet-three-edge-chain.firmament
@@ -0,0 +1,40 @@
+firmament:
+ version: 1
+
+model:
+ name: m5b_invalid_fillet_three_edge_chain
+ units: mm
+
+ops[3]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 30
+ 20
+ 10
+ -
+ op: add
+ id: lroot
+ to: base
+ with:
+ op: box
+ size[3]:
+ 20
+ 10
+ 10
+ place:
+ on: origin
+ offset[3]:
+ 20
+ 10
+ 0
+ -
+ op: fillet
+ id: bad_three_edge_chain
+ from: lroot
+ edges[3]:
+ inner_x_min_y_min
+ inner_x_max_y_min
+ inner_x_max_y_max
+ radius: 1
diff --git a/testdata/firmament/fixtures/m5b-valid-fillet-concave-chained-adjacent-pair.firmament b/testdata/firmament/fixtures/m5b-valid-fillet-concave-chained-adjacent-pair.firmament
new file mode 100644
index 00000000..fba61218
--- /dev/null
+++ b/testdata/firmament/fixtures/m5b-valid-fillet-concave-chained-adjacent-pair.firmament
@@ -0,0 +1,55 @@
+firmament:
+ version: 1
+
+model:
+ name: m5b_valid_fillet_concave_chained_adjacent_pair
+ units: mm
+
+ops[4]:
+ -
+ op: box
+ id: base
+ size[3]:
+ 12
+ 4
+ 10
+ -
+ op: add
+ id: mid
+ to: base
+ with:
+ op: box
+ size[3]:
+ 6
+ 2
+ 10
+ place:
+ on: origin
+ offset[3]:
+ 0
+ 2
+ 0
+ -
+ op: add
+ id: croot
+ to: mid
+ with:
+ op: box
+ size[3]:
+ 12
+ 2
+ 10
+ place:
+ on: origin
+ offset[3]:
+ 0
+ 4
+ 0
+ -
+ op: fillet
+ id: chained_inner_fillet
+ from: croot
+ edges[2]:
+ inner_x_min_y_min
+ inner_x_min_y_max
+ radius: 0.4