public static void ResizeSquareGraph(Graph graph, OffsetTypes offsetType, int newWidth, int newHeight, TerrainType defaultTerrainType) { var offsetCoordinates = Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType); var areCoordinatesInitialized = offsetCoordinates.Any(); var width = areCoordinatesInitialized ? offsetCoordinates.Select(item => item.X).Max() + 1 : 0; var height = areCoordinatesInitialized ? offsetCoordinates.Select(item => item.Y).Max() + 1 : 0; if (width > newWidth) { offsetCoordinates = Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType); var coordinatesToRemove = Coordinate2D.To3D(offsetCoordinates.Where(coordinate => coordinate.X >= newWidth).ToList()); graph.RemoveCells(coordinatesToRemove); } if (height > newHeight) { offsetCoordinates = Coordinate3D.To2D(graph.GetAllCellsCoordinates(), offsetType); var coordinatesToRemove = Coordinate2D.To3D(offsetCoordinates.Where(coordinate => coordinate.Y >= newHeight).ToList()); graph.RemoveCells(coordinatesToRemove); } if (newWidth > width) { var cellsToAdd = new List <CellState>(); // We'll add new columns width already updated height for (var x = width; x < newWidth; x++) { cellsToAdd.AddRange(CreateNewCellsForColumn(x, 0, newHeight, defaultTerrainType, offsetType)); } graph.AddCells(cellsToAdd); } if (newHeight <= height) { return; } { var cellsToAdd = new List <CellState>(); // New columns already will have correct height; So only old needs to be resized. for (var x = 0; x < width; x++) { cellsToAdd.AddRange(CreateNewCellsForColumn(x, height, newHeight, defaultTerrainType, offsetType)); } graph.AddCells(cellsToAdd); } }
public List <Coordinate2D> GetAllCellsCoordinates(OffsetTypes offsetType) { var result = PoolProvider.OffsetCoordinateListPool.Get(); var cells = GetAllCellsCoordinates(); Coordinate3D.To2D(cells, offsetType, result); ReturnListToPool(cells); return(result); }
public List <Coordinate2D> GetPassableNeighbors(Coordinate2D position) { var list = GetNeighbors(position.To3D(), true); var neighbors = Coordinate3D.To2D( list, position.OffsetType ); ReturnListToPool(list); return(neighbors); }
public List <Coordinate2D> GetShortestPath(Coordinate2D start, Coordinate2D goal, MovementType unitMovementType) { var path = GetShortestPath(start.To3D(), goal.To3D(), unitMovementType); var result = PoolProvider.OffsetCoordinateListPool.Get(); Coordinate3D.To2D( path, start.OffsetType, result ); ReturnListToPool(path); return(result); }
public List <Coordinate2D> GetRange(Coordinate2D startPosition, int radius) { var list = GetRange(startPosition.To3D(), radius); var result = PoolProvider.OffsetCoordinateListPool.Get(); Coordinate3D.To2D( list, startPosition.OffsetType, result ); ReturnListToPool(list); return(result); }
public List <Coordinate2D> GetMovementRange(Coordinate2D startPosition, int movementPoints, MovementType movementType) { var list = GetMovementRange(startPosition.To3D(), movementPoints, movementType); var result = PoolProvider.OffsetCoordinateListPool.Get(); Coordinate3D.To2D( list, startPosition.OffsetType, result ); ReturnListToPool(list); return(result); }
public static string ToString(List <Coordinate3D> coordinate3Ds) { return(ToString(Coordinate3D.To2D(coordinate3Ds, OffsetTypes.OddRowsRight))); }