33 std::optional<sf::IntRect>
RectPack::pack(
const int width,
const int height)
noexcept
36 std::optional<sf::IntRect> result = std::nullopt;
39 for (
auto rit = m_free_rects.rbegin(); rit != m_free_rects.rend();)
44 if (width <= space.size.x && height <= space.size.y)
47 result = std::make_optional<sf::IntRect>(sf::IntRect({space.position.x, space.position.y}, {width, height}));
50 if (width == space.size.x && height == space.size.y)
54 m_free_rects.erase(rit.base());
56 else if (width == space.size.x)
59 space.position.y += height;
60 space.size.y -= height;
62 else if (height == space.size.y)
65 space.position.x += width;
66 space.size.x -= width;
71 m_free_rects.emplace_back(sf::IntRect({space.position.x + width, space.position.y}, {space.size.x - width, height}));
73 space.position.y += height;
74 space.size.y -= height;