mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiunits] Fix measure isNear function (#6313)
Now the function allows comparison between negative numbers, positive numbers or both.
This commit is contained in:
@@ -260,10 +260,9 @@ public interface Measure<U extends Unit<U>> extends Comparable<Measure<U>> {
|
||||
}
|
||||
|
||||
// abs so negative inputs are calculated correctly
|
||||
var allowedVariance = Math.abs(varianceThreshold);
|
||||
var tolerance = Math.abs(other.baseUnitMagnitude() * varianceThreshold);
|
||||
|
||||
return other.baseUnitMagnitude() * (1 - allowedVariance) <= this.baseUnitMagnitude()
|
||||
&& other.baseUnitMagnitude() * (1 + allowedVariance) >= this.baseUnitMagnitude();
|
||||
return Math.abs(this.baseUnitMagnitude() - other.baseUnitMagnitude()) <= tolerance;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user