Class MathUtils
java.lang.Object
org.glavo.monetfx.internal.utils.MathUtils
Utility methods for mathematical operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doubleclampDouble(double min, double max, double input) Clamps an integer between two floating-point numbers.static intclampInt(int min, int max, int input) Clamps an integer between two integers.static doubledifferenceDegrees(double a, double b) Distance of two points on a circle, represented using degrees.static doublelerp(double start, double stop, double amount) The linear interpolation function.static double[]matrixMultiply(double[] row, double[][] matrix) Multiplies a 1x3 row vector with a 3x3 matrix.static doublerotationDirection(double from, double to) Sign of direction change needed to travel from one angle to another.static doublesanitizeDegreesDouble(double degrees) Sanitizes a degree measure as a floating-point number.static intsanitizeDegreesInt(int degrees) Sanitizes a degree measure as an integer.static intsignum(double num) The signum function.
-
Method Details
-
signum
public static int signum(double num) The signum function.- Returns:
- 1 if num > 0, -1 if num invalid input: '<' 0, and 0 if num = 0
-
lerp
public static double lerp(double start, double stop, double amount) The linear interpolation function.- Returns:
- start if amount = 0 and stop if amount = 1
-
clampInt
public static int clampInt(int min, int max, int input) Clamps an integer between two integers.- Returns:
- input when min invalid input: '<'= input invalid input: '<'= max, and either min or max otherwise.
-
clampDouble
public static double clampDouble(double min, double max, double input) Clamps an integer between two floating-point numbers.- Returns:
- input when min invalid input: '<'= input invalid input: '<'= max, and either min or max otherwise.
-
sanitizeDegreesInt
public static int sanitizeDegreesInt(int degrees) Sanitizes a degree measure as an integer.- Returns:
- a degree measure between 0 (inclusive) and 360 (exclusive).
-
sanitizeDegreesDouble
public static double sanitizeDegreesDouble(double degrees) Sanitizes a degree measure as a floating-point number.- Returns:
- a degree measure between 0.0 (inclusive) and 360.0 (exclusive).
-
rotationDirection
public static double rotationDirection(double from, double to) Sign of direction change needed to travel from one angle to another.For angles that are 180 degrees apart from each other, both directions have the same travel distance, so either direction is shortest. The value 1.0 is returned in this case.
- Parameters:
from- The angle travel starts from, in degrees.to- The angle travel ends at, in degrees.- Returns:
- -1 if decreasing from leads to the shortest travel distance, 1 if increasing from leads to the shortest travel distance.
-
differenceDegrees
public static double differenceDegrees(double a, double b) Distance of two points on a circle, represented using degrees. -
matrixMultiply
public static double[] matrixMultiply(double[] row, double[][] matrix) Multiplies a 1x3 row vector with a 3x3 matrix.
-