added mathx.inverse_lerp, mathx.remap_range, mathx.remap_range_clamped

This commit is contained in:
Max Cahill 2023-08-10 14:43:59 +10:00
parent 097c19bda5
commit b019767a16

View File

@ -77,6 +77,21 @@ function mathx.bilerp(a, b, c, d, u, v)
) )
end end
--get the lerp factor on a range, inverse_lerp(6, 0, 10) == 0.6
function mathx.inverse_lerp(v, min, max)
return (v - min) / (max - min)
end
--remap a value from one range to another
function mathx.remap_range(v, in_min, in_max, out_min, out_max)
return mathx.lerp(out_min, out_max, mathx.inverse_lerp(v, in_min, in_max))
end
--remap a value from one range to another, staying within that range
function mathx.remap_range_clamped(v, in_min, in_max, out_min, out_max)
return mathx.lerp(out_min, out_max, mathx.clamp01(mathx.inverse_lerp(v, in_min, in_max)))
end
--easing curves --easing curves
--(generally only "safe" for 0-1 range, see mathx.clamp01) --(generally only "safe" for 0-1 range, see mathx.clamp01)