blob: b7486f570f296289f62dab53f0b645d13311e25d (
plain)
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
|
from operationscore.Behavior import *
class Oval(Behavior):
def processResponse(self, sensors, recurs):
ret = []
for data in sensors:
#import pdb; pdb.set_trace()
height = width = 1
if 'Height' in self:
height = 1/float(self['Height'])
if 'Width' in self:
width = 1/float(self['Width'])
if 'CenterLoc' in data:
xLoc = data['CenterLoc'][0]
yLoc = data['CenterLoc'][1]
else:
data['CenterLoc'] = tuple(data['Location'])
xLoc = data['Location'][0]
yLoc = data['Location'][1]
if not self['Id']+'Radius' in data:
data[self['Id']+'Radius'] = self['Radius']
rad = data[self['Id']+'Radius']
cond = '>=' if self['Outside'] else '<='
circleStr = \
'math.sqrt((({x}-%(xLoc)d))**2*%(width)d+(({y}-%(yLoc)d)**2)*%(height)d)%(cond)s%(rad)d' % \
locals()
if self['Combine']:
data['Location'] += ',' + circleStr
else:
data['Location'] = circleStr
ret.append(data)
return (ret, [])
def setLastOutput(self, output):
coutput = Behavior.deepCopyPacket(output)
for data in coutput:
data['Location'] = data['CenterLoc']
return coutput
|