-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
71 lines (64 loc) · 1.74 KB
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function safeIndex(t, ...)
for _, k in pairs({...}) do
if type(t) ~= 'table' then return nil end
t = t[k]
end
return t
end
function lerpAngle(a, b, t)
local theta = b - a
if theta > math.pi then
a = a + 2*math.pi
elseif theta < -math.pi then
a = a - 2*math.pi
end
return lume.lerp(a, b, t)
end
function hash(x)
local z = math.sin(x)*43758.5453
return z - math.floor(z)
end
function hash2(x, y)
local z = math.sin(x*12.9898 + y*78.233)*43758.5453
return z - math.floor(z)
end
ease = {
inQuad = function (t) return t*t end,
outQuad = function (t) return t*(2-t) end,
inOutQuad = function (t) return t<0.5 and 2*t*t or -1+(4-2*t)*t end,
inCubic = function (t) return t*t*t end,
outCubic = function (t) return math.pow(t-1,3)+1 end,
inOutCubic = function (t) return t<0.5 and 4*t*t*t or (t-1)*(2*t-2)*(2*t-2)+1 end,
inQuart = function (t) return t*t*t*t end,
outQuart = function (t) return 1-math.pow(t-1,4) end,
inOutQuart = function (t) return t<0.5 and 8*math.pow(t,4) or 1-8*math.pow(t-1,4) end,
inQuint = function (t) return t*t*t*t*t end,
outQuint = function (t) return 1+math.pow(t-1,5) end,
inOutQuint = function (t) return t<0.5 and 16*math.pow(t,5) or 1+16*math.pow(t-1,5) end
}
function buildName(name, postfix)
return name .. (postfix ~= 0 and '(' .. postfix .. ')' or '')
end
function isort(_t, comp, rev)
if comp == nil then
comp = function(a, b) return a < b end
elseif type(comp) ~= 'function' then
local k = comp
comp = function(a, b) return a[k] < b[k] end
end
if rev then
_comp = comp
comp = function(a, b) return not _comp(a, b) end
end
local t = {}
for i=1, #_t do
local v = _t[i]
local j = i - 1
while j > 0 and not comp(t[j], v) do
t[j+1] = t[j]
j = j - 1
end
t[j+1] = v
end
return t
end