function Map(v,R,E,e,U)return((v-R)*(U-e))/(E-R)+e end function numLerp(v,R,E)return v+(R-v)*E end function RAND(v,R,E)return numLerp(v,R,math.random())end function Round(v,R)return math.floor(v/R+.5)*R end function getNearestPoint(v,R,E)local e=(v-E).magnitude local U=(R-E).magnitude return math.min(e,U)==e and v or R end
--------------------[ MATH FUNCTIONS ]------------------------------------------------

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
