-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtypes.py
150 lines (115 loc) · 3.38 KB
/
types.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import dataclasses
import enum
class ColorProfile(enum.Enum):
auto = "auto"
cloud = "cloud"
rainbow = "rainbow"
def __str__(self):
return self.value
class Stat:
"""
Defines a summary stat describing the solution.
"""
def __init__(self, name, desc, stat):
self.desc = desc
self.name = name
self.val = stat
@dataclasses.dataclass
class BoundingBox:
"""
Represents a bounding box.
"""
min_x: float
max_x: float
min_y: float
max_y: float
def __post_init__(self):
self.width = self.max_x - self.min_x
self.height = self.max_y - self.min_y
def __str__(self):
return f"BoundingBox(min_x={self.min_x}, max_x={self.max_x}, " + f"min_y={self.min_y}, max_y={self.max_y})"
@dataclasses.dataclass
class Position:
lon: float
lat: float
desc: str
distance: float = 0
def __getitem__(self, key):
if key == 0:
return self.lon
elif key == 1:
return self.lat
else:
raise Exception(f'Unrecognized key "{key}", use 0 for lon and 1 for lat')
def __str__(self) -> str:
return f"Pos({self.lon},{self.lat})"
@staticmethod
def equal(p1, p2) -> bool:
"""
Compares the two points for equality.
"""
return p1.lon == p2.lon and p1.lat == p2.lat
def clone(self):
"""
Creates a clone of this position.
"""
return Position(self.lon, self.lat, self.desc, self.distance)
class Point:
"""
Defines one point and is used to append additional info to it.
"""
def __init__(self, points):
self.points = points
def __str__(self):
return ",".join(self.point[0]) if len(self.point) > 0 else "empty"
class Cluster:
"""
Defines one cluster and is used to append additional info to it.
"""
def __init__(self, cluster):
self.points = cluster
def __str__(self):
return f"len: {len(self.points)}"
class Route:
"""
Defines one route and is used to append additional info for it.
"""
def __init__(self, points: list[Position]):
self.points = points
self.legs = None
self.leg_costs = 0
def to_points(self, omit_start: bool, omit_end: bool) -> list[Position]:
"""
Returns all points of the route.
"""
ps = []
start = 1 if omit_start else 0
stop = len(self.points) - 1 if omit_end else len(self.points)
for i in range(start, stop):
ps.append(self.points[i])
return ps
def to_polyline(self, omit_start: bool, omit_end: bool) -> list[Position]:
"""
Returns the full polyline that can be used for plotting.
"""
line = []
start = 1 if omit_start else 0
stop = len(self.points) - 1 if omit_end else len(self.points)
if self.legs is not None:
for i in range(start, stop - 1):
line.extend(self.legs[i])
else:
for i in range(start, stop):
line.append(self.points[i])
return line
def __str__(self):
return f"len: {len(self.points)}"
class RouteDirectionIndicator(enum.Enum):
"""
Distinguishes the different route direction indicators.
"""
none = "none"
arrow = "arrow"
animation = "animation"
def __str__(self):
return self.value