Package frc.team88.swerve.util
Class MathUtils
- java.lang.Object
-
- frc.team88.swerve.util.MathUtils
-
public class MathUtils extends java.lang.Object
Contains general math utility functions.
-
-
Constructor Summary
Constructors Constructor Description MathUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
clamp(double x, double minValue, double maxValue)
Clamps x such that it is at least minValue and at most maxValue.static boolean
doubleEquals(double a, double b)
Determines if 2 double values are equal to with a reasonable floating point errorstatic double
limitChange(double current, double desired, double maxChange)
Limits the ammount of change when trying to go from the current value to the desired value.static double
signedPow(double base, int exp)
Calculates the exponentiation while mantaining sign for even exponents.
-
-
-
Method Detail
-
doubleEquals
public static boolean doubleEquals(double a, double b)
Determines if 2 double values are equal to with a reasonable floating point error- Parameters:
a
- The expected valueb
- The actual value- Returns:
- If the 2 values are approximately equal
-
limitChange
public static double limitChange(double current, double desired, double maxChange)
Limits the ammount of change when trying to go from the current value to the desired value.- Parameters:
current
- The current valuedesired
- The desired valuemaxChange
- The maximum amount that the returned value can differ from the current value- Returns:
- The value that is as close to the desired value as possible without exceeing the maximum change
-
signedPow
public static double signedPow(double base, int exp)
Calculates the exponentiation while mantaining sign for even exponents.- Parameters:
base
- The base value.exp
- The exponent value.- Returns:
- The result of the exponentiation.
-
clamp
public static double clamp(double x, double minValue, double maxValue)
Clamps x such that it is at least minValue and at most maxValue.- Parameters:
x
- The value to clamp.minValue
- The lower limit.maxValue
- The upper limit.- Returns:
- Clamped x.
-
-