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