1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00
RedMew/utils/math.lua
Matthew c49f5007fa Utils cleanup (#411)
* Clean up unused vars and using same var names

* Autoformat
2018-11-20 11:46:42 +01:00

38 lines
759 B
Lua

local _sin = math.sin
local _cos = math.cos
math.sqrt2 = math.sqrt(2)
math.inv_sqrt2 = 1 / math.sqrt2
math.tau = 2 * math.pi
math.sin = function(x)
return math.floor(_sin(x) * 10000000 + 0.5) / 10000000
end
math.cos = function(x)
return math.floor(_cos(x) * 10000000 + 0.5) / 10000000
end
-- rounds number (num) to certain number of decimal places (idp)
math.round = function(num, idp)
local mult = 10 ^ (idp or 0)
return math.floor(num * mult + 0.5) / mult
end
math.clamp = function(num, min, max)
if num < min then
return min
elseif num > max then
return max
else
return num
end
end
local deg_to_rad = math.tau / 360
math.degrees = function(angle)
return angle * deg_to_rad
end
return math