Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Implement G5 bounded counterbore coaxial stack validation

Yuechen Li0d4498afd9f9
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
index 7448aaac..58a91b66 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs
@@ -894,7 +894,7 @@ public sealed class BrepBooleanTests
}
[Fact]
- public void Subtract_ComposedContainedThenThroughCoaxial_ReturnsUnsupportedTwoSidedEntryStackDiagnostic()
+ public void Subtract_ComposedContainedThenThroughCoaxial_Succeeds_AsContainedEntryCounterboreStack()
{
var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-25d, 25d, -20d, 20d, -10d, 10d)).Value;
var containedPocket = BrepPrimitives.CreateCylinder(6d, 6d).Value;
@@ -904,10 +904,9 @@ public sealed class BrepBooleanTests
Assert.True(first.IsSuccess);
var result = BrepBoolean.Subtract(first.Value, through);
- Assert.False(result.IsSuccess);
- var diagnostic = Assert.Single(result.Diagnostics);
- Assert.Equal("BrepBoolean.AnalyticHole.NotFullySpanning", diagnostic.Source);
- Assert.Contains("open on the same top entry face", diagnostic.Message, StringComparison.Ordinal);
+ Assert.True(result.IsSuccess);
+ Assert.Equal(9, result.Value.Topology.Faces.Count());
+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);
}
[Fact]
@@ -927,6 +926,23 @@ public sealed class BrepBooleanTests
Assert.Contains("strictly larger entry-segment radius", diagnostic.Message, StringComparison.Ordinal);
}
+ [Fact]
+ public void Subtract_ComposedBlindPocketThenLargerThroughSegment_ReturnsInvalidCounterboreRadiusOrderingDiagnostic()
+ {
+ var baseBox = BrepBooleanBoxRecognition.CreateBoxFromExtents(new AxisAlignedBoxExtents(-35d, 35d, -20d, 20d, -8d, 8d)).Value;
+ var pocket = TransformBody(BrepPrimitives.CreateCylinder(3.5d, 6d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 0d, 5d)));
+ var through = BrepPrimitives.CreateCylinder(5d, 24d).Value;
+
+ var first = BrepBoolean.Subtract(baseBox, pocket);
+ Assert.True(first.IsSuccess);
+
+ var second = BrepBoolean.Subtract(first.Value, through);
+ Assert.False(second.IsSuccess);
+ var diagnostic = Assert.Single(second.Diagnostics);
+ Assert.Equal("BrepBoolean.AnalyticHole.TangentContact", diagnostic.Source);
+ Assert.Contains("invalid counterbore radius ordering", diagnostic.Message, StringComparison.Ordinal);
+ }
+
[Fact]
public void Subtract_ComposedOverlappingHoles_FailsWithDeterministicInterferenceDiagnostic()
{
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs
index 8f998c4b..7e734ccb 100644
--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs
+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanCoaxialSubtractStackFamily.cs
@@ -50,19 +50,12 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
return false;
}
- var firstTop = ResolveTop(first);
- var firstBottom = ResolveBottom(first);
- var secondTop = ResolveTop(second);
- var secondBottom = ResolveBottom(second);
-
var firstTopEntry = IsTopEntry(first, outerBox, tolerance);
var secondTopEntry = IsTopEntry(second, outerBox, tolerance);
var firstBottomEntry = IsBottomEntry(first, outerBox, tolerance);
var secondBottomEntry = IsBottomEntry(second, outerBox, tolerance);
var hasTopEntry = firstTopEntry || secondTopEntry;
var hasBottomEntry = firstBottomEntry || secondBottomEntry;
- var hasTopBlindEntry = IsTopBlindEntry(first, outerBox, tolerance) || IsTopBlindEntry(second, outerBox, tolerance);
- var hasBottomBlindEntry = IsBottomBlindEntry(first, outerBox, tolerance) || IsBottomBlindEntry(second, outerBox, tolerance);
if (!hasTopEntry && !hasBottomEntry)
{
@@ -73,7 +66,14 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
return false;
}
- if (hasTopBlindEntry && hasBottomBlindEntry)
+ var firstTopOnlyEntry = firstTopEntry && !firstBottomEntry;
+ var secondTopOnlyEntry = secondTopEntry && !secondBottomEntry;
+ var firstBottomOnlyEntry = firstBottomEntry && !firstTopEntry;
+ var secondBottomOnlyEntry = secondBottomEntry && !secondTopEntry;
+ var hasTopOnlyEntry = firstTopOnlyEntry || secondTopOnlyEntry;
+ var hasBottomOnlyEntry = firstBottomOnlyEntry || secondBottomOnlyEntry;
+
+ if (hasTopOnlyEntry && hasBottomOnlyEntry)
{
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
@@ -82,12 +82,42 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
return false;
}
- var entryFromTop = hasTopEntry;
- var entryIsFirst = firstTopEntry || firstBottomEntry;
+ var entryFromTop = hasTopOnlyEntry;
+ var firstIsEntryCandidate = entryFromTop ? firstTopOnlyEntry : firstBottomOnlyEntry;
+ var secondIsEntryCandidate = entryFromTop ? secondTopOnlyEntry : secondBottomOnlyEntry;
+ var fallbackContainedEntry = false;
+ if (!firstIsEntryCandidate && !secondIsEntryCandidate)
+ {
+ var firstContained = first.SpanKind == SupportedBooleanHoleSpanKind.Contained;
+ var secondContained = second.SpanKind == SupportedBooleanHoleSpanKind.Contained;
+ if (firstContained == secondContained)
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ featureId,
+ "bounded contained coaxial subtract-stack support requires one shallow segment to open on exactly one box entry face.");
+ return false;
+ }
+
+ fallbackContainedEntry = true;
+ }
+
+ var entryIsFirst = fallbackContainedEntry
+ ? first.SpanKind == SupportedBooleanHoleSpanKind.Contained
+ : firstIsEntryCandidate && (!secondIsEntryCandidate || first.BottomRadius >= second.BottomRadius);
var entryHole = entryIsFirst ? first : second;
var deepHole = entryIsFirst ? second : first;
- if (entryHole.SpanKind == SupportedBooleanHoleSpanKind.Contained)
+ if (fallbackContainedEntry)
+ {
+ entryFromTop = IsTopEntry(deepHole, outerBox, tolerance)
+ ? true
+ : IsBottomEntry(deepHole, outerBox, tolerance)
+ ? false
+ : (outerBox.MaxZ - ResolveTop(entryHole)) <= (ResolveBottom(entryHole) - outerBox.MinZ);
+ }
+
+ if (!fallbackContainedEntry && !IntersectsEntryFace(entryHole, entryFromTop, outerBox, tolerance))
{
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
@@ -96,18 +126,27 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
return false;
}
+ if (fallbackContainedEntry && !IntersectsEntryFace(deepHole, entryFromTop, outerBox, tolerance))
+ {
+ diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
+ BooleanOperation.Subtract.ToString(),
+ featureId,
+ "bounded contained coaxial subtract-stack support requires the deeper segment to intersect the selected entry face when the entry segment is fully contained.");
+ return false;
+ }
+
var entryShoulder = entryFromTop ? ResolveBottom(entryHole) : ResolveTop(entryHole);
var deepTop = ResolveTop(deepHole);
var deepBottom = ResolveBottom(deepHole);
if (entryFromTop)
{
- if (deepTop < (outerBox.MaxZ - tolerance.Linear))
+ if (deepTop < (entryShoulder - tolerance.Linear))
{
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
featureId,
- "bounded contained coaxial subtract-stack support requires the deeper segment to open on the same top entry face.");
+ "bounded contained coaxial subtract-stack support requires the deeper segment to reach the shoulder plane; unsupported deeper continuation shape.");
return false;
}
@@ -116,18 +155,18 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
featureId,
- "bounded contained coaxial subtract-stack support requires the deeper segment to extend below the shoulder plane.");
+ "bounded contained coaxial subtract-stack support requires the deeper segment to continue below the shoulder plane.");
return false;
}
}
else
{
- if (deepBottom > (outerBox.MinZ + tolerance.Linear))
+ if (deepBottom > (entryShoulder + tolerance.Linear))
{
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
featureId,
- "bounded contained coaxial subtract-stack support requires the deeper segment to open on the same bottom entry face.");
+ "bounded contained coaxial subtract-stack support requires the deeper segment to reach the shoulder plane; unsupported deeper continuation shape.");
return false;
}
@@ -136,7 +175,7 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
diagnostic = BrepBooleanCylinderRecognition.CreateNotFullySpanningDiagnostic(
BooleanOperation.Subtract.ToString(),
featureId,
- "bounded contained coaxial subtract-stack support requires the deeper segment to extend above the shoulder plane.");
+ "bounded contained coaxial subtract-stack support requires the deeper segment to continue above the shoulder plane.");
return false;
}
}
@@ -146,7 +185,7 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
diagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(
BooleanOperation.Subtract.ToString(),
featureId,
- "bounded contained coaxial subtract-stack support requires a strictly larger entry-segment radius than the deeper segment radius to avoid degenerate shoulder geometry.");
+ "bounded contained coaxial subtract-stack support requires a strictly larger entry-segment radius than the deeper segment radius; invalid counterbore radius ordering or degenerate shoulder geometry.");
return false;
}
@@ -164,13 +203,10 @@ internal static class BrepBooleanCoaxialSubtractStackFamily
private static bool IsBottomEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)
=> ResolveBottom(hole) <= (outerBox.MinZ + tolerance.Linear);
- private static bool IsTopBlindEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)
- => hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromTop
- || (hole.SpanKind == SupportedBooleanHoleSpanKind.Contained && IsTopEntry(hole, outerBox, tolerance));
-
- private static bool IsBottomBlindEntry(in SupportedBooleanHole hole, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)
- => hole.SpanKind == SupportedBooleanHoleSpanKind.BlindFromBottom
- || (hole.SpanKind == SupportedBooleanHoleSpanKind.Contained && IsBottomEntry(hole, outerBox, tolerance));
+ private static bool IntersectsEntryFace(in SupportedBooleanHole hole, bool entryFromTop, AxisAlignedBoxExtents outerBox, ToleranceContext tolerance)
+ => entryFromTop
+ ? IsTopEntry(hole, outerBox, tolerance)
+ : IsBottomEntry(hole, outerBox, tolerance);
private static bool IsWorldZAligned(Direction3D axis, ToleranceContext tolerance)
{
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index dcb43f57..f85af2a4 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -274,6 +274,22 @@ public sealed class FirmamentBuildAndExportTests
Assert.Contains("CYLINDRICAL_SURFACE", first.Value.Export.StepText, StringComparison.Ordinal);
}
+ [Fact]
+ public void Run_FrictionLabCounterboreHole_NowBuildsAndExports()
+ {
+ var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/counterbore-hole/part.firmament");
+
+ var first = FirmamentBuildAndExport.Run(fullSourcePath);
+ var second = FirmamentBuildAndExport.Run(fullSourcePath);
+
+ Assert.True(first.IsSuccess);
+ Assert.True(second.IsSuccess);
+ Assert.NotEmpty(first.Value.Export.StepText);
+ Assert.Equal(first.Value.Export.StepText, second.Value.Export.StepText);
+ Assert.Contains("MANIFOLD_SOLID_BREP", first.Value.Export.StepText, StringComparison.Ordinal);
+ Assert.Contains("CYLINDRICAL_SURFACE", first.Value.Export.StepText, StringComparison.Ordinal);
+ }
+
[Fact]
public void Semantic_Placement_Build_Is_Deterministic()
{