Ottimizzazioni

This commit is contained in:
Andrea Bontempi 2018-02-21 11:06:15 +01:00
parent 936f7a9d29
commit adba3efab5
3 changed files with 11 additions and 15 deletions

View File

@ -22,11 +22,6 @@ void Fractal::setRenderFunction(std::function<sf::Color (int iteration_number, i
this->hasChanged = true; this->hasChanged = true;
} }
std::complex<double> Fractal::scale_point(std::complex<double> point) {
std::complex<double> aux(point.real() / (double)this->image_width * this->domain.width() + this->domain.x_min, point.imag() / (double)this->image_height * this->domain.height() + domain.y_min);
return aux;
}
sf::Image Fractal::getFrame(){ sf::Image Fractal::getFrame(){
if (this->hasChanged) { if (this->hasChanged) {
@ -60,7 +55,7 @@ sf::Image Fractal::getFrame(){
void Fractal::moveTo(int x, int y) { void Fractal::moveTo(int x, int y) {
std::complex<double> point(x, y); std::complex<double> point(x, y);
point = this->scale_point(point); point = scale_point(point);
this->domain.centralize(point); this->domain.centralize(point);
this->hasChanged = true; this->hasChanged = true;
} }
@ -75,10 +70,5 @@ void Fractal::zoom(double factor, bool invert) {
this->hasChanged = true; this->hasChanged = true;
} }
int Fractal::compute_max_iterations(int window_width, double domain_width) {
int max = 50 * std::pow(std::log10(window_width / domain_width), 1.25);
return (max > 0)? max : 0;
}

View File

@ -63,7 +63,7 @@ struct Domain {
} }
void centralize(std::complex<double> point) { void centralize(const std::complex<double>& point) {
double x_frac = width() / 2; double x_frac = width() / 2;
double y_frac = height() / 2; double y_frac = height() / 2;
@ -88,9 +88,15 @@ private:
sf::Image frame; sf::Image frame;
bool hasChanged; bool hasChanged;
Domain domain; Domain domain;
inline std::complex<double> scale_point(const std::complex<double>& point) {
return std::complex<double>(point.real() / (double)this->image_width * this->domain.width() + this->domain.x_min, point.imag() / (double)this->image_height * this->domain.height() + domain.y_min);
}
std::complex<double> scale_point(std::complex<double> point); inline int compute_max_iterations(const int& window_width, const double& domain_width) {
int compute_max_iterations(int window_width, double domain_width); int max = 50 * std::pow(std::log10(window_width / domain_width), 1.25);
return (max > 0)? max : 0;
}
public: public:

View File

@ -7,7 +7,7 @@
typedef std::complex<double> (*fractal_function)(std::complex<double>, std::complex<double>); typedef std::complex<double> (*fractal_function)(std::complex<double>, std::complex<double>);
template <fractal_function F> template <fractal_function F>
int fractal_function_template(std::complex<double> point, int max_iterations) { int fractal_function_template(const std::complex<double>& point, const int& max_iterations) {
std::complex<double> z(0); std::complex<double> z(0);
int iter = 0; int iter = 0;