Optibits
Loading...
Searching...
No Matches
BinPacker.hpp
1#pragma once
2
3#include <Optibits/Platform.hpp>
4#include <Optibits/Utility.hpp>
5#include <mutex>
6#include <memory>
7#include <vector>
8
9namespace Optibits
10{
11
12
13 class BinPacker : private Noncopyable
14 {
15 const int mWidth, mHeight;
16 std::vector<Rect> mFreeRects;
17 std::mutex mMutex;
18
19
20 public:
21 BinPacker(int width, int height);
22
23 int width() const { return mWidth; }
24 int height() const { return mHeight; }
25
26 std::shared_ptr<const Rect> alloc(int width, int height);
27
28 void addFreeRect(const Rect& rect);
29
30 private:
31
32 const Rect* bestFreeRect(int width, int height) const;
33
34 void removeFreeRect(int index, int* otherIndex = nullptr);
35
36 void mergeNeighbors(int index);
37
38 };
39
40
41
42}
Definition BinPacker.hpp:14
Definition Utility.hpp:24
Definition Utility.hpp:39