Class MathUtil
java.lang.Object
de.arstwo.twotil.math.MathUtil
Various math-related content that fits nowhere else.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final doublestatic final floatstatic final double -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanaboutEqual(double a, double b, double delta) Checks if two doubles are equal within the given tolerance.static booleanaboutEqual(float a, float b, float delta) Checks if two floats are equal within the given tolerance.static byteabs(byte x) Much faster but less generic abs implementation.static doubleabs(double x) Much faster but less generic abs implementation.static floatabs(float x) Much faster but less generic abs implementation.static intabs(int x) Much faster but less generic abs implementation.static longabs(long x) Much faster but less generic abs implementation.static shortabs(short x) Much faster but less generic abs implementation.static <T extends Comparable<T>>
TwithinRange(T value, T min, T max) Returns the given value clamped to the min/max valued specified.
-
Field Details
-
TO_DEGREE_D
public static final double TO_DEGREE_D- See Also:
-
TO_DEGREE
public static final float TO_DEGREE- See Also:
-
TO_RADIANS_D
public static final double TO_RADIANS_D- See Also:
-
TO_RADIANS
public static final float TO_RADIANS- See Also:
-
-
Method Details
-
abs
public static byte abs(byte x) Much faster but less generic abs implementation. -
abs
public static short abs(short x) Much faster but less generic abs implementation. -
abs
public static int abs(int x) Much faster but less generic abs implementation. -
abs
public static long abs(long x) Much faster but less generic abs implementation. -
abs
public static float abs(float x) Much faster but less generic abs implementation. -
abs
public static double abs(double x) Much faster but less generic abs implementation. -
aboutEqual
public static boolean aboutEqual(float a, float b, float delta) Checks if two floats are equal within the given tolerance.- Parameters:
a- any floatb- any floatdelta- the maximum difference that is accepted as equal- Returns:
- true if both values are equal within the given tolerance, false otherwise.
-
aboutEqual
public static boolean aboutEqual(double a, double b, double delta) Checks if two doubles are equal within the given tolerance.- Parameters:
a- any doubleb- any doubledelta- the maximum difference that is accepted as equal- Returns:
- true if both values are equal within the given tolerance, false otherwise.
-
withinRange
Returns the given value clamped to the min/max valued specified.- Type Parameters:
T- any comparable- Parameters:
value- the value to check and returnmin- minimum value to clamp tomax- maximum value to clamp to- Returns:
- the value given, clamped to the specified boundaries.
-