def test_size_fit_area(): size = geom.Size(100, 100) assert size.fit_area(64) == geom.Size(8, 8) assert size.fit_area(64, downscale=False) == size assert size.fit_area(14400) == geom.Size(120, 120) assert size.fit_area(14400, upscale=False) == size size = geom.Size(200, 300) assert size.fit_area(100) == geom.Size(8, 12) assert size.fit_area(7) == geom.Size(2, 3) assert size.fit_area(8) == geom.Size(2, 4) assert size.fit_area(9) == geom.Size(3, 3) assert size.fit_area(10) == geom.Size(3, 3) assert size.fit_area(11) == geom.Size(2, 5)
def test_size_zero(): size = geom.Size(0, 0) assert size == geom.empty assert not size assert size.width == 0 assert size.height == 0 assert size.x == 0 assert size.y == 0 assert tuple(size) == (0, 0)
def create(userid, x1, y1, x2, y2): x1, y1, x2, y2 = d.get_int(x1), d.get_int(y1), d.get_int(x2), d.get_int(y2) db = d.connect() im = db.query(orm.MediaItem).get( avatar_source(userid)['mediaid']).as_image() file_type = images.image_file_type(im) bounds = None size = im.size.width, im.size.height if image.check_crop(size, x1, y1, x2, y2): bounds = geometry.Rectangle(x1, y1, x2, y2) thumb = image.shrinkcrop(im, geometry.Size(100, 100), bounds) media_item = orm.MediaItem.fetch_or_create( thumb.to_buffer(format=file_type), file_type=file_type, im=thumb) orm.UserMediaLink.make_or_replace_link(userid, 'avatar', media_item) orm.UserMediaLink.clear_link(userid, 'avatar-source')
def _determine_popup_size(size): shrunk = size.fit_inside(POPUP_MAX_SIZE) return geometry.Size(max(shrunk.width, POPUP_MIN_EDGE), max(shrunk.height, POPUP_MIN_EDGE))
def test_size_fit_around(): assert geom.Size(50, 50).fit_around((10, 10)) == geom.Size(10, 10) assert geom.Size(50, 50).fit_around((20, 10)) == geom.Size(20, 20) assert geom.Size(50, 50).fit_around((10, 20)) == geom.Size(20, 20) assert geom.Size(50, 50).fit_around((10, 10), upscale=False) == geom.Size(10, 10) assert geom.Size(50, 50).fit_around((10, 10), downscale=False) == geom.Size(50, 50) assert geom.Size(50, 50).fit_around((100, 100)) == geom.Size(100, 100) assert geom.Size(50, 50).fit_around((200, 100)) == geom.Size(200, 200) assert geom.Size(50, 50).fit_around((100, 200)) == geom.Size(200, 200) assert geom.Size(50, 50).fit_around((100, 100), upscale=False) == geom.Size(50, 50) assert geom.Size(50, 50).fit_around( (100, 100), downscale=False) == geom.Size(100, 100) # Float rounding edge cases assert geom.Size(600, 398).fit_around((120, 120)) == geom.Size(180, 120) assert geom.Size(398, 600).fit_around((120, 120)) == geom.Size(120, 180) assert geom.Size(398, 398).fit_around((120, 120)) == geom.Size(120, 120)
def test_rect_simple(): rect = geom.Rectangle(0, 0, 3, 4) assert rect.size == geom.Size(3, 4)
def test_size_fit_around(): assert geom.Size(600, 398).fit_around((120, 120)) == geom.Size(180, 120) assert geom.Size(398, 600).fit_around((120, 120)) == geom.Size(120, 180) assert geom.Size(398, 398).fit_around((120, 120)) == geom.Size(120, 120)
def test_size_fit_inside(): assert geom.Size(600, 398).fit_inside((120, 120)) == geom.Size(120, 79) assert geom.Size(398, 600).fit_inside((120, 120)) == geom.Size(79, 120) assert geom.Size(398, 398).fit_inside((120, 120)) == geom.Size(120, 120)