method
Math.inverse_lerp
Math.inverse_lerp(a, b, v) -> fixed
The inverse of Math.lerp: given endpoints a and b and a value v, it returns the fraction (v - a) / (b - a) — 0.0 when v equals a, 1.0 when it equals b. Use it to turn a raw quantity into a normalized amount: how full a health bar is, how far a timer has run, or the t to feed into another Math.lerp. The endpoints must differ, since equal ones would divide by zero.
Parameters
athe endpoint that maps to 0.0bthe endpoint that maps to 1.0vthe value to locate between themExample
program HealthFraction {
const MAX_HP: fixed = 200.0
var hp: fixed = 150.0
handler Draw phase Render {
let fraction = Math.inverse_lerp(0.0, MAX_HP, hp) # 0.75
}
}