]> git.mar77i.info Git - bigintmandel/blob - mandel.h
make zoom_factor part of MandelSettings
[bigintmandel] / mandel.h
1
2 /*
3 * mandel.h
4 *
5 * This file is covered by the LICENSE file in the root of this project.
6 */
7
8 #ifndef MANDEL_H
9 #define MANDEL_H
10
11 #include <QJsonObject>
12 #include <QPixmap>
13 #include <QPoint>
14 #include <QVector>
15 #include <gmpxx.h>
16
17 class MpzPoint {
18 mpz_class x, y;
19 public:
20 MpzPoint() : x(), y() {}
21 explicit MpzPoint(mpz_class x, mpz_class y) : x(x), y(y) {}
22 MpzPoint(const MpzPoint &other) : x(other.x), y(other.y) {}
23 inline const mpz_class get_x() const { return x; }
24 inline const mpz_class get_y() const { return y; }
25 };
26
27 class MandelResultCell {
28 quint64 iter;
29 MpzPoint rpos;
30 public:
31 MandelResultCell() : iter(0) {}
32 explicit MandelResultCell(quint64 iter, MpzPoint rpos)
33 : iter(iter), rpos(rpos) {}
34 inline const quint64 get_iter() const { return iter; }
35 inline const MpzPoint get_rpos() const { return rpos; }
36 };
37
38 class MandelParams {
39 private:
40 quint64 max_iter;
41 QSize size;
42 MpzPoint center_f, offset;
43 mpz_class one;
44
45 public:
46 // required by the MandelSettings constructor
47 MandelParams();
48 explicit MandelParams(
49 quint64 max_iter,
50 QSize size,
51 MpzPoint center_f,
52 mpz_class one
53 );
54 MandelParams(const MandelParams &other);
55 inline const quint64 get_max_iter() const { return max_iter; }
56 inline void set_max_iter(const quint64 max_iter) {
57 this->max_iter = max_iter;
58 }
59 inline const QSize get_size() const { return size; }
60 void set_size(const QSize &size);
61 inline const MpzPoint get_center_f() const { return center_f; }
62 inline const MpzPoint &get_offset() const {
63 return offset;
64 }
65 inline const mpz_class get_one() const { return one; }
66
67 static MandelParams from_json(const QJsonObject &json);
68 QJsonObject to_json() const;
69 };
70
71 class MandelCell;
72
73 class MandelSettings {
74 MandelParams params;
75 QImage *img;
76 QVector<MandelCell> cells;
77 int zoom_factor;
78
79 public:
80 explicit MandelSettings(quint64 max_iter, QSize size);
81 void clear();
82 inline QPixmap get_pixmap() const { return QPixmap::fromImage(*img); }
83 inline const QVector<MandelCell> get_cells() const { return cells; }
84 inline const MandelParams &get_params() const { return params; }
85 inline void set_params(const MandelParams &params) {
86 this->params = params;
87 }
88 inline quint64 get_max_iter() const { return params.get_max_iter(); }
89 inline void set_max_iter(quint64 max_iter) {
90 params.set_max_iter(max_iter);
91 }
92 inline void set_size(const QSize &size) {
93 params.set_size(size);
94 }
95 inline int get_zoom_factor() const {
96 return zoom_factor;
97 }
98 inline void set_zoom_factor(int zoom_factor) {
99 this->zoom_factor = zoom_factor;
100 }
101
102 void zoom(const QSize size, int zoom_factor, const QPoint pos);
103 void finished_cell(int num, const MandelResultCell &cell);
104 void save_img(QString file_name);
105 void reset(quint64 max_iter, QSize size);
106 void from_json(const QJsonObject &json);
107 QJsonObject to_json();
108 };
109
110 extern QVector<QColor> colors;
111
112 class MandelCell {
113 const MandelParams *params;
114 QPoint pos;
115 MpzPoint rpos0;
116 MandelResultCell result;
117
118 public:
119 MandelCell(const MandelParams *params);
120 explicit MandelCell(
121 const MandelParams *params,
122 const QPoint pos,
123 const MpzPoint rpos0,
124 const MandelResultCell result
125 );
126 MandelCell(const MandelCell &cell);
127 inline const QPoint get_pos() const { return pos; }
128 inline const MpzPoint get_rpos0() const { return rpos0; }
129 inline const QColor get_color() const {
130 quint64 iter = result.get_iter();
131 return iter < params->get_max_iter()
132 ? colors[iter % colors.size()]
133 : Qt::GlobalColor::black;
134 }
135
136 void setup(const QPoint pos);
137 inline void set_result(const MandelResultCell &result) {
138 this->result = result;
139 }
140 MandelResultCell iterate() const;
141 MandelResultCell from_json(const QJsonObject &json);
142 QJsonObject to_json() const;
143 };
144
145 #endif // MANDEL_H