-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommons.py
More file actions
executable file
·57 lines (49 loc) · 1.65 KB
/
Commons.py
File metadata and controls
executable file
·57 lines (49 loc) · 1.65 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
#projection mode
class ProjMode:
CENTER = 1
LEFTTOP = 2
#random create color
def randomColor():
r = lambda: random.randint(0,255)
return ('#%02X%02X%02X' % (r(),r(),r()))
#check if two bbox don't overlay
#if they dont overlay, bbox1 is outside of bbox2, return true
def checkIsOutside(bbox1, bbox2):
return bbox1[0] > bbox2[2] or bbox1[1] > bbox2[3] or bbox1[2] < bbox2[0] or bbox1[3] < bbox2[1]
#project map coordinate to screen coordinate in different mode
def transformX(x, map):
if map.mode == ProjMode.CENTER:
return (x - map.center.x)*map.ratio + 400
elif map.mode == ProjMode.LEFTTOP :
return int((x-map.minx)*map.ratio)
else:
return None
def transformY(y, map):
if map.mode == ProjMode.CENTER:
return (map.center.y - y)*map.ratio + 300
elif map.mode == ProjMode.LEFTTOP:
return int((map.maxy-y)*map.ratio)
else:
return None
#project screen coordinates to map corrdications
def transform2X(winx, map):
if map.mode == ProjMode.CENTER:
return (winx - 400)/map.ratio + map.center.x
elif map.mode == ProjMode.LEFTTOP :
return winx/map.ratio + map.minx
else:
return None
def transform2Y(winy, map):
if map.mode == ProjMode.CENTER:
return map.center.y - (winy -300)/map.ratio
elif map.mode == ProjMode.LEFTTOP:
return map.maxy-winy/map.ratio
else:
return None
def unbindCanvas(can):
can.unbind('<ButtonPress-1>')
can.unbind('<B1-Motion>')
can.unbind('<ButtonRelease-1>')
can.unbind('<Button-1>')
can.unbind('<Button-3>')