From 4175c5e7a411e1e29905ff8b4fa964dc60ad5fec Mon Sep 17 00:00:00 2001 From: Karryanna Date: Tue, 12 May 2015 14:25:12 +0200 Subject: [PATCH] Labelling: Cutting long edges into more segments --- labeller.c | 66 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/labeller.c b/labeller.c index ee740ba..a0f3d57 100644 --- a/labeller.c +++ b/labeller.c @@ -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; ilabel->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)) -- 2.39.5