diff options
author | rcoh <rcoh@mit.edu> | 2010-12-14 20:36:48 -0500 |
---|---|---|
committer | rcoh <rcoh@mit.edu> | 2010-12-14 20:36:48 -0500 |
commit | 17577b1b19387b2cefb7ac777ed1323dd36be086 (patch) | |
tree | b7037bf63730184f6050946ab8b4d0a3839af4c1 /pixelmappers | |
parent | 8cecf83f16fcdec5b3ee68cc40c2b360e0f845d0 (diff) |
early stages of support for pixel regions
Diffstat (limited to 'pixelmappers')
-rw-r--r-- | pixelmappers/SimpleMapper.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py index 7d730f1..45082b5 100644 --- a/pixelmappers/SimpleMapper.py +++ b/pixelmappers/SimpleMapper.py @@ -2,13 +2,25 @@ from operationscore.PixelMapper import * import Util class SimpleMapper(PixelMapper): def mappingFunction(self, eventLocation, screen): - bestDist = 10**10 #don't kill me, I'm lazy - bestPixel = None - for pixel in screen: - pixelDist = Util.dist(pixel.location, eventLocation) - if pixelDist < bestDist: - bestPixel = pixel - bestDist = pixelDist - return [(bestPixel,1)] - - + if type(eventLocation) == type(tuple()): + bestDist = 10**10 #don't kill me, I'm lazy + bestPixel = None + for pixel in screen: + pixelDist = Util.dist(pixel.location, eventLocation) + if pixelDist < bestDist: + bestPixel = pixel + bestDist = pixelDist + return [(bestPixel,1)] + elif type(type(str)): + #[{x}>5,{y}<k] + #TODO: we should probably encapsulate this somewhere + ret = [] + eventLocation = eventLocation.replace('{x}', 'pixel.location[0]') + eventLocation = eventLocation.replace('{y}', 'pixel.location[1]') + for pixel in screen: + try: + pixelValid = sum(eval(eventLocation)) == len(eventLocation) + ret.append((pixel, 1)) + except: + raise Exception('Bad event condition') + return ret |