Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Extract bounded edge-finishing kernel logic into Brep/EdgeFinishing

Yuechen Lib91f04f65efc
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs
index 294e776f..9ad055d6 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedChamferTests.cs
@@ -1,5 +1,5 @@
using Aetheris.Kernel.Core.Brep.Boolean;
-using Aetheris.Kernel.Core.Brep.Features;
+using Aetheris.Kernel.Core.Brep.EdgeFinishing;
namespace Aetheris.Kernel.Core.Tests.Brep.Features;
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
index 213a63c1..a3fca1c6 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Features/BrepBoundedManufacturingFilletPreflightTests.cs
@@ -1,5 +1,5 @@
using Aetheris.Kernel.Core.Brep.Boolean;
-using Aetheris.Kernel.Core.Brep.Features;
+using Aetheris.Kernel.Core.Brep.EdgeFinishing;
namespace Aetheris.Kernel.Core.Tests.Brep.Features;
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepBoundedChamfer.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
similarity index 97%
rename from Aetheris.Kernel.Core/Brep/Features/BrepBoundedChamfer.cs
rename to Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
index a4f827a7..0577a8b0 100644
--- a/Aetheris.Kernel.Core/Brep/Features/BrepBoundedChamfer.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedChamfer.cs
@@ -1,9 +1,10 @@
using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Brep.Features;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Results;
-namespace Aetheris.Kernel.Core.Brep.Features;
+namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
/// <summary>
/// M5a bounded functional chamfer for convex planar-planar external edges on axis-aligned box-like bodies.
diff --git a/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs
new file mode 100644
index 00000000..c950feb5
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedEdgeFinishingToolParser.cs
@@ -0,0 +1,113 @@
+namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
+
+/// <summary>
+/// Shared bounded tool-field parsing seam for explicit edge-finishing selectors.
+/// Candidate resolution/utility-based selection remains deferred to later milestones.
+/// </summary>
+public static class BrepBoundedEdgeFinishingToolParser
+{
+ public 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 tokens = ParseSingleTokenArray(edgesRaw, out error);
+ if (tokens is null)
+ {
+ return false;
+ }
+
+ 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;
+ }
+
+ public 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 tokens = ParseSingleTokenArray(edgesRaw, out error);
+ if (tokens is null)
+ {
+ return false;
+ }
+
+ 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 string[]? ParseSingleTokenArray(string raw, out string error)
+ {
+ error = string.Empty;
+ var trimmed = raw.Trim();
+ if (!trimmed.StartsWith("[", StringComparison.Ordinal) || !trimmed.EndsWith("]", StringComparison.Ordinal))
+ {
+ error = "expected array-like edges value";
+ return null;
+ }
+
+ return trimmed[1..^1]
+ .Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries)
+ .Select(token => token.Trim().Trim('"'))
+ .Where(token => !string.IsNullOrWhiteSpace(token))
+ .ToArray();
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.cs b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
similarity index 99%
rename from Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.cs
rename to Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
index 879dc556..1bdfe738 100644
--- a/Aetheris.Kernel.Core/Brep/Features/BrepBoundedManufacturingFilletPreflight.cs
+++ b/Aetheris.Kernel.Core/Brep/EdgeFinishing/BrepBoundedManufacturingFilletPreflight.cs
@@ -2,7 +2,7 @@ using Aetheris.Kernel.Core.Brep.Boolean;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Results;
-namespace Aetheris.Kernel.Core.Brep.Features;
+namespace Aetheris.Kernel.Core.Brep.EdgeFinishing;
/// <summary>
/// M5b bounded manufacturing-fillet preflight for explicit internal concave planar vertical edges on
diff --git a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
index 1bacb1cd..57a1c4ab 100644
--- a/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
+++ b/Aetheris.Kernel.Firmament/Execution/FirmamentPrimitiveExecutor.cs
@@ -1,6 +1,7 @@
using System.Globalization;
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Brep.EdgeFinishing;
using Aetheris.Kernel.Core.Brep.Features;
using Aetheris.Kernel.Core.Diagnostics;
using Aetheris.Kernel.Core.Geometry;
@@ -750,7 +751,7 @@ internal static class FirmamentPrimitiveExecutor
]);
}
- if (!TryParseChamferEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
+ if (!BrepBoundedEdgeFinishingToolParser.TryParseChamferEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
{
return KernelResult<BrepBody>.Failure(
[
@@ -765,55 +766,6 @@ internal static class FirmamentPrimitiveExecutor
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 KernelResult<BrepBody> ExecuteBoundedManufacturingFilletOnRecognizedOrthogonalRoot(
FirmamentLoweredBoolean boolean,
BrepBody baseBody,
@@ -848,7 +800,7 @@ internal static class FirmamentPrimitiveExecutor
]);
}
- if (!TryParseFilletEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
+ if (!BrepBoundedEdgeFinishingToolParser.TryParseFilletEdge(boolean.Tool.RawFields, out var edge, out var edgeError))
{
return KernelResult<BrepBody>.Failure(
[
@@ -892,55 +844,6 @@ internal static class FirmamentPrimitiveExecutor
]);
}
- 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,