Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

Fix cone side trim bounds to align with base cap

Yuechen Li02db0176bafd
diff --git a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
index 64014c43..5fc9ee76 100644
--- a/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
+++ b/Aetheris.Kernel.Core.Tests/Step242/Step242ImporterTests.cs
@@ -479,6 +479,17 @@ public sealed class Step242ImporterTests
return surface!.Kind == SurfaceGeometryKind.Cone;
});
+ var baseFace = Assert.Single(import.Value.Topology.Faces, face =>
+ {
+ Assert.True(import.Value.Bindings.TryGetFaceBinding(face.Id, out var binding));
+ Assert.True(import.Value.Geometry.TryGetSurface(binding.SurfaceGeometryId, out var surface));
+ return surface!.Kind == SurfaceGeometryKind.Plane;
+ });
+
+ Assert.True(import.Value.Bindings.TryGetFaceBinding(baseFace.Id, out var baseFaceBinding));
+ Assert.True(import.Value.Geometry.TryGetSurface(baseFaceBinding.SurfaceGeometryId, out var baseFaceSurface));
+ var basePlane = baseFaceSurface!.Plane!.Value;
+
var loopIds = import.Value.GetLoopIds(coneFace.Id);
var loopId = Assert.Single(loopIds);
var coedges = import.Value.GetCoedgeIds(loopId)
@@ -520,6 +531,14 @@ public sealed class Step242ImporterTests
Assert.True(patchA.Positions.SequenceEqual(patchB.Positions));
Assert.True(patchA.Normals.SequenceEqual(patchB.Normals));
Assert.True(patchA.TriangleIndices.SequenceEqual(patchB.TriangleIndices));
+
+ var baseNormal = basePlane.Normal.ToVector();
+ var signedDistances = patchA.Positions
+ .Select(point => (point - basePlane.Origin).Dot(baseNormal))
+ .ToArray();
+
+ Assert.True(signedDistances.Min() >= -1e-8d);
+ Assert.True(signedDistances.Count(distance => double.Abs(distance) <= 1e-8d) >= 8);
}
[Fact]
diff --git a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
index 2c678b04..8a4918cd 100644
--- a/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
+++ b/Aetheris.Kernel.Core/Brep/Tessellation/BrepDisplayTessellator.cs
@@ -254,7 +254,14 @@ public static class BrepDisplayTessellator
private static KernelResult<DisplayFaceMeshPatch> TessellateConeFace(BrepBody body, FaceId faceId, ConeSurface cone, DisplayTessellationOptions options)
{
- var parameters = GetRevolvedFaceParameters(body, faceId, options, radiusHint: 1d, allowThreeCoedgeConeTopology: true);
+ var axis = cone.Axis.ToVector();
+ var parameters = GetRevolvedFaceParameters(
+ body,
+ faceId,
+ options,
+ radiusHint: 1d,
+ allowThreeCoedgeConeTopology: true,
+ axialParameterFromPoint: point => (point - cone.Apex).Dot(axis));
if (!parameters.IsSuccess)
{
return KernelResult<DisplayFaceMeshPatch>.Failure(parameters.Diagnostics);
@@ -346,7 +353,8 @@ public static class BrepDisplayTessellator
FaceId faceId,
DisplayTessellationOptions options,
double radiusHint,
- bool allowThreeCoedgeConeTopology)
+ bool allowThreeCoedgeConeTopology,
+ Func<Point3D, double>? axialParameterFromPoint = null)
{
var loopIds = body.GetLoopIds(faceId);
if (loopIds.Count != 1)
@@ -389,9 +397,43 @@ public static class BrepDisplayTessellator
}
var lineTrimInterval = lineTrimBinding.TrimInterval ?? new ParameterInterval(0d, 1d);
+ var lineTrimStart = lineTrimInterval.Start;
+ var lineTrimEnd = lineTrimInterval.End;
+
+ if (axialParameterFromPoint is not null)
+ {
+ var vertexPointsResult = BuildLoopVertexPointLookup(body, coedges, faceId);
+ if (!vertexPointsResult.IsSuccess)
+ {
+ return KernelResult<(double, double, int, int)>.Failure(vertexPointsResult.Diagnostics);
+ }
+
+ var projected = vertexPointsResult.Value.Values
+ .Select(axialParameterFromPoint)
+ .Where(double.IsFinite)
+ .ToArray();
+
+ if (projected.Length != 0)
+ {
+ var projectedMin = projected.Min();
+ var projectedMax = projected.Max();
+ if (lineTrimEnd >= lineTrimStart)
+ {
+ lineTrimStart = projectedMin;
+ lineTrimEnd = projectedMax;
+ }
+ else
+ {
+ lineTrimStart = projectedMax;
+ lineTrimEnd = projectedMin;
+ }
+ }
+ }
+
var angularSegments = CalculateSegmentCount(2d * double.Pi, System.Math.Max(1e-6d, radiusHint), options);
- var axialSegments = System.Math.Max(1, System.Math.Clamp((int)double.Ceiling((lineTrimInterval.End - lineTrimInterval.Start) / options.ChordTolerance), 1, options.MaximumSegments));
- return KernelResult<(double, double, int, int)>.Success((lineTrimInterval.Start, lineTrimInterval.End, angularSegments, axialSegments));
+ var axialSpan = double.Abs(lineTrimEnd - lineTrimStart);
+ var axialSegments = System.Math.Max(1, System.Math.Clamp((int)double.Ceiling(axialSpan / options.ChordTolerance), 1, options.MaximumSegments));
+ return KernelResult<(double, double, int, int)>.Success((lineTrimStart, lineTrimEnd, angularSegments, axialSegments));
}
if (coedges.Length != 4)