Class CommonMath


  • public final class CommonMath
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int fractionToPercent​(long numerator, long denominator)
      Converts a fraction into a percentage
      static int getAngleOf​(Locatable target)
      Gets the angle of the target entity using the local player as the origin
      static int getAngleOf​(Locatable origin, Locatable target)
      Gets the angle of the target entity from the provided origin.
      static int getBitMask​(int length)  
      static int[] getBitMasks()  
      static int getBitRange​(int value, int leastSignificantBit, int mostSignificantBit)  
      static int getDistanceBetweenAngles​(int angleA, int angleB)
      Gets the minimum distance between the two angles.
      static double normalize​(double current, double minimum, double maximum)
      Normalizes a given value to a value between 0.00 and 1.00
      static double rate​(java.util.concurrent.TimeUnit unit, long runtime, double value)  
      static double round​(double number, int significantPlaces)
      Rounds a double to a specified amount of significant digits.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • fractionToPercent

        public static int fractionToPercent​(long numerator,
                                            long denominator)
        Converts a fraction into a percentage
        Parameters:
        numerator - numerator
        denominator - denominator
        Returns:
        the calculated percentage
      • normalize

        public static double normalize​(double current,
                                       double minimum,
                                       double maximum)
        Normalizes a given value to a value between 0.00 and 1.00
        Parameters:
        current - The current value
        minimum - The minimum value
        maximum - The maximum value
        Returns:
        A normalized value
      • round

        public static double round​(double number,
                                   int significantPlaces)
        Rounds a double to a specified amount of significant digits. If the number is infinite or NaN, then it's returned unmodified.
      • rate

        public static double rate​(java.util.concurrent.TimeUnit unit,
                                  long runtime,
                                  double value)
        Parameters:
        unit - the time unit
        runtime - the runtime in milliseconds
        value - the value to calculate the rate of
        Returns:
        the amount of value collected during runtime at the rate of unit
      • getDistanceBetweenAngles

        public static int getDistanceBetweenAngles​(int angleA,
                                                   int angleB)
        Gets the minimum distance between the two angles. For example, if the angles are 25 and 290, the result would be 95.
        Parameters:
        angleA -
        angleB -
        Returns:
      • getAngleOf

        public static int getAngleOf​(Locatable target)
        Gets the angle of the target entity using the local player as the origin
        Parameters:
        target -
        Returns:
      • getAngleOf

        public static int getAngleOf​(Locatable origin,
                                     Locatable target)
        Gets the angle of the target entity from the provided origin.
        Parameters:
        origin -
        target -
        Returns:
      • getBitMasks

        public static int[] getBitMasks()
      • getBitMask

        public static int getBitMask​(int length)
      • getBitRange

        public static int getBitRange​(int value,
                                      int leastSignificantBit,
                                      int mostSignificantBit)