Class MathUtilities

java.lang.Object
de.gurkenlabs.litiengine.util.MathUtilities

public class MathUtilities
extends java.lang.Object
  • Method Summary

    Modifier and TypeMethodDescription
    static byteclamp​(byte value, byte min, byte max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static doubleclamp​(double value, double min, double max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static floatclamp​(float value, float min, float max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static intclamp​(int value, int min, int max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static longclamp​(long value, long min, long max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static shortclamp​(short value, short min, short max)
    Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
    static booleanequals​(double d1, double d2, double epsilon) 
    static doublegetAverage​(double[] numbers) 
    static floatgetAverage​(float[] numbers) 
    static intgetAverage​(int[] numbers) 
    static intgetFullPercent​(double value, double fraction) 
    static intgetMax​(int... numbers) 
    static doublegetPercent​(double value, double fraction) 
    static booleanisInt​(double value) 
    static booleanisOddNumber​(int num) 
    static doubleround​(double value, int places) 
    static floatround​(float value, int places) 

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • equals

      public static boolean equals​(double d1, double d2, double epsilon)
    • round

      public static float round​(float value, int places)
    • round

      public static double round​(double value, int places)
    • clamp

      public static double clamp​(double value, double min, double max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static float clamp​(float value, float min, float max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static byte clamp​(byte value, byte min, byte max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static short clamp​(short value, short min, short max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static int clamp​(int value, int min, int max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • clamp

      public static long clamp​(long value, long min, long max)
      Modifies the value (if necessary) such that it lies within the boundaries of the specified minimum and maximum.
      Parameters:
      value - The value to be clamped.
      min - The minimum value to be accepted.
      max - The maximum value to be accepted.
      Returns:
      A value clamped to the specified boundaries.
    • getAverage

      public static double getAverage​(double[] numbers)
    • getAverage

      public static float getAverage​(float[] numbers)
    • getAverage

      public static int getAverage​(int[] numbers)
    • getMax

      public static int getMax​(int... numbers)
    • isInt

      public static boolean isInt​(double value)
    • isOddNumber

      public static boolean isOddNumber​(int num)
    • getFullPercent

      public static int getFullPercent​(double value, double fraction)
    • getPercent

      public static double getPercent​(double value, double fraction)