TraffiSim 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
traffisim/utils.py ADDED
@@ -0,0 +1,50 @@
1
+ """
2
+ utils.py
3
+ --------
4
+ Helper functions for TraffiSim.
5
+ """
6
+
7
+ import math
8
+
9
+ def dist(a, b):
10
+ """
11
+ Euclidean distance between points a and b.
12
+ """
13
+ return math.hypot(a[0] - b[0], a[1] - b[1])
14
+
15
+ def define_exit_point(cx, cy, direction, turn, SCREEN_WIDTH, SCREEN_HEIGHT):
16
+ """
17
+ Return the final exit coordinate for a vehicle that starts in 'direction'
18
+ and picks 'turn' among {'left','straight','right'}.
19
+ Used for full-route mode.
20
+ """
21
+ margin = 100
22
+ if direction == 'N':
23
+ if turn == 'left':
24
+ return (-margin, cy)
25
+ elif turn == 'right':
26
+ return (SCREEN_WIDTH + margin, cy)
27
+ else:
28
+ return (cx, SCREEN_HEIGHT + margin)
29
+ elif direction == 'S':
30
+ if turn == 'left':
31
+ return (SCREEN_WIDTH + margin, cy)
32
+ elif turn == 'right':
33
+ return (-margin, cy)
34
+ else:
35
+ return (cx, -margin)
36
+ elif direction == 'E':
37
+ if turn == 'left':
38
+ return (cx, -margin)
39
+ elif turn == 'right':
40
+ return (cx, SCREEN_HEIGHT + margin)
41
+ else:
42
+ return (-margin, cy)
43
+ elif direction == 'W':
44
+ if turn == 'left':
45
+ return (cx, SCREEN_HEIGHT + margin)
46
+ elif turn == 'right':
47
+ return (cx, -margin)
48
+ else:
49
+ return (SCREEN_WIDTH + margin, cy)
50
+ return (cx, cy)