mirror of
https://github.com/t-affeldt/climate_api.git
synced 2024-11-16 23:50:26 +01:00
59bf43aa28
* Remove is_connected() and use minetest counterpart * Less calls to minetest.get_connected_players() * Deprecated: get_player_velocity * Luacheck: unused assignements * Luacheck: unused variable * Luacheck: already declared variable --------- Co-authored-by: mazes 80 <>
35 lines
891 B
Lua
35 lines
891 B
Lua
local utility = {}
|
|
|
|
function utility.rangelim(value, min, max)
|
|
return math.min(math.max(value, min), max)
|
|
end
|
|
|
|
-- from https://stackoverflow.com/a/29133654
|
|
-- merges two tables together
|
|
-- if in conflict, b will override values of a
|
|
function utility.merge_tables(a, b)
|
|
if type(a) == "table" and type(b) == "table" then
|
|
for k,v in pairs(b) do
|
|
if type(v)=="table" and type(a[k] or false)=="table" then
|
|
utility.merge_tables(a[k],v)
|
|
else a[k]=v end
|
|
end
|
|
end
|
|
return a
|
|
end
|
|
|
|
-- see https://en.wikipedia.org/wiki/Logistic_function
|
|
function utility.sigmoid(value, max, growth, midpoint)
|
|
return max / (1 + math.exp(-growth * (value - midpoint)))
|
|
end
|
|
|
|
-- generates a wave of cycle length 1
|
|
-- maps parameters to values between 0 and 1
|
|
-- 0 is mapped to 0 and 0.5 to 1
|
|
function utility.normalized_cycle(value)
|
|
return math.cos((2 * value + 1) * math.pi) / 2 + 0.5
|
|
end
|
|
|
|
|
|
return utility
|