isNear

open infix fun Measure<*>.isNear(varianceThreshold: Double): Boolean

Checks if this measure is near another measure of the same unit. Provide a variance threshold for use for a +/- scalar, such as 0.05 for +/- 5%.

Inches.of(11).isNear(Inches.of(10), 0.1) // true
Inches.of(12).isNear(Inches.of(10), 0.1) // false

Return

true if this unit is near the other measure, otherwise false

Parameters

varianceThreshold

the acceptable variance threshold, in terms of an acceptable +/- error range multiplier. Checking if a value is within 10% means a value of 0.1 should be passed; checking if a value is within 1% means a value of 0.01 should be passed, and so on.


open infix fun Measure<U>.isNear(tolerance: Measure<U>): Boolean

Checks if this measure is near another measure of the same unit, with a specified tolerance of the same unit.

Meters.of(1).isNear(Meters.of(1.2), Millimeters.of(300)) // true
Degrees.of(90).isNear(Rotations.of(0.5), Degrees.of(45)) // false

Return

true if this unit is near the other measure, otherwise false.

Parameters

tolerance

the tolerance allowed in which the two measures are defined as near each other.