Example #1
0
 public IEnumerable <TCellValue> GetRingValues(CubeCoord center, uint radius)
 {
     foreach (HexGridCell <TCellValue> cell in GetRingCells(center, radius))
     {
         yield return(cell.Value);
     }
 }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        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);
                    }
                }
            }
        }
Example #4
0
 public static void CubeToAxial(ref CubeCoord coord, out AxialCoord outCoord)
 {
     outCoord = new AxialCoord(coord.x, coord.y);
 }
Example #5
0
 public static CubeCoord GetNeighbour(CubeCoord coord, uint direction)
 {
     return(coord + CubeCoord.Directions[direction]);
 }
Example #6
0
        public static PixelCoord AxialToPixel(CubeCoord coord, float size)
        {
            AxialCoord coord2 = CubeToAxial(coord);

            return(AxialToPixel(coord2, size));
        }
Example #7
0
 public static void AxialToCube(ref AxialCoord coord, out CubeCoord outCoord)
 {
     outCoord = new CubeCoord(coord.q, coord.r, -coord.q - coord.r);
 }
Example #8
0
 public static AxialCoord CubeToAxial(CubeCoord coord)
 {
     return(new AxialCoord(coord.x, coord.y));
 }
Example #9
0
        public void SetCellValue(TCellValue value, CubeCoord coord)
        {
            HexGridCell <TCellValue> cell = GetCell(coord);

            cell.Value = value;
        }
Example #10
0
 public TCellValue GetCellValue(CubeCoord coord)
 {
     return(GetCell(coord).Value);
 }
Example #11
0
 public HexGridCell <TCellValue> GetCell(CubeCoord coord)
 {
     HexCoord.CubeToAxial(ref coord, out var outCoord);
     return(GetCell(outCoord));
 }
Example #12
0
 public int Distance(CubeCoord other)
 {
     return((Math.Abs(x - other.x) + Math.Abs(y - other.y) + Math.Abs(z - other.z)) / 2);
 }