Package Exports
- snap-lerp
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (snap-lerp) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
snap-lerp
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.
Usage
snapLerp(a, b, t, min, [forceSnapToB])
Linearly interpolate between a
and b
for a given range t
:
a + (b - a) * t
However, if Math.abs(a - b) <= min
, snap to the closest value:
const snapLerp = require('snap-lerp')
15 === snapLerp(10, 20, 0.50, 1)
20 === snapLerp(10, 20, 0.50, 10)
10 === snapLerp(10, 20, 0.49, 10)
If required, you may also pass forceSnapToB
as true
to ensure that the value
snapped will always be the second supplied:
const snapLerp = require('snap-lerp')
15 === snapLerp(10, 20, 0.50, 1, true)
20 === snapLerp(10, 20, 0.50, 10, true)
20 === snapLerp(10, 20, 0.49, 10, true)
License
MIT. See LICENSE.md for details.