Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel
H7: harden planar analytic domain support boundaries
Yuechen Lib194bbdf4df4
diff --git a/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayPacketBuilderTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayPacketBuilderTests.csindex 5b69c752..f419d00b 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayPacketBuilderTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayPacketBuilderTests.cs@@ -23,6 +23,23 @@ public sealed class AnalyticDisplayPacketBuilderTestsAssert.All(packet.AnalyticFaces, face => Assert.Equal(SurfaceGeometryKind.Plane, face.SurfaceKind));}++ [Fact]+ public void Build_RotatedBoxBody_RoutesNonAxisPlanarFacesToFallback()+ {+ var body = TransformBody(BrepPrimitives.CreateBox(2d, 2d, 2d).Value, Transform3D.CreateRotationX(double.Pi / 4d));++ var packet = AnalyticDisplayPacketBuilder.Build(body);++ Assert.NotEmpty(packet.AnalyticFaces);+ Assert.NotEmpty(packet.FallbackFaces);+ Assert.All(packet.FallbackFaces, face =>+ {+ Assert.Equal(AnalyticDisplayFallbackReason.UnsupportedTrim, face.Reason);+ Assert.Equal(SurfaceGeometryKind.Plane, face.SurfaceKind);+ });+ }+[Fact]public void Build_BoxCylinderThroughHole_ProducesPlanarAndCylindricalAnalyticEntries(){diff --git a/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayQueryTests.cs b/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayQueryTests.csindex 9d4f7825..6c262ff6 100644--- a/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayQueryTests.cs+++ b/Aetheris.Kernel.Core.Tests/Brep/Queries/AnalyticDisplayQueryTests.cs@@ -30,6 +30,43 @@ public sealed class AnalyticDisplayQueryTestsAssert.Equal(-1d, faceHit.Normal.Z, 12);}++ [Fact]+ public void PlanarFace_RotatedBoxSide_RejectsOutOfDomainPlaneHit()+ {+ var rotated = TransformBody(BrepPrimitives.CreateBox(2d, 2d, 2d).Value, Transform3D.CreateRotationZ(double.Pi / 4d));+ var sideFaceId = rotated.Topology.Faces+ .Select(face => face.Id)+ .First(faceId =>+ {+ var surface = rotated.GetFaceSurface(faceId);+ return surface.Kind == SurfaceGeometryKind.Plane+ && surface.Plane is { } plane+ && double.Abs(plane.Normal.Z) < 0.1d;+ });++ var plane = rotated.GetFaceSurface(sideFaceId).Plane!.Value;+ var outsideOnPlane = plane.Origin + (plane.VAxis.ToVector() * 5d);+ var ray = new Ray3D(outsideOnPlane - (plane.Normal.ToVector() * 3d), Direction3D.Create(plane.Normal.ToVector()));++ Assert.False(AnalyticDisplayQuery.TryIntersectFace(rotated, sideFaceId, ray, out _));+ }++ [Fact]+ public void PlanarFace_CircularCap_StillUsesAnalyticDomain()+ {+ var cylinder = BrepPrimitives.CreateCylinder(2d, 6d).Value;+ var capFaceId = cylinder.Topology.Faces+ .Select(face => face.Id)+ .First(faceId => cylinder.GetFaceSurface(faceId).Kind == SurfaceGeometryKind.Plane);++ var hitRay = new Ray3D(new Point3D(0d, 0d, 10d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));+ var missRay = new Ray3D(new Point3D(3d, 0d, 10d), Direction3D.Create(new Vector3D(0d, 0d, -1d)));++ Assert.True(AnalyticDisplayQuery.TryIntersectFace(cylinder, capFaceId, hitRay, out _));+ Assert.False(AnalyticDisplayQuery.TryIntersectFace(cylinder, capFaceId, missRay, out _));+ }+[Fact]public void Sphere_HitMissAndNormal(){diff --git a/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayPacket.cs b/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayPacket.csindex 4955808e..63c66524 100644--- a/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayPacket.cs+++ b/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayPacket.cs@@ -1,4 +1,5 @@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;@@ -110,7 +111,12 @@ public static class AnalyticDisplayPacketBuilderprivate static bool IsSupportedTrim(BrepBody body, FaceId faceId, SurfaceGeometryKind kind){- if (kind is SurfaceGeometryKind.Plane or SurfaceGeometryKind.Sphere or SurfaceGeometryKind.Torus)+ if (kind is SurfaceGeometryKind.Plane)+ {+ return IsSupportedPlanarTrim(body, faceId);+ }++ if (kind is SurfaceGeometryKind.Sphere or SurfaceGeometryKind.Torus){return true;}@@ -138,6 +144,51 @@ public static class AnalyticDisplayPacketBuilderreturn true;}++ private static bool IsSupportedPlanarTrim(BrepBody body, FaceId faceId)+ {+ if (!body.Bindings.TryGetFaceBinding(faceId, out var faceBinding)+ || !body.Geometry.TryGetSurface(faceBinding.SurfaceGeometryId, out var surface)+ || surface?.Plane is not PlaneSurface plane+ || !body.Topology.TryGetFace(faceId, out var face)+ || face is null)+ {+ return false;+ }++ var normal = plane.Normal.ToVector();+ var axisAlignedPlane = double.Abs(normal.X) > 0.9d || double.Abs(normal.Y) > 0.9d || double.Abs(normal.Z) > 0.9d;+ if (axisAlignedPlane)+ {+ return true;+ }++ if (face.LoopIds.Count != 1)+ {+ return false;+ }++ var loop = body.Topology.GetLoop(face.LoopIds[0]);+ if (loop.CoedgeIds.Count == 0)+ {+ return false;+ }++ foreach (var coedgeId in loop.CoedgeIds)+ {+ var edgeId = body.Topology.GetCoedge(coedgeId).EdgeId;+ if (!body.Bindings.TryGetEdgeBinding(edgeId, out var edgeBinding)+ || !body.Geometry.TryGetCurve(edgeBinding.CurveGeometryId, out var curve)+ || curve is null+ || curve.Kind != CurveGeometryKind.Circle3)+ {+ return false;+ }+ }++ return true;+ }+private static AnalyticDisplayFaceDomainHint? TryResolveDomainHint(BrepBody body, FaceId faceId, SurfaceGeometry surface){switch (surface.Kind)diff --git a/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayQuery.cs b/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayQuery.csindex 174584a3..192224ba 100644--- a/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayQuery.cs+++ b/Aetheris.Kernel.Core/Brep/Queries/AnalyticDisplayQuery.cs@@ -418,10 +418,19 @@ public static class AnalyticDisplayQuery}}+ var normal = plane.Normal.ToVector();+ var axisAlignedPlane = double.Abs(normal.X) > 0.9d || double.Abs(normal.Y) > 0.9d || double.Abs(normal.Z) > 0.9d;++ if (!axisAlignedPlane)+ {+ return circularBoundaries.Count == 1+ && face.LoopIds.Count == 1+ && IsPointInsideCircularBoundary(point, plane, circularBoundaries[0].Center, circularBoundaries[0].Radius, tolerance);+ }+var inAxisAlignedFaceBounds = true;if (TryResolveAxisAlignedBoxBounds(body, out var min, out var max)){- var normal = plane.Normal.ToVector();if (double.Abs(normal.X) > 0.9d){inAxisAlignedFaceBounds = point.Y >= min.Y - tolerance.Linear && point.Y <= max.Y + tolerance.Linear@@ -432,7 +441,7 @@ public static class AnalyticDisplayQueryinAxisAlignedFaceBounds = point.X >= min.X - tolerance.Linear && point.X <= max.X + tolerance.Linear&& point.Z >= min.Z - tolerance.Linear && point.Z <= max.Z + tolerance.Linear;}- else if (double.Abs(normal.Z) > 0.9d)+ else{inAxisAlignedFaceBounds = point.X >= min.X - tolerance.Linear && point.X <= max.X + tolerance.Linear&& point.Y >= min.Y - tolerance.Linear && point.Y <= max.Y + tolerance.Linear;