Skip to content

nicolasjinchereau/bin-packing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A rectangular bin packing algorithm for texture atlases.

#include <binpacking.h>
using namespace binpacking;

// sizes of input rectangles
std::vector<Size> sizes;
sizes.push_back(Size(20, 60));
sizes.push_back(Size(30, 40));
// ...

// Max side length of an output bin.
// Must be a power of two.
// Output bin may be non-square.
int maxSize = 128;

// Pixels of padding between rectangles in the bin (see image below).
int padding = 2;

// Set this to true to allow input rectangles to be rotated by
// 90 degrees when doing so would result in tighter packing.
bool allowRotation = true;

// Returns N-1 bins of 'maxSize' by 'maxSize', and one bin of equal or smaller size.
// Each bin will contain a set of RectMapping objects that map input sizes to bin positions.
std::vector<Bin> bins = Pack(sizes, maxSize, padding, allowRotation);

for(auto& bin : bins) {
    for(auto& mapping : bin.mappings) {
        // ...
    }
}

demo

About

Rectangular bin packing algorithm for texture atlases.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages