public IEnumerable <TCellValue> GetRingValues(CubeCoord center, uint radius) { foreach (HexGridCell <TCellValue> cell in GetRingCells(center, radius)) { yield return(cell.Value); } }
public IEnumerable <HexGridCell <TCellValue> > GetRingCells(CubeCoord center, uint radius) { CubeCoord direction = CubeCoord.Directions[4] * (int)radius; CubeCoord cube = center + direction; for (uint i = 0u; i < 6; i++) { for (uint j = 0u; j < radius; j++) { HexGridCell <TCellValue> cell = GetCell(cube); if (cell != null) { yield return(cell); } cube = HexCoord.GetNeighbour(cube, i); } } }
public IEnumerable <HexGridCell <TCellValue> > GetSpiralCells(CubeCoord center, uint radius) { HexGridCell <TCellValue> centerCell = GetCell(center); if (centerCell != null) { yield return(centerCell); } for (uint i = 1u; i <= radius; i++) { foreach (HexGridCell <TCellValue> cell in GetRingCells(center, i)) { if (cell != null) { yield return(cell); } } } }
public static void CubeToAxial(ref CubeCoord coord, out AxialCoord outCoord) { outCoord = new AxialCoord(coord.x, coord.y); }
public static CubeCoord GetNeighbour(CubeCoord coord, uint direction) { return(coord + CubeCoord.Directions[direction]); }
public static PixelCoord AxialToPixel(CubeCoord coord, float size) { AxialCoord coord2 = CubeToAxial(coord); return(AxialToPixel(coord2, size)); }
public static void AxialToCube(ref AxialCoord coord, out CubeCoord outCoord) { outCoord = new CubeCoord(coord.q, coord.r, -coord.q - coord.r); }
public static AxialCoord CubeToAxial(CubeCoord coord) { return(new AxialCoord(coord.x, coord.y)); }
public void SetCellValue(TCellValue value, CubeCoord coord) { HexGridCell <TCellValue> cell = GetCell(coord); cell.Value = value; }
public TCellValue GetCellValue(CubeCoord coord) { return(GetCell(coord).Value); }
public HexGridCell <TCellValue> GetCell(CubeCoord coord) { HexCoord.CubeToAxial(ref coord, out var outCoord); return(GetCell(outCoord)); }
public int Distance(CubeCoord other) { return((Math.Abs(x - other.x) + Math.Abs(y - other.y) + Math.Abs(z - other.z)) / 2); }