Class Util

java.lang.Object
frc.spectrumLib.util.Util

public class Util extends Object
Math and driver station helpers. Based on 254's Util, imported from 1678-2024.
  • Field Details

  • Method Details

    • limit

      public static double limit(double v, double maxMagnitude)
      Clamps v to [-maxMagnitude, maxMagnitude].
    • limit

      public static double limit(double v, double min, double max)
      Clamps v to [min, max], both bounds inclusive.
    • inRange

      public static boolean inRange(double v, double maxMagnitude)
      True when the magnitude of v is under maxMagnitude, bounds exclusive.
    • inRange

      public static boolean inRange(double v, double min, double max)
      True when v sits between min and max, both bounds exclusive.
    • inRange

      public static boolean inRange(DoubleSupplier v, DoubleSupplier min, DoubleSupplier max)
      Reads each supplier once and tests the result against the two bounds. Use this instead of calling inRange(double, double, double) on values that are still moving.
    • interpolate

      public static double interpolate(double a, double b, double x)
      Interpolates from a at x = 0 to b at x = 1, clamping x.
    • joinStrings

      public static String joinStrings(String delim, List<?> strings)
    • epsilonEquals

      public static boolean epsilonEquals(double a, double b, double epsilon)
      True when a and b differ by epsilon or 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

      public static boolean allCloseTo(List<Double> list, double value, double epsilon)