using System.Numerics; using AcDream.App.Rendering; using Xunit; namespace AcDream.App.Tests.Rendering; public sealed class ViewconeCullerReuseTests { [Fact] public void ReusedCuller_ReplacesPriorCellAndOutsideState() { const uint firstCell = 0xA9B40100; const uint secondCell = 0xA9B40101; var clipFrame = ClipFrame.NoClip(); var assemblyScratch = new ClipFrameAssembly(); var culler = new ViewconeCuller(); var first = Frame(firstCell, includeOutside: true); ClipFrameAssembly firstAssembly = ClipFrameAssembler.Assemble( clipFrame, first, assemblyScratch); Assert.Same(culler, ViewconeCuller.Build(firstAssembly, Matrix4x4.Identity, culler)); Assert.True(culler.SphereVisibleInCell(firstCell, Vector3.Zero, 0f)); Assert.True(culler.SphereVisibleOutside(Vector3.Zero, 0f)); var second = Frame(secondCell, includeOutside: false); ClipFrameAssembly secondAssembly = ClipFrameAssembler.Assemble( clipFrame, second, assemblyScratch); Assert.Same(culler, ViewconeCuller.Build(secondAssembly, Matrix4x4.Identity, culler)); Assert.False(culler.SphereVisibleInCell(firstCell, Vector3.Zero, 0f)); Assert.True(culler.SphereVisibleInCell(secondCell, Vector3.Zero, 0f)); Assert.False(culler.SphereVisibleInCell(secondCell, new Vector3(2f, 0f, 0f), 0f)); Assert.False(culler.SphereVisibleOutside(Vector3.Zero, 0f)); } private static PortalVisibilityFrame Frame(uint cellId, bool includeOutside) { var result = new PortalVisibilityFrame(); var cellView = new CellView(); cellView.Add(Square(0.5f)); result.CellViews.Add(cellId, cellView); result.OrderedVisibleCells.Add(cellId); if (includeOutside) result.OutsideView.Add(Square(0.5f)); return result; } private static ViewPolygon Square(float half) => new(new[] { new Vector2(-half, -half), new Vector2(half, -half), new Vector2(half, half), new Vector2(-half, half), }); }