-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathState.py
36 lines (31 loc) · 1.32 KB
/
State.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
import skgeom as sg
from scikit_utils import get_tuple_from_polygon_set
class State:
def __init__(self, position, parent, contaminated_shadows, safezones, neighbors=[]):
self.pos = position # Tuple (x,y)
self.contaminated_shadows = contaminated_shadows # PolygonSet
self.safezones = safezones # PolygonSet
self.neighbors_pos = neighbors # List[(x,y),(x,y)]
self.safezones_tuple = get_tuple_from_polygon_set(self.safezones)
self.shadows_tuple = get_tuple_from_polygon_set(self.contaminated_shadows)
self.parent = parent
def as_point(self):
return sg.Point2(self.pos[0], self.pos[1])
def __eq__(self, other):
if type(self) != type(other):
return False
shadows_diff = self.contaminated_shadows.difference(other.contaminated_shadows)
# print(shadows_diff)
if shadows_diff:
return False
safezones_diff = self.safezones.difference(other.safezones)
# print(safezones_diff)
if safezones_diff:
return False
if self.pos[0] != other.pos[0] or self.pos[1] != other.pos[1]:
return False
return True
def __ne__(self, other):
return not self.__eq__(other)
def __hash__(self):
return hash((self.pos, self.safezones_tuple, self.shadows_tuple))