def test_merge(self):
        border = Boundary()

        border.merge(boundary.get_tile(Vect(0, 0), 'FFFF'))
        self.assertEqual(len(border), 4)
        self.assertEqual(border.labels, list('FFFF'))

        border.merge(boundary.get_tile(Vect(1, 0), 'FFFF'))
        self.assertEqual(len(border), 6)
        self.assertEqual(border.labels, list('FFFFFF'))
 def test_common_segments_1(self):
     tile1 = boundary.get_tile(Vect(2, 1), 'FFFF')
     self.assertEqual(self.border.common_segments(tile1), [(3, 0, 0)])
     tile2 = boundary.get_tile(Vect(1, 1), 'FFFF')
     self.assertEqual(self.border.common_segments(tile2), [(3, 0, 1)])
     self.assertEqual(tile1.common_segments(tile2), [(3, 1, 1)])
     self.assertEqual(tile2.common_segments(tile1), [(1, 3, 1)])
     tile3 = Boundary()
     tile3.append(Vect(2, 2), 'F')
     tile3.append(Vect(1, 2), 'F')
     tile3.append(Vect(1, 1), 'F')
     tile3.append(Vect(2, 1), 'F')
     self.assertEqual(tile1.common_segments(tile3), [(3, 3, 1)])
     self.assertEqual(tile3.common_segments(tile1), [(3, 3, 1)])
 def test_find_matching_rotations(self):
     tiles_args = [
         (Vect(0, 0), 'FFFF'),
         (Vect(0, 1), 'FFFF'),
         (Vect(1, 1), 'TFFF')]
     border = make_border_from_tiles(tiles_args)
     border.rotate_to_start_with(Vect(0, 0))
     self.assertEqual(len(border), 8)
     self.assertEqual(border.labels, list('FFTFFFFF'))
     tile = boundary.get_tile(Vect(1, 0), 'TFFF')
     self.assertEqual(border.common_segments(tile), [(1, 2, 2)])
     self.assertEqual(list(border.find_matching_rotations(tile, (1, 2, 2))), [2])
 def test_corner_case_1(self):
     tiles_args = [
         (Vect(1, 0), 'FFFF'),
         (Vect(2, 0), 'FFFF'),
         (Vect(2, 1), 'FFFF'),
         (Vect(2, 2), 'FFFF'),
         (Vect(1, 2), 'FFFF'),
         (Vect(0, 2), 'FFFF')]
     border = make_border_from_tiles(tiles_args)
     self.assertEqual(len(border), 14)
     tile = boundary.get_tile(Vect(0, 1), 'FFFF')
     segments = border.common_segments(tile)
     self.assertEqual(len(segments), 2)
 def test_get_tile(self):
     bottom_left = Vect(5, 7)
     tile = boundary.get_tile(bottom_left, 'FFTF')
     self.assertEqual(len(tile), 4)
     self.assertEqual(tile.orientation(), Orientation.COUNTERCLOCKWISE)
     self.assertEqual(tile.get_point(0), bottom_left)
     self.assertEqual(tile.bottom_left(), bottom_left)
     self.assertEqual(tile.get_edge(0), Vect(1, 0))
     self.assertEqual(tile.get_edge(1), Vect(0, 1))
     self.assertEqual(tile.get_edge(2), Vect(-1, 0))
     self.assertEqual(tile.get_edge(3), Vect(0, -1))
     self.assertEqual(tile.get_label(0), 'F')
     self.assertEqual(tile.get_label(2), 'T')
 def test_common_segments_2(self):
     tiles_bottom_left = [Vect(0, 0), Vect(1, 0), Vect(1, 1), Vect(0, 1)]
     for single_idx in range(4):
         single_tile = boundary.get_tile(tiles_bottom_left[single_idx])
         three_other_tiles = [(bl,) for bl in tiles_bottom_left[single_idx+1:] + tiles_bottom_left[:single_idx]]
         border = make_border_from_tiles(three_other_tiles)
         self.assertEqual(len(border), 8)
         border.rotate_to_start_with(Vect(1, 1))
         for ii in range(len(border)):
             segments = border.common_segments(single_tile)
             self.assertEqual(len(segments), 1)
             (i, j, L) = segments[0]
             self.assertEqual(L, 2)
             self.assertEqual(j, (single_idx + 1) % 4)
             self.assertEqual(i, 7 - ii)
             border.rotate_to_start_with(border.points[1])
def make_border_from_tiles(tiles_args):
    return functools.reduce(lambda border, args: border.merge(boundary.get_tile(*args)), tiles_args, Boundary())
示例#8
0
 def get_boundary(self, desc = [None, None, None, None]):
     return boundary.get_tile(self.pos, desc)