]> mj.ucw.cz Git - leo.git/blobdiff - labeller.c
Labelling: Variants may have offset
[leo.git] / labeller.c
index 3c5e4fa486c1ec6ca1e908b1fec10a60f29eb4da..345b70cee807a813adbd80afcaff491b891291bf 100644 (file)
@@ -100,9 +100,10 @@ int pop2_ind;
 int conf_part_size = 50;
 
 int move_min = 0;
-int move_max = 1;
+int move_max = 5;
 
 int num_requests = 0;
+int num_placements = 0;
 
 int conf_map_part_width = 5;
 int conf_map_part_height = 5;
@@ -150,7 +151,7 @@ void dump_longlines(void);
 void dump_linelabel_requests(void);
 void dump_individual(struct individual *individual);
 void print_label(struct symbol *sym);
-void dump_penalties(void);
+void dump_penalties(struct individual **population);
 
 double gen_movement(void);
 double gen_movement_uniform(void);
@@ -251,6 +252,8 @@ void labeller_init(void)
 
 void make_bitmap(struct variant *v, struct symbol *sym)
 {
+  v->offset_x = v->offset_y = 0;
+
   switch (sym->type)
   {
     case SYMBOLIZER_POINT:
@@ -324,20 +327,14 @@ void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t
   struct osm_node *n = (struct osm_node *) object; // FIXME: Compiler warning
   r->x = n->x;
   r->y = n->y;
+  make_bitmap(v, sym);
   switch (sym->type)
   {
     case SYMBOLIZER_ICON:
-      make_bitmap_icon(v, (struct sym_icon *) sym);
+      // FIXME: Really?
       r->x = ((struct sym_icon *)sym)->sir.x;
       r->y = ((struct sym_icon *)sym)->sir.y;
       break;
-    case SYMBOLIZER_POINT:
-      make_bitmap_point(v, (struct sym_point *) sym);
-      break;
-    case SYMBOLIZER_TEXT: ;
-      struct sym_text *st = (struct sym_text *) sym;
-      struct osm_node *n = (struct osm_node *) object;
-      make_bitmap_label(v, st);
     default:
       // FIXME
       return;
@@ -389,21 +386,7 @@ void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t
 
   GARY_INIT(r->request.variants, 0);
   struct variant *v = GARY_PUSH(r->request.variants);
-  switch (sym->type)
-  {
-    case SYMBOLIZER_ICON:
-      if (dbg_requests)
-        printf("DEBUG: Icon label\n");
-      make_bitmap_icon(v, (struct sym_icon *) sym);
-      break;
-    case SYMBOLIZER_TEXT:
-      if (dbg_requests)
-        printf("DEBUG: Text label\n");
-      make_bitmap_label(v, (struct sym_text *) sym);
-    default:
-      // FIXME
-      ;
-  }
+  make_bitmap(v, sym);
 }
 
 void make_graph(void)
@@ -837,8 +820,7 @@ void make_segments(void)
       rs->x2 = e->n2->o->x;
       rs->y2 = e->n2->o->y;
 
-      // FIXME: Set text rotation
-      rs->angle = atan2(rs->x2 - rs->x1, rs->y2 - rs->y1);
+      rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1);
       rs->zindex = e->zindex;
 
       cur_length += e->length;
@@ -1042,11 +1024,11 @@ if (dbg_plan)
   }
 }
 
-void dump_penalties(void)
+void dump_penalties(struct individual **population)
 {
   for (int i=0; i<conf_pop_size; i++)
   {
-    printf("Individual %d has penalty %d\n", i, population1[i]->penalty);
+    printf("Individual %d has penalty %d\n", i, population[i]->penalty);
   }
 }
 
@@ -1066,7 +1048,7 @@ printf("Having %u point requests, %u line requests and %u area requests\n", GARY
   qsort(population1, conf_pop_size, sizeof(struct individual *), cmp_individual);
 
   if (dbg_evolution)
-    dump_penalties();
+    dump_penalties(population1);
 
   printf("Dealing with %d requests\n", num_requests);
 
@@ -1101,13 +1083,13 @@ printf("Having %u point requests, %u line requests and %u area requests\n", GARY
     pop2_ind = 0;
 
     if (dbg_evolution)
-      dump_penalties();
+      dump_penalties(population1);
 
     rank_population();
     qsort(population1, conf_pop_size, sizeof(struct individual *), cmp_individual);
 
     if (dbg_evolution)
-      dump_penalties();
+      dump_penalties(population1);
   }
 
   plan_individual(population1[0]);
@@ -1125,6 +1107,7 @@ void make_population(void)
 {
   for (int i=0; i<conf_pop_size; i++)
   {
+    num_placements = 0; // FIXME: This IS a terrible HACK
     struct individual *i2 = ep_alloc(ep_individuals);
     init_individual(i2);
     population2[i] = i2;
@@ -1557,7 +1540,7 @@ void gen_coords(struct placement *p)
 
 double gen_movement(void)
 {
-  double m = (random() % 1000000) / 10000;
+  double m = (random() % 100000) / 10000;
   m = pow(m, 1.0/3) * flip(1, -1);
   if (dbg_movement)
     printf("Movement %.2f\n", m);
@@ -1720,6 +1703,7 @@ void hide_segment_labels(struct individual *individual)
 void init_placement(struct placement *p, struct individual *individual, struct request *r)
 {
   // FIXME
+  p->ind = num_placements++;
   p->request = r;
   p->processed = 0;
   p->x = p->y = 0; // To prevent valgrind from complaining