Class EMath

java.lang.Object
de.eldoria.eldoutilities.utils.EMath

public final class EMath extends Object
Utility class with basic math functions which are not covered by java.math
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    clamp(double min, double max, double value)
    Clamp a value.
    static float
    clamp(float min, float max, float value)
    Clamp a value.
    static int
    clamp(int min, int max, int value)
    Clamp a value.
    static long
    clamp(long min, long max, long value)
    Clamp a value.
    compareValues(double a, double b)
    Compare two values
    static Pair<Float,Float>
    compareValues(float a, float b)
    Compare two values
    compareValues(int a, int b)
    Compare two values
    static double
    diff(double a, double b)
    Returns the total difference between two numbers
    static float
    diff(float a, float b)
    Returns the total difference between two numbers
    static int
    diff(int a, int b)
    Returns the total difference between two numbers
    static double
    parabolaValue(double xVector, double yVector, double xPoint, double yPoint, double x)
    Method to get a point from a parabola.
    static double
    smoothCurveValue(double x)
    Returns a smooth curve created with two opposite parabolas.
    static double
    smoothCurveValue(Pair<Double,Double> start, Pair<Double,Double> end, double x)
    Returns a smooth curve created with two opposite parabolas.

    Methods inherited from class java.lang.Object

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

    • clamp

      public static int clamp(int min, int max, int value)
      Clamp a value.
      Parameters:
      min - min value
      max - max value
      value - value to clamp
      Returns:
      value with a size between min and max
    • clamp

      public static float clamp(float min, float max, float value)
      Clamp a value.
      Parameters:
      min - min value
      max - max value
      value - value to clamp
      Returns:
      value with a size between min and max
    • clamp

      public static long clamp(long min, long max, long value)
      Clamp a value.
      Parameters:
      min - min value
      max - max value
      value - value to clamp
      Returns:
      value with a size between min and max
    • clamp

      public static double clamp(double min, double max, double value)
      Clamp a value.
      Parameters:
      min - min value
      max - max value
      value - value to clamp
      Returns:
      value with a size between min and max
    • diff

      public static float diff(float a, float b)
      Returns the total difference between two numbers
      Parameters:
      a - first value
      b - second value
      Returns:
      the total difference between two numbers
    • diff

      public static double diff(double a, double b)
      Returns the total difference between two numbers
      Parameters:
      a - first value
      b - second value
      Returns:
      the total difference between two numbers
    • diff

      public static int diff(int a, int b)
      Returns the total difference between two numbers
      Parameters:
      a - first value
      b - second value
      Returns:
      the total difference between two numbers
    • compareValues

      public static Pair<Integer,Integer> compareValues(int a, int b)
      Compare two values
      Parameters:
      a - first value
      b - second value
      Returns:
      Pair of values. smaller value is first.
    • compareValues

      public static Pair<Float,Float> compareValues(float a, float b)
      Compare two values
      Parameters:
      a - first value
      b - second value
      Returns:
      Pair of values. smaller value is first.
    • compareValues

      public static Pair<Double,Double> compareValues(double a, double b)
      Compare two values
      Parameters:
      a - first value
      b - second value
      Returns:
      Pair of values. smaller value is first.
    • parabolaValue

      public static double parabolaValue(double xVector, double yVector, double xPoint, double yPoint, double x)
      Method to get a point from a parabola.

      Creates a parabola from a point and the vertex of a parabola.

      Parameters:
      xVector - X Value of the Vector
      yVector - Y Value of the Vector
      xPoint - x Value of the Point
      yPoint - Y Value of the Point
      x - The Value of x in f(x);
      Returns:
      Returns the value of f(x) at the specified point.
    • smoothCurveValue

      public static double smoothCurveValue(double x)
      Returns a smooth curve created with two opposite parabolas.

      The slope at the start and end is 0.

      The curve is generated by a start and endpoint.

      The x value of the start point must be smaller than the end point

      Returns always a value between half of the height and 0;

      Parameters:
      x - The Point x between the start and end point.
      Returns:
      Returns a value between 0 and 1.
    • smoothCurveValue

      public static double smoothCurveValue(Pair<Double,Double> start, Pair<Double,Double> end, double x)
      Returns a smooth curve created with two opposite parabolas.

      The slope at the start and end is 0.

      The curve is generated by a start and endpoint.

      The x value of the start point must be smaller than the end point

      Parameters:
      start - The start point as a tuple of two floats
      end - The end point as a tuple of two floats
      x - The Point x between the start end end point.
      Returns:
      Returns a float which contains the value of the curve at the point x