diff --git a/include/libdraw.h b/include/libdraw.h index 30f8138f2f68d90b6415a9b1ef58d268da61be7e..dbf6f18b37f0dab790efb311c5c09649622136bb 100644 --- a/include/libdraw.h +++ b/include/libdraw.h @@ -18,6 +18,9 @@ #define _LIBDRAW_H_ #include <common.h> +#define WIDTH 50 +#define HEIGHT 50 +#define SIZE 100 BEGIN_C_DECLS diff --git a/include/libhqr.h b/include/libhqr.h index c9bf812919ae5e604c63fec38b9677ec8a711486..04871044fa5e57c601d3353acb531ce38622e467 100644 --- a/include/libhqr.h +++ b/include/libhqr.h @@ -194,7 +194,10 @@ void libhqr_hqr_finalize( libhqr_tree_t *qrtree ); * function for treewalk */ -void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *file, int size); +void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *file); +void draw_rectangle(int k, int p, int m, int *tiles, FILE *file); +void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file); +void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file); /* * Debugging functions diff --git a/src/treewalk.c b/src/treewalk.c index b68cfaeae4a771b09571d85acadab3d2a5dfd87c..b5e4d746c911fc472e1b2032d38b09fd1af25e78 100644 --- a/src/treewalk.c +++ b/src/treewalk.c @@ -25,33 +25,41 @@ * p - annihilator * m - tile eliminated * file - File where the lines are drawn - * size - Size parameter of the drawing * tiles - table stocking the tiles */ -void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file, int size){ +void draw_horizontal_line(int k, int p, int m, int *tiles, FILE *file){ int y, ordinate1, ordinate2, absciss1, absciss2, absciss3, absciss4; - ordinate1 = size + size * m; - ordinate2 = size + size * p; - absciss1 = (size + (size / 4)) + size * tiles[m]; - absciss3 = (size + (size / 4)) + size * tiles[p]; + ordinate1 = SIZE + SIZE * m; + ordinate2 = SIZE + SIZE * p; + absciss1 = (SIZE + (SIZE / 4)) + SIZE * tiles[m]; + absciss3 = (SIZE + (SIZE / 4)) + SIZE * tiles[p]; /* Increasing the step */ y = libhqr_imax(tiles[m], tiles[p]) + 1; tiles[m] = tiles[p] = y; - absciss2 = (size + (size / 4)) + size * tiles[m]; - absciss4 = (size + (size / 4)) + size * tiles[p]; + absciss2 = (SIZE + (SIZE / 4)) + SIZE * tiles[m]; + absciss4 = (SIZE + (SIZE / 4)) + SIZE * tiles[p]; libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file); libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, k, file); } -void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file, int size){ +void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file){ int absciss, ordinate1, ordinate2; - absciss = size + size * tiles[m]; - ordinate1 = size + size * m; - ordinate2 = size + size * p; + absciss = SIZE + SIZE * tiles[m]; + ordinate1 = SIZE + SIZE * m; + ordinate2 = SIZE + SIZE * p; libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, file); } +void draw_rectangle(int k, int p, int m, int *tiles, FILE *file){ + int absciss, ordinate; + absciss = ((SIZE * 3) /4) + SIZE * tiles[m]; + ordinate = ((SIZE * 3) /4) + SIZE * m; + libhqr_drawTS(absciss, ordinate, WIDTH, HEIGHT, k, file); + ordinate = ((SIZE * 3) /4) + SIZE * p; + libhqr_drawTT(absciss, ordinate, WIDTH, HEIGHT, k, file); +} + /**************************************************** * LIBHQR_TREEWALK ***************************************************/ @@ -71,11 +79,8 @@ void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file, int size){ * @param[in] file * File where the tree is drawn * - * @param[in] size - * Paramter for the size of the drawing - * */ -void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file, int size) +void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file) { int tsid = -1, ttid = -1; int p = k; @@ -113,8 +118,8 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file, printf("POP TS: %d\n", tsid); printf("Call function on (%d, %d)\n", qrtree->currpiv(qrtree, k, tsid), tsid ); - draw_horizontal_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file, size); - draw_vertical_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file, size); + draw_horizontal_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file); + draw_vertical_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file); tsid = libhqr_queue_tile_head(&ts); } pivot = p = ttid; diff --git a/testings/testing_treedraw.c b/testings/testing_treedraw.c index 8ccebd0ba21cb70c62e4c90965d1b332a739539d..d29066ce8b1ff71ea21d0a0ec931063cb4bb3446 100644 --- a/testings/testing_treedraw.c +++ b/testings/testing_treedraw.c @@ -21,16 +21,12 @@ #include "libdraw.h" #include "libhqr.h" -#define WIDTH 50 -#define HEIGHT 50 -#define SIZE 100 - int main(int argc, char ** argv) { libhqr_tree_t qrtree; libhqr_tiledesc_t matrix; - int maxMN, absciss1, ordinate1, k, i, j; + int maxMN, k, i; int *tiles; matrix.nodes = 1; matrix.p = 1; @@ -46,25 +42,10 @@ main(int argc, char ** argv) libhqr_writeheader(tree); for (k = 0; k < 3; k++){ /* Drawing the lines */ - libhqr_treewalk(&qrtree, k, tiles, tree, SIZE); + libhqr_treewalk(&qrtree, k, tiles, tree); /* Drawing the rectangles */ for (i = k + 1; i < maxMN; i++){ - if(qrtree.gettype(&qrtree, k, i) == 0){ - absciss1 = ((SIZE * 3) /4) + SIZE * tiles[i]; - ordinate1 = ((SIZE * 3) /4) + SIZE * i; - libhqr_drawTS(absciss1, ordinate1, WIDTH, HEIGHT, k, tree); - j = qrtree.currpiv(&qrtree, k, i); - ordinate1 = ((SIZE * 3) /4) + SIZE * j; - libhqr_drawTT(absciss1, ordinate1, WIDTH, HEIGHT, k, tree); - } - else { - absciss1 = ((SIZE * 3) /4) + SIZE * tiles[i]; - ordinate1 = ((SIZE * 3) /4) + SIZE * i; - libhqr_drawTS(absciss1, ordinate1, WIDTH, HEIGHT, k, tree); - j = qrtree.currpiv(&qrtree, k, i); - ordinate1 = ((SIZE * 3) /4) + SIZE * j; - libhqr_drawTT(absciss1, ordinate1, WIDTH, HEIGHT, k, tree); - } + draw_rectangle(k, qrtree.currpiv(&qrtree, k, i), i, tiles, tree); } } libhqr_writeend(tree);