]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: Cutting long edges into more segments
authorKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 12:25:12 +0000 (14:25 +0200)
committerKarryanna <karry@karryanna.cz>
Tue, 12 May 2015 12:25:12 +0000 (14:25 +0200)
labeller.c

index ee740ba8451558ba49a019493d5c6a15340c83ee..a0f3d57be20fc4a015af6edfc1a55143310f6743 100644 (file)
@@ -41,6 +41,8 @@ struct eltpool *ep_individuals;
 struct individual **population1;
 struct individual **population2;
 
+int dbg_segments = 0;
+
 int page_width_int;
 int page_height_int;
 
@@ -105,6 +107,7 @@ void make_bitmap_icon(struct point_variant *v, struct sym_icon *si);
 void make_bitmap_point(struct point_variant *v, struct sym_point *sp);
 void make_bitmap_label(struct point_variant *v, struct sym_text *text);
 
+void cut_edge(struct graph_edge *e, double dist);
 struct request_line *make_new_line(void);
 struct request_section *make_new_section(struct request_line *rl);
 struct request_segment *make_new_segment(struct request_section *rls, struct symbol *sym);
@@ -686,6 +689,39 @@ struct request_segment *make_new_segment(struct request_section *rls, struct sym
   return rs;
 }
 
+void cut_edge(struct graph_edge *e, double dist)
+{
+  if (dbg_segments)
+    printf("Cutting [%.2f; %.2f] -- [%.2f; %.2f] to dist %.2f\n", e->n1->o->x, e->n1->o->y, e->n2->o->x, e->n2->o->y, dist);
+
+  struct graph_edge *new = malloc(sizeof(struct graph_edge));
+  *new = *e;
+  e->next = new;
+
+  struct osm_node *n1 = e->n1->o;
+  struct osm_node *n2 = e->n2->o;
+
+  // FIXME
+  if ((n1->x == n2->x) && (n1->y == n2->y))
+  {
+    printf("[%.2f; %.2f] -- [%.2f; %.2f]\n", n1->x, n1->y, n2->x, n2->y);
+    printf("Won't cut point\n");
+    return;
+  }
+
+  struct osm_node *n11 = malloc(sizeof(struct osm_node));
+  struct graph_node *gn = malloc(sizeof(struct graph_node));
+  gn->o = n11;
+  double vsize = sqrt(pow(n1->x - n2->x, 2) + pow(n1->y - n2->y, 2));
+  n11->x = n1->x + (n2->x - n1->x) / vsize * dist;
+  n11->y = n1->y + (n2->y - n1->y) / vsize * dist;
+
+  e->n2 = new->n1 = gn;
+
+  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));
+}
+
 void make_segments(void)
 {
   for (uns i=0; i<GARY_SIZE(longlines); i++)
@@ -699,7 +735,7 @@ void make_segments(void)
     struct request_segment *rs = NULL;
 
     struct graph_edge *e = longlines[i].first;
-    int cur_length = 0;
+    double cur_length = 0;
 
     struct sym_text *st = NULL;
     if (e->label->type == SYMBOLIZER_TEXT)
@@ -713,26 +749,34 @@ void make_segments(void)
       // FIXME;
     }
 
+    printf("New longline\n");
     while (e)
     {
-      if ((cur_length + e->length > conf_max_section_length) &&
-          !(cur_length + e->length < conf_max_section_overlay))
+      if (cur_length + e->length > conf_max_section_length + conf_max_section_overlay)
       {
-        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 *n = e->n1->o;
+        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);
+      }
+
+      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 = n->x;
-        rs->y1 = n->y;
-        // FIXME: Truly compute x2, y2
-        rs->x2 = n->x;
-        rs->y2 = n->y;
+        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 (st && (e->length < st->tw))