-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFractal.h
254 lines (228 loc) · 6.96 KB
/
Fractal.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifndef CPP_EX2_FRACTAL_H
#define CPP_EX2_FRACTAL_H
// ------------------------------ includes ------------------------------
#include <vector>
#include <iostream>
// -------------------------- const definitions -------------------------
/**
* @brief holds the char that is to be printed if we want to draw the current cell
*/
#define TO_DROW '#'
/**
* @brief holds the char that is to be printed if we don't want to draw the current cell
*/
#define NOT_DROW ' '
/**
* @brief the minimum dimension that a fractal can have
*/
#define MIN_DIM (1)
/**
* @brief the maximum dimension that a fractal can have
*/
#define MAX_DIM (6)
/**
* @brief the size of a sierpinski carpet of dimension 1 (the lowest that can be)
*/
#define CARPET_SIZE (3)
/**
* @brief the size of a sierpinski triangle of dimension 1 (the lowest that can be)
*/
#define TRIANGLE_SIZE (2)
/**
* @brief the size of a vicsek fractal of dimension 1 (the lowest that can be)
*/
#define VICSEK_SIZE (3)
/**
* @brief the number of points that the sierpinski carpet is filling in every step
*/
#define CARPET_NUM_POINTS (8)
/**
* @brief the number of points that the sierpinski triangle carpet is filling in every step
*/
#define TRIANGLE_NUM_POINTS (3)
/**
* @brief the number of points that the vicsek fractal is filling in every step
*/
#define VICSEK_NUM_POINTS (5)
/**
* @brief the index got from the user that stands for the sierpinski carpet
*/
#define CARPET_INDEX (1)
/**
* @brief the index got from the user that stands for the sierpinski triangle
*/
#define TRIANGLE_INDEX (2)
/**
* @brief the index got from the user that stands for the vicsek fractal
*/
#define VICSEK_INDEX (3)
/**
* @brief the minimum index that represents a fractal
*/
#define MIN_INDEX (1)
/**
* @brief the maximum index that represents a fractal
*/
#define MAX_INDEX (3)
// ------------------------------ classes -----------------------------
/**
* @brief This stands for a point in the vector*vector, that is to be filled at the fractal it is
* held at
*/
struct Point
{
int row;
int col;
} typedef Point;
/**
* @brief the abstract fractal base class
*/
class Fractal
{
protected:
/**
* @brief sets the abstract fractal to hold the dimensions it must have, called only from one of
* it's sons
* @param dims the dimensions of the fractal
*/
explicit Fractal(int dims);
/**
* @brief the dimensions of the wanted fractal
*/
int dimensions;
/**
* @brief the vector of vectors of chars that holds the fractal itself
*/
std::vector<std::vector<char>> f;
/**
* @brief this resets the vector to the wanted size, with the value of not printing anything
* in each cell
* @param size the size of the wanted vector (will be set to size*size)
*/
void resetVector(int size);
/**
* @brief sets the vector to hold the whole fractal
* @param rowIdx the row index to start filling at
* @param colIdx the column index to start filling at
* @param thisSize the root size of the current fractal's smallest size (when dim=1)
* @param dims the dimension of the wanted fractal
* @param places the points that should be filled
* @param pointNum the number of points in @param places
*/
void setVector(int rowIdx, int colIdx, int thisSize, int dims, const Point *places, int
pointNum);
/**
* @brief prints the fractal
* @param size the root size of the fractal
*/
void toPrint(int size) const;
public:
/**
* @brief a method that only the sons have, that makes the fractal and prints it (using other
* methods as well)
*/
virtual void makeAndPrint() = 0;
/**
* @brief the virtual destructor of the fractal (as it is abstract and base class for other
* classes)
*/
virtual ~Fractal() = default;
};
/**
* @brief the sierpinski carpet fractal that inherits from the fractal class
*/
class SierpinskiCarpet : public Fractal
{
private:
/**
* @brief an array of points that are to be filled in this fractal
*/
const Point _points[CARPET_NUM_POINTS]{{0, 0},
{0, 1},
{0, 2},
{1, 0},
{1, 2},
{2, 0},
{2, 1},
{2, 2}};
public:
/**
* @brief the constructor of this class, which resets the dimensions and vector as given from
* the user
* @param dims the dimensions of the fractal
*/
explicit SierpinskiCarpet(int dims);
/**
* @brief this sets the vector to hold the whole fractal, and prints it (using other methods)
*/
void makeAndPrint() override;
};
/**
* @brief the sierpinski triangle fractal that inherits from the fractal class
*/
class SierpinskiTriangle : public Fractal
{
private:
/**
* @brief an array of points that are to be filled in this fractal
*/
const Point _points[TRIANGLE_NUM_POINTS]{{0, 0},
{0, 1},
{1, 0}};
public:
/**
* @brief the constructor of this class, which resets the dimensions and vector as given from
* the user
* @param dims the dimensions of the fractal
*/
explicit SierpinskiTriangle(int dims);
/**
* @brief this sets the vector to hold the whole fractal, and prints it (using other methods)
*/
void makeAndPrint() override;
};
/**
* @brief the vicsek fractal fractal that inherits from the fractal class
*/
class VicsekFractal : public Fractal
{
private:
/**
* @brief an array of points that are to be filled in this fractal
*/
const Point _points[VICSEK_NUM_POINTS]{{0, 0},
{0, 2},
{1, 1},
{2, 0},
{2, 2}};
public:
/**
* @brief the constructor of this class, which resets the dimensions and vector as given from
* the user
* @param dims the dimensions of the fractal
*/
explicit VicsekFractal(int dims);
/**
* @brief this sets the vector to hold the whole fractal, and prints it (using other methods)
*/
void makeAndPrint() override;
};
/**
* @brief this is the fractal factory which makes a fractal as the index given
*/
class FractalFactory
{
public:
/**
* @brief the fractal factory can't have an instance as it is not needed
*/
FractalFactory() = delete;
/**
* @brief the static method that makes the fractal from the given index and dimension
* @param index the index of the wanted fractal, should be from 1 to 3
* @param dims the dimensions of the wanted fractal, should be from 1 to 6
* @note there is memory allocated in this method that should be freed!
*/
static Fractal *makeFractal(int index, int dims);
};
#endif //CPP_EX2_FRACTAL_H