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 @@
#define _LIBDRAW_H_
#include <common.h>
#define WIDTH 50
#define HEIGHT 50
#define SIZE 100
BEGIN_C_DECLS
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
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