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