dp_rect_pack
1.1.3
Rectangle packing library for C++
|
Rectangle packer. More...
#include <dp_rect_pack.h>
Classes | |
struct | InsertResult |
Result returned by RectPacker::insert(). More... | |
struct | Padding |
struct | Position |
struct | Spacing |
Public Member Functions | |
RectPacker (GeomT maxPageWidth, GeomT maxPageHeight, const Spacing &rectsSpacing=Spacing(0), const Padding &pagePadding=Padding(0)) | |
RectPacker constructor. More... | |
std::size_t | getNumPages () const |
Return the current number of pages. More... | |
void | getPageSize (std::size_t pageIndex, GeomT &width, GeomT &height) const |
Return the current size of the page. More... | |
InsertResult | insert (GeomT width, GeomT height) |
Insert a rectangle. More... | |
Rectangle packer.
GeomT is not required to hold negative numbers, and thus can be an unsigned integer. It's also possible to use a floating-point or a custom numeric type.
A custom type for GeomT should support:
GeomT | numeric type to use for geometry |
|
inline |
RectPacker constructor.
maxPageWidth and maxPageHeight define the maximum size of a single page, including the padding. Depending on this limit and the features of GeomT, a RectPacker can work in multipage or infinite single-page mode.
To enable infinite single-page mode, you have two choices, depending on the properties of GeomT:
If GeomT can hold negative values, the maximum page size, spacing, and padding will be clamped to 0. Keep in mind that if the maximum page size is 0, or if the total padding greater or equal to the maximum page size, pages will have no free space for rectangles, and all calls to insert() will result in InsertStatus::rectTooBig.
maxPageWidth | maximum width of a page, including the horizontal padding |
maxPageHeight | maximum height of a page, including the vertical padding |
rectsSpacing | space between rectangles |
pagePadding | space between rectangles and edges of a page |
|
inline |
Return the current number of pages.
|
inline |
Return the current size of the page.
pageIndex | index of the page in range [0..getNumPages()) | |
[out] | width | width of the page |
[out] | height | height of the page |
RectPacker< GeomT >::InsertResult dp::rect_pack::RectPacker< GeomT >::insert | ( | GeomT | width, |
GeomT | height | ||
) |
Insert a rectangle.
The rectangles you'll feed to insert() should be sorted in descending order by comparing first by height, then by width. A comparison function for std::sort may look like the following:
width | width of the rectangle |
height | height of the rectangle |