X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lab-lines.c;h=e33fd0a6891e1511a4d533f9c2c27ef421b6d2fe;hb=refs%2Fheads%2Flabelling;hp=4436e4dff19525dd1bdf451044fa61b482c6b45a;hpb=1b17564442494d9827c24abbdfd24dc2848bb107;p=leo.git diff --git a/lab-lines.c b/lab-lines.c index 4436e4d..e33fd0a 100644 --- a/lab-lines.c +++ b/lab-lines.c @@ -3,7 +3,6 @@ #include #include -#include #include #include @@ -25,6 +24,7 @@ enum edge_dir DIR_BWD, }; +// List of lines (osm_ways) making up a logical line struct longline { uns id; @@ -36,27 +36,25 @@ struct graph_node osm_id_t id; struct osm_node *o; struct graph_edge **edges; - int num; + int num; // Used for debug, mostly debug prints }; struct graph_edge { - osm_id_t id; - double length; + osm_id_t id; // Actual line (osm_way) ID + struct sym_line *line; color_t color; - int visited; - struct graph_edge *prev; - struct graph_edge *next; - struct graph_node *n1; - struct graph_node *n2; - uns longline; struct symbol *label; - struct sym_line *line; - z_index_t zindex; - enum edge_dir dir; - struct graph_node *anode; - struct graph_node *bnode; // DEBUG PRINT - int num; // DEBUG + z_index_t zindex; // z-index of label + double length; + int visited; // Iteration when line was last visited with BFS + uns longline; // Logical line this line was made part of + enum edge_dir dir; // Direction with respect to logical line, used by BFS + struct graph_node *n1; // Actual line endpoints + struct graph_node *n2; + struct graph_edge *prev; // Neighbouring lines in logical line + struct graph_edge *next; + int num; // Used for debug }; #define HASH_NODE struct graph_node @@ -86,20 +84,7 @@ static int dbg_num_hits = 0; static struct graph_edge **bfs_queue; -static double conf_max_section_length = 80, conf_max_section_overlay = 10; - -static struct cf_section lines_cf = { - CF_ITEMS { - CF_DOUBLE("MaxSectionLenght", &conf_max_section_length), - CF_DOUBLE("MaxSectionOverlay", &conf_max_section_overlay), - CF_END - } -}; - -void lines_conf(void) -{ - cf_declare_section("Labelling", &lines_cf, 0); -} +double conf_max_section_length = 80, conf_max_section_overlay = 10; static struct request_line *make_new_line(void) { @@ -117,7 +102,6 @@ static struct request_section *make_new_section(struct request_line *rl) struct request_section *rls = GARY_PUSH(rl->sections); rls->request.ind = num_requests++; rls->request.type = REQUEST_SECTION; - rls->num_segments = 0; GARY_INIT(rls->segments, 0); GARY_INIT(rls->request.variants, 0); @@ -127,7 +111,6 @@ static struct request_section *make_new_section(struct request_line *rl) static struct request_segment *make_new_segment(struct request_section *rls, struct symbol *sym) { struct request_segment *rs = GARY_PUSH(rls->segments); - rls->num_segments++; rs->request.ind = num_requests++; rs->request.type = REQUEST_SEGMENT; @@ -289,8 +272,7 @@ static void bfs_edge(struct graph_edge *e, struct graph_node *node, struct graph if (((other->n1->id == node->id) || (other->n2->id == node->id)) && (e->label) && (other->label) && - (e->label->type == SYMBOLIZER_TEXT) && (other->label->type == SYMBOLIZER_TEXT) && - (((struct sym_text *) e->label)->text == ((struct sym_text *) other->label)->text)) + (sym_look_same(e->label, other->label))) { if (! candidate || (other->length > candidate->length)) candidate = other; @@ -409,15 +391,7 @@ static void cut_edge(struct graph_edge *e, double dist) *new = *e; e->next = new; - switch (e->label->type) - { - case SYMBOLIZER_TEXT: - new->label = xmalloc(sizeof(struct sym_text)); - *((struct sym_text *) new->label) = *((struct sym_text *) e->label); - break; - default: - ; - } + new->label = sym_copy(e->label); struct osm_node *n1 = e->n1->o; struct osm_node *n2 = e->n2->o; @@ -429,6 +403,8 @@ static void cut_edge(struct graph_edge *e, double dist) return; } + // BEWARE: This creates new OSM object and modifies original data + // FIXME: Though this doesn't crash anything now, it could become deathly curse one day struct osm_node *n11 = xmalloc(sizeof(struct osm_node)); struct graph_node *gn = xmalloc(sizeof(struct graph_node)); gn->o = n11; @@ -506,8 +482,18 @@ static void make_segments(void) rs->x2 = e->n2->o->x; rs->y2 = e->n2->o->y; - rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1); - ((struct sym_text *) rs->label)->rotate = convert_to_deg(atan(rs->slope)); + if (fabs(rs->x2 - rs->x1) > 0.01) + { + rs->slope = (rs->y2 - rs->y1) / (rs->x2 - rs->x1); + // This works a little bit magically :) + // It's possible not to care about quadrants as it "just works" as expected + ((struct sym_text *) rs->label)->rotate = convert_to_deg(atan(rs->slope)); + } + else + { + rs->slope = 142; // Magic! + ((struct sym_text *) rs->label)->rotate = 1; + } struct variant *v = GARY_PUSH(rs->request.variants); make_bitmap(v, rs->label); @@ -525,7 +511,7 @@ static void make_segments(void) e = e->next; } - if (request->sections[0].num_segments == 0) + if (GARY_SIZE(request->sections[0].segments) == 0) { DEBUG(dbg_segments, VERBOSITY_INDIVIDUAL, "WARNING: Longline without any segment, skipped\n");