aboutsummaryrefslogtreecommitdiff
path: root/pixelmappers
diff options
context:
space:
mode:
authorGravatar Russell <rcoh@rcoh.(none)>2011-01-10 12:21:19 -0500
committerGravatar Russell <rcoh@rcoh.(none)>2011-01-10 12:21:19 -0500
commitcbdc42af021f898e82d3e78ce7c636d3fb5eece0 (patch)
treef36ca72463702c104dd02f026e9fbcd6de3f0da8 /pixelmappers
parent1679719e7ca8ce433c5714474a32c926161dc5b8 (diff)
Some performance improvements. Faster evaluation of range-based queries with
lambda expressions. Faster exp with approximated fastexp. Some changes to the component registry.
Diffstat (limited to 'pixelmappers')
-rw-r--r--pixelmappers/SimpleMapper.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/pixelmappers/SimpleMapper.py b/pixelmappers/SimpleMapper.py
index 4d12fe4..2df24e0 100644
--- a/pixelmappers/SimpleMapper.py
+++ b/pixelmappers/SimpleMapper.py
@@ -14,17 +14,21 @@ class SimpleMapper(PixelMapper):
bestPixel = pixel
bestDist = pixelDist
return [(bestPixel,1)]
- elif type(type(str)):
- #[{x}>5,{y}<k]
+ else:
+ #{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]')
+ conditions = eventLocation.split(',')
+ conditionLambdas = [eval('lambda pixel:'+condition) for condition in conditions]
for pixel in screen:
try:
- preValid = eval(eventLocation)
- pixelValid = sum(preValid) == len(preValid) #TODO: some
- #optimizations possible. This might be slow in the long run
+ pixelValid = True
+ for p in conditionLambdas:
+ if p(pixel) == False:
+ pixelValid = False
+ continue
if pixelValid:
ret.append((pixel, 1))
except Exception as exp: