Class MathUtils


  • public class MathUtils
    extends java.lang.Object
    Contains general math utility functions.
    • Constructor Summary

      Constructors 
      Constructor Description
      MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double clamp​(double x, double minValue, double maxValue)
      Clamps x such that it is at least minValue and at most maxValue.
      static boolean doubleEquals​(double a, double b)
      Determines if 2 double values are equal to with a reasonable floating point error
      static double limitChange​(double current, double desired, double maxChange)
      Limits the ammount of change when trying to go from the current value to the desired value.
      static double signedPow​(double base, int exp)
      Calculates the exponentiation while mantaining sign for even exponents.
      • 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

      • doubleEquals

        public static boolean doubleEquals​(double a,
                                           double b)
        Determines if 2 double values are equal to with a reasonable floating point error
        Parameters:
        a - The expected value
        b - The actual value
        Returns:
        If the 2 values are approximately equal
      • limitChange

        public static double limitChange​(double current,
                                         double desired,
                                         double maxChange)
        Limits the ammount of change when trying to go from the current value to the desired value.
        Parameters:
        current - The current value
        desired - The desired value
        maxChange - The maximum amount that the returned value can differ from the current value
        Returns:
        The value that is as close to the desired value as possible without exceeing the maximum change
      • signedPow

        public static double signedPow​(double base,
                                       int exp)
        Calculates the exponentiation while mantaining sign for even exponents.
        Parameters:
        base - The base value.
        exp - The exponent value.
        Returns:
        The result of the exponentiation.
      • clamp

        public static double clamp​(double x,
                                   double minValue,
                                   double maxValue)
        Clamps x such that it is at least minValue and at most maxValue.
        Parameters:
        x - The value to clamp.
        minValue - The lower limit.
        maxValue - The upper limit.
        Returns:
        Clamped x.