Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Fix shallow-cone vertex reconstruction stability in STEP export

Yuechen Lib64e5e13c5d9
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
index c5584d49..c44ab9b2 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ExporterTests.cs
@@ -158,6 +158,54 @@ END-ISO-10303-21;";
}
}
+ [Fact]
+ public void ExportBody_Ctc02RoundTrip_ShallowCones_PreserveApexCoordinates()
+ {
+ var fixturePath = Path.Combine(Step242CorpusManifestRunner.RepoRoot(), "testdata", "step242", "nist", "CTC", "nist_ctc_02_asme1_ap242-e2.stp");
+ var source = File.ReadAllText(fixturePath);
+
+ var import = Step242Importer.ImportBody(source);
+ Assert.True(import.IsSuccess);
+
+ var expectedShallowCones = import.Value.Geometry.Surfaces
+ .Select(surface => surface.Value)
+ .Where(surface => surface.Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cone && surface.Cone.HasValue)
+ .Select(surface => surface.Cone!.Value)
+ .Where(cone => cone.SemiAngleRadians < 0.1d)
+ .Select(cone => cone.Apex)
+ .OrderBy(point => point.X)
+ .ThenBy(point => point.Y)
+ .ThenBy(point => point.Z)
+ .ToArray();
+
+ Assert.Equal(10, expectedShallowCones.Length);
+
+ var export = Step242Exporter.ExportBody(import.Value);
+ Assert.True(export.IsSuccess);
+
+ var roundTrip = Step242Importer.ImportBody(export.Value);
+ Assert.True(roundTrip.IsSuccess);
+
+ var actualShallowCones = roundTrip.Value.Geometry.Surfaces
+ .Select(surface => surface.Value)
+ .Where(surface => surface.Kind == Aetheris.Kernel.Core.Geometry.SurfaceGeometryKind.Cone && surface.Cone.HasValue)
+ .Select(surface => surface.Cone!.Value)
+ .Where(cone => cone.SemiAngleRadians < 0.1d)
+ .Select(cone => cone.Apex)
+ .OrderBy(point => point.X)
+ .ThenBy(point => point.Y)
+ .ThenBy(point => point.Z)
+ .ToArray();
+
+ Assert.Equal(expectedShallowCones.Length, actualShallowCones.Length);
+ for (var i = 0; i < expectedShallowCones.Length; i++)
+ {
+ Assert.Equal(expectedShallowCones[i].X, actualShallowCones[i].X, 6);
+ Assert.Equal(expectedShallowCones[i].Y, actualShallowCones[i].Y, 6);
+ Assert.Equal(expectedShallowCones[i].Z, actualShallowCones[i].Z, 6);
+ }
+ }
+
[Fact]
public void ExportBody_EmitsCanonicalRadianPlaneAngleUnitContext()
diff --git a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
index a0142ac1..42ff2b3e 100644
--- a/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
+++ b/Aetheris.Kernel.Core/Step242/Step242Exporter.cs
@@ -433,11 +433,15 @@ public static class Step242Exporter
return KernelResult<Point3D>.Success(resolved);
}
- var fromPlanes = ResolveVertexFromIncidentPlanes(body, model, vertexId);
- if (fromPlanes.IsSuccess)
+ var preferEdgeEndpoint = VertexTouchesNonPlanarFace(body, model, vertexId);
+ if (!preferEdgeEndpoint)
{
- vertexPoints[vertexId] = fromPlanes.Value;
- return fromPlanes;
+ var fromPlanes = ResolveVertexFromIncidentPlanes(body, model, vertexId);
+ if (fromPlanes.IsSuccess)
+ {
+ vertexPoints[vertexId] = fromPlanes.Value;
+ return fromPlanes;
+ }
}
foreach (var edge in model.Edges.OrderBy(e => e.Id.Value))
@@ -465,6 +469,50 @@ public static class Step242Exporter
return FailurePoint($"Vertex {vertexId.Value} cannot be resolved to a geometric point for STEP export.", $"Vertex:{vertexId.Value}");
}
+ private static bool VertexTouchesNonPlanarFace(BrepBody body, TopologyModel model, VertexId vertexId)
+ {
+ foreach (var face in model.Faces.OrderBy(f => f.Id.Value))
+ {
+ var touchesVertex = false;
+ foreach (var loopId in face.LoopIds)
+ {
+ var loop = model.GetLoop(loopId);
+ foreach (var coedgeId in loop.CoedgeIds)
+ {
+ var coedge = model.GetCoedge(coedgeId);
+ var edge = model.GetEdge(coedge.EdgeId);
+ if (edge.StartVertexId == vertexId || edge.EndVertexId == vertexId)
+ {
+ touchesVertex = true;
+ break;
+ }
+ }
+
+ if (touchesVertex)
+ {
+ break;
+ }
+ }
+
+ if (!touchesVertex || !body.Bindings.TryGetFaceBinding(face.Id, out var faceBinding))
+ {
+ continue;
+ }
+
+ if (!body.Geometry.TryGetSurface(faceBinding.SurfaceGeometryId, out var surface) || surface is null)
+ {
+ continue;
+ }
+
+ if (surface.Kind != SurfaceGeometryKind.Plane)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private static KernelResult<Point3D> ResolveVertexFromIncidentPlanes(BrepBody body, TopologyModel model, VertexId vertexId)
{
var planes = new List<PlaneSurface>();