using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
using XFEExtension.NetCore.XUnit.Attributes;
namespace XFEEDToolBox.Test;
[TestFixture]
public class GalaxyFloorSelectorTests
{
[Test] public void SnapsToTheVerticalIntersectionWithoutMovingTheFloorToStarHeight()
{
var camera = GalaxyCamera.Create(new(150, 37, -200), 1600, 900, .3, .6, 4);
var high = new GalaxyFloorCandidate(1, new(150, 900, -200));
var other = new GalaxyFloorCandidate(2, new(155, 37, -200));
var selected = GalaxyFloorSelector.Snap(camera, camera.Focus, [other, high], 12, 18);
Check.Equal(high, selected.Target!.Value);
Check.Equal(new Coordinates(150, 37, -200), selected.Position);
Check.That(!camera.Project(high.Position).IsVisible, "The floor intersection, rather than the elevated body's screen position, is the selection target.");
}
[Test] public void StickyTargetReleasesWhenRemovedByTheActiveFilter()
{
var camera = GalaxyCamera.Create(new(0, 7, 0), 1600, 900, 0, .7, 4);
var held = new GalaxyFloorCandidate(3, new(3, -150, 0));
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [held], 10, 16).Target is null);
Check.Equal(held, GalaxyFloorSelector.Snap(camera, camera.Focus, [held], 10, 16, held).Target!.Value);
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [], 10, 16, held).Target is null);
var moved = held with { Position = new(5, -150, 0) };
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [moved], 10, 16, held).Target is null);
}
[Test] public void ScreenDistanceDeterminesCaptureWithPerspective()
{
var camera = GalaxyCamera.Create(new(49985, -610, 24105), 1600, 900, 1.2, -.55, 2);
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, 808, 450, camera.Focus.Y, out var a));
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, 800, 455, camera.Focus.Y, out var b));
var first = new GalaxyFloorCandidate(10, a with { Y = 1000 });
var closer = new GalaxyFloorCandidate(11, b with { Y = -1000 });
Check.Equal(closer, GalaxyFloorSelector.Snap(camera, camera.Focus, [first, closer], 10, 16).Target!.Value);
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [first, closer], 4, 6).Target is null);
}
[Test] public void InfiniteGeometryDoesNotCaptureASelectorOutsideTheFiniteCatalogueView()
{
var camera=GalaxyCamera.Create(new(0,0,0),1600,900,0,0,4);
var outside=new GalaxyFloorCandidate(99,new(0,0,camera.QueryFar-camera.Distance+100));
Check.That(camera.Project(outside.Position).IsVisible,"The original geometry projection has no far clip.");
Check.That(GalaxyFloorSelector.Snap(camera,camera.Focus,[outside],12,18).Target is null,
"An outside-query floor intersection must not become a selectable cached system.");
}
[Test] public void RingRemainsOnGalacticPlaneAndDoesNotEmitBehindEyeGeometry()
{
var camera = GalaxyCamera.Create(new(-43187, 287, 38116), 1600, 900, -.7, .6, 4);
Span<MapSegment> lines = stackalloc MapSegment[64];
var count = GalaxyFloorSelector.WriteRing(lines, camera, camera.Focus, 5);
Check.Equal(64, count);
foreach (var line in lines[..count])
{
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, line.X1, line.Y1, camera.Focus.Y, out var point));
Check.That(Math.Abs(point.DistanceTo(camera.Focus) - 5) < 1e-7);
}
var edgeOn = GalaxyCamera.Create(new(0, 0, 0), 1600, 900, 0, 0, 4);
Check.That(!GalaxyFloorSelector.TryScreenToPlane(edgeOn, 800, 450, 0, out _));
var behind = new Coordinates(camera.Eye.X - camera.Forward.X * camera.Distance,
camera.Eye.Y - camera.Forward.Y * camera.Distance, camera.Eye.Z - camera.Forward.Z * camera.Distance);
Check.Equal(0, GalaxyFloorSelector.WriteRing(lines, camera, behind, 1));
}
}
using XFEEDToolBox.Core.Galaxy;
using XFEEDToolBox.Core.Models;
using XFEExtension.NetCore.XUnit.Attributes;
namespace XFEEDToolBox.Test;
[TestFixture]
public class GalaxyFloorSelectorTests
{
[Test] public void SnapsToTheVerticalIntersectionWithoutMovingTheFloorToStarHeight()
{
var camera = GalaxyCamera.Create(new(150, 37, -200), 1600, 900, .3, .6, 4);
var high = new GalaxyFloorCandidate(1, new(150, 900, -200));
var other = new GalaxyFloorCandidate(2, new(155, 37, -200));
var selected = GalaxyFloorSelector.Snap(camera, camera.Focus, [other, high], 12, 18);
Check.Equal(high, selected.Target!.Value);
Check.Equal(new Coordinates(150, 37, -200), selected.Position);
Check.That(!camera.Project(high.Position).IsVisible, "The floor intersection, rather than the elevated body's screen position, is the selection target.");
}
[Test] public void StickyTargetReleasesWhenRemovedByTheActiveFilter()
{
var camera = GalaxyCamera.Create(new(0, 7, 0), 1600, 900, 0, .7, 4);
var held = new GalaxyFloorCandidate(3, new(3, -150, 0));
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [held], 10, 16).Target is null);
Check.Equal(held, GalaxyFloorSelector.Snap(camera, camera.Focus, [held], 10, 16, held).Target!.Value);
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [], 10, 16, held).Target is null);
var moved = held with { Position = new(5, -150, 0) };
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [moved], 10, 16, held).Target is null);
}
[Test] public void ScreenDistanceDeterminesCaptureWithPerspective()
{
var camera = GalaxyCamera.Create(new(49985, -610, 24105), 1600, 900, 1.2, -.55, 2);
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, 808, 450, camera.Focus.Y, out var a));
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, 800, 455, camera.Focus.Y, out var b));
var first = new GalaxyFloorCandidate(10, a with { Y = 1000 });
var closer = new GalaxyFloorCandidate(11, b with { Y = -1000 });
Check.Equal(closer, GalaxyFloorSelector.Snap(camera, camera.Focus, [first, closer], 10, 16).Target!.Value);
Check.That(GalaxyFloorSelector.Snap(camera, camera.Focus, [first, closer], 4, 6).Target is null);
}
[Test] public void InfiniteGeometryDoesNotCaptureASelectorOutsideTheFiniteCatalogueView()
{
var camera=GalaxyCamera.Create(new(0,0,0),1600,900,0,0,4);
var outside=new GalaxyFloorCandidate(99,new(0,0,camera.QueryFar-camera.Distance+100));
Check.That(camera.Project(outside.Position).IsVisible,"The original geometry projection has no far clip.");
Check.That(GalaxyFloorSelector.Snap(camera,camera.Focus,[outside],12,18).Target is null,
"An outside-query floor intersection must not become a selectable cached system.");
}
[Test] public void RingRemainsOnGalacticPlaneAndDoesNotEmitBehindEyeGeometry()
{
var camera = GalaxyCamera.Create(new(-43187, 287, 38116), 1600, 900, -.7, .6, 4);
Span<MapSegment> lines = stackalloc MapSegment[64];
var count = GalaxyFloorSelector.WriteRing(lines, camera, camera.Focus, 5);
Check.Equal(64, count);
foreach (var line in lines[..count])
{
Check.That(GalaxyFloorSelector.TryScreenToPlane(camera, line.X1, line.Y1, camera.Focus.Y, out var point));
Check.That(Math.Abs(point.DistanceTo(camera.Focus) - 5) < 1e-7);
}
var edgeOn = GalaxyCamera.Create(new(0, 0, 0), 1600, 900, 0, 0, 4);
Check.That(!GalaxyFloorSelector.TryScreenToPlane(edgeOn, 800, 450, 0, out _));
var behind = new Coordinates(camera.Eye.X - camera.Forward.X * camera.Distance,
camera.Eye.Y - camera.Forward.Y * camera.Distance, camera.Eye.Z - camera.Forward.Z * camera.Distance);
Check.Equal(0, GalaxyFloorSelector.WriteRing(lines, camera, behind, 1));
}
}