]> mj.ucw.cz Git - leo.git/commitdiff
Labelling: Support for rotated labels
authorKarryanna <karry@karryanna.cz>
Wed, 10 Jun 2015 09:23:06 +0000 (11:23 +0200)
committerKarryanna <karry@karryanna.cz>
Wed, 10 Jun 2015 09:23:06 +0000 (11:23 +0200)
This forced some changes in segment initialization which are not nice
and might deserve some rethinking in the future.

labeller.c

index da3bb52d177cbb040708ca40ff26e2fc582ab766..a747552c0b6004ac82123dfa25a52ae01d4ba137 100644 (file)
@@ -281,14 +281,45 @@ void make_bitmap_point(struct variant *v, struct sym_point *sp)
 
 void make_bitmap_label(struct variant *v, struct sym_text *text)
 {
-  v->width = ceil(text->tw);
-  v->height = ceil(text->th);
+  int tw = ceil(text->tw);
+  int th = ceil(text->th);
+
+  double rotate_rad = text->rotate / (-180 / M_PI);
+
+  // Initially, ll = [0; 0], lr = [tw, 0], ul = [0, th], ur = [tw, th]
+  // They could be declared before but should not be initialized in code
+  // as reassigning x-coordinate affects computation of y-cordinate
+  int llx = 0;
+  int lly = 0;
+
+  int lrx = tw * cos(rotate_rad);
+  int lry = tw * sin(rotate_rad);
+
+  int ulx = th * sin(rotate_rad);
+  int uly = th * cos(rotate_rad);
+
+  int urx = tw * cos(rotate_rad) + th * sin(rotate_rad);
+  int ury = tw * sin(rotate_rad) + th * cos(rotate_rad);
+
+  int min_x = min4(llx, lrx, ulx, urx);
+  int min_y = min4(lly, lry, uly, ury);
+  int max_x = max4(llx, lrx, ulx, urx);
+  int max_y = max4(lly, lry, uly, ury);
+
+  v->width = max_x - min_x + 1;
+  v->height = max_y - min_y + 1;
   v->bitmap = malloc(v->width * v->height * sizeof(bool));
-  for (int i=0; i<v->height; i++)
-    for (int j=0; j<v->width; j++)
+  memset(v->bitmap, 0, v->width * v->height * sizeof(bool));
+
+  for (int i=0; i<th; i++)
+  {
+    for (int j=0; j<tw; j++)
     {
-      v->bitmap[i*v->width + j] = 1;
+      int nx = j*cos(rotate_rad) + i*sin(rotate_rad);
+      int ny = j*sin(rotate_rad) + i*cos(rotate_rad);
+      v->bitmap[(ny-min_y)*v->width + (nx-min_x)] = 1;
     }
+  }
 }
 
 void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex)
@@ -715,8 +746,11 @@ struct request_segment *make_new_segment(struct request_section *rls, struct sym
   rs->request.type = REQUEST_SEGMENT;
 
   GARY_INIT(rs->request.variants, 0);
-  struct variant *v = GARY_PUSH(rs->request.variants);
-  make_bitmap(v, sym);
+  if (sym)
+  {
+    struct variant *v = GARY_PUSH(rs->request.variants);
+    make_bitmap(v, sym);
+  }
 
   return rs;
 }
@@ -825,7 +859,7 @@ void make_segments(void)
         cut_edge(e, max2(conf_max_section_length - cur_length, 2));
       }
 
-      rs = make_new_segment(rls, e->label);
+      rs = make_new_segment(rls, NULL);
       rs->label = malloc(sizeof(struct sym_text));
       *((struct sym_text *) rs->label) = *((struct sym_text *) e->label);
 
@@ -835,6 +869,11 @@ void make_segments(void)
       rs->y2 = e->n2->o->y;
 
       rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
+      ((struct sym_text *) rs->label)->rotate = atan(rs->slope) * (-180 / M_PI);
+      struct variant *v = GARY_PUSH(rs->request.variants);
+      printf("Request %d\n", rs->request.ind);
+      make_bitmap(v, rs->label);
+
       rs->zindex = e->zindex;
 
       cur_length += e->length;