Repository navigation
fix vector lerp edge case - #1032
Conversation
|
I like this investigation of different lerp implementations by zeux: https://gist.github.com/zeux/ea70d4574a50cc819e5f02b6d7ebb1f2 The implementation in this PR (and in maf) adds the "exactness" property but loses "monotonicity" and "determinancy". Luau went with |
|
Although, the branch could be more expensive in Lua than it is in C (LuaJIT probably handles it well though). |
|
Interesting! I proposed this change after actually running into the issue in question, but I can look into those additional properties. Skimming over the investigation, "monotonicity" does look important, but I'm not sure "determinancy" ("NaN only if t is infinite or a/b/t are NaN") is as important as a practical consideration. It feels like trying to lerp infinity or NaN is just kind of a "here be dragons" space. |
I'm already betting on LuaJIT optimizations a little by repeating |
|
Pushed a change to do
I also included an assertion on the test itself ( This Stack Overflow answer helped point me in the direction of how to work out a monotonicity test, though the particular test values (41808 and 3598) were found by searching random numbers until I found some that tripped the test. I only set out to adjust |
|
Thanks, looks good to me! I can take care of the maf changes |
There are two common ways to implement lerp:
a + (b - a) * tanda * (1 - t) + b * t.LOVR actually uses both techniques: the
vectortype uses the former, whilevec3_lerpin src/core/maf.h uses the latter.Despite its extra multiplication, it's actually better to use the latter technique, because it guarantees that
lerp(a, b, 1) == b. In the former technique,lerp(a, b, 1)may diverge frombin some cases, because floating point numbers are gonna be floating point numbers, and this can make a difference in things like interpolated procedural geometry vertex positions.This pull request changes the
vectortype to use thea * (1 - t) + b * tform of lerp, and adds a test that failed on the old logic.(The test also tosses in a handful of other tests for good measure, but only the final assertion failed before the change in lerp.)