Example #1
0
        /// <summary>
        /// Returns an array of CubicHexCoords of a area centering around the given center hex and
        /// extending in every direction up to the given range. The hexes are ordered starting from
        /// the maximum range, in the given direction, spiraling inward in a clockwise direction
        /// until the center is reached (and is the last element in the array).
        /// </summary>
        /// <param name="center">The CubicHexCoord around which the spiral is formed.</param>
        /// <param name="range">The number of grid steps distance away from the center that the
        /// edge of the spiral will be.</param>
        /// <param name="startDirection">The direction in which the first CubicHexCoord of the
        /// spiral will appear in.</param>
        /// <returns>An array of CubicHexCoords ordered as a spiral, beginning from the outside
        /// and proceeding clockwise until it reaches the center of the spiral.</returns>
        public static CubicHexCoord[] SpiralOutward(CubicHexCoord center, int range, DirectionEnum startDirection = DirectionEnum.E)
        {
            if (range <= 0)
            {
                throw new ArgumentOutOfRangeException("range must be a positive integer value.");
            }
            else if (range == 0)
            {
                return(new CubicHexCoord[1] {
                    center
                });
            }

            int arraySize = 1;

            for (int i = range; i > 0; i--)
            {
                arraySize += 6 * i;
            }

            CubicHexCoord[] result = new CubicHexCoord[arraySize];

            result[0] = center;

            int arrayIndex = 1;

            for (int i = 1; i <= range; i++)
            {
                CubicHexCoord[] ring = CubicHexCoord.Ring(center, i, startDirection);
                ring.CopyTo(result, arrayIndex);
                arrayIndex += ring.Length;
            }

            return(result);
        }
Example #2
0
 /// <summary>
 /// Returns an array of CubicHexCoords that appear at the given range around this hex.
 /// The ring begins from the CubicHexCoord range grid steps away from the center, heading
 /// in the given direction, and encircling the center in clockwise order.
 /// </summary>
 /// <param name="range">The number of grid steps distance away from the center that the
 /// ring will be.</param>
 /// <param name="startDirection">The direction in which the first CubicHexCoord of the
 /// ring will appear in.</param>
 /// <returns>An array of CubicHexCoords ordered as a ring.</returns>
 public        CubicHexCoord[] RingAround(int range, DirectionEnum startDirection = DirectionEnum.E)
 {
     return(CubicHexCoord.Ring(this, range, startDirection));
 }