20 #ifndef ANTKEEPER_GEOM_RECT_PACK_HPP
21 #define ANTKEEPER_GEOM_RECT_PACK_HPP
118 root.bounds = {T{0}, T{0}, w, h};
130 root.bounds = {{T{0}, T{0}}, {w, h}};
136 root.children[0].reset();
137 root.children[1].reset();
138 root.occupied =
false;
144 return insert(root, w, h);
157 if (node.children[0] && node.children[1])
160 node_type* result = insert(*node.children[0], w, h);
167 return insert(*node.children[1], w, h);
178 scalar_type node_w = node.bounds.max.x() - node.bounds.min.x();
179 scalar_type node_h = node.bounds.max.y() - node.bounds.min.y();
182 if (w > node_w || h > node_h)
188 if (w == node_w && h == node_h)
190 node.occupied =
true;
195 node.children[0] = std::make_unique<node_type>();
196 node.children[1] = std::make_unique<node_type>();
199 scalar_type dw = node_w -
w;
200 scalar_type dh = node_h -
h;
203 node.children[0]->bounds.min = node.bounds.min;
204 node.children[0]->bounds.max = {node.bounds.min.x() +
w, node.bounds.max.y()};
205 node.children[1]->bounds.min = {node.bounds.min.x() +
w, node.bounds.min.y()};
206 node.children[1]->bounds.max = {node.bounds.max};
210 node.children[0]->bounds.min = node.bounds.min;
211 node.children[0]->bounds.max = {node.bounds.max.x(), node.bounds.min.y() +
h};
212 node.children[1]->bounds.min = {node.bounds.min.x(), node.bounds.min.y() +
h};
213 node.children[1]->bounds.max = {node.bounds.max};
217 return insert(*node.children[0], w, h);
const node_type * pack(scalar_type w, scalar_type h)
Packs a rect into the rect pack.
T scalar_type
Scalar type.
void resize(scalar_type w, scalar_type h)
Clears the pack and resizes the root node bounds.
rect_pack()
Creates an empty rect pack.
void clear()
Clear the pack, deallocating all nodes.
const node_type & get_root() const
Returns a reference to the root node.
n-dimensional axis-aligned rectangle.
Node used in 2D rectangle packing.
bool occupied
true if the node is occupied, false otherwise.
std::unique_ptr< rect_pack_node > children[2]
Pointers to the two children of the node, if any.
T scalar_type
Scalar type.
rect_type bounds
Bounds of the node.