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.
- Host: GitHub
- URL: https://github.com/houmain/rect_pack
- Owner: houmain
- License: unlicense
- Created: 2021-03-04T17:04:51.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-08-09T07:00:52.000Z (10 months ago)
- Last Synced: 2024-08-09T08:26:27.817Z (10 months ago)
- Topics: bin-packing, binpacking, public-domain, sprite-atlas, sprite-sheets
- Language: C++
- Homepage:
- Size: 52.7 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
#includenamespace 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
```