Skip to content

Commit

Permalink
feat: speed up by checking for point in cardioid
Browse files Browse the repository at this point in the history
  • Loading branch information
istudyatuni committed Feb 12, 2022
1 parent 9f736df commit 29d8297
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/wasm/mandelbrot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,40 @@ extern "C" {
}
#endif

#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
#endif
bool checkCardioid(double x, double i) {
double a4 = x - 0.25,
b2 = i * i;
double q = a4 * a4 + b2;

// cardioid
if (q * (q + a4) < b2 * 0.25) {
return true;
}

double x1 = x + 1;

// circle to the left of cardioid
if (x1 * x1 + b2 < 1/16) {
return true;
}

return false;
}

const int R = 2, N = 100;
const complex<double> z0 = 0;

#ifdef __EMSCRIPTEN__
EMSCRIPTEN_KEEPALIVE
#endif
unsigned short checkSeries(double x, double i) {
if (checkCardioid(x, i)) {
return 1;
}

complex<double> point = complex<double>(x, i);
complex<double> num = z0 + point;

Expand Down

0 comments on commit 29d8297

Please sign in to comment.