5 #include "stb_rect_pack.h"
7 #ifndef STBRP_LARGE_RECTS
8 #error int is not available in stb rect packing
14 std::vector<std::optional<Recti>>
18 const std::vector<size2i>& to_pack
23 auto packed_rects = std::vector<stbrp_rect>(num_rects);
26 for(
const auto s: to_pack)
28 auto&
r = packed_rects[index];
41 const int num_nodes = container.
width;
42 auto context = stbrp_context{};
43 auto nodes = std::vector<stbrp_node>(num_nodes);
52 stbrp_pack_rects(&context, packed_rects.data(), num_rects);
55 auto ret = std::vector<std::optional<Recti>>(to_pack.size());
56 for(
int rect_index = 0; rect_index < num_rects; ++rect_index)
58 const stbrp_rect& rect = packed_rects[rect_index];
59 if(rect.was_packed == 0)
std::vector< std::optional< Recti > > pack(const size2i &container, const std::vector< size2i > &to_pack)
int c_sizet_to_int(size_t t)
static Recti from_top_left_width_height(const vec2i &topleft, int width, int height)