Class MathUtils


  • public class MathUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int chebyshevDistance​(int ax, int ay, int bx, int by)
      Finds the chebyshev distance between two tiles.
      static int clamp​(int value, int minInclusive, int maxInclusive)
      Clamps a value to an inclusive range.
      static long modInverse​(long val)
      Computes the inverse mod given a value and bits to shift left by
      static java.math.BigInteger modInverse​(java.math.BigInteger val, int bits)
      Computes the inverse mod given a value and bits to shift left by
      static boolean overlaps​(int aX, int aY, int aSize, int bX, int bY, int bSize)
      Returns whether two square footprints overlap.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MathUtils

        public MathUtils()
    • Method Detail

      • modInverse

        public static java.math.BigInteger modInverse​(java.math.BigInteger val,
                                                      int bits)
        Computes the inverse mod given a value and bits to shift left by
        Parameters:
        val - BigInteger value
        bits - int number of bits to shift left
        Returns:
        Mod inverse of the value passed.
      • modInverse

        public static long modInverse​(long val)
        Computes the inverse mod given a value and bits to shift left by
        Parameters:
        val - BigInteger value
        Returns:
        Mod inverse of the value passed.
      • clamp

        public static int clamp​(int value,
                                int minInclusive,
                                int maxInclusive)
        Clamps a value to an inclusive range.
        Parameters:
        value - The value to clamp
        minInclusive - The min value to (inclusive of the value itself) i.e. 10 would include 10 itself.
        maxInclusive - The max value (inclusive of the value itself)
        Returns:
        The clamped value between the min and the max
      • chebyshevDistance

        public static int chebyshevDistance​(int ax,
                                            int ay,
                                            int bx,
                                            int by)
        Finds the chebyshev distance between two tiles. This is defined as the distance between two vectors as the maximum absolute difference along any single coordinate dimension.
        Parameters:
        ax - The x coordinate of the first tile.
        ay - The y coordinate of the first tile.
        bx - The x coordinate of the second tile.
        by - The y coordinate of the second tile.
        Returns:
        Chebyshev distance between two tiles.
      • overlaps

        public static boolean overlaps​(int aX,
                                       int aY,
                                       int aSize,
                                       int bX,
                                       int bY,
                                       int bSize)
        Returns whether two square footprints overlap.
        Parameters:
        aX - The x coordinate of the SW first tile
        aY - The y coordinate of the SW first tile
        aSize - The size of the set of tiles
        bX - The x coordinate of the SW second tile
        bY - The y coordinate of the SW second tile
        bSize - The size of the second set of tiles
        Returns:
        True if any of the tiles overlap and false otherwise.