Update types in math include

This commit is contained in:
Cooldude2606
2024-10-21 00:45:15 +01:00
parent e78234898e
commit 64a7b34824

View File

@@ -13,19 +13,19 @@ math.inv_sqrt2 = 1 / math.sqrt2
math.tau = 2 * math.pi math.tau = 2 * math.pi
--- Rounds a number to certain number of decimal places, does not work on significant figures --- Rounds a number to certain number of decimal places, does not work on significant figures
-- @tparam number num The number to be rounded --- @param num number The number to be rounded
-- @tparam[opt=0] number idp The number of decimal places to round to --- @param idp number? The number of decimal places to round to
-- @treturn number The input number rounded to the given number of decimal places --- @return number
math.round = function(num, idp) math.round = function(num, idp)
local mult = 10 ^ (idp or 0) local mult = 10 ^ (idp or 0)
return floor(num * mult + 0.5) / mult return floor(num * mult + 0.5) / mult
end end
--- Clamp a number better a minimum and maximum value, preserves NaN (not the same as nil) --- Clamp a number better a minimum and maximum value, preserves NaN (not the same as nil)
-- @tparam number num The number to be clamped --- @param num number The number to be clamped
-- @tparam number min The lower bound of the accepted range --- @param min number The lower bound of the accepted range
-- @tparam number max The upper bound of the accepted range --- @param max number The upper bound of the accepted range
-- @treturn number The input number clamped to the given range --- @return number
math.clamp = function(num, min, max) math.clamp = function(num, min, max)
if num < min then if num < min then
return min return min
@@ -37,28 +37,37 @@ math.clamp = function(num, min, max)
end end
--- Returns the slope / gradient of a line given two points on the line --- Returns the slope / gradient of a line given two points on the line
-- @tparam number x1 The X coordinate of the first point on the line --- @param x1 number The X coordinate of the first point on the line
-- @tparam number y1 The Y coordinate of the first point on the line --- @param y1 number The Y coordinate of the first point on the line
-- @tparam number x2 The X coordinate of the second point on the line --- @param x2 number The X coordinate of the second point on the line
-- @tparam number y2 The Y coordinate of the second point on the line --- @param y2 number The Y coordinate of the second point on the line
-- @treturn number The slope of the line --- @return number
math.slope = function(x1, y1, x2, y2) math.slope = function(x1, y1, x2, y2)
return abs((y2 - y1) / (x2 - x1)) return abs((y2 - y1) / (x2 - x1))
end end
--- Returns the y-intercept of a line given ibe point on the line and its slope --- Returns the y-intercept of a line given ibe point on the line and its slope
-- @tparam number x The X coordinate of point on the line --- @param x number The X coordinate of point on the line
-- @tparam number y The Y coordinate of point on the line --- @param y number The Y coordinate of point on the line
-- @tparam number slope The slope / gradient of the line --- @param slope number The slope / gradient of the line
-- @treturn number The y-intercept of the line --- @return number
math.y_intercept = function(x, y, slope) math.y_intercept = function(x, y, slope)
return y - (slope * x) return y - (slope * x)
end end
local deg_to_rad = math.tau / 360 local deg_to_rad = math.tau / 360
--- Returns the angle x (given in radians) in degrees --- Returns the angle x (given in radians) in degrees
--- @param x number
--- @return number
math.degrees = function(x) math.degrees = function(x)
return x * deg_to_rad return x * deg_to_rad
end end
--- Returns the sign of the input value
--- @param x number
--- @return number
math.sign = function(x)
return x < 0 and -1 or 0
end
return math return math