Package xbot.common.math
Class ContiguousDouble
java.lang.Object
xbot.common.math.ContiguousDouble
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 Summary
ConstructorDescriptionContiguousDouble
(double lowerBound, double upperBound) ContiguousDouble
(double value, double lowerBound, double upperBound) -
Method Summary
Modifier and TypeMethodDescriptionclone()
double
difference
(double otherValue) Computes the difference between two values (other - this), accounting for wrapping.double
difference
(ContiguousDouble otherValue) Computes the difference between two values (other - this), accounting for wrappingdouble
double
double
getValue()
double
Shifts the value so that it still represents the same position but is within the current bounds.static double
reboundValue
(double value, double lowerBound, double upperBound) void
setLowerBound
(double newValue) void
setUpperBound
(double newValue) void
setValue
(double newValue) shiftBounds
(double shiftMagnitude) Shifts both bounds by the specified amountshiftValue
(double shiftMagnitude) Shifts value by the specified amount (addition)toString()
double
Calculates a number representing the current value that is higher than (or equal to) the upper bound.double
Calculates a number representing the current value that is lower than (or equal to) the lower bound.
-
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
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
Shifts both bounds by the specified amount- Parameters:
shiftMagnitude
- the amount to add to each bound
-
shiftValue
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
-
toString
-