local u={}u.E=2.718281828459 u.Tau=math.pi*2 function u.lerp(u,z,C)return u+(z-u)*C end function u.round(u,z)z=z or 1 return math.floor(u/z+.5)*z end function u.map(u,z,C,N,Y)return((u-z)*(Y-N))/(C-z)+N end function u.rotate2D(u,z)local C=math.sin(z)local N=math.cos(z)return Vector2.new(u.X*N+u.Y*C,-u.X*C+u.Y*N)end function u.angleDelta(z,C)local N=(C-z)%u.Tau if N>math.pi then N=N-u.Tau end return N end function u.blendMultiply(z,C)local N for z,Y in pairs(z)do N=N and u.lerp(N,C or 1,Y)or Y end return N end function u.blendAdditive(u)local z=0 for u,C in pairs(u)do z=z+C end return z end return u
local Math = {}

Math.E = 2.718281828459
Math.Tau = math.pi * 2

--- Linear intepolation between 2 numbers
-- @param origin Starting point (alpha = 0)
-- @param target Ending point (alpha = 1)
-- @param alpha Progress from origin to target (range [0, 1])
function Math.lerp(origin, target, alpha)
	return origin + (target - origin) * alpha
end

--- Rounds a number
-- @param number Number to round
-- @param step Increment to round the number to (default: 1)
function Math.round(number, step)
	step = step or 1
	return math.floor(number / step + 0.5) * step
end

--- Maps a number from one range to another
-- @param number Number to map
-- @param min Minimum of the current range
-- @param max Maximum of the current range
-- @param newMin Minimum of the target range
-- @param newMax Maximum of the target range
function Math.map(number, min, max, newMin, newMax)
	return (((number - min) * (newMax - newMin)) / (max - min)) + newMin
end

--- Rotates a Vector2 value
-- @param vector Vector2 to be rotated
-- @param angle Amount in radians to rotate the Vector2 by
function Math.rotate2D(vector, angle)
	local sin = math.sin(angle)
	local cos = math.cos(angle)

	return Vector2.new(
		vector.X * cos + vector.Y * sin,
		-vector.X * sin + vector.Y * cos
	)
end

--- Gets the delta between 2 angles
-- @param origin Starting angle
-- @param target Ending angle
function Math.angleDelta(origin, target)
	local delta = (target - origin) % Math.Tau

	if delta > math.pi then
		delta = delta - Math.Tau
	end

	return delta
end

--- Multiplicative blending of alpha values
-- @param alphaValues A list of alpha values to blend
-- @param target The alpha value to lerp towards (default: 1)
function Math.blendMultiply(alphaValues, target)
	local output

	for _, value in pairs(alphaValues) do
		output = output and Math.lerp(output, target or 1, value) or value
	end

	return output
end

--- Additive blending of alpha values
-- @param alphaValues A list of alpha values to blend
function Math.blendAdditive(alphaValues)
	local output = 0

	for _, value in pairs(alphaValues) do
		output = output + value
	end

	return output
end

return Math