snap-lerp1.1.0 • Public • Published
Linearly interpolate two numbers, but snap to the closest value if the difference between them is small enough. Comes in handy if you're running an animation but don't want to keep making unnecessary updates to a value as it approaches JS's limits in numerical precision.
snapLerp(a, b, t, min, [forceSnapToB])
Linearly interpolate between
b for a given range
a + b - a * t
Math.abs(a - b) <= min, snap to the closest value:
const snapLerp =15 ===20 ===10 ===
If required, you may also pass
true to ensure that the value
snapped will always be the second supplied:
const snapLerp =15 ===20 ===20 ===
MIT. See LICENSE.md for details.