create GraphArea.check_connection
This commit is contained in:
parent
0b44acc8b0
commit
e3990fcaf0
1 changed files with 51 additions and 51 deletions
|
@ -30,15 +30,24 @@ class GraphArea():
|
|||
|
||||
def build_connections(self):
|
||||
for point1, point2 in combinations(self._built_points, 2):
|
||||
|
||||
there, back = self.check_connection(point1, point2)
|
||||
|
||||
if there is not None:
|
||||
point1.connect_to(point2, ctype=there)
|
||||
|
||||
if back is not None:
|
||||
point2.connect_to(point1, ctype=back)
|
||||
|
||||
def check_connection(self, point1, point2):
|
||||
path = Path(np.vstack((point1.xy, point2.xy)))
|
||||
|
||||
# lies within room
|
||||
if self.mpl_clear.intersects_path(path):
|
||||
continue
|
||||
return None, None
|
||||
|
||||
# stair checker
|
||||
angle = coord_angle(point1.xy, point2.xy)
|
||||
valid = True
|
||||
stair_direction_up = None
|
||||
for stair_path, stair_angle in self.mpl_stairs:
|
||||
if not path.intersects_path(stair_path):
|
||||
|
@ -50,19 +59,13 @@ class GraphArea():
|
|||
if stair_direction_up is None:
|
||||
stair_direction_up = new_direction_up
|
||||
elif stair_direction_up != new_direction_up:
|
||||
valid = False
|
||||
break
|
||||
return None, None
|
||||
|
||||
if not (40 < abs(angle_diff) < 150):
|
||||
valid = False
|
||||
break
|
||||
|
||||
if not valid:
|
||||
continue
|
||||
return None, None
|
||||
|
||||
# escalator checker
|
||||
angle = coord_angle(point1.xy, point2.xy)
|
||||
valid = True
|
||||
escalator_direction_up = None
|
||||
escalator_swap_direction = False
|
||||
for escalator in self.escalators:
|
||||
|
@ -71,28 +74,25 @@ class GraphArea():
|
|||
|
||||
if escalator_direction_up is not None:
|
||||
# only one escalator per connection
|
||||
valid = False
|
||||
break
|
||||
return None, None
|
||||
|
||||
angle_diff = ((escalator.angle - angle + 180) % 360) - 180
|
||||
|
||||
escalator_direction_up = (angle_diff > 0)
|
||||
escalator_swap_direction = (escalator_direction_up != escalator.direction_up)
|
||||
|
||||
if not valid:
|
||||
continue
|
||||
|
||||
if stair_direction_up is not None:
|
||||
point1.connect_to(point2, ctype=('stairs_up' if stair_direction_up else 'stairs_down'))
|
||||
point2.connect_to(point1, ctype=('stairs_down' if stair_direction_up else 'stairs_up'))
|
||||
return (
|
||||
('stairs_up' if stair_direction_up else 'stairs_down'),
|
||||
('stairs_down' if stair_direction_up else 'stairs_up'),
|
||||
)
|
||||
elif escalator_direction_up is not None:
|
||||
if not escalator_swap_direction:
|
||||
point1.connect_to(point2, ctype=('escalator_up' if escalator_direction_up else 'escalator_down'))
|
||||
return ('escalator_up' if escalator_direction_up else 'escalator_down'), None
|
||||
else:
|
||||
point2.connect_to(point1, ctype=('escalator_down' if escalator_direction_up else 'escalator_up'))
|
||||
else:
|
||||
point1.connect_to(point2)
|
||||
point2.connect_to(point1)
|
||||
return None, ('escalator_down' if escalator_direction_up else 'escalator_up')
|
||||
|
||||
return '', ''
|
||||
|
||||
def add_point(self, point):
|
||||
if not self.mpl_clear.contains_point(point.xy):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue