예제 #1
0
 def test_that_it_fails_on_undefined_domain(self):
     tessagon = FakeTessagon()
     # No u_range, v_range, corner options passed
     with pytest.raises(ValueError) as exception_info:
         AbstractTile(tessagon)
     assert "Must set either option 'corners' or "\
         "options 'u_range' and 'v_range'" in str(exception_info.value)
예제 #2
0
    def test_blend_when_initialized_with_ranges(self):
        tessagon = FakeTessagon()
        tile = AbstractTile(tessagon, u_range=[0.5, 1.0], v_range=[2.5, 4.5])

        assert tile.blend(0, 0) == [0.5, 2.5]
        assert tile.blend(1, 0) == [1.0, 2.5]
        assert tile.blend(0, 1) == [0.5, 4.5]
        assert tile.blend(1, 1) == [1.0, 4.5]
        assert tile.blend(0.5, 0.25) == [0.75, 3.0]
        assert tile.blend(0.75, 0.5) == [0.875, 3.5]
예제 #3
0
    def test_blend_when_initialized_with_corners(self):
        tessagon = FakeTessagon()
        tile = AbstractTile(tessagon,
                            corners=[[0.5, 2.5], [1.5, 4.5], [1.5, 4.5],
                                     [2.5, 6.5]])

        assert tile.blend(0, 0) == [0.5, 2.5]
        assert tile.blend(1, 0) == [1.5, 4.5]
        assert tile.blend(0, 1) == [1.5, 4.5]
        assert tile.blend(1, 1) == [2.5, 6.5]
        assert tile.blend(0.5, 0.5) == [1.5, 4.5]
예제 #4
0
    def test_add_vert(self):
        tessagon = FakeTessagon()
        tile = FakeTileSubClass(tessagon, u_range=[0.5, 1.0],
                                v_range=[2.5, 3.0])
        tile.add_vert(['top', 'left'], 0.25, 0.75)
        assert tile.blend(0.25, 0.75) == [0.625, 2.875]

        # One vert added
        assert tile.verts['top']['left'] == tile.f(0.625, 2.875)
        assert tile.verts['top']['right'] is None
        assert tile.verts['bottom']['left'] is None
        assert tile.verts['bottom']['right'] is None
예제 #5
0
    def test_add_vert_u_v_symmetric(self):
        tessagon = FakeTessagon()
        tile = FakeTileSubClass(tessagon, u_range=[0.5, 1.0],
                                v_range=[2.5, 3.0],
                                u_symmetric=True, v_symmetric=True)
        tile.add_vert(['top', 'left'], 0.25, 0.75)
        # [0.75, 0.25] is reflection of [0.25, 0.75] in U and V directions
        assert tile.blend(0.75, 0.25) == [0.875, 2.625]

        # Four verts added
        assert tile.verts['top']['left'] == tile.f(0.625, 2.875)
        assert tile.verts['top']['right'] == tile.f(0.875, 2.875)
        assert tile.verts['bottom']['left'] == tile.f(0.625, 2.625)
        assert tile.verts['bottom']['right'] == tile.f(0.875, 2.625)
예제 #6
0
    def test_neighbors(self):
        tessagon = FakeTessagon()
        tile = AbstractTile(tessagon, u_range=[0.5, 1.0], v_range=[2.5, 4.0])
        tiles = []
        for i in range(5):
            tiles.append(
                AbstractTile(tessagon, u_range=[0.5, 1.0], v_range=[2.5, 4.0]))
        tile.set_neighbors(top=tiles[0],
                           bottom=tiles[1],
                           right=tiles[2],
                           left=tiles[3])
        tiles[3].set_neighbors(top=tiles[4])

        assert tile.get_neighbor_tile(['left']) == tiles[3]
        assert tile.get_neighbor_tile(['right']) == tiles[2]
        assert tile.get_neighbor_tile(['top']) == tiles[0]
        assert tile.get_neighbor_tile(['bottom']) == tiles[1]
        assert tile.get_neighbor_tile(['left', 'top']) == tiles[4]
예제 #7
0
    def test_u_v_cyclic(self):
        tessagon = FakeTessagon()
        tile_generator = TileGenerator(tessagon,
                                       u_range=[0.5, 1.0],
                                       v_range=[2.5, 4.0],
                                       u_num=2,
                                       v_num=3,
                                       u_cyclic=True,
                                       v_cyclic=True)
        tiles = tile_generator.initialize_tiles(FakeTileSubClass)
        assert len(tiles) == 2
        assert len(tiles[0]) == 3
        assert len(tiles[1]) == 3

        tile_generator.initialize_neighbors(tiles)
        assert (tiles[0][0].get_neighbor_tile(['left']) is tiles[1][0])
        assert (tiles[0][0].get_neighbor_tile(['bottom']) is tiles[0][2])
        assert (tiles[0][0].get_neighbor_tile(['right']) is tiles[1][0])
        assert (tiles[0][0].get_neighbor_tile(['top']) is tiles[0][1])

        assert (tiles[1][2].get_neighbor_tile(['left']) is tiles[0][2])
        assert (tiles[1][2].get_neighbor_tile(['bottom']) is tiles[1][1])
        assert (tiles[1][2].get_neighbor_tile(['right']) is tiles[0][2])
        assert (tiles[1][2].get_neighbor_tile(['top']) is tiles[1][0])
예제 #8
0
 def test_u_range_v_range_params(self):
     tessagon = FakeTessagon()
     tile = AbstractTile(tessagon, u_range=[0.5, 1.0], v_range=[2.5, 4.0])
     assert (tile.corners == [[0.5, 2.5], [1, 2.5], [0.5, 4.0], [1.0, 4.0]])
예제 #9
0
 def test_corner_params(self):
     tessagon = FakeTessagon()
     tile = AbstractTile(tessagon,
                         corners=[[0.5, 2.5], [1, 2.5], [0.5, 4.0],
                                  [1.0, 4.0]])
     assert (tile.corners == [[0.5, 2.5], [1, 2.5], [0.5, 4.0], [1.0, 4.0]])