Class MathUtils

java.lang.Object
de.florianmichael.rclasses.math.MathUtils

public class MathUtils extends Object
Implementation of a math utility.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    averageDouble(double... data)
     
    static double
    averageDouble(float... data)
     
    static double
    averageDouble(int... data)
     
    static double
    averageDouble(long... data)
     
    static double
    averageDouble(short... data)
     
    static float
    averageFloat(double... data)
     
    static float
    averageFloat(float... data)
     
    static float
    averageFloat(int... data)
     
    static float
    averageFloat(long... data)
     
    static float
    averageFloat(short... data)
     
    static int
    averageInt(double... data)
     
    static int
    averageInt(float... data)
     
    static int
    averageInt(int... data)
     
    static int
    averageInt(long... data)
     
    static int
    averageInt(short... data)
     
    static short
    averageShort(double... data)
     
    static short
    averageShort(float... data)
     
    static short
    averageShort(int... data)
     
    static short
    averageShort(long... data)
     
    static short
    averageShort(short... data)
     
    static double
    boxMuellerDistribution(Random random, double min, double max, double mean, double sigma)
     
    static float
    boxMuellerDistribution(Random random, float min, float max, float mean, float sigma)
     
    static double
    clamp(double value, double minimum, double maximum)
     
    static float
    clamp(float value, float minimum, float maximum)
     
    static int
    clamp(int value, int minimum, int maximum)
     
    static long
    clamp(long value, long minimum, long maximum)
     
    static short
    clamp(short value, short minimum, short maximum)
     
    static double
    conjugate(double value)
     
    static float
    conjugate(float value)
     
    static int
    conjugate(int value)
     
    static long
    conjugate(long value)
     
    static short
    conjugate(short value)
     
    static double
    interpolate(double start, double end, double progress)
    Interpolates between two values with the given progress.
    static float
    interpolate(float start, float end, float progress)
    Interpolates between two values with the given progress.
    static boolean
    isInBounds(double x, double y, double left, double up, double right, double down)
     
    static boolean
    isInBounds(float x, float y, float left, float up, float right, float down)
     
    static boolean
    isInBounds(int x, int y, int left, int up, int right, int down)
     
    static boolean
    isInBounds(long x, long y, long left, long up, long right, long down)
     
    static boolean
    isInBounds(short x, short y, short left, short up, short right, short down)
     
    static boolean
    isInBoundsAbsolute(double x, double y, double left, double up, double right, double down)
     
    static boolean
    isInBoundsAbsolute(float x, float y, float left, float up, float right, float down)
     
    static boolean
    isInBoundsAbsolute(int x, int y, int left, int up, int right, int down)
     
    static boolean
    isInBoundsAbsolute(long x, long y, long left, long up, long right, long down)
     
    static boolean
    isInBoundsAbsolute(short x, short y, short left, short up, short right, short down)
     
    static double
    kurtosis(double... data)
     
    static float
    kurtosis(float... data)
     
    static double
    median(double... data)
     
    static float
    median(float... data)
     
    static double
    roundAvoid(double value, int places)
     
    static float
    roundAvoid(float value, int places)
     
    static double
     
    static double
    skewness(double... data)
     
    static float
    skewness(float... data)
     
    static double
    standardDeviation(double... data)
     
    static float
    standardDeviation(float... data)
     
    static double
    standardDeviation(long... data)
     
    static double
    sum(double... values)
     
    static float
    sum(float... values)
     
    static int
    sum(int... values)
     
    static long
    sum(long... values)
     
    static short
    sum(short... values)
     
    static double
    variance(double... data)
     
    static float
    variance(float... data)
     
    static double
    variance(long... data)
     

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • MathUtils

      public MathUtils()
  • Method Details

    • interpolate

      public static float interpolate(float start, float end, float progress)
      Interpolates between two values with the given progress.
      Parameters:
      start - The start value.
      end - The end value.
      progress - The progress.
      Returns:
      The interpolated value.
    • interpolate

      public static double interpolate(double start, double end, double progress)
      Interpolates between two values with the given progress.
      Parameters:
      start - The start value.
      end - The end value.
      progress - The progress.
      Returns:
      The interpolated value.
    • conjugate

      public static short conjugate(short value)
      Parameters:
      value - The value to be conjugated.
      Returns:
      the reciprocal value of the given value.
    • conjugate

      public static int conjugate(int value)
      Parameters:
      value - The value to be conjugated.
      Returns:
      the reciprocal value of the given value.
    • conjugate

      public static long conjugate(long value)
      Parameters:
      value - The value to be conjugated.
      Returns:
      the reciprocal value of the given value.
    • conjugate

      public static float conjugate(float value)
      Parameters:
      value - The value to be conjugated.
      Returns:
      the reciprocal value of the given value.
    • conjugate

      public static double conjugate(double value)
      Parameters:
      value - The value to be conjugated.
      Returns:
      the reciprocal value of the given value.
    • isInBounds

      public static boolean isInBounds(short x, short y, short left, short up, short right, short down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are relative.
    • isInBounds

      public static boolean isInBounds(int x, int y, int left, int up, int right, int down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are relative.
    • isInBounds

      public static boolean isInBounds(long x, long y, long left, long up, long right, long down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are relative.
    • isInBounds

      public static boolean isInBounds(float x, float y, float left, float up, float right, float down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are relative.
    • isInBounds

      public static boolean isInBounds(double x, double y, double left, double up, double right, double down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are relative.
    • isInBoundsAbsolute

      public static boolean isInBoundsAbsolute(short x, short y, short left, short up, short right, short down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are absolute.
    • isInBoundsAbsolute

      public static boolean isInBoundsAbsolute(int x, int y, int left, int up, int right, int down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are absolute.
    • isInBoundsAbsolute

      public static boolean isInBoundsAbsolute(long x, long y, long left, long up, long right, long down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are absolute.
    • isInBoundsAbsolute

      public static boolean isInBoundsAbsolute(float x, float y, float left, float up, float right, float down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are absolute.
    • isInBoundsAbsolute

      public static boolean isInBoundsAbsolute(double x, double y, double left, double up, double right, double down)
      Parameters:
      x - The x value.
      y - The y value.
      left - The left value.
      up - The up value.
      right - The right value.
      down - The down value.
      Returns:
      Whether the given point is in the bounds of the given rectangle. The bounds are absolute.
    • roundAvoid

      public static double roundAvoid(double value, int places)
      Parameters:
      value - The value to round.
      places - The number of places to round to.
      Returns:
      The given value rounded to the given number of places.
    • roundAvoid

      public static float roundAvoid(float value, int places)
      Parameters:
      value - The value to round.
      places - The number of places to round to.
      Returns:
      The given value rounded to the given number of places.
    • sum

      public static short sum(short... values)
      Parameters:
      values - The values to sum.
      Returns:
      The sum of the given values.
    • sum

      public static int sum(int... values)
      Parameters:
      values - The values to sum.
      Returns:
      The sum of the given values.
    • sum

      public static long sum(long... values)
      Parameters:
      values - The values to sum.
      Returns:
      The sum of the given values.
    • sum

      public static float sum(float... values)
      Parameters:
      values - The values to sum.
      Returns:
      The sum of the given values.
    • sum

      public static double sum(double... values)
      Parameters:
      values - The values to sum.
      Returns:
      The sum of the given values.
    • averageShort

      public static short averageShort(short... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as short.
    • averageShort

      public static short averageShort(int... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as short.
    • averageShort

      public static short averageShort(long... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as short.
    • averageShort

      public static short averageShort(float... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as short.
    • averageShort

      public static short averageShort(double... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as short.
    • averageInt

      public static int averageInt(short... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as int.
    • averageInt

      public static int averageInt(int... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as int.
    • averageInt

      public static int averageInt(long... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as int.
    • averageInt

      public static int averageInt(float... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as int.
    • averageInt

      public static int averageInt(double... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as int.
    • averageFloat

      public static float averageFloat(short... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as float.
    • averageFloat

      public static float averageFloat(int... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as float.
    • averageFloat

      public static float averageFloat(long... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as float.
    • averageFloat

      public static float averageFloat(float... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as float.
    • averageFloat

      public static float averageFloat(double... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as float.
    • averageDouble

      public static double averageDouble(short... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as double.
    • averageDouble

      public static double averageDouble(int... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as double.
    • averageDouble

      public static double averageDouble(long... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as double.
    • averageDouble

      public static double averageDouble(float... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as double.
    • averageDouble

      public static double averageDouble(double... data)
      Parameters:
      data - The data to average.
      Returns:
      The average of the given data as double.
    • clamp

      public static short clamp(short value, short minimum, short maximum)
      Parameters:
      value - The value to clamp.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
    • clamp

      public static int clamp(int value, int minimum, int maximum)
      Parameters:
      value - The value to clamp.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
    • clamp

      public static long clamp(long value, long minimum, long maximum)
      Parameters:
      value - The value to clamp.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
    • clamp

      public static float clamp(float value, float minimum, float maximum)
      Parameters:
      value - The value to clamp.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
    • clamp

      public static double clamp(double value, double minimum, double maximum)
      Parameters:
      value - The value to clamp.
      minimum - The minimum value.
      maximum - The maximum value.
      Returns:
      The clamped value. If the value is smaller than the minimum, the minimum is returned. If the value is greater than the maximum, the maximum is returned. Otherwise, the value is returned.
    • median

      public static float median(float... data)
      Parameters:
      data - The data to calculate the median from.
      Returns:
      The median of the given data.
    • median

      public static double median(double... data)
      Parameters:
      data - The data to calculate the median from.
      Returns:
      The median of the given data.
    • kurtosis

      public static float kurtosis(float... data)
      Parameters:
      data - The data to calculate the kurtosis from.
      Returns:
      The kurtosis of the given data.
    • kurtosis

      public static double kurtosis(double... data)
      Parameters:
      data - The data to calculate the kurtosis from.
      Returns:
      The kurtosis of the given data.
    • skewness

      public static float skewness(float... data)
      Parameters:
      data - The data to calculate the skewness from.
      Returns:
      The skewness of the given data.
    • skewness

      public static double skewness(double... data)
      Parameters:
      data - The data to calculate the skewness from.
      Returns:
      The skewness of the given data.
    • variance

      public static float variance(float... data)
      Parameters:
      data - The data to calculate the variance from.
      Returns:
      The variance of the given data.
    • variance

      public static double variance(double... data)
      Parameters:
      data - The data to calculate the variance from.
      Returns:
      The variance of the given data.
    • variance

      public static double variance(long... data)
      Parameters:
      data - The data to calculate the variance from.
      Returns:
      The variance of the given data.
    • standardDeviation

      public static float standardDeviation(float... data)
      Parameters:
      data - The data to calculate the standard deviation from.
      Returns:
      The standard deviation of the given data.
    • standardDeviation

      public static double standardDeviation(double... data)
      Parameters:
      data - The data to calculate the standard deviation from.
      Returns:
      The standard deviation of the given data.
    • standardDeviation

      public static double standardDeviation(long... data)
      Parameters:
      data - The data to calculate the standard deviation from.
      Returns:
      The standard deviation of the given data.
    • roundAwayFromZero

      public static double roundAwayFromZero(double x)
      Parameters:
      x - The number to round.
      Returns:
      The rounded number. If the number is negative, it will be rounded down. If the number is positive, it will be rounded up.
    • boxMuellerDistribution

      public static float boxMuellerDistribution(Random random, float min, float max, float mean, float sigma)
      Parameters:
      random - The random object to use.
      min - The minimum value.
      max - The maximum value.
      mean - The mean value.
      sigma - The sigma value.
      Returns:
      A random number between the minimum and maximum value, with the given mean and sigma.
    • boxMuellerDistribution

      public static double boxMuellerDistribution(Random random, double min, double max, double mean, double sigma)
      Parameters:
      random - The random object to use.
      min - The minimum value.
      max - The maximum value.
      mean - The mean value.
      sigma - The sigma value.
      Returns:
      A random number between the minimum and maximum value, with the given mean and sigma.