[lua] curve_yval comments

Viewer

copydownloadembedprintName: curve_yval comments
  1. function curve_yval(curve, x)
  2.         -- curve - table of curves, x -- value to get the Y
  3.         -- no check if not a table - bad
  4.         local low, high_index, high, last
  5.  
  6.         for i, v in ipairs(curve) do
  7.                 -- so here we seek x in table that is equal or greater than input
  8.                 -- if there is then high found
  9.                 if x <= v.then
  10.                         high = v
  11.                         high_index = i
  12.                         break
  13.                 end
  14.                 -- if not the last one becomes i
  15.                 last = i
  16.         end
  17.  
  18.         if not high then
  19.                 -- if high bracket wasn't found then it just returns last y of cuvre table
  20.                 return curve[last].y
  21.         end
  22.  
  23.         low = curve[high_index - 1] -- step back to get lower Y
  24.         if not low then
  25.                 -- if there is no lower value in table then it returns upper one
  26.                 return high.y
  27.         end
  28.         -- if both high and low pairs was found then it calculates
  29.         -- low + delta of and low multipled by delta of given x and lower x divided by delta of high and low x
  30.         return low.+ (high.- low.y) * (- low.x) / (high.- low.x)
  31. end

Editor

You can edit this paste and save as new:


File Description
  • curve_yval comments
  • Paste Code
  • 28 Mar-2023
  • 949 Bytes
You can Share it: