function Map(z,i,P,J,L)return((z-i)*(L-J))/(P-i)+J end function numLerp(z,i,P)return z+(i-z)*P end function RAND(z,i,P)return numLerp(z,i,math.random())end function Round(z,i)return math.floor(z/i+.5)*i end function getNearestPoint(z,i,P)local J=(z-P).magnitude local L=(i-P).magnitude return math.min(J,L)==J and z or i end


function Map(Val, fromLow, fromHigh, toLow, toHigh)
	return (Val - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow
end

function numLerp(A, B, Alpha)
	return A + (B - A) * Alpha
end

function RAND(Min, Max, Accuracy)
	return numLerp(Min, Max, math.random())
	--[[local Inverse = 1 / (Accuracy or 1)
	return (math.random(Min * Inverse, Max * Inverse) / Inverse)]]
end

function Round(Num, toNearest)
	return math.floor(Num / toNearest + 0.5) * toNearest
end

function getNearestPoint(A, B, Origin)
	local A2 = (A - Origin).magnitude
	local B2 = (B - Origin).magnitude
	return (math.min(A2, B2) == A2 and A or B)
end
