in System.Numerics/SIMD/Mandelbrot/MainWindow.xaml.cs [166:224]
private void DrawMandelbrot(int cw, int ch)
{
double range, xc, yc;
lock (valRWLock)
{
RenderRange = range = Range;
RenderXC = xc = XC;
RenderYC = yc = YC;
width = cw;
height = ch;
bytes = new byte[width * height * 4];
}
lock (renderLock)
{
var render = FractalRenderer.SelectRender(AddPixel, CheckAbort, UseSIMD, !UseFloat, UseThreads, UseADT);
Unsupported = render == null;
if (render == null)
return;
abort = false;
done = false;
Dispatcher.InvokeAsync(renderClock.Start);
double xmin = (xc - range / 2.0).Clamp(-3.0, 1);
double xmax = (xc + range / 2.0).Clamp(-3.0, 1);
if (xmin > xmax)
{
double t = xmin;
xmin = xmax;
xmax = t;
}
double ymin = (yc - range / 2.0).Clamp(-1.5f, 1.5f);
double ymax = (yc + range / 2.0).Clamp(-1.5f, 1.5f);
if (ymin > ymax)
{
double t = ymin;
ymin = ymax;
ymax = t;
}
double ystep = (range / (double)ch).Clamp(0, ymax - ymin);
double xstep = (range / (double)cw).Clamp(0, xmax - xmin);
double step = Math.Max(ystep, xstep);
xmin = xc - (cw * step / 2);
xmax = xc + (cw * step / 2);
ymin = yc - (ch * step / 2);
ymax = yc + (ch * step / 2);
if (xmin == xmax || ymin == ymax ||
xmin + xstep <= xmin || ymin + ystep <= ymin ||
ymax - ystep >= ymax || xmax - xstep >= xmax)
return;
Stopwatch timer = new Stopwatch();
timer.Start();
render((float)xmin, (float)xmax, (float)ymin, (float)ymax, (float)step);
ElapsedTime = timer.ElapsedMilliseconds;
abort = false;
done = true;
}
}