points = nil function getPoints() return points end function init(points_) points = points_ pointDistances = {} local distAd2Sum = 0 local lastP = nil for pointIdx, p in ipairs(points) do if lastP ~= nil then local distAd2 = lastP:distAd2(p) pointDistances[pointIdx-1] = distAd2 distAd2Sum = distAd2Sum + distAd2 end lastP = p end for pointIdx, distAd2 in ipairs(pointDistances) do pointDistances[pointIdx] = distAd2 / distAd2Sum end end function eval(t) if points == nil or #points == 0 then return nil end -- find the closest points for the given t parameter local pointIdx = 1 while pointIdx <= #pointDistances and t - pointDistances[pointIdx] >= 0 do t = t - pointDistances[pointIdx] pointIdx = pointIdx + 1 end if pointIdx == #pointDistances + 1 then return points[pointIdx] end -- normalize the t parameter to only mean the distance between the two closest points t = t / pointDistances[pointIdx] return points[pointIdx]:interpolate(points[pointIdx+1], t) end