Class ContiguousDouble

java.lang.Object
xbot.common.math.ContiguousDouble

public class ContiguousDouble extends Object
Wraps a double to allow easy comparison and manipulation of sensor readings that wrap (e.g. -180 to 180). For bounds 0 - 10, logically: - 10 + 1 == 1 - 0 - 1 == 9 - 0 == 10
  • Constructor Details

    • ContiguousDouble

      public ContiguousDouble(double value, double lowerBound, double upperBound)
    • ContiguousDouble

      public ContiguousDouble(double lowerBound, double upperBound)
    • ContiguousDouble

      public ContiguousDouble()
  • Method Details

    • reboundValue

      public double reboundValue()
      Shifts the value so that it still represents the same position but is within the current bounds.
      Returns:
      the new value for chaining functions
    • reboundValue

      public static double reboundValue(double value, double lowerBound, double upperBound)
    • unwrapBelow

      public double unwrapBelow()
      Calculates a number representing the current value that is lower than (or equal to) the lower bound. Used to make normal numerical comparisons without needing to handle wrap cases.
      Returns:
      the computed value
    • unwrapAbove

      public double unwrapAbove()
      Calculates a number representing the current value that is higher than (or equal to) the upper bound. Used to make normal numerical comparisons without needing to handle wrap cases.
      Returns:
      the computed value
    • difference

      public double difference(double otherValue)
      Computes the difference between two values (other - this), accounting for wrapping. Treats the given 'other' value as a number within the same bounds as the current instance.
      Parameters:
      otherValue - the other value to compare against
      Returns:
      the computed difference
    • difference

      public double difference(ContiguousDouble otherValue)
      Computes the difference between two values (other - this), accounting for wrapping
      Parameters:
      otherValue - the other value to compare against (must have the same bounds as the current instance)
      Returns:
      the computed difference
    • shiftBounds

      public ContiguousDouble shiftBounds(double shiftMagnitude)
      Shifts both bounds by the specified amount
      Parameters:
      shiftMagnitude - the amount to add to each bound
    • shiftValue

      public ContiguousDouble shiftValue(double shiftMagnitude)
      Shifts value by the specified amount (addition)
      Parameters:
      shiftMagnitude - the amount to add to the current value
      Returns:
      A reference to the current ContiguousDouble, for daisy chaining.
    • getValue

      public double getValue()
    • setValue

      public void setValue(double newValue)
    • getUpperBound

      public double getUpperBound()
    • setUpperBound

      public void setUpperBound(double newValue)
    • getLowerBound

      public double getLowerBound()
    • setLowerBound

      public void setLowerBound(double newValue)
    • clone

      public ContiguousDouble clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object