Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
binpacker.h
Go to the documentation of this file.
1 
18 #ifndef ION_TEXT_BINPACKER_H_
19 #define ION_TEXT_BINPACKER_H_
20 
21 #include <memory>
22 #include <vector>
23 
24 #include "ion/base/invalid.h"
25 #include "ion/math/vector.h"
26 
27 namespace ion {
28 namespace text {
29 
36 class BinPacker {
37  public:
39  struct Rectangle {
40  Rectangle() = delete;
41 
43  Rectangle(uint64 id_in, const math::Vector2ui& size_in)
44  : id(id_in), size(size_in), bottom_left(math::Point2ui::Zero()) {}
45 
46  uint64 id; // Input client identifier for rectangle.
47  math::Vector2ui size; // Input 2D size.
48  math::Point2ui bottom_left; // Output position of rectangle.
49  };
50 
51  BinPacker();
52  ~BinPacker();
53 
55  explicit BinPacker(const BinPacker& from);
56  BinPacker& operator=(const BinPacker& from);
57 
60  void AddRectangle(uint64 id, const math::Vector2ui& size) {
61  rectangles_.push_back(Rectangle(id, size));
62  }
63 
67  bool Pack(const math::Vector2ui& bin_size);
68 
72  const std::vector<Rectangle>& GetRectangles() const {
73  return rectangles_;
74  }
75 
76  private:
78  class Skyline;
79 
80  std::vector<Rectangle> rectangles_;
81  std::unique_ptr<Skyline> skyline_;
83  size_t num_rectangles_packed_;
84 };
85 
86 } // namespace text
87 } // namespace ion
88 
89 #endif // ION_TEXT_BINPACKER_H_
BinPacker()
BinPacker functions.
Definition: binpacker.cc:201
const std::vector< Rectangle > & GetRectangles() const
Returns the vector of rectangles (including positions) resulting from the last call to Pack()...
Definition: binpacker.h:72
Structure representing a rectangle to pack into the bin.
Definition: binpacker.h:39
std::string text
void AddRectangle(uint64 id, const math::Vector2ui &size)
Adds a rectangle of the given size to pack into the bin.
Definition: binpacker.h:60
Rectangle(uint64 id_in, const math::Vector2ui &size_in)
Constructor that takes an ID and size.
Definition: binpacker.h:43
bool Pack(const math::Vector2ui &bin_size)
Tries to pack all of the rectangles into a bin of the given size.
Definition: binpacker.cc:215
This class implements generic 2D bin-packing using a modified version of the Skyline Bottom-Left algo...
Definition: binpacker.h:36
BinPacker & operator=(const BinPacker &from)
Definition: binpacker.cc:207