def gen_supertile_tiles(self, st_bounds): x0, x1, y0, y1 = st_bounds '''Yield UL coordinates in (y, x) pairs''' xt0 = ceil_mult(x0, self.tw, align=self.x0) xt1 = ceil_mult(x1, self.tw, align=self.x0) if xt0 >= xt1: print x0, x1 print xt0, xt1 raise Exception('Bad input x dimensions') yt0 = ceil_mult(y0, self.th, align=self.y0) yt1 = ceil_mult(y1, self.th, align=self.y0) if yt0 >= yt1: print y0, y1 print yt0, yt1 raise Exception('Bad input y dimensions') if self.tw <= 0 or self.th <= 0: raise Exception('Bad step values') skip_xl_check = False skip_xh_check = False # If this is an edge supertile skip the buffer check if x0 == self.left(): #print 'X check skip (%d): left border' % x0 skip_xl_check = True if x1 == self.right(): #print 'X check skip (%d): right border' % x1 skip_xh_check = True skip_yl_check = False skip_yh_check = False if y0 == self.top(): print 'Y check skip (%d): top border' % y0 skip_yl_check = True if y1 == self.bottom(): print 'Y check skip (%d): bottom border' % y1 skip_yh_check = True for y in xrange(yt0, yt1, self.th): # Are we trying to construct a tile in the buffer zone? if (not skip_yl_check) and y < y0 + self.clip_height: if self.verbose: print 'Rejecting tile @ y%d, x*: yl clip' % (y) continue if (not skip_yh_check) and y + self.th >= y1 - self.clip_height: if self.verbose: print 'Rejecting tile @ y%d, x*: yh clip' % (y) continue for x in xrange(xt0, xt1, self.tw): # Are we trying to construct a tile in the buffer zone? if (not skip_xl_check) and x < x0 + self.clip_width: if self.verbose: print 'Rejecting tiles @ y%d, x%d: xl clip' % (y, x) continue if (not skip_xh_check) and x + self.tw >= x1 - self.clip_width: if self.verbose: print 'Rejecting tiles @ y%d, x%d: xh clip' % (y, x) continue yield (y, x)
def test_ceil_mult(self): self.assertEqual(ceil_mult(0, 256), 0) self.assertEqual(ceil_mult(1, 256), 256) self.assertEqual(ceil_mult(2, 256), 256) self.assertEqual(ceil_mult(255, 256), 256) self.assertEqual(ceil_mult(256, 256), 256) self.assertEqual(ceil_mult(257, 256), 512) self.assertEqual(ceil_mult(258, 256), 512) self.assertEqual(ceil_mult(0, 256, 1), 1) self.assertEqual(ceil_mult(1, 256, 1), 1) self.assertEqual(ceil_mult(2, 256, 1), 257) self.assertEqual(ceil_mult(3, 256, 1), 257) self.assertEqual(ceil_mult(256, 256, 1), 257) self.assertEqual(ceil_mult(257, 256, 1), 257) self.assertEqual(ceil_mult(258, 256, 1), 513) self.assertEqual(ceil_mult(259, 256, 1), 513)