[wpiunits] Fix measure isNear function (#6313)

Now the function allows comparison between negative numbers, positive numbers or both.
This commit is contained in:
vichik
2024-01-31 23:18:47 +02:00
committed by GitHub
parent cb094e4ff6
commit 90bb6cfffa
2 changed files with 26 additions and 3 deletions

View File

@@ -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;
}
/**