-
Notifications
You must be signed in to change notification settings - Fork 1
/
packer.h
168 lines (132 loc) · 4.71 KB
/
packer.h
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <iostream>
#include <utility>
#include <cassert>
#include <vector>
#include <string>
#include <chrono>
#include <map>
#include "Draw/ez-draw.h"
using namespace std;
using namespace std::chrono;
class SHAPE; // Initiate class SHAPE before SHAPES typedef so we don't get errors
typedef map <int, SHAPE*> SHAPES;
// Class SHAPE : Will either be a RECTANGLE or a HOLE
class SHAPE
{
public:
int x1 = 0;
int y1 = 0;
int x2 = 0;
int y2 = 0;
int id = 0;
int origin = 0;
bool isRotated = false;
// Colors for Draw memory
Ez_uint32 Color;
// ------------------------------------------------------------------------------------
// FUNCTIONS
// ------------------------------------------------------------------------------------
void Print(string Type, int maxID, int maxDims, int maxCoords);
// Rotate : Flips Shape1 (this) 90° : Shape1->Rotate();
void Rotate();
// sameAs : Shape1 (this) same properties as Shape2 (Shape) : Shape1->sameAs(Shape2);
bool sameAs(SHAPE* Shape);
// smallerThan : Shape1 (this) smaller than Shape2 (Shape) : Shape1->smallerThan(Shape2);
bool smallerThan(SHAPE* Shape);
// fitsIn : Shape1 (this) fits inside Shape2 (Shape) : Shape1->fitsIn(Shape2);
bool fitsIn(SHAPE* Shape);
// Overlaps : Checks if Shape1 (this) overlaps with Shape 2 (Shape) : Shape1->Overlaps(Shape2);
bool Overlaps(SHAPE* Shape);
// isCovered : Shape1 (this) covered by some Shape in Shapes : Shape1->isCovered(Shapes, ExceptionShape);
bool isCovered(SHAPES* Shapes, SHAPE* ExceptionShape);
// removeShape : Removes Shape1 (this) from Shapes : Shape1->Rotate(Shapes);
void removeFrom(SHAPES* Shapes);
// appendTo : Adds Shape1 to Shapes : Shape1->appendTo(Shapes);
void appendTo(SHAPES* Shapes);
};
class RECTANGLE : public SHAPE {};
class HOLE : public SHAPE {};
// Result Class
class RESULT
{
public:
int Width = 0;
int Height = 0;
int Theoretical_Height = 0;
int Rect_Area = 0;
bool Rotate = false;
int Holes_Created = 0;
int Sort_Strategy = 1;
duration <int64_t, nano> Total_Time;
SHAPES Rectangles;
};
// GLOBAL Class
class GLOBAL
{
public:
int Rect_ID_Counter = 1;
int Hole_ID_Counter = 1;
vector<SHAPE*> Stored_Rectangles;
SHAPES Rectangles;
SHAPES Holes;
// Run Info
int Width = 0;
int Height = 0;
int Theoretical_Height = 0;
int Rect_Area = 0;
bool Rotate = false;
int Sort_Strategy = 0;
chrono::_V2::system_clock::time_point Start_Time;
chrono::_V2::system_clock::time_point End_Time;
duration <int64_t, nano> Total_Time;
// ------------------------------------------------------------------------------------
// GLOBAL FUNCTIONS
// ------------------------------------------------------------------------------------
// newRectID : Returns a new ID for new Rectangle;
int newRectID();
// newHoleID : Returns a new ID for new Hole;
int newHoleID();
// resetRectCounter : Resets the ID counter
void resetRectCounter();
// resetHoleCounter : Resets the ID counter
void resetHoleCounter();
// newRectangle : Adds a new Rectangle in Rectangles;
void newRectangle(SHAPE* Rectangle);
// newHole : Adds a new Hole in Holes;
void newHole(SHAPE* Hole);
// clearShapes : clears rectangles and holes
void clearShapes();
// Copy Shapes //
SHAPES copyRectangles();
SHAPES copyHoles();
// ----------- //
RESULT* getResult();
void Solve(int Sort_Strategy);
};
// EZ Class
class EZ
{
public:
Ez_window WINDOW;
SHAPE* CANVAS = NULL;
float DEFAULT_SCALE = 1;
float RECT_SCALE = DEFAULT_SCALE;
float ZOOM_INC = 0.05; // Increment in x,y fact. for zooming
// Colors
bool RAINBOW = false;
float SATURATION = 78; // /100
float VALUE = 100; // /100
bool SHOW_IDS = true;
// Offsets for Controls
int MARGIN = 20; // (Start Offset)
int PAN_SPEED = 30;
int VERTICAL = MARGIN;
int HORIZONTAL = MARGIN;
// ------- //
// drawOutlined : Draw the border of a rectangle
void drawOutlined(SHAPE* Rectangle);
// drawFilled : Draw the whole rectangle (+ border)
void drawFilled(SHAPE* Rectangle);
// drawCanvas : Draw/Redraw Canvas with all Rectangles ( Update settings )
void drawCanvas(RESULT* EndResult);
};