An open API service indexing awesome lists of open source software.

https://github.com/houmain/rect_pack

A library for packing rectangles to one or more sprite sheets/atlases with optional constraints.
https://github.com/houmain/rect_pack

bin-packing binpacking public-domain sprite-atlas sprite-sheets

Last synced: 4 months ago
JSON representation

A library for packing rectangles to one or more sprite sheets/atlases with optional constraints.

Awesome Lists containing this project

README

        

# Multi-sheet rectangle packing

A C++17 library for packing rectangles to one or more sprite sheets/atlases with optional constraints.

It is part of the [spright](https://github.com/houmain/spright) project and utilizing [Sean T. Barrett's Skyline](https://github.com/nothings/stb) and [Jukka Jylänki's MaxRects](https://github.com/juj/RectangleBinPack) packing algorithm implementations.

Simply pass your sheet constraints and the rectangle sizes to the _pack_ function. It will return one or more sheets with rectangle positions. The _id_ can be used to correlate in- and output (there are no rectangles for sizes which did not fit).

For now the header may serve as documentation:

## rect_pack.h

```cpp
#include

namespace rect_pack {

enum class Method {
Best,
Best_Skyline,
Best_MaxRects,
Skyline_BottomLeft,
Skyline_BestFit,
MaxRects_BestShortSideFit,
MaxRects_BestLongSideFit,
MaxRects_BestAreaFit,
MaxRects_BottomLeftRule,
MaxRects_ContactPointRule
};

struct Size {
int id;
int width;
int height;
};

struct Rect {
int id;
int x;
int y;
int width;
int height;
bool rotated;
};

struct Sheet {
int width;
int height;
std::vector rects;
};

struct Settings {
Method method;
int max_sheets;
bool power_of_two;
bool square;
bool allow_rotate;
int align_width;
int border_padding;
int over_allocate;
int min_width;
int min_height;
int max_width;
int max_height;
};

std::vector pack(Settings settings, std::vector sizes);

} // namespace
```