Planimeter / game-engine-2d

Planimeter Game Engine 2D - LÖVE-based game engine for Lua
https://github.com/Planimeter/game-engine-2d/wiki
MIT License
736 stars 74 forks source link

Fix math.remap; Add math.remapClamp #112

Closed Deco closed 3 years ago

Deco commented 3 years ago

The source range passed to math.remap is now considered properly. The mistake is only obvious with a non-zero source range low value, which is why is probably wasn't noticed before.

-- Before (wrong) print(math.remap(15, 10, 20, 80, 90)) -- 95.0

-- After print(math.remap(15, 10, 20, 80, 90)) -- 85.0

Also added math.remapClamp, which is similar to math.remap but the value returned is clamped to the destination range, even if the input value is beyond the source range.

andrewmcwatters commented 3 years ago

Interesting that we missed this.