]> mj.ucw.cz Git - leo.git/blobdiff - lab-lines.c
Symbolizers may return copy of symbol
[leo.git] / lab-lines.c
index e3c3005df336cf6503c73a0786293c91cd1efc45..a32997317a57485c3d25e39a6fba45bb0bab3d31 100644 (file)
@@ -406,15 +406,7 @@ static void cut_edge(struct graph_edge *e, double dist)
   *new = *e;
   e->next = new;
 
-  switch (e->label->type)
-  {
-    case SYMBOLIZER_TEXT:
-      new->label = xmalloc(sizeof(struct sym_text));
-      *((struct sym_text *) new->label) = *((struct sym_text *) e->label);
-      break;
-    default:
-      ;
-  }
+  new->label = sym_copy(e->label);
 
   struct osm_node *n1 = e->n1->o;
   struct osm_node *n2 = e->n2->o;
@@ -426,6 +418,8 @@ static void cut_edge(struct graph_edge *e, double dist)
     return;
   }
 
+  // BEWARE: This creates new OSM object and modifies original data
+  // FIXME: Though this doesn't crash anything now, it could become deathly curse one day
   struct osm_node *n11 = xmalloc(sizeof(struct osm_node));
   struct graph_node *gn = xmalloc(sizeof(struct graph_node));
   gn->o = n11;
@@ -503,8 +497,18 @@ static void make_segments(void)
       rs->x2 = e->n2->o->x;
       rs->y2 = e->n2->o->y;
 
-      rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
-      ((struct sym_text *) rs->label)->rotate = convert_to_deg(atan(rs->slope));
+      if (fabs(rs->x2 - rs->x1) > 0.01)
+      {
+        rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
+        // This works a little bit magically :)
+        // It's possible not to care about quadrants as it "just works" as expected
+        ((struct sym_text *) rs->label)->rotate = convert_to_deg(atan(rs->slope));
+      }
+      else
+      {
+        rs->slope = 142; // Magic!
+        ((struct sym_text *) rs->label)->rotate = 1;
+      }
       struct variant *v = GARY_PUSH(rs->request.variants);
       make_bitmap(v, rs->label);