blob: 5d4dcebcca19a56945570817c62acc26b9a282ce (
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
|
from operationscore.PixelMapper import *
import util.Geo as Geo
class SimpleMapper(PixelMapper):
def mappingFunction(self, eventLocation, screen):
if type(eventLocation) == type(tuple()):
bestDist = 10**10 #don't kill me, I'm lazy
bestPixel = None
for pixel in screen:
pixelDist = Geo.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(eval(eventLocation)) #TODO: some
#optimizations possible. This might be slow in the long run
if pixelValid:
ret.append((pixel, 1))
except Exception as exp:
raise Exception('Bad event condition')
return ret
|