Differences From Artifact [276f7a5d6e]:
- File mods/vtlib/math.lua — part of check-in [4b3aa092f8] at 2024-05-06 20:58:38 on branch trunk — add storage crate & generic interface for, add LED for print completion, add program tooltips, disfuckulate some longstanding idiot bugs (user: lexi, size: 4542) [annotate] [blame] [check-ins using]
To Artifact [818384c4da]:
- File mods/vtlib/math.lua — part of check-in [e905f495dc] at 2024-05-07 23:16:29 on branch trunk — fix some bugs, start work on actually using the tier system, add usage docs (user: lexi, size: 4564) [annotate] [blame] [check-ins using]
89 89 function fn.lerp(t, a, b) return (1-t)*a + t*b end 90 90 function fn.gradient(grad, pos) 91 91 local n = #grad 92 92 if n == 1 then return grad[1] end 93 93 local op = pos*(n-1) 94 94 local idx = math.floor(op) 95 95 local t = op-idx 96 - return fn.lerp(t, grad[1 + idx], grad[2 + idx]) 96 + return fn.lerp(t, grad[1 + idx] or grad[n], grad[2 + idx] or grad[n]) 97 97 end 98 98 99 99 function fn.trim(fl, prec) 100 100 local fac = 10^prec 101 101 return math.floor(fl * fac) / fac 102 102 end 103 103