Skip to content

falki147/RectBinPack

Repository files navigation

Build status Build Status codecov

Rectangle Bin Packing Library

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.

Features

  • C++ 11 support
  • Header only
  • Custom types

Example

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);

Installation

Just copy and paste the include folder into your project, add it to your include path or install it with CMake.

Usage

See src/Example.cpp or Doxygen