def _init_linked_region(regions_map, boundary): for coord, region in regions_map.items(): for linked_coord in {c for c in generate_square_linked_coordinates(coord) if 0 <= c[0] <= boundary[0] and 0 <= c[1] <= boundary[1]}: linked_region = regions_map.get(linked_coord) if linked_region is not None: region.add_neighbor(linked_region)
def generate_edge_coordinates(coord_map): coords_set = set() for coord in coord_map: for linked_coord in generate_square_linked_coordinates(coord): if linked_coord not in coord_map: coords_set.add(coord) break return coords_set
def test_neighbor_coordinate(self): coord = 0, 0 neighbors = generate_square_linked_coordinates(coord) self.assertEqual(len(neighbors), 8)