Package org.team1540.rooster.util
Class MathUtils
- java.lang.Object
-
- org.team1540.rooster.util.MathUtils
-
public class MathUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description MathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
constrain(double input, double cap)
Constrains an input to a given range in either direction from zero.static double
constrain(double input, double lowerCap, double upperCap)
Constrains an input to a given range.static double
negateDoubleIf(boolean shouldInvert, double toInvert)
Inverts the provided value ifshouldInvert
istrue
.static double
preserveSignRaiseToPower(double input, double pow)
Raises the input to the provided power while preserving the sign.
-
-
-
Method Detail
-
negateDoubleIf
@Contract(pure=true) public static double negateDoubleIf(boolean shouldInvert, double toInvert)
Inverts the provided value ifshouldInvert
istrue
.- Parameters:
shouldInvert
- Whether to invert the number.toInvert
- The number to invert.- Returns:
- If
shouldInvert
istrue
,-toInvert
; otherwise,toInvert
-
constrain
@Contract(pure=true) public static double constrain(double input, double cap)
Constrains an input to a given range in either direction from zero. This does not map the input to the range; it simply hard-caps it when it's outside.- Parameters:
input
- The input to constrain.cap
- The distance from zero to constraininput
to.- Returns:
- If
input
>cap
, returncap
; ifinput
<-cap
, return-cap
; otherwise, returninput
.
-
constrain
@Contract(pure=true) public static double constrain(double input, double lowerCap, double upperCap)
Constrains an input to a given range. This does not map the input to the range; it simply hard-caps it when it's outside.- Parameters:
input
- The input to constrain.lowerCap
- The lower bound of the range.upperCap
- The upper bound of the range.- Returns:
- If
input
>upperCap
, returnupperCap
; ifinput
<lowerCap
, returnlowerCap
; otherwise, returninput
.
-
preserveSignRaiseToPower
@Contract(pure=true) public static double preserveSignRaiseToPower(double input, double pow)
Raises the input to the provided power while preserving the sign. Useful for joystick scaling.- Parameters:
input
- The input to be raised.pow
- The power.- Returns:
- The input raised to the provided power, with the sign of the input.
-
-