Class MathUtils

java.lang.Object
buildengine.math.MathUtils

public class MathUtils extends Object
A hand full of utilities related to math and numbers.
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    interpolate(double goal, double current, double deltaTime)
    Interpolate a positive of negative double, based on a delta time object and goal
    static Vector2f
    interpolate(Vector2f goal, Vector2f current, double deltaTime)
    Interpolate a positive of negative point, based on a delta time object and goal
    static double
    max(double... numbers)
    Gets the highest of a number array
    static double
    min(double... numbers)
    Gets the lowest of a number array
    static Vector2f
    rotatePoint(double theta, Vector2f center, Vector2f point)
    Rotate a point around a center object
    static Vector2i
    rotatePoint(double theta, Vector2i center, Vector2i point)
    Rotate a point around a center object
    static double
    round(double value, int places)
    Round any double, to a specific number of decimals
    static float
    toFloat(double value)
    Safely converts any double/float value to an int.
    static int
    toInt(double value)
    Safely converts any double/float value to an int.

    Methods inherited from class java.lang.Object

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

    • round

      public static double round(double value, int places)
      Round any double, to a specific number of decimals
      Parameters:
      value - The value to round
      places - The number of decimals
      Returns:
      The rounded double
    • toInt

      public static int toInt(double value)
      Safely converts any double/float value to an int. Rounds mathematically.
      Parameters:
      value - The double/float to convert
      Returns:
      The converted int
    • toFloat

      public static float toFloat(double value)
      Safely converts any double/float value to an int. Rounds mathematically.
      Parameters:
      value - The double/float to convert
      Returns:
      The converted int
    • min

      public static double min(double... numbers)
      Gets the lowest of a number array
      Parameters:
      numbers - Array of numbers
      Returns:
      The lowest double.
    • max

      public static double max(double... numbers)
      Gets the highest of a number array
      Parameters:
      numbers - Array of numbers
      Returns:
      The lowest double.
    • rotatePoint

      public static Vector2f rotatePoint(double theta, Vector2f center, Vector2f point)
      Rotate a point around a center object
      Parameters:
      theta - The amount of rotation in theta
      center - The center point
      point - The point to rotate
      Returns:
      A new rotated point
    • rotatePoint

      public static Vector2i rotatePoint(double theta, Vector2i center, Vector2i point)
      Rotate a point around a center object
      Parameters:
      theta - The amount of rotation in theta
      center - The center point
      point - The point to rotate
      Returns:
      A new rotated point
    • interpolate

      public static double interpolate(double goal, double current, double deltaTime)
      Interpolate a positive of negative double, based on a delta time object and goal
      Parameters:
      goal - The goal to interpolate to
      current - The current progress toward that goal
      deltaTime - The delta time, or the speed to interpolate with
      Returns:
      A new double representing the updated current value
    • interpolate

      public static Vector2f interpolate(Vector2f goal, Vector2f current, double deltaTime)
      Interpolate a positive of negative point, based on a delta time object and goal
      Parameters:
      goal - The goal to interpolate to
      current - The current progress toward that goal
      deltaTime - The delta time, or the speed to interpolate with
      Returns:
      A new Vector representing the updated current point