in mae_envs/modules/walls.py [0:0]
def choose_new_split(walls, min_dist_between, num_tries=10, random_state=np.random.RandomState()):
'''
Given a list of walls, choose a random wall and draw a new wall perpendicular to it.
NOTE: Right now this O(n_walls^2). We could probably get this to linear if we did
something smarter with the occupancy grid. Until n_walls gets way bigger this
should be fine though.
Args:
walls (Wall list): walls to possibly draw a new wall from
min_dist_between (int): closest another parallel wall can be to the new wall in grid cells.
num_tries (int): number of times before we can fail in placing a wall before giving up
random_state (np.random.RandomState): random state to use for sampling
'''
for i in range(num_tries):
wall1 = random_state.choice(walls)
proposed_walls = [connect_walls(wall1, wall2, min_dist_between, random_state=random_state)
for wall2 in walls if wall2 != wall1]
proposed_walls = [wall for wall in proposed_walls
if wall is not None
and not np.any([wall.intersects(_wall) for _wall in walls])]
if len(proposed_walls):
new_wall = random_state.choice(proposed_walls)
for wall in walls:
wall.maybe_add_edge(new_wall)
new_wall.maybe_add_edge(wall)
return new_wall
return None