Class MathUtils

java.lang.Object
dev.prozilla.pine.common.math.MathUtils

public final class MathUtils extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static float
    clamp(float value, float min, float max)
    Clamps a value between a min and a max value.
    static int
    clamp(int value, int min, int max)
    Clamps a value between a min and a max value.
    static float
    cubicBezier(float t, float x1, float y1, float x2, float y2)
    Calculates the value of a cubic Bézier function based on given control points.
    static String
    floatToString(float value)
     
    static boolean
    isRound(float value)
     
    static boolean
     
    static float
    lerp(float start, float end, float step)
    Linear interpolation between two values.
    static double
    max(double[] values)
     
    static float
    max(float... values)
     
    static float
    min(float... values)
     
    static void
    normalize(double[] values)
     
    static float
    remap(float value, float a, float b)
    Remaps a float value between 0f and 1f.
    static float
    remap(float value, float x, float y, float a, float b)
    Remaps a float value from one range to another.
    static float
    remap(float value, Vector2f bounds)
    Remaps a float value between 0f and 1f.

    Methods inherited from class java.lang.Object

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

    • clamp

      public static float clamp(float value, float min, float max)
      Clamps a value between a min and a max value.
      Parameters:
      value - Value
      min - Min value
      max - Max value
      Returns:
      Clamped value
    • clamp

      public static int clamp(int value, int min, int max)
      Clamps a value between a min and a max value.
      Parameters:
      value - Value
      min - Min value
      max - Max value
      Returns:
      Clamped value
    • lerp

      public static float lerp(float start, float end, float step)
      Linear interpolation between two values.
      Parameters:
      start - Start value
      end - End value
      step - Amount to interpolate (between 0f and 1f)
      Returns:
      Interpolated value between start and value
    • remap

      public static float remap(float value, Vector2f bounds)
      Remaps a float value between 0f and 1f.
      Parameters:
      value - The input value to remap
      Returns:
      The remapped value in the range [a, b]
    • remap

      public static float remap(float value, float a, float b)
      Remaps a float value between 0f and 1f.
      Parameters:
      value - The input value to remap
      a - The lower bound of the target range
      b - The upper bound of the target range
      Returns:
      The remapped value in the range [a, b]
    • remap

      public static float remap(float value, float x, float y, float a, float b) throws IllegalArgumentException
      Remaps a float value from one range to another.
      Parameters:
      value - The input value to remap
      x - The lower bound of the original range
      y - The upper bound of the original range
      a - The lower bound of the target range
      b - The upper bound of the target range
      Returns:
      The remapped value in the range [a, b]
      Throws:
      IllegalArgumentException
    • normalize

      public static void normalize(double[] values)
    • min

      public static float min(float... values)
    • max

      public static float max(float... values)
    • max

      public static double max(double[] values)
    • cubicBezier

      public static float cubicBezier(float t, float x1, float y1, float x2, float y2)
      Calculates the value of a cubic Bézier function based on given control points.
      Parameters:
      x1 - X coordinate of first control point
      y1 - Y coordinate of first control point
      x2 - X coordinate of second control point
      y2 - Y coordinate of second control point
    • isValidInteger

      public static boolean isValidInteger(String string)
    • floatToString

      public static String floatToString(float value)
    • isRound

      public static boolean isRound(float value)