Package de.florianmichael.rclasses.math
Class MathUtils
java.lang.Object
de.florianmichael.rclasses.math.MathUtils
Implementation of a math utility.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleaverageDouble(double... data) static doubleaverageDouble(float... data) static doubleaverageDouble(int... data) static doubleaverageDouble(long... data) static doubleaverageDouble(short... data) static floataverageFloat(double... data) static floataverageFloat(float... data) static floataverageFloat(int... data) static floataverageFloat(long... data) static floataverageFloat(short... data) static intaverageInt(double... data) static intaverageInt(float... data) static intaverageInt(int... data) static intaverageInt(long... data) static intaverageInt(short... data) static shortaverageShort(double... data) static shortaverageShort(float... data) static shortaverageShort(int... data) static shortaverageShort(long... data) static shortaverageShort(short... data) static doubleboxMuellerDistribution(Random random, double min, double max, double mean, double sigma) static floatboxMuellerDistribution(Random random, float min, float max, float mean, float sigma) static doubleclamp(double value, double minimum, double maximum) static floatclamp(float value, float minimum, float maximum) static intclamp(int value, int minimum, int maximum) static longclamp(long value, long minimum, long maximum) static shortclamp(short value, short minimum, short maximum) static doubleconjugate(double value) static floatconjugate(float value) static intconjugate(int value) static longconjugate(long value) static shortconjugate(short value) static doubleinterpolate(double start, double end, double progress) Interpolates between two values with the given progress.static floatinterpolate(float start, float end, float progress) Interpolates between two values with the given progress.static booleanisInBounds(double x, double y, double left, double up, double right, double down) static booleanisInBounds(float x, float y, float left, float up, float right, float down) static booleanisInBounds(int x, int y, int left, int up, int right, int down) static booleanisInBounds(long x, long y, long left, long up, long right, long down) static booleanisInBounds(short x, short y, short left, short up, short right, short down) static booleanisInBoundsAbsolute(double x, double y, double left, double up, double right, double down) static booleanisInBoundsAbsolute(float x, float y, float left, float up, float right, float down) static booleanisInBoundsAbsolute(int x, int y, int left, int up, int right, int down) static booleanisInBoundsAbsolute(long x, long y, long left, long up, long right, long down) static booleanisInBoundsAbsolute(short x, short y, short left, short up, short right, short down) static doublekurtosis(double... data) static floatkurtosis(float... data) static doublemedian(double... data) static floatmedian(float... data) static doubleroundAvoid(double value, int places) static floatroundAvoid(float value, int places) static doubleroundAwayFromZero(double x) static doubleskewness(double... data) static floatskewness(float... data) static doublestandardDeviation(double... data) static floatstandardDeviation(float... data) static doublestandardDeviation(long... data) static doublesum(double... values) static floatsum(float... values) static intsum(int... values) static longsum(long... values) static shortsum(short... values) static doublevariance(double... data) static floatvariance(float... data) static doublevariance(long... data)
-
Field Details
-
TAU
public static final float TAU- See Also:
-
-
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.
-