def test_bin_selection(self): # Check rectangles are packed into the bin with the best fittness # score. In this case the one wasting less area. p = packer.PackerBBF(pack_algo=guillotine.GuillotineBafSas, rotation=False) p.add_bin(10, 10) p.add_bin(15, 15) p.add_bin(55, 55) p.add_bin(50, 50) # First rectangle is packed into the first bin where it fits p.add_rect(50, 30) p.pack() self.assertEqual(len(p), 1) self.assertEqual(p[0].width, 55) # Another bin is opened when it doesn't fit into first one p.add_rect(50, 30) p.pack() self.assertEqual(len(p), 2) self.assertEqual(p[1].width, 50) # rectangle is placed into the bin with the best fitness, not # the first one where it fits. p.add_rect(20, 20) p.pack() self.assertEqual(len(p), 2) self.assertTrue((1, 0, 30, 20, 20, None) in p.rect_list())
def test_skyline_bl(self): s = packer.PackerBBF(pack_algo=skyline.SkylineBl, sort_algo=packer.SORT_LSIDE, rotation=True) self.setup_packer(s) s.pack() s.validate_packing()
def test_maxrects_blsf(self): m = packer.PackerBBF(pack_algo=maxrects.MaxRectsBlsf, sort_algo=packer.SORT_LSIDE, rotation=True) self.setup_packer(m) m.pack() m.validate_packing()
def test_guillotine_baf_minas(self): g = packer.PackerBBF(pack_algo=guillotine.GuillotineBafMinas, sort_algo=packer.SORT_LSIDE, rotation=True) self.setup_packer(g) g.pack() g.validate_packing()
def test_guillotine_bssf_llas(self): g = packer.PackerBBF(pack_algo=guillotine.GuillotineBssfLlas, sort_algo=packer.SORT_SSIDE, rotation=True) self.setup_packer(g) g.pack() g.validate_packing()
def test_repack_rectangle_sort(self): # check rectangles are sorted before a repack p = packer.PackerBBF(rotation=False, sort_algo=packer.SORT_AREA) p.add_bin(100, 100) p.add_bin(90, 90) p.add_bin(80, 80) p.add_rect(70, 70) p.add_rect(80, 80) p.pack() self.assertTrue((0, 0, 0, 80, 80, None) in p.rect_list()) self.assertTrue((1, 0, 0, 70, 70, None) in p.rect_list()) # add bigger rectangle and repack p.add_rect(90, 90) p.pack() self.assertTrue((0, 0, 0, 90, 90, None) in p.rect_list()) self.assertTrue((1, 0, 0, 80, 80, None) in p.rect_list()) self.assertTrue((2, 0, 0, 70, 70, None) in p.rect_list())