]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: Hacks and fixes in segment creation
authorKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 18:58:09 +0000 (20:58 +0200)
committerKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 18:58:09 +0000 (20:58 +0200)
labeller.c

index 5e82680e6648342ed180ca389ba834d2c924f16e..514819e26428aee065cdb6060af29a53e0ca3b88 100644 (file)
@@ -723,6 +723,7 @@ void cut_edge(struct graph_edge *e, double dist)
 
   e->length = hypot(abs(n1->x - n11->x), abs(n1->y - n11->y));
   new->length = hypot(abs(n11->x - n2->x), abs(n11->y - n2->y));
+  new->visited = 0;
 }
 
 void make_segments(void)
@@ -755,40 +756,31 @@ void make_segments(void)
     printf("New longline\n");
     while (e)
     {
-      if (cur_length + e->length > conf_max_section_length + conf_max_section_overlay)
+      if (e->visited < 0)
       {
-        if (dbg_segments)
-          printf("Edge too long, length is %.2f; %.2f - %.2f = %.2f\n", e->length, conf_max_section_length, cur_length, conf_max_section_length - cur_length);
-        cut_edge(e, conf_max_section_length - cur_length);
+        printf("BEWARE: Edge cycle\n");
+        break;
       }
+      e->visited = -1; // FIXME
 
-      if (cur_length + e->length > conf_max_section_length)
-      {
-        if (dbg_segments)
-          printf("Making new section, new length would be %f, allowed is %.2f / %.2f\n", cur_length + e->length, conf_max_section_length, conf_max_section_overlay);
-
-        struct osm_node *n1 = e->n1->o;
-        struct osm_node *n2 = e->n2->o;
-        rs = make_new_segment(rls, e->label);
-        rs->x1 = n1->x;
-        rs->y1 = n1->y;
-        rs->x2 = n2->x;
-        rs->y2 = n2->y;
-        rs->zindex = e->zindex;
-
-        rs->label = malloc(sizeof(struct sym_text));
-        *((struct sym_text *) rs->label) = *((struct sym_text *) e->label);
-        rls = make_new_section(request);
-        cur_length = 0;
-      }
+      if (dbg_segments)
+        printf("Taking edge from [%.2f; %.2f] to [%.2f; %.2f] of length %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, e->length);
 
       if (st && (e->length < st->tw))
       {
         e = e->next;
-        printf("Warning: Skipping segment\n");
+        //printf("Warning: Skipping segment\n");
         continue;
       }
 
+      if (cur_length + e->length > conf_max_section_length + conf_max_section_overlay)
+      {
+        if (dbg_segments)
+          printf("Edge too long, length is %.2f; %.2f - %.2f = %.2f\n", e->length, conf_max_section_length, cur_length, conf_max_section_length - cur_length);
+        // HACK to prevent cutting to 0 lenght
+        cut_edge(e, max2(conf_max_section_length - cur_length, 2));
+      }
+
       rs = make_new_segment(rls, e->label);
       rs->label = malloc(sizeof(struct sym_text));
       *((struct sym_text *) rs->label) = *((struct sym_text *) e->label);
@@ -803,6 +795,15 @@ void make_segments(void)
       rs->zindex = e->zindex;
 
       cur_length += e->length;
+      if (cur_length > conf_max_section_length)
+      {
+        if (dbg_segments)
+          printf("Making new section, new length would be %f, allowed is %.2f / %.2f\n", cur_length + e->length, conf_max_section_length, conf_max_section_overlay);
+
+        rls = make_new_section(request);
+        cur_length = 0;
+      }
+
       e = e->next;
     }