diff options
-rw-r--r-- | navit/route.c | 11 | ||||
-rw-r--r-- | navit/route_protected.h | 5 | ||||
-rw-r--r-- | navit/traffic.c | 31 |
3 files changed, 36 insertions, 11 deletions
diff --git a/navit/route.c b/navit/route.c index 451af6016..fef80fe9d 100644 --- a/navit/route.c +++ b/navit/route.c @@ -74,10 +74,6 @@ struct map_priv { int debug_route=0; -#define RP_TRAFFIC_DISTORTION 1 -#define RP_TURN_RESTRICTION 2 -#define RP_TURN_RESTRICTION_RESOLVED 4 - #define RSD_OFFSET(x) *((int *)route_segment_data_field_pos((x), attr_offset)) #define RSD_SIZE_WEIGHT(x) *((struct size_weight_limit *)route_segment_data_field_pos((x), attr_vehicle_width)) @@ -2324,7 +2320,7 @@ static void route_graph_change_traffic_distortion(struct route_graph *this, stru * @param this The route graph to add to * @param item The item to add */ -static void route_graph_add_turn_restriction(struct route_graph *this, struct item *item) { +void route_graph_add_turn_restriction(struct route_graph *this, struct item *item) { struct route_graph_point *pnt[4]; struct coord c[5]; int i,count; @@ -2345,6 +2341,7 @@ static void route_graph_add_turn_restriction(struct route_graph *this, struct it data.item=item; data.flags=0; data.len=0; + data.score = 0; route_graph_add_segment(this, pnt[0], pnt[1], &data); route_graph_add_segment(this, pnt[1], pnt[2], &data); #if 1 @@ -2971,6 +2968,7 @@ static void route_graph_clone_segment(struct route_graph *this, struct route_gra data.len=s->data.len+1; data.maxspeed=-1; data.dangerous_goods=0; + data.score = s->data.score; if (s->data.flags & AF_SPEED_LIMIT) data.maxspeed=RSD_MAXSPEED(&s->data); if (s->data.flags & AF_SEGMENTED) @@ -3091,7 +3089,8 @@ void route_graph_build_done(struct route_graph *rg, int cancel) { rg->sel=NULL; if (! cancel) { route_graph_process_restrictions(rg); - callback_call_0(rg->done_cb); + if (rg->done_cb) + callback_call_0(rg->done_cb); } rg->busy=0; } diff --git a/navit/route_protected.h b/navit/route_protected.h index b22630bb8..be38749f2 100644 --- a/navit/route_protected.h +++ b/navit/route_protected.h @@ -35,6 +35,10 @@ extern "C" { #endif +#define RP_TRAFFIC_DISTORTION 1 +#define RP_TURN_RESTRICTION 2 +#define RP_TURN_RESTRICTION_RESOLVED 4 + #define RSD_MAXSPEED(x) *((int *)route_segment_data_field_pos((x), attr_maxspeed)) /** @@ -157,6 +161,7 @@ void route_add_traffic_distortion(struct route *this_, struct item *item); void route_remove_traffic_distortion(struct route *this_, struct item *item); void route_change_traffic_distortion(struct route *this_, struct item *item); struct route_graph_point * route_graph_add_point(struct route_graph *this, struct coord *f); +void route_graph_add_turn_restriction(struct route_graph *this, struct item *item); void route_graph_free_points(struct route_graph *this); struct route_graph_point *route_graph_get_point(struct route_graph *this, struct coord *c); void route_graph_add_segment(struct route_graph *this, struct route_graph_point *start, diff --git a/navit/traffic.c b/navit/traffic.c index 03c73da4d..e9b8b25a4 100644 --- a/navit/traffic.c +++ b/navit/traffic.c @@ -1315,6 +1315,12 @@ static int traffic_point_match_attributes(struct traffic_point * this_, struct i static int traffic_route_get_seg_cost(struct route_graph_segment *over, int dir) { if (over->data.flags & (dir >= 0 ? AF_ONEWAYREV : AF_ONEWAY)) return INT_MAX; + if (dir > 0 && (over->start->flags & RP_TURN_RESTRICTION)) + return INT_MAX; + if (dir < 0 && (over->end->flags & RP_TURN_RESTRICTION)) + return INT_MAX; + if ((over->data.item.type < route_item_first) || (over->data.item.type > route_item_last)) + return INT_MAX; return over->data.len * (100 - over->data.score) * (PENALTY_OFFROAD - 1) / 100 + over->data.len; } @@ -1502,8 +1508,9 @@ static void traffic_location_populate_route_graph(struct traffic_location * this continue; } while ((item = map_rect_get_item(rg->mr))) { - /* TODO we might need turn restrictions as well */ - if ((item->type < route_item_first) || (item->type > route_item_last)) + if (item->type == type_street_turn_restriction_no || item->type == type_street_turn_restriction_only) + route_graph_add_turn_restriction(rg, item); + else if ((item->type < route_item_first) || (item->type > route_item_last)) continue; if (item_get_default_flags(item->type)) { @@ -1583,7 +1590,7 @@ static void traffic_location_populate_route_graph(struct traffic_location * this map_rect_destroy(rg->mr); rg->mr = NULL; } - route_graph_build_done(rg, 1); + route_graph_build_done(rg, 0); } /** @@ -1774,8 +1781,14 @@ static struct route_graph_point * traffic_route_flood_graph(struct route_graph * p = rg->hash[i]; while (p) { if (!g_list_find(existing, p)) { - p->value = PENALTY_OFFROAD * transform_distance(projection_mg, &p->c, c_dst); - p->el = fh_insertkey(heap, p->value, p); + if (!(p->flags & RP_TURN_RESTRICTION)) { + p->value = PENALTY_OFFROAD * transform_distance(projection_mg, &p->c, c_dst); + p->el = fh_insertkey(heap, p->value, p); + } else { + /* ignore points which are part of turn restrictions */ + p->value = INT_MAX; + p->el = NULL; + } p->seg = NULL; } p = p->hash_next; @@ -1907,6 +1920,8 @@ static struct route_graph_segment * traffic_route_append(struct route_graph *rg, continue; if (s_cmp->data.flags & AF_ONEWAYREV) continue; + if (s_cmp->end->flags & RP_TURN_RESTRICTION) + continue; if ((s_cmp->data.item.id_hi == s->data.item.id_hi) && (s_cmp->data.item.id_lo == s->data.item.id_lo)) { s_next = s_cmp; @@ -1925,6 +1940,8 @@ static struct route_graph_segment * traffic_route_append(struct route_graph *rg, continue; if (s_cmp->data.flags & AF_ONEWAY) continue; + if (s_cmp->end->flags & RP_TURN_RESTRICTION) + continue; if ((s_cmp->data.item.id_hi == s->data.item.id_hi) && (s_cmp->data.item.id_lo == s->data.item.id_lo)) { s_next = s_cmp; @@ -2155,6 +2172,10 @@ static GList * traffic_location_get_matching_points(struct traffic_location * th if (!(p = route_graph_get_point(rg, &c))) continue; + /* exclude points where turn restrictions apply */ + if (p->flags & RP_TURN_RESTRICTION) + continue; + /* exclude items with a zero score */ if (!(score = traffic_point_match_attributes(trpoint, item))) continue; |