Base pathfinding implementation, conversion from packet<->pathing coordinate space in tests is still off

This commit is contained in:
Kyle Belanger
2024-02-24 04:37:42 -05:00
parent ded826adf0
commit 432ceb2506
3 changed files with 198 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
using BLHX.Server.Common.Data;
namespace BLHX.Server.Common.Utils;
public static class GridExtensions
{
public static GridItem? Find(this List<GridItem> nodes, uint x, uint y)
=> nodes.FirstOrDefault(n => n.Row == x && n.Column == y);
public static GridItem? Find(this List<GridItem> nodes, int x, int y)
=> Find(nodes, (uint)x, (uint)y);
public static (uint, uint, uint, uint) GetDimensions(this List<GridItem> grid)
{
uint startX = uint.MaxValue;
uint startY = uint.MaxValue;
uint width = 0;
uint height = 0;
foreach (var node in grid)
{
if (node.Column < startX)
startX = node.Column;
if (node.Row < startY)
startY = node.Row;
if (node.Column > width)
width = node.Column;
if (node.Row > height)
height = node.Row;
}
return (startX, startY, width, height);
}
}