Pack a set of rectangles into an enclosing rectangle with minimum area
Project description
Rectangle packing program.
Given a set of rectangles with fixed orientations, we want to
find an enclosing rectangle of minimum area that contains
them all with no overlap.
This project is inspired by the blog post [Fast Optimizing Rectangle Packing Algorithm for Building CSS Sprites](http://www.codeproject.com/Articles/210979/Fast-optimizing-rectangle-packing-algorithm-for-bu) written by Matt Perdeck.

## Installation
Download the package or clone the repository, then install with:
```bash
python setup.py install
```
or use pypi:
```bash
pip install rectangle-packer
```
## Basic Usage
```python
import rpack # This is the module name
# Create a bunch of rectangles (width, height)
recs = [(58, 206), (231, 176), (35, 113), (46, 109), (68, 65), (90, 63)]
# Run the algorithm
positions = rpack.pack(recs)
# The result will be a list of (x, y) positions:
>>> positions
[(0, 0), (58, 0), (289, 0), (289, 113), (58, 176), (126, 176)]
```
The output positions is the top left corner coordinates of each
rectangle in the input (if we assume origin is in the top left corner).
These positions will yield a packing with no overlaps and enclosing
area as small as possible.
*For best result, sort the rectangles by height, highest first,
before running* ``rpack.pack``. The algorithm is probably far from
the best available. But in most cases it gives quite good results.
Note that you can only provide positive integers as rectangle width
and height.
## Example

Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rectangle-packer-1.0.0.tar.gz.
File metadata
- Download URL: rectangle-packer-1.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e168481dcfcdfc31f4607629b2e787ad768810c0f6170d6d99c1f121f268b01
|
|
| MD5 |
41916f85f1d76056073a0a28d402bc0b
|
|
| BLAKE2b-256 |
43d6443dcc458765f082f0a1d6376bafd1bb5f9556cd9b4fae2b9c4ca45990e5
|
File details
Details for the file rectangle_packer-1.0.0-cp36-cp36m-win_amd64.whl.
File metadata
- Download URL: rectangle_packer-1.0.0-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 13.1 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b15319d14fa6a05355c88d4619df1e70741cb1d293cb9707df46817d057a847
|
|
| MD5 |
11dd87e2b179e9271dc1508d8d165b7f
|
|
| BLAKE2b-256 |
f88bdc160526656dff3c843d8205aa699d0de95482220e32f5fba266fa7095ae
|
File details
Details for the file rectangle_packer-1.0.0-cp36-cp36m-win32.whl.
File metadata
- Download URL: rectangle_packer-1.0.0-cp36-cp36m-win32.whl
- Upload date:
- Size: 11.5 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7feb75ef251262369d513d5d66d9f5349b2c45a03b5cdc0aa49dfe2d40938ade
|
|
| MD5 |
7648b35b593933668a54a87325f2f91a
|
|
| BLAKE2b-256 |
50b9f7668552081d2942d03ce1cb1d03bf73830bdccc0f2780e21d7eed8b4499
|
File details
Details for the file rectangle_packer-1.0.0-cp35-cp35m-win_amd64.whl.
File metadata
- Download URL: rectangle_packer-1.0.0-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 13.1 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b72a8994c9559f42a4e27991b46187efc943d75a1ebc62112f7fab868cf71d4d
|
|
| MD5 |
cb011ba70a90ab7e50b588fb5e20b584
|
|
| BLAKE2b-256 |
b17bef5dc924012560d54f850a05be163e1c01be83e5d2ba27e11c5854ff70fb
|
File details
Details for the file rectangle_packer-1.0.0-cp35-cp35m-win32.whl.
File metadata
- Download URL: rectangle_packer-1.0.0-cp35-cp35m-win32.whl
- Upload date:
- Size: 11.5 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddd283e3ef3b7166922574d5af4250500c35baac00014f3347536748a860f4da
|
|
| MD5 |
800d86633fb7e2f33367e74e2cd2576f
|
|
| BLAKE2b-256 |
f6cfa14082cda418eeb25e8b81908386776d5601af6ed3fa854dd4864300e1d2
|