mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 03:25:23 +09:00
Update types in math include
This commit is contained in:
@@ -13,19 +13,19 @@ math.inv_sqrt2 = 1 / math.sqrt2
|
||||
math.tau = 2 * math.pi
|
||||
|
||||
--- Rounds a number to certain number of decimal places, does not work on significant figures
|
||||
-- @tparam number num The number to be rounded
|
||||
-- @tparam[opt=0] number idp The number of decimal places to round to
|
||||
-- @treturn number The input number rounded to the given number of decimal places
|
||||
--- @param num number The number to be rounded
|
||||
--- @param idp number? The number of decimal places to round to
|
||||
--- @return number
|
||||
math.round = function(num, idp)
|
||||
local mult = 10 ^ (idp or 0)
|
||||
return floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
--- Clamp a number better a minimum and maximum value, preserves NaN (not the same as nil)
|
||||
-- @tparam number num The number to be clamped
|
||||
-- @tparam number min The lower bound of the accepted range
|
||||
-- @tparam number max The upper bound of the accepted range
|
||||
-- @treturn number The input number clamped to the given range
|
||||
--- @param num number The number to be clamped
|
||||
--- @param min number The lower bound of the accepted range
|
||||
--- @param max number The upper bound of the accepted range
|
||||
--- @return number
|
||||
math.clamp = function(num, min, max)
|
||||
if num < min then
|
||||
return min
|
||||
@@ -37,28 +37,37 @@ math.clamp = function(num, min, max)
|
||||
end
|
||||
|
||||
--- 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
|
||||
-- @tparam number y1 The Y coordinate of the first point on the line
|
||||
-- @tparam number x2 The X coordinate of the second point on the line
|
||||
-- @tparam number y2 The Y coordinate of the second point on the line
|
||||
-- @treturn number The slope of the line
|
||||
--- @param x1 number The X coordinate of the first point on the line
|
||||
--- @param y1 number The Y coordinate of the first point on the line
|
||||
--- @param x2 number The X coordinate of the second point on the line
|
||||
--- @param y2 number The Y coordinate of the second point on the line
|
||||
--- @return number
|
||||
math.slope = function(x1, y1, x2, y2)
|
||||
return abs((y2 - y1) / (x2 - x1))
|
||||
end
|
||||
|
||||
--- 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
|
||||
-- @tparam number y The Y coordinate of point on the line
|
||||
-- @tparam number slope The slope / gradient of the line
|
||||
-- @treturn number The y-intercept of the line
|
||||
--- @param x number The X coordinate of point on the line
|
||||
--- @param y number The Y coordinate of point on the line
|
||||
--- @param slope number The slope / gradient of the line
|
||||
--- @return number
|
||||
math.y_intercept = function(x, y, slope)
|
||||
return y - (slope * x)
|
||||
end
|
||||
|
||||
local deg_to_rad = math.tau / 360
|
||||
--- Returns the angle x (given in radians) in degrees
|
||||
--- @param x number
|
||||
--- @return number
|
||||
math.degrees = function(x)
|
||||
return x * deg_to_rad
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user