Class Scalars

java.lang.Object
civitas.celestis.math.Scalars

public final class Scalars extends Object
A static utility class containing various constants and methods related to mathematical scalars, primarily of the type double.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    A very small constant used in various applications.
    static final double
    The mathematical constant TAU. (2 * pi)
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    bezier(double p0, double p1, double p2, double p3, double t)
    Performs cubic Bezier interpolation between four scalar values, using the interpolation parameter t.
    static double
    clamp(double val, double min, double max)
    Clamps the provided value to respect the boundaries of [min, max].
    static double
    factorial(double n)
    Calculates the factorial of the provided input n.
    static long
    factorial(long n)
    Calculates the factorial of the provided input n.
    static double
    gamma(double n)
    Returns the gamma of the given input n.
    static boolean
    isInRange(double val, double min, double max)
    Returns whether the provided value val is within the range of [min, max].
    static double
    lerp(double s, double e, double t)
    Performs linear interpolation (LERP) between the starting value s and the ending value e.
    static double
    Returns a random value within the range of [0, 1).
    static double
    random(double min, double max)
    Returns a random value within the range of [min, max).

    Methods inherited from class java.lang.Object

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

    • EPSILON

      public static final double EPSILON
      A very small constant used in various applications.
      See Also:
    • TAU

      public static final double TAU
      The 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 value val is within the range of [min, max].
      Parameters:
      val - The value to validate
      min - The minimum allowed value (inclusive)
      max - The maximum allowed value (inclusive)
      Returns:
      true if 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 clamp
      min - 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 value s and the ending value e.
      Parameters:
      s - The starting value
      e - The ending value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated value between the starting and ending values s and e
    • 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 parameter t.
      Parameters:
      p0 - The starting scalar value
      p1 - The first control point scalar value
      p2 - The second control point scalar value
      p3 - The ending scalar value
      t - The interpolation parameter ([0, 1])
      Returns:
      The interpolated scalar value
    • gamma

      public static double gamma(double n)
      Returns the gamma of the given input n.
      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 input n. 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 input n. Note that this requires a non-negative input. Values over 20 will trigger an integer overflow.
      Parameters:
      n - The number to get the factorial of
      Returns:
      The factorial of n