Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

2.8 KB
Raw Blame
using Aetheris.Kernel.Core.Brep;
using Aetheris.Kernel.Core.Brep.Queries;
using Aetheris.Kernel.Core.Geometry;
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Core.Numerics;

namespace Aetheris.Kernel.Core.Tests.Brep.Queries;

public sealed class FaceDomainQueryTests
{
    [Fact]
    public void PlanarFace_Inside_ReturnsInsideWithDiagnostics()
    {
        var box = BrepPrimitives.CreateBox(2d, 2d, 2d).Value;
        var faceId = box.Topology.Faces.OrderBy(f => f.Id.Value).First().Id;

        var result = FaceDomainQuery.TryClassifyPointOnFace(box, faceId, new Point3D(0d, 0d, -1d), ToleranceContext.Default);

        Assert.True(result.IsSuccess);
        Assert.Equal(FaceDomainClassification.Inside, result.Classification);
        Assert.Equal("FaceDomainQuery.Planar", result.Source);
        Assert.NotNull(result.ProjectedUv);
    }

    [Fact]
    public void PlanarFace_Outside_ReturnsOutside()
    {
        var box = BrepPrimitives.CreateBox(2d, 2d, 2d).Value;
        var faceId = box.Topology.Faces.OrderBy(f => f.Id.Value).First().Id;

        var result = FaceDomainQuery.TryClassifyPointOnFace(box, faceId, new Point3D(2d, 0d, -1d));

        Assert.True(result.IsSuccess);
        Assert.Equal(FaceDomainClassification.Outside, result.Classification);
    }

    [Fact]
    public void PlanarFace_Boundary_ReturnsOnBoundaryAndNearEdgeFlag()
    {
        var box = BrepPrimitives.CreateBox(2d, 2d, 2d).Value;
        var faceId = box.Topology.Faces.OrderBy(f => f.Id.Value).First().Id;

        var result = FaceDomainQuery.TryClassifyPointOnFace(box, faceId, new Point3D(1d, 0d, -1d));

        Assert.True(result.IsSuccess);
        Assert.Equal(FaceDomainClassification.OnBoundary, result.Classification);
        Assert.True(result.NearEdge);
        Assert.True(result.BoundaryDistance <= ToleranceContext.Default.Linear + 1e-12d);
    }

    [Fact]
    public void CylinderFace_PointOnSurfaceWithinTrim_ReturnsInsideOrAmbiguous()
    {
        var cylinder = BrepPrimitives.CreateCylinder(2d, 6d).Value;
        var faceId = cylinder.Topology.Faces.Single(f => cylinder.GetFaceSurface(f.Id).Kind == SurfaceGeometryKind.Cylinder).Id;

        var result = FaceDomainQuery.TryClassifyPointOnFace(cylinder, faceId, new Point3D(2d, 0d, 0d));

        Assert.Equal("FaceDomainQuery.Cylinder", result.Source);
        Assert.Contains(result.Classification, new[] { FaceDomainClassification.Inside, FaceDomainClassification.Ambiguous });
    }

    [Fact]
    public void TorusFace_Unsupported_ReturnsStructuredReason()
    {
        var torus = BrepPrimitives.CreateTorus(4d, 1d).Value;
        var faceId = torus.Topology.Faces.First().Id;
        var result = FaceDomainQuery.TryClassifyPointOnFace(torus, faceId, new Point3D(5d, 0d, 0d));
        Assert.Equal(FaceDomainClassification.Unsupported, result.Classification);
    }
}