using System.Numerics; using AcDream.Core.Physics; using AcDream.Core.World.Cells; using DatReaderWriter.Enums; using DatReaderWriter.Types; using Xunit; using UcgCellPortal = AcDream.Core.World.Cells.CellPortal; namespace AcDream.Core.Tests.World.Cells; public class EnvCellTests { private static EnvCell Make(Vector3 min, Vector3 max, Matrix4x4? transform = null) { var t = transform ?? Matrix4x4.Identity; Matrix4x4.Invert(t, out var inv); return new EnvCell(0xA9B40174u, t, inv, min, max, System.Array.Empty(), System.Array.Empty(), seenOutside: false, containmentBsp: null); } [Fact] public void PointInCell_NullBsp_Aabb_InsideIsTrue() => Assert.True(Make(new Vector3(0,0,0), new Vector3(10,10,10)).PointInCell(new Vector3(5,5,5))); [Fact] public void PointInCell_NullBsp_Aabb_OutsideIsFalse() => Assert.False(Make(new Vector3(0,0,0), new Vector3(10,10,10)).PointInCell(new Vector3(20,5,5))); [Fact] public void PointInCell_TransformsWorldToLocalBeforeTesting() { var c = Make(new Vector3(0,0,0), new Vector3(10,10,10), Matrix4x4.CreateTranslation(100,0,0)); Assert.True(c.PointInCell(new Vector3(105,5,5))); Assert.False(c.PointInCell(new Vector3(5,5,5))); } [Fact] public void PointInCell_PreparedContainmentIsAuthoritative() { var graphRoot = new CellBSPNode { Type = BSPNodeType.BPIn, SplittingPlane = new Plane(Vector3.UnitX, -1f), PosNode = new CellBSPNode { Type = BSPNodeType.Leaf }, }; var flatRoot = new CellBSPNode { Type = BSPNodeType.Leaf, LeafIndex = 1, }; FlatCellContainmentBsp flat = FlatCollisionAssetBuilder.FlattenCellContainmentBsp(flatRoot); var cell = new EnvCell( 0xA9B4_0174u, Matrix4x4.Identity, Matrix4x4.Identity, -Vector3.One, Vector3.One, Array.Empty(), Array.Empty(), seenOutside: false, containmentBsp: new CellBSPTree { Root = graphRoot }, flatContainmentBsp: flat); Assert.True(cell.PointInCell(Vector3.Zero)); Assert.False(BSPQuery.PointInsideCellBsp(graphRoot, Vector3.Zero)); } }