[giv] Git rid of the union used for text annotation (which included a bad bug!)



commit e21852ea3988eb00c2c74fad3b90b1d7847f1cae
Author: Dov Grobgeld <dov grobgeld gmail com>
Date:   Wed Aug 3 21:00:28 2011 +0300

    Git rid of the union used for text annotation (which included a bad bug!)
    
    2011-08-03  Dov Grobgeld  <dov grobgeld gmail com>
    
            * GivRenderer.cc, giv-data.h, giv-parser.cc : Got
            rid of the union used for text annotation.

 ChangeLog          |    5 +++++
 src/GivRenderer.cc |   20 ++++++++++----------
 src/giv-data.h     |   11 ++---------
 src/giv-parser.cc  |   26 ++++++++++++--------------
 4 files changed, 29 insertions(+), 33 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 76404ff..10b2673 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-08-03  Dov Grobgeld  <dov grobgeld gmail com>
+
+        * GivRenderer.cc, giv-data.h, giv-parser.cc : Got
+        rid of the union used for text annotation.
+
 2011-06-30  Dov Grobgeld  <dov grobgeld gmail com>
 
         * plugins/SConstruct: Fixed compilation under windows for
diff --git a/src/GivRenderer.cc b/src/GivRenderer.cc
index ff12ce5..31058b4 100644
--- a/src/GivRenderer.cc
+++ b/src/GivRenderer.cc
@@ -102,8 +102,8 @@ void GivRenderer::paint()
                 for (int p_idx=0; p_idx<(int)dataset->points->len; p_idx++) {
                     point_t p = g_array_index(dataset->points, point_t, p_idx);
 
-                    double m_x = p.data.point.x * scale_x - shift_x;
-                    double m_y = p.data.point.y * scale_y - shift_y;
+                    double m_x = p.x * scale_x - shift_x;
+                    double m_y = p.y * scale_y - shift_y;
 
                     if (i < 2 && p.op == OP_DRAW) {
                         double cx0=old_x, cy0=old_y, cx1=m_x, cy1=m_y;
@@ -124,8 +124,8 @@ void GivRenderer::paint()
                     }
                     else if (p.op == OP_QUIVER) {
                         double qscale = dataset->quiver_scale;
-                        double q_x = old_x + p.data.point.x * scale_x * qscale;
-                        double q_y = old_y + p.data.point.y * scale_y * qscale;
+                        double q_x = old_x + p.x * scale_x * qscale;
+                        double q_y = old_y + p.y * scale_y * qscale;
                         painter.add_line_segment(old_x, old_y, q_x, q_y,
                                                  false);
                         need_paint = true;
@@ -184,8 +184,8 @@ void GivRenderer::paint()
                     has_text = true;
                 }
                 else {
-                    double m_x = p.data.point.x * scale_x - shift_x;
-                    double m_y = p.data.point.y * scale_y - shift_y;
+                    double m_x = p.x * scale_x - shift_x;
+                    double m_y = p.y * scale_y - shift_y;
 
                     // Crop marks 
                     if (m_x < -mark_size_x || m_x > width+mark_size_x
@@ -220,10 +220,10 @@ void GivRenderer::paint()
                 point_t p = g_array_index(dataset->points, point_t, p_idx);
 
                 if (p.op == OP_TEXT) {
-                    double m_x = p.data.point.x * scale_x - shift_x;
-                    double m_y = p.data.point.y * scale_y - shift_y;
-                    const char *text = p.data.text_object->string;
-                    int text_align = p.data.text_object->text_align;
+                    double m_x = p.x * scale_x - shift_x;
+                    double m_y = p.y * scale_y - shift_y;
+                    const char *text = p.text_object->string;
+                    int text_align = p.text_object->text_align;
                     painter.add_text(text, m_x, m_y, text_align, dataset->do_pango_markup);
                 }
             }
diff --git a/src/giv-data.h b/src/giv-data.h
index 64e7696..c91b0e9 100644
--- a/src/giv-data.h
+++ b/src/giv-data.h
@@ -80,7 +80,6 @@ typedef struct
 typedef struct
 {
     char *string;
-    double x, y;
     double size;
     int text_align; // A number between 1 and 9 like the numeric keypad. Default is 1.
 } text_mark_t;
@@ -88,14 +87,8 @@ typedef struct
 typedef struct
 {
   gint op;
-  union
-  {
-    struct
-    {
-      gdouble x, y;
-    } point;
-    text_mark_t *text_object;
-  } data;
+  gdouble x, y;
+  text_mark_t *text_object;
 } point_t;
 
 giv_dataset_t *new_giv_dataset(int num_datasets);
diff --git a/src/giv-parser.cc b/src/giv-parser.cc
index eb8cbdb..103ac99 100644
--- a/src/giv-parser.cc
+++ b/src/giv-parser.cc
@@ -611,7 +611,7 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
     case STRING_MOVE:
     case STRING_QUIVER:
         if (type == STRING_DRAW) {
-            if (sscanf(S_, "%lf %lf", &p.data.point.x, &p.data.point.y)==2) {
+            if (sscanf(S_, "%lf %lf", &p.x, &p.y)==2) {
                 if (marks->points->len == 0)
                     p.op = OP_MOVE;
                 else
@@ -619,7 +619,7 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
             }
         }
         else {
-            if (sscanf(S_, "%s %lf %lf", dummy, &p.data.point.x, &p.data.point.y)==3) {
+            if (sscanf(S_, "%s %lf %lf", dummy, &p.x, &p.y)==3) {
                 if (type == STRING_QUIVER) {
                     p.op = OP_QUIVER;
                     marks->has_quiver = TRUE;
@@ -630,28 +630,26 @@ giv_parser_giv_marks_data_add_line(GivParser *gp,
         }
 
         /* Find marks bounding box */
-        if (p.data.point.x < gp->global_mark_min_x)
-            gp->global_mark_min_x = p.data.point.x - ms2;
-        if (p.data.point.x > gp->global_mark_max_x)
-            gp->global_mark_max_x = p.data.point.x + ms2;
-        if (p.data.point.y < gp->global_mark_min_y)
-            gp->global_mark_min_y = p.data.point.y - ms2;
-        if (p.data.point.y > gp->global_mark_max_y)
-            gp->global_mark_max_y = p.data.point.y + ms2;
+        if (p.x < gp->global_mark_min_x)
+            gp->global_mark_min_x = p.x - ms2;
+        if (p.x > gp->global_mark_max_x)
+            gp->global_mark_max_x = p.x + ms2;
+        if (p.y < gp->global_mark_min_y)
+            gp->global_mark_min_y = p.y - ms2;
+        if (p.y > gp->global_mark_max_y)
+            gp->global_mark_max_y = p.y + ms2;
         g_array_append_val(marks->points, p);
         break;
     case STRING_TEXT:
         {
             text_mark_t *tm = (text_mark_t*)g_new(text_mark_t, 1);
-            sscanf(S_, "%s %lf %lf", dummy, &tm->x, &tm->y);
+            sscanf(S_, "%s %lf %lf", dummy, &p.x, &p.y);
             tm->text_align = 1;
             if (S_[1] >= '0' && S_[1] <= '9') 
                 tm->text_align = atoi(&S_[1]);
             tm->string = string_strdup_rest(S_, 3);
             p.op = OP_TEXT;
-            p.data.point.x = tm->x;
-            p.data.point.y = tm->y;
-            p.data.text_object = tm;
+            p.text_object = tm;
             g_array_append_val(marks->points, p);
         }
         break;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]