From 1f3bde001ddde1cdd78ea8d9ca936400d2548e00 Mon Sep 17 00:00:00 2001
From: Raphael Boucherie <raphael.boucherie@inria.fr>
Date: Fri, 14 Apr 2017 11:12:47 +0200
Subject: [PATCH] changed name and interface, still need to factorize the
 drawing of rectangle

---
 include/libdraw.h | 10 +++++-----
 include/libhqr.h  |  2 +-
 src/treedraw.c    | 22 ++++++++++-----------
 src/treewalk.c    | 50 ++++++++++++++++++++++++++++-------------------
 4 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/include/libdraw.h b/include/libdraw.h
index 35e836a..30f8138 100644
--- a/include/libdraw.h
+++ b/include/libdraw.h
@@ -31,11 +31,11 @@ extern char *color[4];
  * function for treedraw
  */
 
-void libhqr_writeheader(FILE *tree);
-void libhqr_writeend(FILE *tree);
-void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree);
-void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree);
-void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *tree);
+void libhqr_writeheader(FILE *file);
+void libhqr_writeend(FILE *file);
+void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *file);
+void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *file);
+void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file);
 
 END_C_DECLS
 
diff --git a/include/libhqr.h b/include/libhqr.h
index 9f516dc..c9bf812 100644
--- a/include/libhqr.h
+++ b/include/libhqr.h
@@ -194,7 +194,7 @@ void libhqr_hqr_finalize( libhqr_tree_t *qrtree );
  * function for treewalk
  */
 
-void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *tree, int size);
+void libhqr_treewalk(const libhqr_tree_t *qrtree,int k, int *tiles, FILE *file, int size);
 
 /*
  * Debugging functions
diff --git a/src/treedraw.c b/src/treedraw.c
index f834e16..4c3a05d 100644
--- a/src/treedraw.c
+++ b/src/treedraw.c
@@ -28,8 +28,8 @@ char *colortree[4] = {"red", "blue", "green", "purple"};
  * functions writing in the svg file
  */
 
-void libhqr_writeheader(FILE *tree){
-    if(fprintf(tree, "<?xml version=\"1.0\" standalone=\"no\"?>\n"
+void libhqr_writeheader(FILE *file){
+    if(fprintf(file, "<?xml version=\"1.0\" standalone=\"no\"?>\n"
                      "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"
                      "<svg width=\"2000\" height=\"2000\" version=\"1.1\" \n xmlns=\"http://www.w3.org/2000/svg\">\n") <0)
         return;
@@ -44,25 +44,25 @@ void libhqr_writeheader(FILE *tree){
  *    k - Factorization step for the color
  */
 
-void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *tree){
-    if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
+void libhqr_drawTT(int x, int y, int w, int h, int k, FILE *file){
+    if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
         return;
 }
 
-void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *tree){
-    if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
+void libhqr_drawTS(int x, int y, int w, int h, int k, FILE *file){
+    if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill=\"%s\" /> \n", x, y, w, h, colortree[k%4]) < 0 )
         return;
     int x2 = x + (w / 4);
     int y2 = y + (h / 4);
     int w2 = (w / 2);
     int h2 = (h / 2);
-    if(fprintf(tree,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n", x2, y2, w2, h2) < 0 ) return;
+    if(fprintf(file,"<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" fill =\"white\"/> \n", x2, y2, w2, h2) < 0 ) return;
 }
 
-void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *tree){
-    if(fprintf(tree,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:%s;stroke-width:2px;\"/> \n", x1, y1, x2, y2, colortree[k%4]) < 0 ) return;
+void libhqr_drawline(int x1, int y1, int x2, int y2, int k, FILE *file){
+    if(fprintf(file,"<line x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" style=\"fill:none;stroke:%s;stroke-width:2px;\"/> \n", x1, y1, x2, y2, colortree[k%4]) < 0 ) return;
 }
 
-void libhqr_writeend(FILE *tree){
-    if(fprintf(tree, "</svg>") < 0) return;
+void libhqr_writeend(FILE *file){
+    if(fprintf(file, "</svg>") < 0) return;
 }
diff --git a/src/treewalk.c b/src/treewalk.c
index dfdf64b..b68cfae 100644
--- a/src/treewalk.c
+++ b/src/treewalk.c
@@ -19,27 +19,37 @@
 #include <stdio.h>
 #include <assert.h>
 
-void draw_horizontal_line(int pivot, int k, FILE *tree,int size, int *tiles, int killed){
+/*
+ * Common prameters to the 2 following functions:
+ *    k     - Factorization step for the color
+ *    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){
     int y, ordinate1, ordinate2, absciss1, absciss2, absciss3, absciss4;
-    ordinate1 =  size + size * killed;
-    ordinate2  = size + size * pivot;
-    absciss1 = (size + (size / 4)) + size * tiles[killed];
-    absciss3 = (size + (size / 4)) + size * tiles[pivot];
+    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[killed],  tiles[pivot]) + 1;
-    tiles[killed] = tiles[pivot] = y;
-    absciss2 = (size + (size / 4)) + size * tiles[killed];
-    absciss4 = (size + (size / 4)) + size * tiles[pivot];
-    libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, tree);
-    libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, k, tree);
+    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];
+    libhqr_drawline( absciss1, ordinate1, absciss2, ordinate1, k, file);
+    libhqr_drawline( absciss3, ordinate2, absciss4, ordinate2, k, file);
 }
 
-void draw_vertical_line(int pivot, int k, FILE *tree,int size, int *tiles, int killed){
+void draw_vertical_line(int k, int p, int m, int *tiles, FILE *file, int size){
     int absciss, ordinate1, ordinate2;
-    absciss = size + size * tiles[killed];
-    ordinate1 = size + size * killed;
-    ordinate2 = size + size * pivot;
-    libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, tree);
+    absciss = size + size * tiles[m];
+    ordinate1 = size + size * m;
+    ordinate2 = size + size * p;
+    libhqr_drawline(absciss, ordinate1, absciss, ordinate2, k, file);
 }
 
 /****************************************************
@@ -58,14 +68,14 @@ void draw_vertical_line(int pivot, int k, FILE *tree,int size, int *tiles, int k
  * @param[in] tiles
  *         Table stocking the tiles and their step
  *
- * @param[in] tree
+ * @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 *tree, int size)
+void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *file, int size)
 {
     int tsid = -1, ttid = -1;
     int p = k;
@@ -103,8 +113,8 @@ void libhqr_treewalk(const libhqr_tree_t *qrtree, int k, int *tiles, FILE *tree,
             printf("POP TS: %d\n", tsid);
             printf("Call function on (%d, %d)\n",
                    qrtree->currpiv(qrtree, k, tsid), tsid );
-            draw_horizontal_line(qrtree->currpiv(qrtree, k, tsid), k, tree, size, tiles, tsid);
-            draw_vertical_line(qrtree->currpiv(qrtree, k, tsid), k, tree, size, tiles, 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);
             tsid = libhqr_queue_tile_head(&ts);
         }
         pivot = p = ttid;
-- 
GitLab