Class MathUtils


  • public final class MathUtils
    extends java.lang.Object
    General math-related and numeric utility functions.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private MathUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static float distance​(float aX, float aY, float bX, float bY)  
      static float distance​(int aX, int aY, int bX, int bY)  
      static int round​(float d)
      Ends up being a bit faster than Math.round(float).
      static int sum​(int[] array)  
      • Methods inherited from class java.lang.Object

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

      • MathUtils

        private MathUtils()
    • Method Detail

      • round

        public static int round​(float d)
        Ends up being a bit faster than Math.round(float). This merely rounds its argument to the nearest int, where x.5 rounds up to x+1. Semantics of this shortcut differ slightly from Math.round(float) in that half rounds down for negative values. -2.5 rounds to -3, not -2. For purposes here it makes no difference.
        Parameters:
        d - real value to round
        Returns:
        nearest int
      • distance

        public static float distance​(float aX,
                                     float aY,
                                     float bX,
                                     float bY)
        Parameters:
        aX - point A x coordinate
        aY - point A y coordinate
        bX - point B x coordinate
        bY - point B y coordinate
        Returns:
        Euclidean distance between points A and B
      • distance

        public static float distance​(int aX,
                                     int aY,
                                     int bX,
                                     int bY)
        Parameters:
        aX - point A x coordinate
        aY - point A y coordinate
        bX - point B x coordinate
        bY - point B y coordinate
        Returns:
        Euclidean distance between points A and B
      • sum

        public static int sum​(int[] array)
        Parameters:
        array - values to sum
        Returns:
        sum of values in array