Function inverse_lerp
pub fn inverse_lerp(from: f64, to: f64, weight: f64) -> f64Expand description
Returns an interpolation or extrapolation factor considering the range specified in from and to, and the interpolated value specified in weight. The returned value will be between 0.0 and 1.0 if weight is between from and to (inclusive). If weight is located outside this range, then an extrapolation factor will be returned (return value lower than 0.0 or greater than 1.0). Use [method clamp] on the result of [method inverse_lerp] if this is not desired.
# The interpolation ratio in the `lerp()` call below is 0.75.
var middle = lerp(20, 30, 0.75)
# middle is now 27.5.
# Now, we pretend to have forgotten the original ratio and want to get it back.
var ratio = inverse_lerp(20, 30, 27.5)
# ratio is now 0.75.See also [method lerp], which performs the reverse of this operation, and [method remap] to map a continuous series of values to another.