Exemple #1
0
 def test_rect_region_alt__rect_is_a_point(self):
     # this is emergent behavior , not planed one
     tile_width = tile_height_h = 2
     nrows = 7
     ncols = 6
     cells = [['col_%d_row_%d' % (yy, xx) for xx in range(ncols)]
              for yy in range(nrows)]
     m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
     x1, y1 = 5, 8
     x2, y2 = 5, 8
     overlaps = m.get_in_region(x1, y1, x2, y2)
     print('rect is point:', overlaps)
     assert set(overlaps) == set([])
Exemple #2
0
 def test_rect_region_alt__rect_is_a_segment_not_in_cells_boundary(self):
     # this is emergent behavior , not planed one
     tile_width = tile_height_h = 2
     nrows = 7
     ncols = 6
     cells = [['col_%d_row_%d' % (yy, xx) for xx in range(ncols)]
              for yy in range(nrows)]
     m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
     x1, y1 = 5, 8
     x2, y2 = 5, 12
     overlaps = m.get_in_region(x1, y1, x2, y2)
     print('rect is a segment not overlapping cells boundary:', overlaps)
     assert set(overlaps) == set(['col_2_row_4', 'col_2_row_5'])
Exemple #3
0
 def test_rect_region_alt__rect_is_a_point(self):
     # this is emergent behavior , not planed one
     tile_width = tile_height_h = 2
     nrows = 7
     ncols = 6
     cells = [ [ 'col_%d_row_%d'%(yy, xx) for xx in range(ncols)]
                                                   for yy in range(nrows)]        
     m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
     x1, y1 = 5, 8
     x2, y2 = 5, 8
     overlaps = m.get_in_region(x1, y1, x2, y2)
     print('rect is point:', overlaps)
     assert set(overlaps) == set( [] )
Exemple #4
0
 def test_rect_region_alt__rect_is_a_segment_not_in_cells_boundary(self):
     # this is emergent behavior , not planed one
     tile_width = tile_height_h = 2
     nrows = 7
     ncols = 6
     cells = [ [ 'col_%d_row_%d'%(yy, xx) for xx in range(ncols)]
                                                   for yy in range(nrows)]        
     m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
     x1, y1 = 5, 8
     x2, y2 = 5, 12
     overlaps = m.get_in_region(x1, y1, x2, y2)
     print('rect is a segment not overlapping cells boundary:', overlaps)
     assert set(overlaps) == set( ['col_2_row_4', 'col_2_row_5'] )
Exemple #5
0
def gen_rect_map(meta, w, h):
    r = []
    cell = None
    for i, m in enumerate(meta):
        c = []
        r.append(c)
        for j, info in enumerate(m):
            c.append(RectCell(i, j, w, h, dict(info), Tile('dbg', {}, None)))
    return RectMap('debug', w, h, r)
Exemple #6
0
def gen_recthex_map(meta, h):
    r = []
    cell = None
    w = int(h / math.sqrt(3)) * 2
    for i, m in enumerate(meta):
        c = []
        r.append(c)
        for j, info in enumerate(m):
            c.append(RectCell(i, j, w, h, dict(info), Tile('dbg', {}, None)))
    return RectMap('debug', w, h, r)
Exemple #7
0
    def test_rect_region_alt__rect_with_area_gt_0(self):
        tile_width = tile_height_h = 2
        nrows = 7
        ncols = 6
        cells = [['col_%d_row_%d' % (yy, xx) for xx in range(ncols)]
                 for yy in range(nrows)]
        m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
        x1, y1 = 5, 8
        x2, y2 = 8, 12
        overlaps = m.get_in_region(x1, y1, x2, y2)
        print(overlaps)
        # expects all cells which overlaps the x1,y1,x2,y2 rect in an area > 0
        assert set(overlaps) == set(
            ['col_2_row_4', 'col_3_row_4', 'col_2_row_5', 'col_3_row_5'])

        # all rect boundaries overlaps cell boundaries
        x1, y1 = 6, 8
        x2, y2 = 8, 12
        overlaps = m.get_in_region(x1, y1, x2, y2)
        print(overlaps)
        # expects all cells which overlaps the x1,y1,x2,y2 rect in an area > 0
        assert set(overlaps) == set(['col_3_row_4', 'col_3_row_5'])
Exemple #8
0
    def test_rect_region_alt__rect_with_area_gt_0(self):
        tile_width = tile_height_h = 2
        nrows = 7
        ncols = 6
        cells = [ [ 'col_%d_row_%d'%(yy, xx) for xx in range(ncols)]
                                                      for yy in range(nrows)]        
        m = RectMap(42, tile_width, tile_height_h, cells, origin=(0, 0, 0))
        x1, y1 = 5, 8
        x2, y2 = 8, 12
        overlaps = m.get_in_region(x1, y1, x2, y2)
        print(overlaps)
        # expects all cells which overlaps the x1,y1,x2,y2 rect in an area > 0
        assert set(overlaps) == set( ['col_2_row_4', 'col_3_row_4',
                                     'col_2_row_5', 'col_3_row_5'] )

        # all rect boundaries overlaps cell boundaries
        x1, y1 = 6, 8
        x2, y2 = 8, 12
        overlaps = m.get_in_region(x1, y1, x2, y2)
        print(overlaps)
        # expects all cells which overlaps the x1,y1,x2,y2 rect in an area > 0
        assert set(overlaps) == set( ['col_3_row_4', 'col_3_row_5'] )
 def __init__(self, id, tw, th, cells, origin=None, properties=None):
     RectMap.__init__(self, id, tw, th, cells, origin, properties)
     No_Scroll_Map_Layer.__init__(self, properties)
     self._update_sprite_set()