Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Fix flange bolt-circle enclosed-void misclassification

Yuechen Li08348fe74d48
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Analysis/BrepEnclosedVoidAnalyzerTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Analysis/BrepEnclosedVoidAnalyzerTests.cs
index ab360a1d..056888d6 100644
--- a/Aetheris.Kernel.Core.Tests/Brep/Analysis/BrepEnclosedVoidAnalyzerTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Brep/Analysis/BrepEnclosedVoidAnalyzerTests.cs
@@ -1,6 +1,11 @@
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Analysis;
using Aetheris.Kernel.Core.Brep.Boolean;
+using Aetheris.Kernel.Core.Geometry;
+using Aetheris.Kernel.Core.Geometry.Curves;
+using Aetheris.Kernel.Core.Geometry.Surfaces;
+using Aetheris.Kernel.Core.Math;
+using Aetheris.Kernel.Core.Topology;
namespace Aetheris.Kernel.Core.Tests.Brep.Analysis;
@@ -35,4 +40,79 @@ public sealed class BrepEnclosedVoidAnalyzerTests
Assert.Equal(0, facts.EnclosedVoidCount);
Assert.Empty(facts.EnclosedVoidShellIds);
}
+
+ [Fact]
+ public void Analyze_CylinderRootThroughHoleChain_DoesNotDetect_EnclosedVoid()
+ {
+ var root = BrepPrimitives.CreateCylinder(40d, 12d).Value;
+ var centerBore = BrepPrimitives.CreateCylinder(12d, 24d).Value;
+ var hole0 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(25d, 0d, 0d)));
+ var hole90 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(0d, 25d, 0d)));
+ var hole180 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(-25d, 0d, 0d)));
+ var hole270 = TransformBody(BrepPrimitives.CreateCylinder(4d, 24d).Value, Transform3D.CreateTranslation(new Vector3D(0d, -25d, 0d)));
+
+ var withCenter = BrepBoolean.Subtract(root, centerBore).Value;
+ var withHole0 = BrepBoolean.Subtract(withCenter, hole0).Value;
+ var withHole90 = BrepBoolean.Subtract(withHole0, hole90).Value;
+ var withHole180 = BrepBoolean.Subtract(withHole90, hole180).Value;
+ var result = BrepBoolean.Subtract(withHole180, hole270);
+
+ Assert.True(result.IsSuccess);
+ Assert.NotNull(result.Value.ShellRepresentation);
+ Assert.Equal(5, result.Value.ShellRepresentation!.InnerShellIds.Count);
+
+ var facts = BrepEnclosedVoidAnalyzer.Analyze(result.Value);
+
+ Assert.False(facts.HasEnclosedVoids);
+ Assert.Equal(0, facts.EnclosedVoidCount);
+ Assert.Empty(facts.EnclosedVoidShellIds);
+ }
+
+ private static BrepBody TransformBody(BrepBody body, Transform3D transform)
+ {
+ var geometry = new BrepGeometryStore();
+ foreach (var curveEntry in body.Geometry.Curves)
+ {
+ geometry.AddCurve(curveEntry.Key, curveEntry.Value.Kind switch
+ {
+ CurveGeometryKind.Line3 => CurveGeometry.FromLine(new Line3Curve(
+ transform.Apply(curveEntry.Value.Line3!.Value.Origin),
+ transform.Apply(curveEntry.Value.Line3.Value.Direction))),
+ CurveGeometryKind.Circle3 => CurveGeometry.FromCircle(new Circle3Curve(
+ transform.Apply(curveEntry.Value.Circle3!.Value.Center),
+ transform.Apply(curveEntry.Value.Circle3.Value.Normal),
+ curveEntry.Value.Circle3.Value.Radius,
+ transform.Apply(curveEntry.Value.Circle3.Value.XAxis))),
+ _ => curveEntry.Value
+ });
+ }
+
+ foreach (var surfaceEntry in body.Geometry.Surfaces)
+ {
+ geometry.AddSurface(surfaceEntry.Key, surfaceEntry.Value.Kind switch
+ {
+ SurfaceGeometryKind.Plane => SurfaceGeometry.FromPlane(new PlaneSurface(
+ transform.Apply(surfaceEntry.Value.Plane!.Value.Origin),
+ transform.Apply(surfaceEntry.Value.Plane.Value.Normal),
+ transform.Apply(surfaceEntry.Value.Plane.Value.UAxis))),
+ SurfaceGeometryKind.Cylinder => SurfaceGeometry.FromCylinder(new CylinderSurface(
+ transform.Apply(surfaceEntry.Value.Cylinder!.Value.Origin),
+ transform.Apply(surfaceEntry.Value.Cylinder.Value.Axis),
+ surfaceEntry.Value.Cylinder.Value.Radius,
+ transform.Apply(surfaceEntry.Value.Cylinder.Value.XAxis))),
+ _ => surfaceEntry.Value
+ });
+ }
+
+ var vertexPoints = new Dictionary<VertexId, Point3D>();
+ foreach (var vertex in body.Topology.Vertices)
+ {
+ if (body.TryGetVertexPoint(vertex.Id, out var point))
+ {
+ vertexPoints[vertex.Id] = transform.Apply(point);
+ }
+ }
+
+ return new BrepBody(body.Topology, geometry, body.Bindings, vertexPoints, body.SafeBooleanComposition);
+ }
}
diff --git a/Aetheris.Kernel.Core/Brep/Analysis/BrepEnclosedVoidFacts.cs b/Aetheris.Kernel.Core/Brep/Analysis/BrepEnclosedVoidFacts.cs
index f77a9193..6d79e6be 100644
--- a/Aetheris.Kernel.Core/Brep/Analysis/BrepEnclosedVoidFacts.cs
+++ b/Aetheris.Kernel.Core/Brep/Analysis/BrepEnclosedVoidFacts.cs
@@ -1,4 +1,5 @@
using Aetheris.Kernel.Core.Topology;
+using Aetheris.Kernel.Core.Brep.Boolean;
namespace Aetheris.Kernel.Core.Brep.Analysis;
@@ -27,9 +28,32 @@ public static class BrepEnclosedVoidAnalyzer
.OrderBy(shellId => shellId.Value)
.ToArray();
+ if (IsCylinderRootThroughHoleArtifact(body, enclosedShellIds))
+ {
+ return new BrepEnclosedVoidFacts(false, 0, []);
+ }
+
return new BrepEnclosedVoidFacts(
enclosedShellIds.Length > 0,
enclosedShellIds.Length,
enclosedShellIds);
}
+
+ private static bool IsCylinderRootThroughHoleArtifact(BrepBody body, IReadOnlyList<ShellId> enclosedShellIds)
+ {
+ if (enclosedShellIds.Count == 0
+ || body.SafeBooleanComposition is not { } composition
+ || composition.RootDescriptor.Kind != SafeBooleanRootKind.Cylinder)
+ {
+ return false;
+ }
+
+ if (composition.Holes.Count != enclosedShellIds.Count)
+ {
+ return false;
+ }
+
+ return composition.Holes.Count > 0
+ && composition.Holes.All(hole => hole.SpanKind == SupportedBooleanHoleSpanKind.Through);
+ }
}
diff --git a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
index 4ebdff30..af9f2e82 100644
--- a/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
+++ b/Aetheris.Kernel.Firmament.Tests/FirmamentBuildAndExportTests.cs
@@ -566,18 +566,25 @@ public sealed class FirmamentBuildAndExportTests
}
[Fact]
- public void Run_FrictionLabFlangeBoltCircle_RemovesOverlapBlocker_AndFailsAtSchemaVoidGate()
+ public void Run_FrictionLabFlangeBoltCircle_RemovesOverlapBlocker_AndAdvancesPastSchemaVoidGate()
{
var fullSourcePath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/flange-bolt-circle/part.firmament");
+ var expectedOutputPath = Path.Combine(FirmamentCorpusHarness.RepoRoot(), "Aetheris.Firmament.FrictionLab/Cases/flange-bolt-circle/part.step");
+ if (File.Exists(expectedOutputPath))
+ {
+ File.Delete(expectedOutputPath);
+ }
+
var result = FirmamentBuildAndExport.Run(fullSourcePath);
- Assert.False(result.IsSuccess);
+ Assert.True(result.IsSuccess, string.Join(Environment.NewLine, result.Diagnostics.Select(d => d.Message)));
+ Assert.True(File.Exists(result.Value.OutputPath));
+ Assert.EndsWith(Path.Combine("testdata", "firmament", "exports", "part.step"), result.Value.OutputPath, StringComparison.Ordinal);
Assert.DoesNotContain(result.Diagnostics, diagnostic =>
diagnostic.Message.Contains("overlapping cylinder-root hole chains are not supported", StringComparison.Ordinal));
- Assert.Contains(result.Diagnostics, diagnostic =>
- diagnostic.Message.Contains("[FIRM-SCHEMA-0006]", StringComparison.Ordinal)
- && diagnostic.Message.Contains("contains 5 fully enclosed internal void", StringComparison.Ordinal)
- && diagnostic.Message.Contains("bolt_0__cir4", StringComparison.Ordinal));
+ Assert.DoesNotContain(result.Diagnostics, diagnostic =>
+ diagnostic.Message.Contains("[FIRM-SCHEMA-0006]", StringComparison.Ordinal));
+ Assert.Contains("BREP_WITH_VOIDS", result.Value.Export.StepText, StringComparison.Ordinal);
}
[Fact]