From 2df9e408a0ff74539862c4a4e562a878cc11a329 Mon Sep 17 00:00:00 2001 From: rcoh Date: Wed, 16 Feb 2011 18:20:36 -0500 Subject: Code cleanup. Made Oval behavior (circle with h/w). --- behaviors/Oval.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 behaviors/Oval.py (limited to 'behaviors/Oval.py') diff --git a/behaviors/Oval.py b/behaviors/Oval.py new file mode 100644 index 0000000..b7486f5 --- /dev/null +++ b/behaviors/Oval.py @@ -0,0 +1,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 -- cgit v1.2.3