mirror of
https://github.com/Andreabont/OpenMandelbrot.git
synced 2024-11-21 07:07:58 +00:00
Ottimizzazioni
This commit is contained in:
parent
936f7a9d29
commit
adba3efab5
12
Fractal.cpp
12
Fractal.cpp
@ -22,11 +22,6 @@ void Fractal::setRenderFunction(std::function<sf::Color (int iteration_number, i
|
||||
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(){
|
||||
|
||||
if (this->hasChanged) {
|
||||
@ -60,7 +55,7 @@ sf::Image Fractal::getFrame(){
|
||||
|
||||
void Fractal::moveTo(int x, int y) {
|
||||
std::complex<double> point(x, y);
|
||||
point = this->scale_point(point);
|
||||
point = scale_point(point);
|
||||
this->domain.centralize(point);
|
||||
this->hasChanged = true;
|
||||
}
|
||||
@ -75,10 +70,5 @@ void Fractal::zoom(double factor, bool invert) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
12
Fractal.hpp
12
Fractal.hpp
@ -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 y_frac = height() / 2;
|
||||
@ -88,9 +88,15 @@ private:
|
||||
sf::Image frame;
|
||||
bool hasChanged;
|
||||
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);
|
||||
int compute_max_iterations(int window_width, double domain_width);
|
||||
inline int compute_max_iterations(const int& window_width, const double& domain_width) {
|
||||
int max = 50 * std::pow(std::log10(window_width / domain_width), 1.25);
|
||||
return (max > 0)? max : 0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
typedef std::complex<double> (*fractal_function)(std::complex<double>, std::complex<double>);
|
||||
|
||||
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);
|
||||
int iter = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user