Package civitas.celestis.math
Class Scalars
java.lang.Object
civitas.celestis.math.Scalars
A static utility class containing various constants and methods related
to mathematical scalars, primarily of the type
double.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doublebezier(double p0, double p1, double p2, double p3, double t) Performs cubic Bezier interpolation between four scalar values, using the interpolation parametert.static doubleclamp(double val, double min, double max) Clamps the provided value to respect the boundaries of[min, max].static doublefactorial(double n) Calculates the factorial of the provided inputn.static longfactorial(long n) Calculates the factorial of the provided inputn.static doublegamma(double n) Returns the gamma of the given inputn.static booleanisInRange(double val, double min, double max) Returns whether the provided valuevalis within the range of[min, max].static doublelerp(double s, double e, double t) Performs linear interpolation (LERP) between the starting valuesand the ending valuee.static doublerandom()Returns a random value within the range of[0, 1).static doublerandom(double min, double max) Returns a random value within the range of[min, max).
-
Field Details
-
EPSILON
public static final double EPSILONA very small constant used in various applications.- See Also:
-
TAU
public static final double TAUThe mathematical constant TAU. (2 * pi)- See Also:
-
-
Method Details
-
random
public static double random()Returns a random value within the range of[0, 1).- Returns:
- A random value between
[0, 1)
-
random
public static double random(double min, double max) Returns a random value within the range of[min, max).- Parameters:
min- The minimum allowed value (inclusive)max- The maximum allowed value (exclusive)- Returns:
- A random value between
[min, max)
-
isInRange
public static boolean isInRange(double val, double min, double max) Returns whether the provided valuevalis within the range of[min, max].- Parameters:
val- The value to validatemin- The minimum allowed value (inclusive)max- The maximum allowed value (inclusive)- Returns:
trueif the value is within the allowed range
-
clamp
public static double clamp(double val, double min, double max) Clamps the provided value to respect the boundaries of[min, max].- Parameters:
val- The value of which to clampmin- The minimum allowed value (inclusive)max- The maximum allowed value (inclusive)- Returns:
- The clamped value
-
lerp
public static double lerp(double s, double e, double t) Performs linear interpolation (LERP) between the starting valuesand the ending valuee.- Parameters:
s- The starting valuee- The ending valuet- The interpolation parameter ([0, 1])- Returns:
- The interpolated value between the starting and ending values
sande
-
bezier
public static double bezier(double p0, double p1, double p2, double p3, double t) Performs cubic Bezier interpolation between four scalar values, using the interpolation parametert.- Parameters:
p0- The starting scalar valuep1- The first control point scalar valuep2- The second control point scalar valuep3- The ending scalar valuet- The interpolation parameter ([0, 1])- Returns:
- The interpolated scalar value
-
gamma
public static double gamma(double n) Returns the gamma of the given inputn.- Parameters:
n- The value to get the gamma of- Returns:
- The gamma function value of
n
-
factorial
public static double factorial(double n) Calculates the factorial of the provided inputn. Note that this requires a non-negative input.- Parameters:
n- The number to get the factorial of- Returns:
- The factorial of
n
-
factorial
public static long factorial(long n) Calculates the factorial of the provided inputn. Note that this requires a non-negative input. Values over20will trigger an integer overflow.- Parameters:
n- The number to get the factorial of- Returns:
- The factorial of
n
-