Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement bounded same-radius cylindrical termination follow-on fillet

Yuechen Liacd5602bc844
diff --git a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
index be50e93f..0ee5d06b 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/EdgeFinishing/BrepBoundedFilletTests.cs
@@ -66,7 +66,7 @@ public sealed class BrepBoundedFilletTests
}
[Fact]
- public void FilletTrustedPolyhedralSingleInternalConcaveEdge_Rejects_ChainedCylindricalTerminationContext_Explicitly()
+ public void FilletTrustedPolyhedralSingleInternalConcaveEdge_Builds_ChainedCylindricalTermination_ForSameRadiusFollowOnPair()
{
var source = CreatePlanarSourceWithNotchComposition();
var preflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdges(
@@ -80,11 +80,37 @@ public sealed class BrepBoundedFilletTests
var secondPass = BrepBoundedFillet.FilletTrustedPolyhedralSingleInternalConcaveEdge(firstPass.Value, preflight.Value, 1d);
+ Assert.True(secondPass.IsSuccess, string.Join(Environment.NewLine, secondPass.Diagnostics.Select(d => d.Message)));
+ Assert.Contains(
+ secondPass.Value.Bindings.FaceBindings,
+ binding => secondPass.Value.Geometry.GetSurface(binding.SurfaceGeometryId).Kind == SurfaceGeometryKind.Cylinder);
+ }
+
+ [Fact]
+ public void FilletTrustedPolyhedralSingleInternalConcaveEdge_Rejects_ChainedCylindricalTermination_ForMismatchedRadius()
+ {
+ var source = CreatePlanarSourceWithNotchComposition();
+ var firstPreflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdge(
+ source.SafeBooleanComposition!,
+ BrepBoundedManufacturingFilletEdge.InnerXMaxYMin,
+ radius: 0.5d);
+ Assert.True(firstPreflight.IsSuccess);
+
+ var firstPass = BrepBoundedFillet.FilletTrustedPolyhedralSingleInternalConcaveEdge(source, firstPreflight.Value, 0.5d);
+ Assert.True(firstPass.IsSuccess, string.Join(Environment.NewLine, firstPass.Diagnostics.Select(d => d.Message)));
+
+ var chainedPreflight = BrepBoundedManufacturingFilletPreflight.ResolveInternalConcaveVerticalEdges(
+ source.SafeBooleanComposition!,
+ [BrepBoundedManufacturingFilletEdge.InnerXMaxYMin, BrepBoundedManufacturingFilletEdge.InnerXMaxYMax],
+ radius: 1d);
+ Assert.True(chainedPreflight.IsSuccess);
+
+ var secondPass = BrepBoundedFillet.FilletTrustedPolyhedralSingleInternalConcaveEdge(firstPass.Value, chainedPreflight.Value, 1d);
Assert.False(secondPass.IsSuccess);
Assert.Contains(
secondPass.Diagnostics,
d => d.Message.Contains("chained_same_radius_fillet_with_cylindrical_termination", StringComparison.Ordinal)
- && d.Message.Contains("supported=False", StringComparison.Ordinal));
+ && d.Message.Contains("hasMatchingRadiusVerticalCylinder=False", StringComparison.Ordinal));
}
private static BrepBody CreatePlanarSourceWithLRootComposition()
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
index f8afa870..bce87d81 100644
--- a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedFillet.cs
@@ -46,9 +46,7 @@ public static class BrepBoundedFillet
{
SingleEdgeCylindricalFilletCandidate => BuildConcaveFilletBody(sourceBody, context),
ChainedSameRadiusCylindricalFilletCandidate => BuildConcaveFilletBody(sourceBody, context),
- ChainedSameRadiusCylindricalTerminationCandidate => KernelResult<BrepBody>.Failure([Failure(
- "Bounded chained same-radius fillet with cylindrical-context termination is recognized but not yet supported; the current local extrusion rewrite cannot preserve neighboring cylindrical context while terminating the chain.",
- "firmament.fillet-bounded")]),
+ ChainedSameRadiusCylindricalTerminationCandidate => BuildConcaveFilletBody(sourceBody, context),
_ => KernelResult<BrepBody>.Failure([Failure($"Bounded fillet selected unsupported candidate '{judgment.Selection.Value.Candidate.Name}'.", "firmament.fillet-bounded")])
};
}
@@ -88,9 +86,10 @@ public static class BrepBoundedFillet
context => context.IsBoundedRadius,
context => context.HasLocalChainedInteraction,
context => context.HasCylindricalSourceFaces,
+ context => context.HasMatchingRadiusVerticalCylindricalSourceFace,
context => context.IsCylindricalTerminationSupported),
Score: context => context.HasCylindricalSourceFaces ? 175d : 0d,
- RejectionReason: context => $"requires supported chained same-radius cylindrical-context termination context (trusted={context.IsTrustedSource}, count={context.SelectionCount}, concave={context.IsInternalConcave}, bounded={context.IsBoundedRadius}, interacting={context.HasLocalChainedInteraction}, hasCylindricalSourceFaces={context.HasCylindricalSourceFaces}, supported={context.IsCylindricalTerminationSupported})",
+ RejectionReason: context => $"requires supported chained same-radius cylindrical-context termination context (trusted={context.IsTrustedSource}, count={context.SelectionCount}, concave={context.IsInternalConcave}, bounded={context.IsBoundedRadius}, interacting={context.HasLocalChainedInteraction}, hasCylindricalSourceFaces={context.HasCylindricalSourceFaces}, hasMatchingRadiusVerticalCylinder={context.HasMatchingRadiusVerticalCylindricalSourceFace}, supported={context.IsCylindricalTerminationSupported})",
TieBreakerPriority: 2),
new JudgmentCandidate<BrepBoundedFilletContext>(
Name: RejectCandidate,
@@ -104,7 +103,7 @@ public static class BrepBoundedFillet
{
if (context.SelectionCount == 2 && context.HasLocalChainedInteraction && context.HasCylindricalSourceFaces)
{
- return "chained_same_radius_fillet_with_cylindrical_termination: requires supported chained same-radius cylindrical-context termination context (supported=False).";
+ return $"chained_same_radius_fillet_with_cylindrical_termination: requires supported chained same-radius cylindrical-context termination context (hasMatchingRadiusVerticalCylinder={context.HasMatchingRadiusVerticalCylindricalSourceFace}, supported={context.IsCylindricalTerminationSupported}).";
}
return "No bounded single-edge/chained fillet candidate was admissible.";
@@ -660,6 +659,7 @@ internal readonly record struct BrepBoundedFilletContext(
bool HasLocalChainedInteraction,
bool IsPlanarPlanar,
bool HasCylindricalSourceFaces,
+ bool HasMatchingRadiusVerticalCylindricalSourceFace,
bool IsCylindricalTerminationSupported,
bool IsInternalConcave,
bool IsBoundedRadius,
@@ -685,14 +685,39 @@ internal readonly record struct BrepBoundedFilletContext(
var planar = sourceBody.Bindings.FaceBindings.All(binding => sourceBody.Geometry.GetSurface(binding.SurfaceGeometryId).Kind == SurfaceGeometryKind.Plane);
var hasCylindricalFaces = sourceBody.Bindings.FaceBindings.Any(binding => sourceBody.Geometry.GetSurface(binding.SurfaceGeometryId).Kind == SurfaceGeometryKind.Cylinder);
+ var hasMatchingRadiusVerticalCylinder = sourceBody.Bindings.FaceBindings.Any(binding =>
+ {
+ var surface = sourceBody.Geometry.GetSurface(binding.SurfaceGeometryId);
+ if (surface.Kind != SurfaceGeometryKind.Cylinder)
+ {
+ return false;
+ }
+
+ if (surface.Cylinder is null)
+ {
+ return false;
+ }
+
+ var cylinder = surface.Cylinder.Value;
+ return NearlyEqual(cylinder.Radius, radius)
+ && NearlyEqual(cylinder.Axis.X, 0d)
+ && NearlyEqual(cylinder.Axis.Y, 0d)
+ && NearlyEqual(System.Math.Abs(cylinder.Axis.Z), 1d);
+ });
var bounded = radius < selection.MaxAllowedRadius;
+ var cylindricalTerminationSupported =
+ selection.Corners.Count == 2
+ && selection.HasLocalInteraction
+ && hasMatchingRadiusVerticalCylinder
+ && bounded;
return KernelResult<BrepBoundedFilletContext>.Success(new BrepBoundedFilletContext(
IsTrustedSource: true,
SelectionCount: selection.Corners.Count,
HasLocalChainedInteraction: selection.HasLocalInteraction,
IsPlanarPlanar: planar,
HasCylindricalSourceFaces: hasCylindricalFaces,
- IsCylindricalTerminationSupported: false,
+ HasMatchingRadiusVerticalCylindricalSourceFace: hasMatchingRadiusVerticalCylinder,
+ IsCylindricalTerminationSupported: cylindricalTerminationSupported,
IsInternalConcave: true,
IsBoundedRadius: bounded,
Selection: selection,
@@ -700,6 +725,9 @@ internal readonly record struct BrepBoundedFilletContext(
OccupiedCells: occupiedCells));
}
+ 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);
}
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
index 214096eb..4990a571 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentPrimitiveExecutionTests.cs
@@ -514,15 +514,29 @@ public sealed class FirmamentPrimitiveExecutionTests
}
[Fact]
- public void Compile_Rejects_BoundedFillet_ChainedCylindricalTermination_Attempt()
+ public void Compile_Executes_BoundedFillet_ChainedCylindricalTermination_ForSameRadiusFollowOnPair()
{
- var result = CompileFixture("testdata/firmament/fixtures/m5b-invalid-fillet-chained-cylindrical-termination.firmament");
+ var result = CompileFixture("testdata/firmament/fixtures/m5b-valid-fillet-chained-cylindrical-termination-followon.firmament");
+
+ Assert.True(result.Compilation.IsSuccess, string.Join(Environment.NewLine, result.Compilation.Diagnostics.Select(d => d.Message)));
+ var execution = result.Compilation.Value.PrimitiveExecutionResult!;
+ var first = Assert.Single(execution.ExecutedBooleans, executed => executed.FeatureId == "first_inner_fillet");
+ var second = Assert.Single(execution.ExecutedBooleans, executed => executed.FeatureId == "chained_termination_followon");
+ Assert.NotEqual(first.Body.Topology.Faces.Count(), second.Body.Topology.Faces.Count());
+ Assert.True(
+ second.Body.Bindings.FaceBindings.Count(face => second.Body.Geometry.GetSurface(face.SurfaceGeometryId).Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cylinder) >= 2);
+ }
+
+ [Fact]
+ public void Compile_Rejects_BoundedFillet_ChainedCylindricalTermination_Attempt_ForMismatchedRadius()
+ {
+ var result = CompileFixture("testdata/firmament/fixtures/m5b-invalid-fillet-chained-cylindrical-termination-mismatched-radius.firmament");
Assert.False(result.Compilation.IsSuccess);
Assert.Contains(result.Compilation.Diagnostics, diagnostic =>
diagnostic.Source == "firmament.fillet-bounded"
&& diagnostic.Message.Contains("chained_same_radius_fillet_with_cylindrical_termination", StringComparison.Ordinal)
- && diagnostic.Message.Contains("supported=False", StringComparison.Ordinal));
+ && diagnostic.Message.Contains("hasMatchingRadiusVerticalCylinder=False", StringComparison.Ordinal));
}
[Fact]
diff --git a/testdata/firmament/fixtures/m5b-invalid-fillet-chained-cylindrical-termination-mismatched-radius.firmament b/testdata/firmament/fixtures/m5b-invalid-fillet-chained-cylindrical-termination-mismatched-radius.firmament
new file mode 100644
index 00000000..d2d41a37
--- /dev/null
+++ b/testdata/firmament/fixtures/m5b-invalid-fillet-chained-cylindrical-termination-mismatched-radius.firmament
@@ -0,0 +1,62 @@
+firmament:
+ version: 1
+
+model:
+ name: m5b_invalid_fillet_chained_cylindrical_termination_mismatched_radius
+ units: mm
+
+ops[5]:
+ -
+ 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: first_inner_fillet
+ from: croot
+ edges[1]:
+ inner_x_min_y_min
+ radius: 0.2
+ -
+ op: fillet
+ id: chained_termination_attempt
+ from: first_inner_fillet
+ edges[2]:
+ inner_x_min_y_min
+ inner_x_min_y_max
+ radius: 0.4
diff --git a/testdata/firmament/fixtures/m5b-valid-fillet-chained-cylindrical-termination-followon.firmament b/testdata/firmament/fixtures/m5b-valid-fillet-chained-cylindrical-termination-followon.firmament
new file mode 100644
index 00000000..163cc533
--- /dev/null
+++ b/testdata/firmament/fixtures/m5b-valid-fillet-chained-cylindrical-termination-followon.firmament
@@ -0,0 +1,62 @@
+firmament:
+ version: 1
+
+model:
+ name: m5b_valid_fillet_chained_cylindrical_termination_followon
+ units: mm
+
+ops[5]:
+ -
+ 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: first_inner_fillet
+ from: croot
+ edges[1]:
+ inner_x_min_y_min
+ radius: 0.4
+ -
+ op: fillet
+ id: chained_termination_followon
+ from: first_inner_fillet
+ edges[2]:
+ inner_x_min_y_min
+ inner_x_min_y_max
+ radius: 0.4
diff --git a/testdata/firmament/fixtures/m5b-valid-fillet-single-edge-pretermination-source.firmament b/testdata/firmament/fixtures/m5b-valid-fillet-single-edge-pretermination-source.firmament
new file mode 100644
index 00000000..2e07d848
--- /dev/null
+++ b/testdata/firmament/fixtures/m5b-valid-fillet-single-edge-pretermination-source.firmament
@@ -0,0 +1,54 @@
+firmament:
+ version: 1
+
+model:
+ name: m5b_valid_fillet_single_edge_pretermination_source
+ 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: first_inner_fillet
+ from: croot
+ edges[1]:
+ inner_x_min_y_min
+ radius: 0.4