Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

B5 unify boolean diagnostic context and operation guards

Yuechen Li760c6bb7244a
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnosticContext.cs b/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnosticContext.cs
new file mode 100644
index 00000000..3388c440
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BooleanDiagnosticContext.cs
@@ -0,0 +1,15 @@
+namespace Aetheris.Kernel.Core.Brep.Boolean;
+
+public readonly record struct BooleanDiagnosticContext(BooleanOperation Operation, string? FeatureId = null)
+{
+ public string FormatMessage(string detail)
+ {
+ var subject = string.IsNullOrWhiteSpace(FeatureId)
+ ? $"Boolean {Operation}"
+ : $"Boolean feature '{FeatureId}' ({Operation.ToString().ToLowerInvariant()})";
+ return $"{subject} {detail}";
+ }
+
+ public BooleanDiagnostic Error(BooleanDiagnosticCode code, string detail, string source)
+ => new(code, FormatMessage(detail), source);
+}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BooleanGuards.cs b/Aetheris.Kernel.Core/Brep/Boolean/BooleanGuards.cs
new file mode 100644
index 00000000..fe6f6c02
--- /dev/null
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BooleanGuards.cs
@@ -0,0 +1,28 @@
+namespace Aetheris.Kernel.Core.Brep.Boolean;
+
+public static class BooleanGuards
+{
+ public static bool RequireOperation(BooleanOperation actual, BooleanOperation expected, out string? reason)
+ {
+ if (actual == expected)
+ {
+ reason = null;
+ return true;
+ }
+
+ reason = $"requires '{expected}' but received '{actual}'.";
+ return false;
+ }
+
+ public static bool RequireOperation(BooleanOperation actual, BooleanOperation first, BooleanOperation second, out string? reason)
+ {
+ if (actual == first || actual == second)
+ {
+ reason = null;
+ return true;
+ }
+
+ reason = $"requires '{first}' or '{second}' but received '{actual}'.";
+ return false;
+ }
+}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
index 22f7f253..3e63dd8e 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs
@@ -332,17 +332,17 @@ public static class BrepBoolean
RejectionReason: _ => "Planar box-box candidate requires both operands to be recognized axis-aligned boxes."),
new JudgmentCandidate<BooleanCaseContext>(
Name: BooleanTopLevelCase.SubtractAnalyticHole.ToString(),
- IsAdmissible: context => context.Operation == BooleanOperation.Subtract
+ IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out _)
&& (context.LeftRecognizedBox || context.LeftHasSafeComposition)
&& context.RightRecognizedAnalytic,
Score: _ => 300d,
- RejectionReason: context => context.Operation != BooleanOperation.Subtract
- ? "Analytic-hole candidate only applies to subtract operations."
+ RejectionReason: context => !BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out var operationReason)
+ ? $"Analytic-hole candidate {operationReason}"
: "Analytic-hole candidate requires a recognized left root (box/safe-composition) and recognized right analytic tool."),
new JudgmentCandidate<BooleanCaseContext>(
Name: BooleanTopLevelCase.SubtractIntersectRecognizedSafeRoot.ToString(),
IsAdmissible: context =>
- (context.Operation == BooleanOperation.Subtract || context.Operation == BooleanOperation.Intersect)
+ BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, BooleanOperation.Intersect, out _)
&& context.LeftHasSafeComposition
&& context.LeftSafeComposition is not null
&& context.LeftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Box
@@ -500,20 +500,22 @@ public static class BrepBoolean
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.SubtractIntersectOrthogonalCellsExistingRoot.ToString(),
IsAdmissible: context => context.LeftHasOccupiedCells
- && (context.Operation == BooleanOperation.Subtract || context.Operation == BooleanOperation.Intersect),
+ && BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, BooleanOperation.Intersect, out _),
Score: _ => 450d,
RejectionReason: context => context.LeftHasOccupiedCells
- ? "Orthogonal occupied-cell subtract/intersect candidate requires subtract or intersect."
+ ? !BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, BooleanOperation.Intersect, out var operationReason)
+ ? $"Orthogonal occupied-cell subtract/intersect candidate {operationReason}"
+ : "Orthogonal occupied-cell subtract/intersect candidate requires subtract or intersect."
: "Orthogonal occupied-cell subtract/intersect candidate requires a recognized additive safe root with occupied cells."),
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.SubtractBoxSingleBoxResult.ToString(),
- IsAdmissible: context => context.Operation == BooleanOperation.Subtract
+ IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out _)
&& !context.IsTouchingOnly
&& !context.RightContainsLeft
&& (!context.HasPositiveVolumeOverlap || context.CanSubtractToSingleBox),
Score: _ => 400d,
- RejectionReason: context => context.Operation != BooleanOperation.Subtract
- ? "Single-box subtract candidate requires subtract."
+ RejectionReason: context => !BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out var operationReason)
+ ? $"Single-box subtract candidate {operationReason}"
: context.IsTouchingOnly
? "Single-box subtract candidate rejects touching-only contact."
: context.RightContainsLeft
@@ -521,24 +523,24 @@ public static class BrepBoolean
: "Single-box subtract candidate requires either no overlap or a subtract result representable as one box."),
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.SubtractBoxPocketOnRecognizedRoot.ToString(),
- IsAdmissible: context => context.Operation == BooleanOperation.Subtract
+ IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out _)
&& !context.IsTouchingOnly
&& context.HasPositiveVolumeOverlap
&& !context.RightContainsLeft
&& !context.CanSubtractToSingleBox
&& context.CanSubtractToOrthogonalPocket,
Score: _ => 300d,
- RejectionReason: context => context.Operation != BooleanOperation.Subtract
- ? "Orthogonal-pocket subtract candidate requires subtract."
+ RejectionReason: context => !BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Subtract, out var operationReason)
+ ? $"Orthogonal-pocket subtract candidate {operationReason}"
: context.SubtractPocketUnsupportedReason
?? "Orthogonal-pocket subtract candidate rejected because bounded pocket predicates were not satisfied."),
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.IntersectSupportedBoundedCase.ToString(),
- IsAdmissible: context => context.Operation == BooleanOperation.Intersect,
+ IsAdmissible: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Intersect, out _),
Score: _ => 200d,
- RejectionReason: context => context.Operation == BooleanOperation.Intersect
+ RejectionReason: context => BooleanGuards.RequireOperation(context.Operation, BooleanOperation.Intersect, out _)
? "Intersect candidate selected; overlap/emptiness is classified downstream by bounded planar intersection rules."
- : "Intersect candidate only applies to intersect operations."),
+ : "Intersect candidate requires 'Intersect'."),
new JudgmentCandidate<BooleanSubtractIntersectContext>(
Name: BooleanSubtractIntersectFamily.UnsupportedFromRecognizedSafeRoot.ToString(),
IsAdmissible: _ => true,
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
index 0efffe18..024b1386 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs
@@ -56,10 +56,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder
return KernelResult<BrepBody>.Failure([
new BooleanDiagnostic(
BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- null,
- "safe subtract composition only supports one contained spherical cavity when no prior holes have been accepted."),
+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("safe subtract composition only supports one contained spherical cavity when no prior holes have been accepted."),
"BrepBoolean.AnalyticHole.UnsupportedAnalyticSurfaceKind").ToKernelDiagnostic(),
]);
}
@@ -121,10 +118,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder
return KernelResult<BrepBody>.Failure([
new BooleanDiagnostic(
BooleanDiagnosticCode.NotFullySpanning,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- null,
- "cylinder-root safe rebuild in F3 requires a through-hole cylinder chain."),
+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("cylinder-root safe rebuild in F3 requires a through-hole cylinder chain."),
"BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),
]);
}
@@ -438,10 +432,7 @@ public static class BrepBooleanBoxCylinderHoleBuilder
return KernelResult<BrepBody>.Failure([
new BooleanDiagnostic(
BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- null,
- "blind-hole continuation exceeds bounded rebuild support; only recognized orthogonal additive roots with world-Z cylinder/cone hole chains are rebuildable in this milestone."),
+ new BooleanDiagnosticContext(BooleanOperation.Subtract).FormatMessage("blind-hole continuation exceeds bounded rebuild support; only recognized orthogonal additive roots with world-Z cylinder/cone hole chains are rebuildable in this milestone."),
"BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily").ToKernelDiagnostic(),
]);
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
index 824a007a..4d9b06f1 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCylinderRecognition.cs
@@ -175,10 +175,11 @@ public static class BrepBooleanCylinderRecognition
{
profile = default;
diagnostic = null;
+ var diagnosticContext = new BooleanDiagnosticContext(BooleanOperation.Subtract, featureId);
if (!TryResolveBoundaryAxisParameter(cylinder.AxisOrigin, cylinder.Axis, box.MinZ, tolerance, out var bottomAtZ)
|| !TryResolveBoundaryAxisParameter(cylinder.AxisOrigin, cylinder.Axis, box.MaxZ, tolerance, out var topAtZ))
{
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
+ diagnostic = CreateAxisNotAlignedDiagnostic(diagnosticContext, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
return false;
}
@@ -191,8 +192,8 @@ public static class BrepBooleanCylinderRecognition
if (coversBottom && coversTop)
{
- if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", featureId)
- || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", diagnosticContext))
{
return false;
}
@@ -205,19 +206,19 @@ public static class BrepBooleanCylinderRecognition
{
if (!ValidateAxisAlignedZ(cylinder, tolerance))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
return false;
}
var termination = cylinder.MinCenter.Z < cylinder.MaxCenter.Z ? cylinder.MinCenter : cylinder.MaxCenter;
if (termination.Z <= (box.MinZ + tolerance.Linear) || termination.Z >= (box.MaxZ - tolerance.Linear))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
return false;
}
- if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", featureId)
- || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, radialBound, tolerance, out diagnostic, "top boundary section", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", diagnosticContext))
{
return false;
}
@@ -230,19 +231,19 @@ public static class BrepBooleanCylinderRecognition
{
if (!ValidateAxisAlignedZ(cylinder, tolerance))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "currently supports arbitrary-axis cylinder subtract only for through-holes; blind arbitrary-axis cylinder holes remain deferred in this milestone.");
return false;
}
var termination = cylinder.MinCenter.Z > cylinder.MaxCenter.Z ? cylinder.MinCenter : cylinder.MaxCenter;
if (termination.Z <= (box.MinZ + tolerance.Linear) || termination.Z >= (box.MaxZ - tolerance.Linear))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; cylinder blind holes must terminate strictly inside the box.");
return false;
}
- if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", featureId)
- || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, radialBound, tolerance, out diagnostic, "bottom boundary section", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, termination.X, termination.Y, cylinder.Radius, tolerance, out diagnostic, "blind bottom circle", diagnosticContext))
{
return false;
}
@@ -251,7 +252,7 @@ public static class BrepBooleanCylinderRecognition
return true;
}
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
return false;
}
@@ -265,10 +266,11 @@ public static class BrepBooleanCylinderRecognition
{
profile = default;
diagnostic = null;
+ var diagnosticContext = new BooleanDiagnosticContext(BooleanOperation.Subtract, featureId);
if (!TryResolveBoundaryAxisParameter(cone.AxisOrigin, cone.Axis, box.MinZ, tolerance, out var bottomAxisParameter)
|| !TryResolveBoundaryAxisParameter(cone.AxisOrigin, cone.Axis, box.MaxZ, tolerance, out var topAxisParameter))
{
- diagnostic = CreateAxisNotAlignedDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
+ diagnostic = CreateAxisNotAlignedDiagnostic(diagnosticContext, "does not match the bounded arbitrary-axis subtract subset because the tool axis is nearly parallel to the box top/bottom planes.");
return false;
}
@@ -288,12 +290,12 @@ public static class BrepBooleanCylinderRecognition
var topRadius = cone.RadiusAtAxisParameter(topAxisParameter);
if (bottomRadius <= tolerance.Linear || topRadius <= tolerance.Linear)
{
- diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate circular sections where the cone meets the two box boundary planes. Increase the boundary radii at those planes by moving the apex farther away or changing the cone taper.");
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(diagnosticContext, "requires non-degenerate circular sections where the cone meets the two box boundary planes. Increase the boundary radii at those planes by moving the apex farther away or changing the cone taper.");
return false;
}
- if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", featureId)
- || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", diagnosticContext))
{
return false;
}
@@ -306,7 +308,7 @@ public static class BrepBooleanCylinderRecognition
{
if (!IsAxisAlignedWithWorldZ(cone.Axis, tolerance))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cone subtract only for through-holes; blind arbitrary-axis cone holes remain deferred in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "currently supports arbitrary-axis cone subtract only for through-holes; blind arbitrary-axis cone holes remain deferred in this milestone.");
return false;
}
@@ -314,7 +316,7 @@ public static class BrepBooleanCylinderRecognition
var terminationZ = System.Math.Min(cone.MinCenter.Z, cone.MaxCenter.Z);
if (terminationZ <= (box.MinZ + tolerance.Linear) || terminationZ >= (box.MaxZ - tolerance.Linear))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
return false;
}
@@ -322,13 +324,13 @@ public static class BrepBooleanCylinderRecognition
var endRadius = minEndIsLower ? cone.RadiusAtMinAxisParameter : cone.RadiusAtMaxAxisParameter;
if (topRadius <= tolerance.Linear || endRadius <= tolerance.Linear)
{
- diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(diagnosticContext, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
return false;
}
var endCenter = minEndIsLower ? cone.MinCenter : cone.MaxCenter;
- if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", featureId)
- || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, topCenter.X, topCenter.Y, topRadius / axisZ, tolerance, out diagnostic, "top boundary circle", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", diagnosticContext))
{
return false;
}
@@ -341,7 +343,7 @@ public static class BrepBooleanCylinderRecognition
{
if (!IsAxisAlignedWithWorldZ(cone.Axis, tolerance))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "currently supports arbitrary-axis cone subtract only for through-holes; blind arbitrary-axis cone holes remain deferred in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "currently supports arbitrary-axis cone subtract only for through-holes; blind arbitrary-axis cone holes remain deferred in this milestone.");
return false;
}
@@ -349,7 +351,7 @@ public static class BrepBooleanCylinderRecognition
var terminationZ = System.Math.Max(cone.MinCenter.Z, cone.MaxCenter.Z);
if (terminationZ <= (box.MinZ + tolerance.Linear) || terminationZ >= (box.MaxZ - tolerance.Linear))
{
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; cone blind holes must terminate strictly inside the box.");
return false;
}
@@ -357,13 +359,13 @@ public static class BrepBooleanCylinderRecognition
var endRadius = maxEndIsHigher ? cone.RadiusAtMaxAxisParameter : cone.RadiusAtMinAxisParameter;
if (bottomRadius <= tolerance.Linear || endRadius <= tolerance.Linear)
{
- diagnostic = CreateDegenerateBoundarySectionDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
+ diagnostic = CreateDegenerateBoundarySectionDiagnostic(diagnosticContext, "requires non-degenerate entry and bottom sections for supported cone blind holes.");
return false;
}
var endCenter = maxEndIsHigher ? cone.MaxCenter : cone.MinCenter;
- if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", featureId)
- || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", featureId))
+ if (!ValidateCircleInsideBoxFootprint(box, bottomCenter.X, bottomCenter.Y, bottomRadius / axisZ, tolerance, out diagnostic, "bottom boundary circle", diagnosticContext)
+ || !ValidateCircleInsideBoxFootprint(box, endCenter.X, endCenter.Y, endRadius, tolerance, out diagnostic, "blind bottom circle", diagnosticContext))
{
return false;
}
@@ -372,7 +374,7 @@ public static class BrepBooleanCylinderRecognition
return true;
}
- diagnostic = CreateNotFullySpanningDiagnostic(BooleanOperation.Subtract.ToString(), featureId, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
+ diagnostic = CreateNotFullySpanningDiagnostic(diagnosticContext, "does not match the supported subtract span family; only through-holes or one-sided blind holes are allowed in this milestone.");
return false;
}
@@ -422,7 +424,7 @@ public static class BrepBooleanCylinderRecognition
ToleranceContext tolerance,
out BooleanDiagnostic? diagnostic,
string circleLabel,
- string? featureId)
+ in BooleanDiagnosticContext diagnosticContext)
{
diagnostic = null;
@@ -438,7 +440,7 @@ public static class BrepBooleanCylinderRecognition
|| ToleranceMath.AlmostEqual(maxFootprintY, box.MaxY, tolerance);
if (tangentContact)
{
- diagnostic = CreateTangentContactDiagnostic(BooleanOperation.Subtract.ToString(), featureId, $"has {circleLabel} tangent to a box side wall; tangent analytic-hole cases are rejected to avoid zero-thickness geometry. Move the cone inward or reduce the boundary radius at that plane.");
+ diagnostic = CreateTangentContactDiagnostic(diagnosticContext, $"has {circleLabel} tangent to a box side wall; tangent analytic-hole cases are rejected to avoid zero-thickness geometry. Move the cone inward or reduce the boundary radius at that plane.");
return false;
}
@@ -447,7 +449,7 @@ public static class BrepBooleanCylinderRecognition
|| minFootprintY < (box.MinY - tolerance.Linear)
|| maxFootprintY > (box.MaxY + tolerance.Linear))
{
- diagnostic = CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(), featureId, $"has {circleLabel} extending outside the box side-wall footprint. Reduce the boundary radius or move the cone center farther inside the box XY boundary.");
+ diagnostic = CreateRadiusExceedsBoundaryDiagnostic(diagnosticContext, $"has {circleLabel} extending outside the box side-wall footprint. Reduce the boundary radius or move the cone center farther inside the box XY boundary.");
return false;
}
@@ -458,64 +460,67 @@ public static class BrepBooleanCylinderRecognition
=> CreateAxisNotAlignedDiagnostic(operation, null, detail);
public static BooleanDiagnostic CreateAxisNotAlignedDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.AxisNotAligned,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.AxisNotAligned");
+ => CreateAxisNotAlignedDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateAxisNotAlignedDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.AxisNotAligned, detail, "BrepBoolean.AnalyticHole.AxisNotAligned");
public static BooleanDiagnostic CreateNotFullySpanningDiagnostic(string operation, string detail)
=> CreateNotFullySpanningDiagnostic(operation, null, detail);
public static BooleanDiagnostic CreateNotFullySpanningDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.NotFullySpanning,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.NotFullySpanning");
+ => CreateNotFullySpanningDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateNotFullySpanningDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.NotFullySpanning, detail, "BrepBoolean.AnalyticHole.NotFullySpanning");
public static BooleanDiagnostic CreateDegenerateBoundarySectionDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.DegenerateBoundarySection,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.DegenerateBoundarySection");
+ => CreateDegenerateBoundarySectionDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateDegenerateBoundarySectionDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.DegenerateBoundarySection, detail, "BrepBoolean.AnalyticHole.DegenerateBoundarySection");
public static BooleanDiagnostic CreateRadiusExceedsBoundaryDiagnostic(string operation, string detail)
=> CreateRadiusExceedsBoundaryDiagnostic(operation, null, detail);
public static BooleanDiagnostic CreateRadiusExceedsBoundaryDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.RadiusExceedsBoundary,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.RadiusExceedsBoundary");
+ => CreateRadiusExceedsBoundaryDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateRadiusExceedsBoundaryDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.RadiusExceedsBoundary, detail, "BrepBoolean.AnalyticHole.RadiusExceedsBoundary");
public static BooleanDiagnostic CreateTangentContactDiagnostic(string operation, string detail)
=> CreateTangentContactDiagnostic(operation, null, detail);
public static BooleanDiagnostic CreateTangentContactDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.TangentContact,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.TangentContact");
+ => CreateTangentContactDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateTangentContactDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.TangentContact, detail, "BrepBoolean.AnalyticHole.TangentContact");
public static BooleanDiagnostic CreateMultiBodyResultDiagnostic(string operation, string? featureId, string detail)
- => new(
- BooleanDiagnosticCode.MultiBodyResult,
- CreateBooleanMessage(operation, featureId, detail),
- "BrepBoolean.AnalyticHole.MultiBodyResult");
+ => CreateMultiBodyResultDiagnostic(CreateContext(operation, featureId), detail);
+
+ public static BooleanDiagnostic CreateMultiBodyResultDiagnostic(in BooleanDiagnosticContext context, string detail)
+ => context.Error(BooleanDiagnosticCode.MultiBodyResult, detail, "BrepBoolean.AnalyticHole.MultiBodyResult");
public static BooleanDiagnostic CreateUnsupportedAnalyticSurfaceKindDiagnostic(string operation, AnalyticSurfaceKind kind)
=> CreateUnsupportedAnalyticSurfaceKindDiagnostic(operation, kind, null);
public static BooleanDiagnostic CreateUnsupportedAnalyticSurfaceKindDiagnostic(string operation, AnalyticSurfaceKind kind, string? featureId)
- => new(
+ => CreateUnsupportedAnalyticSurfaceKindDiagnostic(CreateContext(operation, featureId), kind);
+
+ public static BooleanDiagnostic CreateUnsupportedAnalyticSurfaceKindDiagnostic(in BooleanDiagnosticContext context, AnalyticSurfaceKind kind)
+ => context.Error(
BooleanDiagnosticCode.UnsupportedAnalyticSurfaceKind,
- CreateBooleanMessage(operation, featureId, $"does not support analytic tool surface kind '{kind}' in the safe boolean family. Use a cylinder or cone through-hole instead."),
+ $"does not support analytic tool surface kind '{kind}' in the safe boolean family. Use a cylinder or cone through-hole instead.",
"BrepBoolean.UnsupportedAnalyticSurfaceKind");
public static string CreateBooleanMessage(string operation, string? featureId, string detail)
- {
- var subject = string.IsNullOrWhiteSpace(featureId)
- ? $"Boolean {operation}"
- : $"Boolean feature '{featureId}' ({operation.ToLowerInvariant()})";
- return $"{subject} {detail}";
- }
+ => CreateContext(operation, featureId).FormatMessage(detail);
+
+ private static BooleanDiagnosticContext CreateContext(string operation, string? featureId)
+ => Enum.TryParse<BooleanOperation>(operation, ignoreCase: true, out var parsedOperation)
+ ? new BooleanDiagnosticContext(parsedOperation, featureId)
+ : new BooleanDiagnosticContext(BooleanOperation.Subtract, featureId);
}
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
index 5ef8965e..671e4301 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs
@@ -20,6 +20,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
updatedComposition = composition;
diagnostic = null;
+ var diagnosticContext = new BooleanDiagnosticContext(BooleanOperation.Subtract, nextFeatureId);
var root = composition.RootDescriptor;
if (root.Kind == SafeBooleanRootKind.Cylinder)
@@ -44,10 +45,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
diagnostic = new BooleanDiagnostic(
BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
- "blind-hole continuation exceeds the bounded family; only recognized orthogonal additive roots with world-Z analytic-hole chains are supported for continued blind-hole composition."),
+ diagnosticContext.FormatMessage("blind-hole continuation exceeds the bounded family; only recognized orthogonal additive roots with world-Z analytic-hole chains are supported for continued blind-hole composition."),
"BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily");
return false;
}
@@ -103,10 +101,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
diagnostic = new BooleanDiagnostic(
BooleanDiagnosticCode.HoleInterference,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
- $"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping safe-hole composition is not supported. Separate the hole centers or reduce one of the boundary radii."),
+ diagnosticContext.FormatMessage($"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping safe-hole composition is not supported. Separate the hole centers or reduce one of the boundary radii."),
"BrepBoolean.AnalyticHole.HoleInterference");
return false;
}
@@ -130,21 +125,20 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
updatedComposition = composition;
diagnostic = null;
+ var diagnosticContext = new BooleanDiagnosticContext(BooleanOperation.Subtract, nextFeatureId);
if (surface.Kind != AnalyticSurfaceKind.Cylinder || surface.Cylinder is not RecognizedCylinder toolCylinder)
{
diagnostic = BrepBooleanCylinderRecognition.CreateUnsupportedAnalyticSurfaceKindDiagnostic(
- BooleanOperation.Subtract.ToString(),
- surface.Kind,
- nextFeatureId);
+ diagnosticContext,
+ surface.Kind);
return false;
}
if (root.Cylinder is not RecognizedCylinder rootCylinder)
{
diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
+ diagnosticContext,
"cannot resolve recognized cylinder-root descriptor.");
return false;
}
@@ -153,8 +147,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
|| !BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(toolCylinder, tolerance))
{
diagnostic = BrepBooleanCylinderRecognition.CreateAxisNotAlignedDiagnostic(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
+ diagnosticContext,
"bounded cylinder-root safe subtract supports only world-Z aligned root and center-bore cylinders.");
return false;
}
@@ -176,8 +169,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
if (!spansRoot)
{
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
+ diagnosticContext,
"is outside the bounded cylinder-root safe subtract family; only through center bores that span both planar caps are supported.");
return false;
}
@@ -206,8 +198,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
|| ringOuterDistance > (rootCylinder.Radius - tolerance.Linear))
{
diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
+ diagnosticContext,
isCoaxialCenterBore
? "must remain strictly smaller than the flange root radius in the bounded cylinder-root safe subtract family."
: "is outside the bounded cylinder-root safe subtract family; off-axis through-holes must remain strictly inside the outer cylindrical wall.");
@@ -240,10 +231,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
{
diagnostic = new BooleanDiagnostic(
BooleanDiagnosticCode.HoleInterference,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- nextFeatureId,
- $"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping cylinder-root hole chains are not supported."),
+ diagnosticContext.FormatMessage($"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping cylinder-root hole chains are not supported."),
"BrepBoolean.AnalyticHole.HoleInterference");
return false;
}
@@ -671,12 +659,10 @@ public static class BrepBooleanSafeCompositionGraphValidator
result.Rejections);
return false;
default:
+ var diagnosticContext = new BooleanDiagnosticContext(BooleanOperation.Subtract, featureId);
diagnostic = new BooleanDiagnostic(
BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- featureId,
- $"blind-hole continuation selected unknown family '{selectedFamily}'."),
+ diagnosticContext.FormatMessage($"blind-hole continuation selected unknown family '{selectedFamily}'."),
"BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily");
return false;
}
@@ -752,10 +738,7 @@ public static class BrepBooleanSafeCompositionGraphValidator
return new BooleanDiagnostic(
BooleanDiagnosticCode.UnsupportedBlindHoleComposition,
- BrepBooleanCylinderRecognition.CreateBooleanMessage(
- BooleanOperation.Subtract.ToString(),
- featureId,
- detail),
+ new BooleanDiagnosticContext(BooleanOperation.Subtract, featureId).FormatMessage(detail),
"BrepBoolean.AnalyticHole.BlindContinuationOutsideBoundedFamily");
}