-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit_packer.hpp
More file actions
35 lines (29 loc) · 892 Bytes
/
split_packer.hpp
File metadata and controls
35 lines (29 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef SPLIT_PACKER_HPP
#define SPLIT_PACKER_HPP
#include <vector>
#include <memory>
#include <optional>
struct PackedRectNode {
int top_left_x, top_left_y, w, h;
bool used = false;
std::shared_ptr<PackedRectNode> left = nullptr;
std::shared_ptr<PackedRectNode> right = nullptr;
PackedRectNode(int x, int y, int w, int h);
};
class Block {
public:
int w, h;
std::optional<PackedRectNode> packed_placement;
Block(int w, int h);
};
class SplitPacker {
public:
SplitPacker(int width, int height);
void fit(std::vector<Block> &blocks);
void fit(Block &block);
private:
std::shared_ptr<PackedRectNode> root;
std::shared_ptr<PackedRectNode> find_node_with_enough_space_rec(std::shared_ptr<PackedRectNode> root, int width,
int height);
};
#endif // SPLIT_PACKER_HPP