Beispiel #1
0
/**
 * Convert a DiagDirection to a TileIndexDiff
 *
 * @param dir The DiagDirection
 * @return The resulting TileIndexDiff
 * @see TileIndexDiffCByDiagDir
 */
//inline
        public static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
        {
            if (dir.IsValidDiagDirection() == false)
            {
                throw new ArgumentOutOfRangeException(nameof(dir));
            }
            return(ToTileIndexDiff(_tileoffs_by_diagdir[(int)dir]));
        }
Beispiel #2
0
/**
 * Convert a DiagDirection to the axis.
 *
 * This function returns the axis which belongs to the given
 * DiagDirection. The axis X belongs to the DiagDirection
 * north-east and south-west.
 *
 * @param d The DiagDirection
 * @return The axis which belongs to the direction
 */
        //inline
        public static Axis DiagDirToAxis(this DiagDirection d)
        {
            if (d.IsValidDiagDirection() == false)
            {
                throw new ArgumentOutOfRangeException(nameof(d));
            }
            return((Axis)((int)d & 1));
        }
Beispiel #3
0
 /**
  * Returns the reverse direction of the given DiagDirection
  *
  * @param d The DiagDirection to get the reverse from
  * @return The reverse direction
  */
 //inline
 public static DiagDirection ReverseDiagDir(this DiagDirection d)
 {
     if (d.IsValidDiagDirection() == false)
     {
         throw new ArgumentOutOfRangeException(nameof(d));
     }
     return((DiagDirection)(2 ^ (int)d));
 }
Beispiel #4
0
/**
 * Convert a DiagDirection to a Direction.
 *
 * This function can be used to convert the 4-way DiagDirection
 * to the 8-way Direction. As 4-way are less than 8-way not all
 * possible directions can be calculated.
 *
 * @param dir The direction to convert
 * @return The resulting Direction
 */
        //inline
        public static Direction DiagDirToDir(this DiagDirection dir)
        {
            if (dir.IsValidDiagDirection() == false)
            {
                throw new ArgumentOutOfRangeException(nameof(dir));
            }
            return((Direction)((int)dir * 2 + 1));

            ;
        }
Beispiel #5
0
        /**
         * Applies a difference on a DiagDirection
         *
         * This function applies a difference on a DiagDirection and returns
         * the new DiagDirection.
         *
         * @param d The DiagDirection
         * @param delta The difference to apply on
         * @return The new direction which was calculated
         */
        //inline
        public static DiagDirection ChangeDiagDir(this DiagDirection d, DiagDirDiff delta)
        {
            if (d.IsValidDiagDirection() == false)
            {
                throw new ArgumentOutOfRangeException(nameof(d));
            }

            /* Cast to uint so compiler can use bitmask. Result can never be negative. */
            return((DiagDirection)(((int)d + (int)delta) % 4));
        }
Beispiel #6
0
 /**
  * Calculate the difference between two DiagDirection values
  *
  * @param d0 The first direction as the base
  * @param d1 The second direction as the offset from the base
  * @return The difference how the second direction drifts of the first one.
  */
 //inline
 public static DiagDirDiff DiagDirDifference(this DiagDirection d0, DiagDirection d1)
 {
     if (d0.IsValidDiagDirection() == false)
     {
         throw new ArgumentOutOfRangeException(nameof(d0));
     }
     if (d1.IsValidDiagDirection() == false)
     {
         throw new ArgumentOutOfRangeException(nameof(d1));
     }
     /* Cast to uint so compiler can use bitmask. Result can never be negative. */
     return((DiagDirDiff)(((int)d0 - (int)d1) % 4));
 }