Class MathUtils
- java.lang.Object
-
- org.pushingpixels.ephemeral.chroma.utils.MathUtils
-
public class MathUtils extends java.lang.Object
Utility methods for mathematical operations.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
MathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
clampDouble(double min, double max, double input)
Clamps an integer between two floating-point numbers.static int
clampInt(int min, int max, int input)
Clamps an integer between two integers.static double
differenceDegrees(double a, double b)
Distance of two points on a circle, represented using degrees.static double
lerp(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 double
rotationDirection(double from, double to)
Sign of direction change needed to travel from one angle to another.static double
sanitizeDegreesDouble(double degrees)
Sanitizes a degree measure as a floating-point number.static int
sanitizeDegreesInt(int degrees)
Sanitizes a degree measure as an integer.static int
signum(double num)
The signum function.
-
-
-
Method Detail
-
signum
public static int signum(double num)
The signum function.- Returns:
- 1 if num > 0, -1 if num < 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 <= 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 <= 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.
-
-