{"id":10194,"library":"rectangle-packer","title":"Rectangle Packer","description":"rectangle-packer is a Python library for efficiently packing a set of 2D rectangles into a minimal bounding box. It utilizes an optimized best-fit heuristic algorithm to achieve high packing density. The current stable version is 2.1.0, and it maintains a moderate release cadence, with updates addressing performance and edge cases, primarily focusing on its core `pack` functionality.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/Penlect/rectangle-packer","tags":["packing","rectangle","layout","bin-packing","optimization"],"install":[{"cmd":"pip install rectangle-packer","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"pack","correct":"from rpack import pack"},{"note":"The 'group' function was removed in version 2.0.6. Use 'rpack.pack' directly.","wrong":"from rpack import group","symbol":"group","correct":"from rpack import pack # 'group' was removed"},{"note":"The internal '_rpack' extension module was removed in version 2.0.6. Use 'rpack.pack' directly.","wrong":"import rpack._rpack","symbol":"_rpack","correct":"from rpack import pack # '_rpack' was removed"}],"quickstart":{"code":"import rpack\n\n# Rectangles are defined as (width, height) tuples\nrects = [\n    (10, 20),\n    (5, 15),\n    (12, 12),\n    (30, 10),\n    (8, 25)\n]\n\n# Pack the rectangles, returns a list of (x, y) positions\n# (0,0) is top-left, increasing x to the right, increasing y downwards\npositions = rpack.pack(rects)\n\n# The positions correspond to the input rectangles order\nfor i, (x, y) in enumerate(positions):\n    print(f\"Rectangle {i+1} (w={rects[i][0]}, h={rects[i][1]}): Position ({x}, {y})\")\n\n# You can find the enclosing dimensions of the packed layout\nwidth, height = rpack.util.enclosing_size(rects, positions)\nprint(f\"Total enclosing size: Width={width}, Height={height}\")","lang":"python","description":"This quickstart demonstrates how to define a list of rectangles as (width, height) tuples and use `rpack.pack()` to find their optimal positions within a minimal bounding box. It then prints the calculated (x, y) positions for each rectangle and the overall dimensions of the packed area."},"warnings":[{"fix":"Migrate any usage of `rpack.group` or direct calls to `rpack._rpack.pack` to use `rpack.pack` directly. The `pack` function is now the sole public API for packing.","message":"The `rpack.group` function and the internal `rpack._rpack` extension module were removed in version 2.0.6. These were part of the older API and have been consolidated.","severity":"breaking","affected_versions":">=2.0.6"},{"fix":"Upgrade to version 2.1.0 or newer. This version introduced bigint preprocessing, including `gcd` normalization and power-of-two scaling, to robustly handle very large Python integers.","message":"Prior to version 2.1.0, packing rectangles with extremely large width/height values (exceeding standard C `long` limits) could lead to `OverflowError` or incorrect results due to integer overflow in the underlying C extension.","severity":"gotcha","affected_versions":"<2.1.0"},{"fix":"Upgrade to version 2.1.0 or newer. This version significantly improved `rpack.pack()` search behavior for such inputs by adding staged coarse candidate stepping with bounded local refinement.","message":"Performance and packing density for 'thin' or 'pathological' rectangle inputs (e.g., 1x1000) were less optimal in versions prior to 2.1.0.","severity":"gotcha","affected_versions":"<2.1.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Upgrade to `rectangle-packer` version 2.0.6 or newer and use `rpack.pack` directly. If you need to pack independent sets of rectangles, call `rpack.pack` for each set.","cause":"The `rpack.group` function was removed in version 2.0.6. It was part of an older API for packing multiple groups of rectangles.","error":"AttributeError: module 'rpack' has no attribute 'group'"},{"fix":"Upgrade to `rectangle-packer` version 2.0.6 or newer. The core packing functionality is now directly exposed via `rpack.pack`. Avoid importing internal modules directly.","cause":"The internal `_rpack` extension module was removed in version 2.0.6 as part of API simplification and consolidation.","error":"ImportError: cannot import name '_rpack' from 'rpack'"},{"fix":"Upgrade to `rectangle-packer` version 2.1.0 or newer. This version includes robust bigint preprocessing to handle large Python integers correctly without overflow.","cause":"This error occurs in versions prior to 2.1.0 when `rpack.pack` is given rectangles with extremely large width or height values that exceed the capacity of the underlying C `long` integer type.","error":"OverflowError: Python int too large to convert to C long"}]}