-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhumangrid.lua
executable file
·71 lines (62 loc) · 1.62 KB
/
humangrid.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
local class = require "middleclass.middleclass"
local Grid = require "grid"
local HumanGrid = class("HumanGrid", Grid)
local global = require "global"
local Collidable = require "collidable"
function HumanGrid:initialize(w, h, cellsize)
Grid.initialize(self, w, h, cellsize)
self.destx = nil
self.desty = nil
end
function HumanGrid:setDest(x, y)
self.destx = x
self.desty = y
end
function HumanGrid:clearDest()
self.destx = nil
self.desty = nil
end
function HumanGrid:compute()
self:reset()
for e, _ in pairs(global.entities) do
if e:isInstanceOf(Collidable) then
if e.w and e.h then
self:putRegion(
function (i, j)
self.resistances[i][j] = e:humanResistance()
end,
e.x, e.y, e.w, e.h
)
else
local x, y = e:center()
self:put(
function (i, j)
self.resistances[i][j] = e:humanResistance()
end,
x, y
)
end
end
end
if self.destx and self.desty then
self:put(
function (i, j)
self.pre_weights[i][j] = 0
end,
self.destx, self.desty
)
end
Grid.compute(self)
end
function HumanGrid:gradientAt(x, y)
local dx, dy = Grid.gradientAt(self, x, y)
local function isnan(x)
return x ~= x
end
if (dx == 0 and dy == 0) or isnan(dx) or isnan(dy) then
dx = 0
dy = 0
end
return dx, dy
end
return HumanGrid