-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxRectPacking.h
More file actions
80 lines (60 loc) · 1.44 KB
/
MaxRectPacking.h
File metadata and controls
80 lines (60 loc) · 1.44 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#pragma once
#include<iostream>
#include<vector>
struct Rect
{
float x;
float y;
float width;
float height;
//回転させたかどうか
bool rotated;
Rect()
{
x = 0.0f;
y = 0.0f;
width = 0.0f;
height = 0.0f;
rotated = false;
}
//引数のrectがこのrectを完全に含んでいるかどうか
bool isContain(const Rect& rect) const
{
return x >= rect.x && y >= rect.y
&& x + width <= rect.x + rect.width
&& y + height <= rect.y + rect.height;
}
};
class MaxRectPacking
{
private:
//ビンの幅と高さ
float binWidth;
float binHeight;
//最新の新しい空き領域の数
size_t newFreeRectLastSize;
//最新の空き領域
std::vector<Rect> newFreeRects;
//使用済みの領域
std::vector<Rect> usedRects;
//最新ではない空き領域
std::vector<Rect> freeRects;
//Rectをビンに配置する
void placeRect(const Rect& node);
//面積を考慮した現在の空き領域の中で最適な領域を選択する
Rect findPositionNewBAF(float width, float height
, float& bestAreaFit, float& bestShortSideFit);
//新しい空き矩形を空きリストに入れる
void insertNewFreeRect(const Rect& rect);
//指定された空きノードと使用済みノードから空きノードを分割する
//分割された場合trueを返す
bool splitFreeNode(const Rect& freeNode, const Rect& usedNode);
//空き矩形リストを調べて、冗長なノードを削除する
void pruneFreeList();
MaxRectPacking() {};
public:
MaxRectPacking(float width, float height);
~MaxRectPacking() {};
//ビンを挿入する
Rect insert(bool& packingSuccess,float width, float height);
};