Logo Search packages:      
Sourcecode: navit version File versions

static struct route_path * route_path_new ( struct route_graph this,
struct route_path oldpath,
struct route_info pos,
struct route_info dst,
struct vehicleprofile profile 
) [static, read]

Creates a new route path.

This creates a new non-trivial route. It therefore needs the routing information created by route_graph_flood, so make shure to run route_graph_flood() after changing the destination before using this function.

Parameters:
this The route graph to create the route from
oldpath (Optional) old path which may contain parts of the new part - this speeds things up a bit. May be NULL.
pos The starting position of the route
dst The destination of the route
preferences The routing preferences
Returns:
The new route path

Definition at line 1885 of file route.c.

References route_graph_point::c, route_info::c, route_graph_segment::data, route_graph_segment::end, route_segment_data::item, street_data::item, route_info::lenextra, route_info::lp, map_projection(), vehicleprofile::mode, route_path::path_hash, route_info::percent, route_path_add_item_from_graph(), route_path_add_line(), route_path_new_offroad(), route_value_seg(), route_graph_point::seg, route_graph_segment::start, route_info::street, route_path::updated, route_graph_point::value, coord::x, and coord::y.

{
      struct route_graph_segment *first,*s=NULL;
      struct route_graph_point *start;
      struct route_info *posinfo, *dstinfo;
      int segs=0;
      int val1=INT_MAX,val2=INT_MAX;
      int val;
      struct route_path *ret;

      if (! pos->street || ! dst->street)
            return NULL;

      if (profile->mode == 2 || (profile->mode == 0 && pos->lenextra + dst->lenextra > transform_distance(map_projection(pos->street->item.map), &pos->c, &dst->c)))
            return route_path_new_offroad(this, pos, dst);
      
      s=route_graph_get_segment(this, pos->street);
      if (!s) {
            dbg(0,"no segment for position found\n");
            return NULL;
      }
      val=route_value_seg(profile, NULL, s, 1);
      if (val != INT_MAX) {
            val=val*(100-pos->percent)/100;
            val1=s->end->value+val;
      }
      val=route_value_seg(profile, NULL, s, -1);
      if (val != INT_MAX) {
            val=val*pos->percent/100;
            val2=s->start->value+val;
      }
      if (val1 == INT_MAX && val2 == INT_MAX) {
            dbg(0,"no route found, pos blocked\n");
            return NULL;
      }
      if (val1 == val2) {
            val1=s->end->value;
            val2=s->start->value;
      }
      if (val1 < val2) 
            start=s->start;
      else 
            start=s->end;
      ret=g_new0(struct route_path, 1);
      ret->updated=1;
      if (pos->lenextra) 
            route_path_add_line(ret, &pos->c, &pos->lp, pos->lenextra);
      ret->path_hash=item_hash_new();
      dstinfo=NULL;
      posinfo=pos;
      first=s;
      while (s && !dstinfo) { /* following start->seg, which indicates the least costly way to reach our destination */
            segs++;
#if 0
            printf("start->value=%d 0x%x,0x%x\n", start->value, start->c.x, start->c.y);
#endif
            if (s->start == start) {            
                  if (item_is_equal(s->data.item, dst->street->item) && (s->end->seg == s || !posinfo))
                        dstinfo=dst;
                  if (!route_path_add_item_from_graph(ret, oldpath, s, 1, posinfo, dstinfo))
                        ret->updated=0;
                  start=s->end;
            } else {
                  if (item_is_equal(s->data.item, dst->street->item) && (s->start->seg == s || !posinfo))
                        dstinfo=dst;
                  if (!route_path_add_item_from_graph(ret, oldpath, s, -1, posinfo, dstinfo))
                        ret->updated=0;
                  start=s->start;
            }
            posinfo=NULL;
            s=start->seg;
      }
      if (dst->lenextra) 
            route_path_add_line(ret, &dst->lp, &dst->c, dst->lenextra);
      dbg(1, "%d segments\n", segs);
      return ret;
}


Generated by  Doxygen 1.6.0   Back to index