Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
Add bounded cylinder-keyway subset diagnostics for shaft case
Yuechen Lif23fb6e80efa
diff --git a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.csindex be4a9cae..31bbd5fb 100644--- a/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs+++ b/Aetheris.Kernel.Core/Brep/Boolean/BrepBoolean.cs@@ -208,6 +208,36 @@ public static class BrepBooleannull);}+ if (operation == BooleanOperation.Subtract+ && leftSafeCompositionRecognized+ && leftSafeComposition is not null+ && leftSafeComposition.RootDescriptor.Kind == SafeBooleanRootKind.Cylinder+ && rightRecognized)+ {+ if (TryClassifyBoundedCylinderRootKeyway(+ leftSafeComposition.RootDescriptor,+ rightBox,+ resolvedTolerance,+ out var keywayUnsupportedReason))+ {+ return new BooleanCaseClassification(+ BooleanExecutionClass.UnsupportedGeneralCase,+ leftSafeComposition,+ leftSafeComposition.OuterBox,+ rightBox,+ null,+ "Boolean Subtract: bounded cylinder-root keyway family is recognized (single world-Z through rectangular slot), but rebuild/export for open-slot topology is not implemented yet.");+ }++ return new BooleanCaseClassification(+ BooleanExecutionClass.UnsupportedGeneralCase,+ leftSafeComposition,+ leftSafeComposition.OuterBox,+ rightBox,+ null,+ keywayUnsupportedReason ?? "Boolean Subtract: cylinder-root subtract with box tool is outside the bounded keyway family.");+ }+if (leftSafeCompositionRecognized){return new BooleanCaseClassification(@@ -759,6 +789,64 @@ public static class BrepBooleanreturn visited.Count == cells.Count;}+ private static bool TryClassifyBoundedCylinderRootKeyway(+ in SafeBooleanRootDescriptor rootDescriptor,+ AxisAlignedBoxExtents toolBox,+ ToleranceContext tolerance,+ out string? unsupportedReason)+ {+ unsupportedReason = null;+ if (rootDescriptor.Kind != SafeBooleanRootKind.Cylinder || rootDescriptor.Cylinder is not RecognizedCylinder rootCylinder)+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires a recognized cylinder root.";+ return false;+ }++ if (!BrepBooleanCylinderRecognition.ValidateAxisAlignedZ(rootCylinder, tolerance))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires a world-Z aligned cylinder root.";+ return false;+ }++ var rootCenterX = (rootCylinder.MinCenter.X + rootCylinder.MaxCenter.X) * 0.5d;+ var rootCenterY = (rootCylinder.MinCenter.Y + rootCylinder.MaxCenter.Y) * 0.5d;+ var rootMinZ = System.Math.Min(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);+ var rootMaxZ = System.Math.Max(rootCylinder.MinCenter.Z, rootCylinder.MaxCenter.Z);++ if (toolBox.MinZ > (rootMinZ + tolerance.Linear) || toolBox.MaxZ < (rootMaxZ - tolerance.Linear))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires a through slot that spans both cylinder end caps along world-Z.";+ return false;+ }++ var hasInteriorPenetration = DistanceFromPointToRectangle(rootCenterX, rootCenterY, toolBox) < (rootCylinder.Radius - tolerance.Linear);+ if (!hasInteriorPenetration)+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family requires the rectangular tool to penetrate inside the shaft radius.";+ return false;+ }++ if (ContainsPoint(toolBox.MinX, toolBox.MaxX, rootCenterX, tolerance)+ && ContainsPoint(toolBox.MinY, toolBox.MaxY, rootCenterY, tolerance))+ {+ unsupportedReason = "Boolean Subtract: bounded keyway family excludes centerline-spanning trenches; slot must remain one-sided off-axis.";+ return false;+ }++ return true;+ }++ private static bool ContainsPoint(double min, double max, double value, ToleranceContext tolerance)+ => value >= (min - tolerance.Linear) && value <= (max + tolerance.Linear);++ private static double DistanceFromPointToRectangle(double px, double py, AxisAlignedBoxExtents rectangle)+ {+ var dx = px < rectangle.MinX ? rectangle.MinX - px : px > rectangle.MaxX ? px - rectangle.MaxX : 0d;+ var dy = py < rectangle.MinY ? rectangle.MinY - py : py > rectangle.MaxY ? py - rectangle.MaxY : 0d;+ return System.Math.Sqrt((dx * dx) + (dy * dy));+ }++private static bool CellsShareVolumeOrFace(AxisAlignedBoxExtents a, AxisAlignedBoxExtents b, ToleranceContext tolerance){var overlap = AxisAlignedBoxExtents.Intersection(a, b);diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.csindex 9e1a0f68..85294a5b 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBooleanCanonicalSuccessTests.cs@@ -210,6 +210,64 @@ public sealed class FirmamentBooleanCanonicalSuccessTestsdiagnostic.Message.Contains("requires at least one executed primitive or boolean body", StringComparison.Ordinal));}+ [Fact]+ public void CylinderRootKeywayPressureCase_Fails_WithExplicitCenterlineSubsetDiagnostic()+ {+ var source = FirmamentCorpusHarness.ReadFixtureText("Aetheris.Firmament.FrictionLab/Cases/shaft-keyway/part.firmament");+ var result = FirmamentCorpusHarness.Compile(source);++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Code == KernelDiagnosticCode.NotImplemented+ && diagnostic.Source == "BrepBoolean.RebuildResult"+ && diagnostic.Message.Contains("bounded keyway family excludes centerline-spanning trenches", StringComparison.Ordinal));+ }++ [Fact]+ public void CylinderRootKeywayOutsideBoundedSubset_Fails_WithSpecificDepthDiagnostic()+ {+ const string source = """+ firmament:+ version: 1++ model:+ name: keyway_depth_outside_subset+ units: mm++ ops[2]:+ -+ op: cylinder+ id: shaft+ radius: 15+ height: 80++ -+ op: subtract+ id: shallow_keyway+ from: shaft+ with:+ op: box+ size[3]:+ 10+ 6+ 30+ place:+ on: origin+ offset[3]:+ 10+ 0+ 0+ """;++ var result = FirmamentCorpusHarness.Compile(source);++ Assert.False(result.Compilation.IsSuccess);+ Assert.Contains(result.Compilation.Diagnostics, diagnostic =>+ diagnostic.Code == KernelDiagnosticCode.NotImplemented+ && diagnostic.Source == "BrepBoolean.RebuildResult"+ && diagnostic.Message.Contains("requires a through slot that spans both cylinder end caps", StringComparison.Ordinal));+ }+public static TheoryData<string, string, string> UnsupportedBoxTorusVariantSources =>new(){diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.csindex 4b9edc07..5d787add 100644--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs@@ -539,7 +539,7 @@ public sealed class FirmamentBuildAndExportTestsdiagnostic.Message.Contains("Requested boolean feature 'keyway' (subtract) could not be executed.", StringComparison.Ordinal));Assert.Contains(result.Diagnostics, diagnostic =>diagnostic.Source == "BrepBoolean.RebuildResult"- && diagnostic.Message.Contains("sequential safe composition only supports subtracting supported analytic holes", StringComparison.Ordinal));+ && diagnostic.Message.Contains("bounded keyway family excludes centerline-spanning trenches", StringComparison.Ordinal));}[Fact]