Moved converge to its own file to reduce REDUNDANCY

This commit is contained in:
Nikola
2026-09-01 18:46:07 +03:00
parent ccf306e288
commit f0207a75e8
6 changed files with 33 additions and 92 deletions
+1 -24
View File
@@ -1,8 +1,6 @@
#include "tricorn.h"
#include "color_table.h"
static unsigned converge(float c_real, float c_imag, unsigned n);
#include "converge_helper.h"
/**
* @brief Generates a Tricorn fractal image using an optimized SIMD algorithm
@@ -131,25 +129,4 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
c_imag += vertical_step;
c_imag_vector = _mm_add_ps(c_imag_vector,vertical_step_vector);
}
}
// Iterative application of the equation given by the assignment
static unsigned converge(float c_real, float c_imag, unsigned n) {
float real = 0.0f;
float imag = 0.0f;
for (unsigned i = 0; i < n; i++) {
float real2 = real * real;
float imag2 = imag * imag;
// If the pixel has diverged calculate the value and return it
if (real2 + imag2 > 4.0f) {
return 255 - 4 * (i % 64);
}
// Calculate imaginary and real parts separately
imag = -2.0f * real * imag + c_imag;
real = real2 - imag2 + c_real;
}
return 0;
}