// mandel.h #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 { size_t iter; MpzPoint rpos; public: MandelResultCell() : iter(0) {} MandelResultCell(size_t iter, MpzPoint rpos) : iter(iter), rpos(rpos) {} inline const size_t get_iter() const { return iter; } inline const MpzPoint get_rpos() const { return rpos; } }; class MandelParams { private: size_t max_iter; QSize size; MpzPoint center_f; mpz_class left, top, one; public: // required by the MandelSettings constructor MandelParams(); MandelParams( size_t max_iter, QSize size, MpzPoint center_f, mpz_class one ); MandelParams(const MandelParams &other); inline const size_t get_max_iter() const { return max_iter; } inline void set_max_iter(const size_t max_iter) { this->max_iter = max_iter; } inline const QSize get_size() const { return size; } inline const MpzPoint get_center_f() const { return center_f; } inline const mpz_class get_left() const { return left; } inline const mpz_class get_top() const { return top; } 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; public: MandelSettings(size_t max_iter, QSize size); 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_max_iter(size_t max_iter) { params.set_max_iter(max_iter); } 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(size_t 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); 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 { size_t 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