mightymandel v16

GPU-based Mandelbrot set explorer

tiling.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
10 #include "tiling.h"
11 #include "utility.h"
12 
25 void tiling_begin(struct tiling *tiling, int cols, int rows, int width, int height, const mpfr_t centerx, const mpfr_t centery, const mpfr_t radius) {
26  mpfr_inits2(53, tiling->centerx, tiling->centery, tiling->radius, tiling->tiled_centerx, tiling->tiled_centery, tiling->tiled_radius, (mpfr_ptr) 0);
27  tiling->width = width;
28  tiling->height = height;
29  tiling->col = -1;
30  tiling->row = 0;
31  tiling->tiled_cols = cols;
32  tiling->tiled_rows = rows;
33  mpfr_set_prec(tiling->tiled_centerx, mpfr_get_prec(centerx));
34  mpfr_set_prec(tiling->tiled_centery, mpfr_get_prec(centery));
35  mpfr_set_prec(tiling->tiled_radius, mpfr_get_prec(radius));
36  mpfr_set(tiling->tiled_centerx, centerx, MPFR_RNDN);
37  mpfr_set(tiling->tiled_centery, centery, MPFR_RNDN);
38  mpfr_set(tiling->tiled_radius, radius, MPFR_RNDN);
39 }
40 
46 void tiling_end(struct tiling *tiling) {
47  mpfr_clears(tiling->centerx, tiling->centery, tiling->radius, tiling->tiled_centerx, tiling->tiled_centery, tiling->tiled_radius, (mpfr_ptr) 0);
48 }
49 
58 bool tiling_next(struct tiling *tiling) {
59  tiling->col++;
60  if (tiling->col >= tiling->tiled_cols) {
61  tiling->col = 0;
62  tiling->row++;
63  if (tiling->row >= tiling->tiled_rows) {
64  return false;
65  }
66  }
67  mpfr_prec_t p = 16 + mpfr_get_prec(tiling->tiled_centerx);
68  mpfr_set_prec(tiling->centerx, p);
69  mpfr_set_prec(tiling->centery, p);
70  double i = (tiling->col + 0.5) * tiling->width;
71  double j = (tiling->row + 0.5) * tiling->height;
72  int width = tiling->width * tiling->tiled_cols;
73  int height = tiling->height * tiling->tiled_rows;
74  pixel_coordinate(tiling->centerx, tiling->centery, width, height, tiling->tiled_centerx, tiling->tiled_centery, tiling->tiled_radius, i, j);
75  mpfr_div_si(tiling->radius, tiling->tiled_radius, tiling->tiled_rows, MPFR_RNDN);
76  return true;
77 }