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 doubleconstrain(double input, double cap)Constrains an input to a given range in either direction from zero.static doubleconstrain(double input, double lowerCap, double upperCap)Constrains an input to a given range.static doublenegateDoubleIf(boolean shouldInvert, double toInvert)Inverts the provided value ifshouldInvertistrue.static doublepreserveSignRaiseToPower(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 ifshouldInvertistrue.- Parameters:
shouldInvert- Whether to invert the number.toInvert- The number to invert.- Returns:
- If
shouldInvertistrue,-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 constraininputto.- 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.
-
-