Package frc.spectrumLib.util
Class Util
java.lang.Object
frc.spectrumLib.util.Util
Math and driver station helpers. Based on 254's Util, imported from 1678-2024.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallCloseTo(List<Double> list, double value, double epsilon) static booleanepsilonEquals(double a, double b) static booleanepsilonEquals(double a, double b, double epsilon) True whenaandbdiffer byepsilonor less.static booleanepsilonEquals(int a, int b, int epsilon) Widens to long before subtracting, so comparing values near the int limits cannot overflow into a wrong answer.static booleaninRange(double v, double maxMagnitude) True when the magnitude ofvis undermaxMagnitude, bounds exclusive.static booleaninRange(double v, double min, double max) True whenvsits betweenminandmax, both bounds exclusive.static booleaninRange(DoubleSupplier v, DoubleSupplier min, DoubleSupplier max) Reads each supplier once and tests the result against the two bounds.static doubleinterpolate(double a, double b, double x) Interpolates fromaatx = 0tobatx = 1, clamping x.static StringjoinStrings(String delim, List<?> strings) static doublelimit(double v, double maxMagnitude) Clampsvto [-maxMagnitude,maxMagnitude].static doublelimit(double v, double min, double max) Clampsvto [min,max], both bounds inclusive.
-
Field Details
-
EPSILON
public static final double EPSILONToleranceepsilonEquals(double, double)uses for floating point equality.- See Also:
-
teleop
-
autoMode
-
testMode
-
disabled
-
dsAttached
-
-
Method Details
-
limit
public static double limit(double v, double maxMagnitude) Clampsvto [-maxMagnitude,maxMagnitude]. -
limit
public static double limit(double v, double min, double max) Clampsvto [min,max], both bounds inclusive. -
inRange
public static boolean inRange(double v, double maxMagnitude) True when the magnitude ofvis undermaxMagnitude, bounds exclusive. -
inRange
public static boolean inRange(double v, double min, double max) True whenvsits betweenminandmax, both bounds exclusive. -
inRange
Reads each supplier once and tests the result against the two bounds. Use this instead of callinginRange(double, double, double)on values that are still moving. -
interpolate
public static double interpolate(double a, double b, double x) Interpolates fromaatx = 0tobatx = 1, clamping x. -
joinStrings
-
epsilonEquals
public static boolean epsilonEquals(double a, double b, double epsilon) True whenaandbdiffer byepsilonor less. -
epsilonEquals
public static boolean epsilonEquals(double a, double b) -
epsilonEquals
public static boolean epsilonEquals(int a, int b, int epsilon) Widens to long before subtracting, so comparing values near the int limits cannot overflow into a wrong answer. -
allCloseTo
-