[lua] curve_yval comments
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- function curve_yval(curve, x)
- -- curve - table of curves, x -- value to get the Y
- -- no check if not a table - bad
- local low, high_index, high, last
- for i, v in ipairs(curve) do
- -- so here we seek x in table that is equal or greater than input
- -- if there is then high found
- if x <= v.x then
- high = v
- high_index = i
- break
- end
- -- if not the last one becomes i
- last = i
- end
- if not high then
- -- if high bracket wasn't found then it just returns last y of cuvre table
- return curve[last].y
- end
- low = curve[high_index - 1] -- step back to get lower Y
- if not low then
- -- if there is no lower value in table then it returns upper one
- return high.y
- end
- -- if both high and low pairs was found then it calculates
- -- low + delta of and low multipled by delta of given x and lower x divided by delta of high and low x
- return low.y + (high.y - low.y) * (x - low.x) / (high.x - low.x)
- end
Editor
You can edit this paste and save as new: