+function adjustCoordsAndDraw(aC_min, aC_max) {
+ let iWidth = 0;
+ try {
+ iWidth = gPref.getIntPref("mandelbrot.image.width");
+ }
+ catch (e) { }
+ if ((iWidth < 10) || (iWidth > 5000)) {
+ iWidth = 300;
+ gPref.setIntPref("mandelbrot.image.width", iWidth);
+ }
+ let iHeight = 0;
+ try {
+ iHeight = gPref.getIntPref("mandelbrot.image.height");
+ }
+ catch (e) { }
+ if ((iHeight < 10) || (iHeight > 5000)) {
+ iHeight = 300;
+ gPref.setIntPref("mandelbrot.image.height", iHeight);
+ }
+
+ // correct coordinates
+ if (aC_min.r < -2)
+ aC_min.r = -2;
+ if (aC_max.r > 2)
+ aC_max.r = 2;
+ if ((aC_min.r > 2) || (aC_max.r < -2) || (aC_min.r >= aC_max.r)) {
+ aC_min.r = -2.0; aC_max.r = 1.0;
+ }
+ if (aC_min.i < -2)
+ aC_min.i = -2;
+ if (aC_max.i > 2)
+ aC_max.i = 2;
+ if ((aC_min.i > 2) || (aC_max.i < -2) || (aC_min.i >= aC_max.i)) {
+ aC_min.i = -1.5; aC_max.i = 1.5;
+ }
+
+ let CWidth = aC_max.r - aC_min.r;
+ let CHeight = aC_max.i - aC_min.i;
+ let C_mid = new complex(aC_min.r + CWidth / 2, aC_min.i + CHeight / 2);
+
+ let CRatio = Math.max(CWidth / iWidth, CHeight / iHeight);
+
+ gPref.setCharPref("mandelbrot.last_image.Cr_min", C_mid.r - iWidth * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Cr_max", C_mid.r + iWidth * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Ci_min", C_mid.i - iHeight * CRatio / 2);
+ gPref.setCharPref("mandelbrot.last_image.Ci_max", C_mid.i + iHeight * CRatio / 2);
+
+ drawImage();
+}
+