-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaths.lua
56 lines (46 loc) · 1.01 KB
/
maths.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
PI = math.pi
TAU = math.pi * 2
--
function collidePointCircle (vector, centerPoint, radius)
local d = vMag({x = centerPoint.x - vector.x, y = centerPoint.y - vector.y})
if d < radius then
return true
end
end
function collideCircles (centerA, radiusA, centerB, radiusB)
return (centerB.x - centerA.x)^2 + (centerB.y - centerA.y)^2 < (radiusA + radiusB)^2
end
--
function randomRealBetween(lowerBound, upperBound)
local n = math.random()
local range = upperBound - lowerBound
n = n * range
n = n + lowerBound
return n
end
function randomIntegerBetween(lowerBound, upperBound)
return math.random(lowerBound, upperBound)
end
--
function randomElement(t)
local keys, i = {}, 1
for k,_ in pairs(t) do
keys[i] = k
i = i + 1
end
local m = randomIntegerBetween(1, #keys)
return t[ keys[m] ]
end
function tableSize(t)
local size = 0
for _,v in pairs(t) do
if v ~= nil then size = size + 1 end
end
return size
end
function appendToTable(t1, t2)
for _,v in pairs(t2) do
table.insert(t1, v)
end
return t1
end