-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMathUtils.lua
58 lines (48 loc) · 1018 Bytes
/
MathUtils.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
FloatThreshold= Range(-0.0001,0.0001)
function dumpstr(struct) --NO SELF CALLING STRUCTS !!
dump="{ "
for k,val in pairs(struct) do
local str=""
if type(val)=="table" then
str=""..dumpstr(val)
elseif type(val)~="function" then
str=""..val
end
dump=dump..k.." : "..str.." ; "
end
return dump.." }"
end
function MSnorm(a,b)
return math.sqrt(a*a + b*b)
end
function MSdistance(point1,point2)
return MSnorm(point2.x-point1.x,point2.y-point1.y)
end
function MSoverlapping(min1,max1,min2,max2)
return min2 <= max1 and min1<= max2
end
function MSclamp(x,min,max)
if x<min then
return min
elseif x>max then
return max
else
return x
end
end
function MScollide(a, b)
local type = {
Rectangle= "R",
Circle= "C",
Line= "L",
Segment= "S",
ORectangle= "OR",
Point= "P",
Ray="R"
}
return a["Col"..type[b:type()]](a,b)
end
-- perp from 3 points
function isLeft(p1,p2,p3)
return ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
end