This library provides algorithms on how to pack rectangles into several bins. It currently contains the MaxRects and Guillotine algorithms. The project is based on the survey of Jukka Jylänki and the reference implementation Possible applications are e.g. Texture Atlas Generators.
- C++ 11 support
- Header only
- Custom types
Full example can be found in src/Example.cpp
struct CustomRect { ... };
// Conversion function from CustomRect to Rect
inline RectBinPack::Rect toRect(const CustomRect& value) { ... }
// Conversion function from BinRect to CustomRect
inline void fromBinRect(CustomRect& value, RectBinPack::BinRect rect) { ... }
std::vector<CustomRect> data { ... };
// Initialize configuration (size x size, 1 bin, no flipping, BestAreaFit)
RectBinPack::MaxRectsConfiguration config {
size, size, 1, 1, false, RectBinPack::MaxRectsHeuristic::BestAreaFit
};
// Pack rectangles
RectBinPack::packMaxRects(config, data);
Just copy and paste the include folder into your project, add it to your include path or install it with CMake.
See src/Example.cpp
or Doxygen