From c6fe2259ad1a11ab3c0591d699f9da26da7da568 Mon Sep 17 00:00:00 2001 From: Karryanna Date: Tue, 12 May 2015 20:58:09 +0200 Subject: [PATCH] Labelling: Hacks and fixes in segment creation --- labeller.c | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/labeller.c b/labeller.c index 5e82680..514819e 100644 --- a/labeller.c +++ b/labeller.c @@ -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; } -- 2.39.2