Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Generalize cylinder-root subtract validation to geometry-first invariants
Yuechen Li906c10ddf34a
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.csindex a280e72d..4c73bb52 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Boolean/BrepBooleanTests.cs@@ -362,6 +362,25 @@ public sealed class BrepBooleanTestsAssert.Equal(firstExport.Value, secondExport.Value);}+ [Fact]+ public void Subtract_CylinderRootOffsetHoleThenCenterBore_Succeeds()+ {+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;+ var offsetHole = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;++ var withOffset = BrepBoolean.Subtract(root, offsetHole);+ Assert.True(withOffset.IsSuccess);+ var result = BrepBoolean.Subtract(withOffset.Value, centerBore);++ Assert.True(result.IsSuccess);+ Assert.True(BrepBindingValidator.Validate(result.Value, true).IsSuccess);+ Assert.Equal(2, result.Value.ShellRepresentation!.InnerShellIds.Count);+ var export = Step242Exporter.ExportBody(result.Value);+ Assert.True(export.IsSuccess);+ Assert.Contains("BREP_WITH_VOIDS", export.Value, StringComparison.Ordinal);+ }+[Fact]public void Subtract_CylinderRootCenterBoreThenWallTouchingOffsetHole_IsRejectedLoudly(){@@ -391,7 +410,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);- Assert.Contains("strictly outside the center bore ring boundary", diagnostic.Message, StringComparison.Ordinal);+ Assert.Contains("overlaps previously accepted hole", diagnostic.Message, StringComparison.Ordinal);}[Fact]@@ -410,7 +429,7 @@ public sealed class BrepBooleanTestsAssert.False(result.IsSuccess);var diagnostic = Assert.Single(result.Diagnostics);- Assert.Contains("tangent to previously accepted off-axis hole", diagnostic.Message, StringComparison.Ordinal);+ Assert.Contains("tangent to previously accepted hole", diagnostic.Message, StringComparison.Ordinal);}[Fact]diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.csindex 621ebf32..b4efd6ef 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanBoxCylinderHoleBuilder.cs@@ -66,21 +66,7 @@ public static class BrepBooleanBoxCylinderHoleBuilderBrepBooleanCylinderRecognition.CreateBooleanMessage(BooleanOperation.Subtract.ToString(),null,- "cylinder-root safe rebuild in F3 requires a center-bore plus optional off-axis through-hole cylinder chain."),- "BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),- ]);- }-- var centerBore = composition.Holes[0];- if (centerBore.Surface.Cylinder is not RecognizedCylinder boreCylinder)- {- return KernelResult<BrepBody>.Failure([- new BooleanDiagnostic(- BooleanDiagnosticCode.NotFullySpanning,- BrepBooleanCylinderRecognition.CreateBooleanMessage(- BooleanOperation.Subtract.ToString(),- centerBore.FeatureId,- "cylinder-root safe rebuild in F3 requires recognized cylindrical tool surfaces."),+ "cylinder-root safe rebuild in F3 requires a through-hole cylinder chain."),"BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),]);}@@ -89,24 +75,6 @@ public static class BrepBooleanBoxCylinderHoleBuilder(rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d,(rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d,(rootCylinder.MinCenter.Z + rootCylinder.MaxCenter.Z) * 0.5d);- var boreCenter = new Point3D(- (boreCylinder.MinCenter.X + boreCylinder.MaxCenter.X) * 0.5d,- (boreCylinder.MinCenter.Y + boreCylinder.MaxCenter.Y) * 0.5d,- (boreCylinder.MinCenter.Z + boreCylinder.MaxCenter.Z) * 0.5d);-- if (!ToleranceMath.AlmostEqual(rootCenter.X, boreCenter.X, tolerance)- || !ToleranceMath.AlmostEqual(rootCenter.Y, boreCenter.Y, tolerance))- {- return KernelResult<BrepBody>.Failure([- new BooleanDiagnostic(- BooleanDiagnosticCode.RadiusExceedsBoundary,- BrepBooleanCylinderRecognition.CreateBooleanMessage(- BooleanOperation.Subtract.ToString(),- null,- "cylinder-root safe rebuild in F2 only supports coaxial center bores."),- "BrepBoolean.AnalyticHole.CylinderRootUnsupportedComposition").ToKernelDiagnostic(),- ]);- }var outer = BrepPrimitives.CreateCylinder(rootCylinder.Radius, rootCylinder.Height);if (!outer.IsSuccess)diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.csindex b6785e2c..92980ca0 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBooleanSafeCompositionGraphValidator.cs@@ -175,87 +175,21 @@ public static class BrepBooleanSafeCompositionGraphValidatorrootMinZ,rootMaxZ);- if (composition.Holes.Count == 0)- {- if (!isCoaxialCenterBore)- {- diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "is outside the bounded cylinder-root safe subtract family; the first subtract must be a coaxial center bore.");- return false;- }-- if (toolCylinder.Radius >= (rootCylinder.Radius - tolerance.Linear))- {- diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "must remain strictly smaller than the flange root radius in the bounded cylinder-root safe subtract family.");- return false;- }-- updatedComposition = composition with- {- Holes = [nextHole],- };-- return true;- }-- var centerBore = composition.Holes[0];- var centerBoreDeltaX = centerBore.CenterX - rootCenter.X;- var centerBoreDeltaY = centerBore.CenterY - rootCenter.Y;- var centerBoreOffset = System.Math.Sqrt((centerBoreDeltaX * centerBoreDeltaX) + (centerBoreDeltaY * centerBoreDeltaY));- if (!ToleranceMath.AlmostZero(centerBoreOffset, tolerance))- {- diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "cannot continue cylinder-root safe subtract composition because the first accepted hole is not a coaxial center bore.");- return false;- }-- if (isCoaxialCenterBore)- {- diagnostic = new BooleanDiagnostic(- BooleanDiagnosticCode.HoleInterference,- BrepBooleanCylinderRecognition.CreateBooleanMessage(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "cannot append another coaxial center bore in the bounded cylinder-root safe family."),- "BrepBoolean.AnalyticHole.HoleInterference");- return false;- }-var ringOuterDistance = radialDistance + toolCylinder.Radius;- var ringInnerDistance = radialDistance - toolCylinder.Radius;if (ToleranceMath.AlmostEqual(ringOuterDistance, rootCylinder.Radius, tolerance)|| ringOuterDistance > (rootCylinder.Radius - tolerance.Linear)){diagnostic = BrepBooleanCylinderRecognition.CreateRadiusExceedsBoundaryDiagnostic(BooleanOperation.Subtract.ToString(),nextFeatureId,- "is outside the bounded cylinder-root safe subtract family; off-axis through-holes must remain strictly inside the outer cylindrical wall.");- return false;- }-- if (ToleranceMath.AlmostEqual(ringInnerDistance, centerBore.BottomRadius, tolerance)- || ringInnerDistance < (centerBore.BottomRadius + tolerance.Linear))- {- diagnostic = new BooleanDiagnostic(- BooleanDiagnosticCode.HoleInterference,- BrepBooleanCylinderRecognition.CreateBooleanMessage(- BooleanOperation.Subtract.ToString(),- nextFeatureId,- "is outside the bounded cylinder-root safe subtract family; off-axis through-holes must remain strictly outside the center bore ring boundary."),- "BrepBoolean.AnalyticHole.HoleInterference");+ 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.");return false;}- for (var i = 1; i < composition.Holes.Count; i++)+ foreach (var existingHole in composition.Holes){- var existingHole = composition.Holes[i];var existingDeltaX = existingHole.CenterX - nextHole.CenterX;var existingDeltaY = existingHole.CenterY - nextHole.CenterY;var centerDistance = System.Math.Sqrt((existingDeltaX * existingDeltaX) + (existingDeltaY * existingDeltaY));@@ -266,7 +200,7 @@ public static class BrepBooleanSafeCompositionGraphValidatordiagnostic = BrepBooleanCylinderRecognition.CreateTangentContactDiagnostic(BooleanOperation.Subtract.ToString(),nextFeatureId,- $"would be tangent to previously accepted off-axis hole {FormatFeatureRef(existingHole.FeatureId)}; tangent safe-hole composition is rejected.");+ $"would be tangent to previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; tangent safe-hole composition is rejected.");return false;}@@ -277,7 +211,7 @@ public static class BrepBooleanSafeCompositionGraphValidatorBrepBooleanCylinderRecognition.CreateBooleanMessage(BooleanOperation.Subtract.ToString(),nextFeatureId,- $"overlaps previously accepted off-axis hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping cylinder-root hole chains are not supported."),+ $"overlaps previously accepted hole {FormatFeatureRef(existingHole.FeatureId)}; overlapping cylinder-root hole chains are not supported."),"BrepBoolean.AnalyticHole.HoleInterference");return false;}