/*
* fractal
* Written in 2020 by Lucas
* CC0 1.0 Universal/Public domain - No rights reserved
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty. You should have received a copy of the CC0 Public Domain
* Dedication along with this software. If not, see
* .
*/
#include
#include
#include
#include "criticals.h"
#include "util.h"
size_t newton_iters = 100;
static size_t idx = 0;
static long double complex criticals[100];
int
behaves_critical(long double complex (*df)(long double complex),
long double complex (*ddf)(long double complex), long double complex z,
long double complex *crit, long double bailout, long double epsilon)
{
size_t i;
for (i = 0; i < newton_iters && cabsl(z) < bailout; i++)
z = z - df(z) / ddf(z);
if (cabsl(df(z)) < epsilon) {
*crit = z;
return 1;
}
return 0;
}
void
add_critical_point(long double complex z)
{
size_t i;
if (idx >= nelems(criticals))
return;
for (i = 0; i < idx; i++)
if (cabsl(z - criticals[i]) < 1.0e-9)
return;
criticals[idx++] = z;
}
size_t
ncriticals(void)
{
return idx;
}
long double complex
get_critical(size_t i)
{
if (i >= idx) {
fprintf(stderr, "get_critical: index %zu out of range", i);
exit(1);
}
return criticals[i];
}