from ..utils.pack2d import maxrects_bssf, pack_patterns from ..library import Library from ..pattern import Pattern def test_maxrects_bssf_simple() -> None: # Pack two 10x10 squares into one 20x10 container rects = [[10, 10], [10, 10]] containers = [[0, 0, 20, 10]] locs, rejects = maxrects_bssf(rects, containers) assert not rejects # They should be at (0,0) and (10,0) assert {tuple(loc) for loc in locs} == {(0.0, 0.0), (10.0, 0.0)} def test_maxrects_bssf_reject() -> None: # Try to pack a too-large rectangle rects = [[10, 10], [30, 30]] containers = [[0, 0, 20, 20]] locs, rejects = maxrects_bssf(rects, containers, allow_rejects=True) assert 1 in rejects # Second rect rejected assert 0 not in rejects def test_pack_patterns() -> None: lib = Library() p1 = Pattern() p1.polygon((1, 0), vertices=[[0, 0], [10, 0], [10, 10], [0, 10]]) lib["p1"] = p1 p2 = Pattern() p2.polygon((1, 0), vertices=[[0, 0], [5, 0], [5, 5], [0, 5]]) lib["p2"] = p2 # Containers: one 20x20 containers = [[0, 0, 20, 20]] # 2um spacing pat, rejects = pack_patterns(lib, ["p1", "p2"], containers, spacing=(2, 2)) assert not rejects assert len(pat.refs) == 2 assert "p1" in pat.refs assert "p2" in pat.refs # Check that they don't overlap (simple check via bounds) # p1 size 10x10, effectively 12x12 # p2 size 5x5, effectively 7x7 # Both should fit in 20x20