1.1 KiB
1.1 KiB
| id | name | category | kind | tokens | sig | tip | order | ns | member |
|---|---|---|---|---|---|---|---|---|---|
| math-inverse_lerp | Math.inverse_lerp | math | namespace-method | Math.inverse_lerp | Math.inverse_lerp(a, b, v) -> fixed | Find where a value sits between two endpoints as a 0..1 fraction. | 9 | Math | inverse_lerp |
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:
a— the endpoint that maps to0.0b— the endpoint that maps to1.0v— the value to locate between them
program HealthFraction {
const MAX_HP: fixed = 200.0
let hp: fixed = 150.0
handler Draw phase Render {
let fraction = Math.inverse_lerp(0.0, MAX_HP, hp) # 0.75
}
}