From 6e0e6869a5ee1e4963071a18f24aa4dfdd442689 Mon Sep 17 00:00:00 2001 From: rcoh Date: Sun, 13 Feb 2011 16:03:39 -0500 Subject: Added a circle behavior to make circles. Added ContinuousCenterInput to do what it says. Modified SimpleMapper a bit. --- behaviors/Circle.py | 29 +++++++++++++++++++++++++++++ behaviors/ModifyParam.py | 2 ++ 2 files changed, 31 insertions(+) create mode 100644 behaviors/Circle.py (limited to 'behaviors') diff --git a/behaviors/Circle.py b/behaviors/Circle.py new file mode 100644 index 0000000..24d71f1 --- /dev/null +++ b/behaviors/Circle.py @@ -0,0 +1,29 @@ +from operationscore.Behavior import * +class Circle(Behavior): + def processResponse(self, sensors, recurs): + ret = [] + for data in sensors: + #import pdb; pdb.set_trace() + 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}-'+str(xLoc)+')**2+(({y}-'+str(yLoc)+')**2))'+cond+str(rad) + 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 diff --git a/behaviors/ModifyParam.py b/behaviors/ModifyParam.py index 0ef3a60..ebcb98f 100644 --- a/behaviors/ModifyParam.py +++ b/behaviors/ModifyParam.py @@ -30,6 +30,8 @@ class ModifyParam(Behavior): #TODO: move elsewhere paramOp = paramOp.replace('{y}', "behaviorInput['Location'][1]") paramOp = paramOp.replace('{x}', "behaviorInput['Location'][0]") + if eval(paramOp) == None: + import pdb; pdb.set_trace() behaviorInput[paramName] = eval(paramOp) if paramType == 'Sensor': #return accordingly return (searchSet, recursiveInputs) -- cgit v1.2.3