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