Skip to content

Next Gen STEP AP242 Native-ish BREP Geometric Modeling Kernel

4.1 KB
Raw Blame
using Aetheris.Continuum.Backends.Sdf;
using Aetheris.Kernel.Core.Math;
using Aetheris.Kernel.Firmament.Lowering;

namespace Aetheris.Kernel.Firmament.Tests;

public sealed class FirmamentCirLoweringTests
{
    [Fact]
    public void FirmamentCirLowerer_BoxBasic_Succeeds()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/box_basic.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.True(lower.IsSuccess);

        var estimate = SdfAnalyzer.EstimateVolume(lower.Value.Root, 40);
        Assert.InRange(estimate, 13950d, 14850d);
    }

    [Fact]
    public void FirmamentCirLowerer_CylinderBasic_Succeeds()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/cylinder_basic.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.True(lower.IsSuccess);

        var bounds = lower.Value.Root.Bounds;
        var center = new Point3D(
            (bounds.Min.X + bounds.Max.X) * 0.5d,
            (bounds.Min.Y + bounds.Max.Y) * 0.5d,
            (bounds.Min.Z + bounds.Max.Z) * 0.5d);

        Assert.Equal(SdfPointClassification.Inside, SdfAnalyzer.ClassifyPoint(lower.Value.Root, center).Classification);
        Assert.Equal(SdfPointClassification.Outside, SdfAnalyzer.ClassifyPoint(lower.Value.Root, new Point3D(100d, 0d, 0d)).Classification);
    }

    [Fact]
    public void FirmamentCirLowerer_OffsetPlacement_StillWorks()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/placed_primitive.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.True(lower.IsSuccess);

        var estimate = SdfAnalyzer.EstimateVolume(lower.Value.Root, 48);
        Assert.InRange(estimate, 200d, 400d);
    }

    [Fact]
    public void FirmamentCirLowerer_OnFacePlacement_UsesSharedAnchor()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/w2_cylinder_root_blind_bore_semantic.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.True(lower.IsSuccess);
        Assert.True(lower.Value.Root.Bounds.Max.Z > 5d);
    }

    [Fact]
    public void FirmamentCirLowerer_UnsupportedPlacement_FailsClearly()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/p1_flange_radial_hole_semantic.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.False(lower.IsSuccess);
        Assert.Contains(lower.Diagnostics, d => d.Message.Contains("around-axis", StringComparison.OrdinalIgnoreCase));
    }


    [Fact]
    public void FirmamentCirLowerer_UnsupportedGeneratedTopologySelector_FailsClearly()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Corpus/valid/m7c-valid-selector-vertices-edges-anchors.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.False(lower.IsSuccess);
        Assert.Contains(lower.Diagnostics, d => d.Message.Contains("supports only authored '.top_face' and '.bottom_face'", StringComparison.Ordinal));
    }
    [Fact]
    public void FirmamentCirLowerer_UnsupportedOp_FailsClearly()
    {
        var compile = FirmamentCorpusHarness.Compile(FirmamentCorpusHarness.ReadFixtureText("fixtures/Compatibility/LegacyV1/Examples/rounded_corner_box_basic.firmament"));
        var lower = FirmamentCirLowerer.Lower(compile.Compilation.Value.PrimitiveLoweringPlan!);
        Assert.False(lower.IsSuccess);
        Assert.Contains(lower.Diagnostics, d => d.Message.Contains("Unsupported primitive", StringComparison.Ordinal));
    }
}