Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 86923d9a authored by BOUCHERIE Raphael's avatar BOUCHERIE Raphael
Browse files

factorized the rectangle drawing, moved some functions

parent 1f3bde00
No related branches found
No related tags found
1 merge request!5Print tree
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#define _LIBDRAW_H_ #define _LIBDRAW_H_
#include <common.h> #include <common.h>
#define WIDTH 50
#define HEIGHT 50
#define SIZE 100
BEGIN_C_DECLS BEGIN_C_DECLS
......
...@@ -194,7 +194,10 @@ void libhqr_hqr_finalize( libhqr_tree_t *qrtree ); ...@@ -194,7 +194,10 @@ void libhqr_hqr_finalize( libhqr_tree_t *qrtree );
* function for treewalk * 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 * Debugging functions
......
...@@ -25,33 +25,41 @@ ...@@ -25,33 +25,41 @@
* p - annihilator * p - annihilator
* m - tile eliminated * m - tile eliminated
* file - File where the lines are drawn * file - File where the lines are drawn
* size - Size parameter of the drawing
* tiles - table stocking the tiles * 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; int y, ordinate1, ordinate2, absciss1, absciss2, absciss3, absciss4;
ordinate1 = size + size * m; ordinate1 = SIZE + SIZE * m;
ordinate2 = size + size * p; ordinate2 = SIZE + SIZE * p;
absciss1 = (size + (size / 4)) + size * tiles[m]; absciss1 = (SIZE + (SIZE / 4)) + SIZE * tiles[m];
absciss3 = (size + (size / 4)) + size * tiles[p]; absciss3 = (SIZE + (SIZE / 4)) + SIZE * tiles[p];
/* Increasing the step */ /* Increasing the step */
y = libhqr_imax(tiles[m], tiles[p]) + 1; y = libhqr_imax(tiles[m], tiles[p]) + 1;
tiles[m] = tiles[p] = y; tiles[m] = tiles[p] = y;
absciss2 = (size + (size / 4)) + size * tiles[m]; absciss2 = (SIZE + (SIZE / 4)) + SIZE * tiles[m];
absciss4 = (size + (size / 4)) + size * tiles[p]; absciss4 = (SIZE + (SIZE / 4)) + SIZE * tiles[p];
libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file); libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file);
libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, 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; int absciss, ordinate1, ordinate2;
absciss = size + size * tiles[m]; absciss = SIZE + SIZE * tiles[m];
ordinate1 = size + size * m; ordinate1 = SIZE + SIZE * m;
ordinate2 = size + size * p; ordinate2 = SIZE + SIZE * p;
libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, file); 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 * LIBHQR_TREEWALK
***************************************************/ ***************************************************/
...@@ -71,11 +79,8 @@ void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file, int size){ ...@@ -71,11 +79,8 @@ void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file, int size){
* @param[in] file * @param[in] file
* File where the tree is drawn * 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 tsid = -1, ttid = -1;
int p = k; int p = k;
...@@ -113,8 +118,8 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file, ...@@ -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("POP TS: %d\n", tsid);
printf("Call function on (%d, %d)\n", printf("Call function on (%d, %d)\n",
qrtree->currpiv(qrtree, k, tsid), tsid ); qrtree->currpiv(qrtree, k, tsid), tsid );
draw_horizontal_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, size); draw_vertical_line(k, qrtree->currpiv(qrtree, k, tsid), tsid, tiles, file);
tsid = libhqr_queue_tile_head(&ts); tsid = libhqr_queue_tile_head(&ts);
} }
pivot = p = ttid; pivot = p = ttid;
......
...@@ -21,16 +21,12 @@ ...@@ -21,16 +21,12 @@
#include "libdraw.h" #include "libdraw.h"
#include "libhqr.h" #include "libhqr.h"
#define WIDTH 50
#define HEIGHT 50
#define SIZE 100
int int
main(int argc, char ** argv) main(int argc, char ** argv)
{ {
libhqr_tree_t qrtree; libhqr_tree_t qrtree;
libhqr_tiledesc_t matrix; libhqr_tiledesc_t matrix;
int maxMN, absciss1, ordinate1, k, i, j; int maxMN, k, i;
int *tiles; int *tiles;
matrix.nodes = 1; matrix.nodes = 1;
matrix.p = 1; matrix.p = 1;
...@@ -46,25 +42,10 @@ main(int argc, char ** argv) ...@@ -46,25 +42,10 @@ main(int argc, char ** argv)
libhqr_writeheader(tree); libhqr_writeheader(tree);
for (k = 0; k < 3; k++){ for (k = 0; k < 3; k++){
/* Drawing the lines */ /* Drawing the lines */
libhqr_treewalk(&qrtree, k, tiles, tree, SIZE); libhqr_treewalk(&qrtree, k, tiles, tree);
/* Drawing the rectangles */ /* Drawing the rectangles */
for (i = k + 1; i < maxMN; i++){ for (i = k + 1; i < maxMN; i++){
if(qrtree.gettype(&qrtree, k, i) == 0){ draw_rectangle(k, qrtree.currpiv(&qrtree, k, i), i, tiles, tree);
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);
}
} }
} }
libhqr_writeend(tree); libhqr_writeend(tree);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment