/* * mandel.h * * This file is covered by the LICENSE file in the root of this project. */ #ifndef MANDEL_H #define MANDEL_H #include #include #include #include #include class MpzPoint { mpz_class x, y; public: MpzPoint() : x(), y() {} explicit MpzPoint(mpz_class x, mpz_class y) : x(x), y(y) {} MpzPoint(const MpzPoint &other) : x(other.x), y(other.y) {} inline const mpz_class get_x() const { return x; } inline const mpz_class get_y() const { return y; } }; class MandelResultCell { quint64 iter; MpzPoint rpos; public: MandelResultCell() : iter(0) {} explicit MandelResultCell(quint64 iter, MpzPoint rpos) : iter(iter), rpos(rpos) {} inline const quint64 get_iter() const { return iter; } inline const MpzPoint get_rpos() const { return rpos; } }; class MandelParams { private: quint64 max_iter; QSize size; MpzPoint center_f, offset; mpz_class one; public: // required by the MandelSettings constructor MandelParams(); explicit MandelParams( quint64 max_iter, QSize size, MpzPoint center_f, mpz_class one ); MandelParams(const MandelParams &other); inline const quint64 get_max_iter() const { return max_iter; } inline void set_max_iter(const quint64 max_iter) { this->max_iter = max_iter; } inline const QSize get_size() const { return size; } void set_size(const QSize &size); inline const MpzPoint get_center_f() const { return center_f; } inline const MpzPoint &get_offset() const { return offset; } inline const mpz_class get_one() const { return one; } static MandelParams from_json(const QJsonObject &json); QJsonObject to_json() const; }; class MandelCell; class MandelSettings { MandelParams params; QImage *img; QVector cells; int zoom_factor; public: explicit MandelSettings(quint64 max_iter, QSize size); void clear(); inline QPixmap get_pixmap() const { return QPixmap::fromImage(*img); } inline const QVector get_cells() const { return cells; } inline const MandelParams &get_params() const { return params; } inline void set_params(const MandelParams ¶ms) { this->params = params; } inline quint64 get_max_iter() const { return params.get_max_iter(); } inline void set_max_iter(quint64 max_iter) { params.set_max_iter(max_iter); } inline void set_size(const QSize &size) { params.set_size(size); } inline int get_zoom_factor() const { return zoom_factor; } inline void set_zoom_factor(int zoom_factor) { this->zoom_factor = zoom_factor; } void zoom(const QSize size, int zoom_factor, const QPoint pos); void finished_cell(int num, const MandelResultCell &cell); void save_img(QString file_name); void reset(quint64 max_iter, QSize size); void from_json(const QJsonObject &json); QJsonObject to_json(); }; extern QVector colors; class MandelCell { const MandelParams *params; QPoint pos; MpzPoint rpos0; MandelResultCell result; public: MandelCell(const MandelParams *params); explicit MandelCell( const MandelParams *params, const QPoint pos, const MpzPoint rpos0, const MandelResultCell result ); MandelCell(const MandelCell &cell); inline const QPoint get_pos() const { return pos; } inline const MpzPoint get_rpos0() const { return rpos0; } inline const QColor get_color() const { quint64 iter = result.get_iter(); return iter < params->get_max_iter() ? colors[iter % colors.size()] : Qt::GlobalColor::black; } void setup(const QPoint pos); inline void set_result(const MandelResultCell &result) { this->result = result; } MandelResultCell iterate() const; MandelResultCell from_json(const QJsonObject &json); QJsonObject to_json() const; }; #endif // MANDEL_H