summaryrefslogtreecommitdiff
path: root/navit
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-04-19 13:20:08 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2009-04-19 13:20:08 +0000
commit20efb4a78648669c496fdb504d76d93df48d9460 (patch)
tree795c5ea322fbb55407ac68e2649b4a16d46f8741 /navit
parentae4b8f3af024fb568121a57fa7ec7920ec34dbf8 (diff)
downloadnavit-20efb4a78648669c496fdb504d76d93df48d9460.tar.gz
Fix:Various:Routing fixes
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2215 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r--navit/attr.c2
-rw-r--r--navit/navit.c7
-rw-r--r--navit/osd/core/osd_core.c3
-rw-r--r--navit/route.c45
-rw-r--r--navit/track.c72
-rw-r--r--navit/track.h4
-rw-r--r--navit/vehicleprofile.c3
7 files changed, 56 insertions, 80 deletions
diff --git a/navit/attr.c b/navit/attr.c
index 370df95e8..ba4c0ac8b 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -134,7 +134,7 @@ attr_new_from_text(const char *name, const char *value)
break;
}
if (attr >= attr_type_int_begin && attr <= attr_type_int_end) {
- ret->u.num=atoi(value);
+ ret->u.num=strtol(value, NULL, 0);
if ((attr >= attr_type_rel_abs_begin) && (attr < attr_type_boolean_begin)) {
/* Absolute values are from -0x40000000 - 0x40000000, with 0x0 being 0 (who would have thought that?)
diff --git a/navit/navit.c b/navit/navit.c
index eca6f12cb..f0082c6b6 100644
--- a/navit/navit.c
+++ b/navit/navit.c
@@ -1280,8 +1280,7 @@ navit_init(struct navit *this_)
return;
}
graphics_init(this_->gra);
- if (this_->vehicle)
- navit_set_vehicle(this_, this_->vehicle);
+ navit_set_vehicle(this_, this_->vehicle);
if (this_->mapsets) {
ms=this_->mapsets->data;
if (this_->route) {
@@ -2036,7 +2035,7 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
fixtime = iso8601_to_secs(attr_time.u.str);
}
- if (tracking_update(this_->tracking, &cursor_pc, nv->dir, attr_hdop.u.numd, nv->speed, fixtime)) {
+ if (tracking_update(this_->tracking, this_->vehicleprofile, &cursor_pc, nv->dir, attr_hdop.u.numd, nv->speed, fixtime)) {
nv->coord.x=cursor_pc.x;
nv->coord.y=cursor_pc.y;
}
@@ -2116,7 +2115,7 @@ navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv)
{
struct attr attr;
this_->vehicle=nv;
- if (vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
+ if (nv && vehicle_get_attr(nv->vehicle, attr_profilename, &attr, NULL)) {
if (navit_set_vehicleprofile(this_, attr.u.str))
return;
}
diff --git a/navit/osd/core/osd_core.c b/navit/osd/core/osd_core.c
index 24f3ce816..3a31aa983 100644
--- a/navit/osd/core/osd_core.c
+++ b/navit/osd/core/osd_core.c
@@ -828,7 +828,8 @@ osd_text_draw(struct osd_text *this, struct navit *navit, struct vehicle *v)
item=tracking_get_current_item(tracking);
if (item && !strcmp(key,"route_speed")) {
double routespeed = -1;
- if ((tracking_get_current_flags(tracking) & AF_SPEED_LIMIT) && tracking_get_current_attr(tracking, attr_maxspeed, &maxspeed_attr)) {
+ int *flags=tracking_get_current_flags(tracking);
+ if (flags && (*flags & AF_SPEED_LIMIT) && tracking_get_current_attr(tracking, attr_maxspeed, &maxspeed_attr)) {
routespeed = maxspeed_attr.u.num;
value = format_speed(routespeed, "");
}
diff --git a/navit/route.c b/navit/route.c
index 81c492a9a..33b1db87f 100644
--- a/navit/route.c
+++ b/navit/route.c
@@ -249,7 +249,7 @@ struct route_graph_point_iterator {
struct route_graph_segment *next; /**< The next segment to be returned */
};
-static struct route_info * route_find_nearest_street(struct mapset *ms, struct pcoord *c);
+static struct route_info * route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *c);
static struct route_graph_point *route_graph_get_point(struct route_graph *this, struct coord *c);
static void route_graph_update(struct route *this, struct callback *cb);
static void route_graph_build_done(struct route_graph *rg, int cancel);
@@ -722,7 +722,7 @@ route_set_position(struct route *this, struct pcoord *pos)
if (this->pos)
route_info_free(this->pos);
this->pos=NULL;
- this->pos=route_find_nearest_street(this->ms, pos);
+ this->pos=route_find_nearest_street(this->vehicleprofile, this->ms, pos);
dbg(1,"this->pos=%p\n", this->pos);
if (! this->pos)
return;
@@ -882,7 +882,7 @@ route_set_destination(struct route *this, struct pcoord *dst)
route_info_free(this->dst);
this->dst=NULL;
if (dst) {
- this->dst=route_find_nearest_street(this->ms, dst);
+ this->dst=route_find_nearest_street(this->vehicleprofile, this->ms, dst);
if(this->dst)
route_info_distances(this->dst, dst->pro);
} else {
@@ -1249,6 +1249,7 @@ route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpa
struct coord *c,*cd,ca[2048];
int offset=1;
int seg_size,seg_dat_size;
+ int len=rgs->data.len;
if (rgs->data.flags & AF_SEGMENTED)
offset=RSD_OFFSET(&rgs->data);
@@ -1272,10 +1273,12 @@ route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpa
dir=1;
ccnt=dst->pos-pos->pos;
c=pos->street->c+pos->pos+1;
+ len=dst->lenneg-pos->lenneg;
} else {
dir=-1;
ccnt=pos->pos-dst->pos;
c=pos->street->c+dst->pos+1;
+ len=pos->lenneg-dst->lenneg;
}
} else {
extra=1;
@@ -1285,9 +1288,11 @@ route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpa
if (dir > 0) {
c=pos->street->c+pos->pos+1;
ccnt=pos->street->count-pos->pos-1;
+ len=pos->lenpos;
} else {
c=pos->street->c;
ccnt=pos->pos+1;
+ len=pos->lenneg;
}
}
} else if (dst) {
@@ -1297,9 +1302,11 @@ route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpa
if (dir > 0) {
c=dst->street->c;
ccnt=dst->pos+1;
+ len=dst->lenpos;
} else {
c=dst->street->c+dst->pos+1;
ccnt=dst->street->count-dst->pos-1;
+ len=dst->lenneg;
}
} else {
ccnt=get_item_seg_coords(&rgs->data.item, ca, 2047, &rgs->start->c, &rgs->end->c);
@@ -1335,9 +1342,8 @@ route_path_add_item_from_graph(struct route_path *this, struct route_path *oldpa
}
memcpy(segment->data, &rgs->data, seg_dat_size);
-
linkold:
- segment->data->len=rgs->data.len;
+ segment->data->len=len;
segment->next=NULL;
item_hash_insert(this->path_hash, &rgs->data.item, segment);
@@ -1423,7 +1429,7 @@ static int
route_value_seg(struct vehicleprofile *profile, struct route_graph_point *from, struct route_segment_data *over, int dir)
{
#if 0
- dbg(0,"flags 0x%x mask 0x%x flags 0x%x\n", over->flags, dir >= 0 ? preferences->flags_forward_mask : preferences->flags_reverse_mask, preferences->flags);
+ dbg(0,"flags 0x%x mask 0x%x flags 0x%x\n", over->flags, dir >= 0 ? profile->flags_forward_mask : profile->flags_reverse_mask, profile->flags);
#endif
if ((over->flags & (dir >= 0 ? profile->flags_forward_mask : profile->flags_reverse_mask)) != profile->flags)
return INT_MAX;
@@ -1553,14 +1559,14 @@ route_graph_flood(struct route_graph *this, struct route_info *dst, struct vehic
dbg(0,"no segment for destination found\n");
return;
}
- val=route_value_seg(profile, NULL, &s->data, 1);
+ val=route_value_seg(profile, NULL, &s->data, -1);
if (val != INT_MAX) {
val=val*(100-dst->percent)/100;
s->end->seg=s;
s->end->value=val;
s->end->el=fh_insertkey(heap, s->end->value, s->end);
}
- val=route_value_seg(profile, NULL, &s->data, -1);
+ val=route_value_seg(profile, NULL, &s->data, 1);
if (val != INT_MAX) {
val=val*dst->percent/100;
s->start->seg=s;
@@ -1746,7 +1752,7 @@ route_path_new(struct route_graph *this, struct route_path *oldpath, struct rout
if (! pos->street || ! dst->street)
return NULL;
- if (profile->mode == 2 || (profile->mode == 0 && pos->lenextra + dst->lenextra + pos->lenpos-dst->lenpos > transform_distance(map_projection(pos->street->item.map), &pos->c, &dst->c)))
+ 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);
@@ -1754,12 +1760,12 @@ route_path_new(struct route_graph *this, struct route_path *oldpath, struct rout
dbg(0,"no segment for position found\n");
return NULL;
}
- val=route_value_seg(profile, NULL, &s->data, -1);
+ val=route_value_seg(profile, NULL, &s->data, 1);
if (val != INT_MAX) {
val=val*(100-pos->percent)/100;
val1=s->end->value+val;
}
- val=route_value_seg(profile, NULL, &s->data, 1);
+ val=route_value_seg(profile, NULL, &s->data, -1);
if (val != INT_MAX) {
val=val*pos->percent/100;
val2=s->start->value+val;
@@ -2013,7 +2019,7 @@ street_data_free(struct street_data *sd)
* @return The nearest street
*/
static struct route_info *
-route_find_nearest_street(struct mapset *ms, struct pcoord *pc)
+route_find_nearest_street(struct vehicleprofile *vehicleprofile, struct mapset *ms, struct pcoord *pc)
{
struct route_info *ret=NULL;
int max_dist=1000;
@@ -2048,12 +2054,14 @@ route_find_nearest_street(struct mapset *ms, struct pcoord *pc)
continue;
}
while ((item=map_rect_get_item(mr))) {
- if (item->type >= route_item_first && item->type <= route_item_last) {
+ if (item_get_default_flags(item->type)) {
sd=street_get_data(item);
if (!sd)
continue;
dist=transform_distance_polyline_sq(sd->c, sd->count, &c, &lp, &pos);
- if (dist < mindist) {
+ if (dist < mindist && (
+ (sd->flags & vehicleprofile->flags_forward_mask) == vehicleprofile->flags ||
+ (sd->flags & vehicleprofile->flags_reverse_mask) == vehicleprofile->flags)) {
mindist = dist;
if (ret->street) {
street_data_free(ret->street);
@@ -2148,7 +2156,6 @@ struct map_rect_priv {
int pos;
struct map_priv *mpriv;
struct item item;
- int length;
unsigned int last_coord;
struct route_path *path;
struct route_path_segment *seg,*seg_next;
@@ -2217,17 +2224,17 @@ rm_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr)
attr->u.route = mr->mpriv->route;
return 1;
case attr_length:
+ mr->attr_next=attr_time;
if (seg)
attr->u.num=seg->data->len;
else
- attr->u.num=mr->length;
- mr->attr_next=attr_time;
+ return 0;
return 1;
case attr_time:
mr->attr_next=attr_none;
- if (seg) {
+ if (seg)
attr->u.num=route_time_seg(route->vehicleprofile, seg->data);
- } else
+ else
return 0;
return 1;
case attr_label:
diff --git a/navit/track.c b/navit/track.c
index 074163589..7c5bb69ac 100644
--- a/navit/track.c
+++ b/navit/track.c
@@ -32,18 +32,11 @@
#include "map.h"
#include "mapset.h"
#include "plugin.h"
+#include "vehicleprofile.h"
struct tracking_line
{
struct street_data *street;
-#if 0
- long segid;
- int linenum;
- struct coord c[2];
- struct coord lpnt;
- int value;
- int dir;
-#endif
struct tracking_line *next;
int angle[0];
};
@@ -85,14 +78,9 @@ struct tracking {
struct mapset *ms;
struct route *rt;
struct map *map;
-#if 0
- struct transformation t;
-#endif
+ struct vehicleprofile *vehicleprofile;
struct pcoord last_updated;
struct tracking_line *lines;
-#if 0
- struct tracking_line **last_ptr;
-#endif
struct tracking_line *curr_line;
int pos;
struct coord curr[2];
@@ -336,7 +324,7 @@ tracking_get_current_item(struct tracking *_this)
return &_this->curr_line->street->item;
}
-int
+int *
tracking_get_current_flags(struct tracking *_this)
{
if (! _this->curr_line || ! _this->curr_line->street)
@@ -414,7 +402,7 @@ tracking_doupdate_lines(struct tracking *tr, struct pcoord *pc)
if (!mr)
continue;
while ((item=map_rect_get_item(mr))) {
- if (item->type >= type_street_0 && item->type <= type_ferry) {
+ if (item_get_default_flags(item->type)) {
street=street_get_data(item);
if (street_data_within_selection(street, sel)) {
tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int));
@@ -431,19 +419,6 @@ tracking_doupdate_lines(struct tracking *tr, struct pcoord *pc)
}
mapset_close(h);
dbg(1, "exit\n");
-#if 0
-
- struct transformation t;
-
- tr->last_ptr=&tr->lines;
- transform_setup_source_rect_limit(&t,c,1000);
- transform_setup_source_rect_limit(&tr->t,c,1000);
-
-
- profile_timer(NULL);
- street_get_block(tr->ma,&t,tst_callback,tr);
- profile_timer("end");
-#endif
}
@@ -477,20 +452,20 @@ tracking_angle_abs_diff(int a1, int a2, int full)
}
static int
-tracking_angle_delta(int vehicle_angle, int street_angle, int flags)
-{
- int full=180;
- int ret;
- if (flags) {
- full=360;
- if (flags & 2) {
- street_angle=(street_angle+180)%360;
- if (flags & 1)
- return 360*360;
+tracking_angle_delta(struct tracking *tr, int vehicle_angle, int street_angle, int flags)
+{
+ int full=180,ret=360,fwd,rev;
+ struct vehicleprofile *profile=tr->vehicleprofile;
+ fwd=((flags & profile->flags_forward_mask) == profile->flags);
+ rev=((flags & profile->flags_reverse_mask) == profile->flags);
+ if (fwd || rev) {
+ if (!fwd || !rev) {
+ full=360;
+ if (rev)
+ street_angle=(street_angle+180)%360;
}
+ ret=tracking_angle_abs_diff(vehicle_angle, street_angle, full);
}
- ret=tracking_angle_abs_diff(vehicle_angle, street_angle, full);
-
return ret*ret;
}
@@ -547,7 +522,7 @@ tracking_value(struct tracking *tr, struct tracking_line *t, int offset, struct
if (value >= min)
return value;
if (flags & 2)
- value += tracking_angle_delta(tr->curr_angle, t->angle[offset], sd->flags)*angle_factor>>4;
+ value += tracking_angle_delta(tr, tr->curr_angle, t->angle[offset], sd->flags)*angle_factor>>4;
if (value >= min)
return value;
if (flags & 4)
@@ -563,7 +538,7 @@ tracking_value(struct tracking *tr, struct tracking_line *t, int offset, struct
int
-tracking_update(struct tracking *tr, struct pcoord *pc, int angle, double *hdop, int speed, time_t fixtime)
+tracking_update(struct tracking *tr, struct vehicleprofile *vehicleprofile, struct pcoord *pc, int angle, double *hdop, int speed, time_t fixtime)
{
struct tracking_line *t;
int i,value,min;
@@ -571,12 +546,9 @@ tracking_update(struct tracking *tr, struct pcoord *pc, int angle, double *hdop,
struct coord cin;
struct pcoord pcf; // Coordinate filtered through the CDF
int anglef; // Angle filtered through the CDF
-#if 0
- int min,dist;
- int debug=0;
-#endif
dbg(1,"enter(%p,%p,%d)\n", tr, pc, angle);
dbg(1,"c=%d:0x%x,0x%x\n", pc->pro, pc->x, pc->y);
+ tr->vehicleprofile=vehicleprofile;
if (pc->x == tr->curr_in.x && pc->y == tr->curr_in.y) {
if (tr->curr_out.x && tr->curr_out.y)
@@ -614,10 +586,6 @@ tracking_update(struct tracking *tr, struct pcoord *pc, int angle, double *hdop,
min=INT_MAX/2;
while (t) {
struct street_data *sd=t->street;
- if ((sd->flags & 3) == 3) {
- t=t->next;
- continue;
- }
for (i = 0; i < sd->count-1 ; i++) {
value=tracking_value(tr,t,i,&lpnt,min,-1);
if (value < min) {
@@ -627,7 +595,7 @@ tracking_update(struct tracking *tr, struct pcoord *pc, int angle, double *hdop,
tr->curr[1]=sd->c[i+1];
dbg(1,"lpnt.x=0x%x,lpnt.y=0x%x pos=%d %d+%d+%d+%d=%d\n", lpnt.x, lpnt.y, i,
transform_distance_line_sq(&sd->c[i], &sd->c[i+1], &cin, &lpnt),
- tracking_angle_delta(anglef, t->angle[i], 0)*angle_factor,
+ tracking_angle_delta(tr, anglef, t->angle[i], 0)*angle_factor,
tracking_is_connected(tr->last, &sd->c[i]) ? connected_pref : 0,
lpnt.x == tr->last_out.x && lpnt.y == tr->last_out.y ? nostop_pref : 0,
value
diff --git a/navit/track.h b/navit/track.h
index 2ce00a513..2c2a0895c 100644
--- a/navit/track.h
+++ b/navit/track.h
@@ -32,13 +32,13 @@ struct pcoord *tracking_get_pos(struct tracking *tr);
int tracking_get_angle(struct tracking *tr);
int tracking_get_segment_pos(struct tracking *tr);
struct street_data *tracking_get_street_data(struct tracking *tr);
-int tracking_update(struct tracking *tr, struct pcoord *c, int angle, double *hdop, int speed, time_t fixtime);
+int tracking_update(struct tracking *tr, struct vehicleprofile *vehicleprofile, struct pcoord *c, int angle, double *hdop, int speed, time_t fixtime);
struct tracking *tracking_new(struct attr *parent, struct attr **attrs);
void tracking_set_mapset(struct tracking *this_, struct mapset *ms);
void tracking_set_route(struct tracking *this_, struct route *rt);
int tracking_get_current_attr(struct tracking *_this, enum attr_type type, struct attr *attr);
struct item *tracking_get_current_item(struct tracking *_this);
-int tracking_get_current_flags(struct tracking *_this);
+int *tracking_get_current_flags(struct tracking *_this);
void tracking_destroy(struct tracking *tr);
struct map * tracking_get_map(struct tracking *this_);
void tracking_init(void);
diff --git a/navit/vehicleprofile.c b/navit/vehicleprofile.c
index 533d8bb18..aba3b03c2 100644
--- a/navit/vehicleprofile.c
+++ b/navit/vehicleprofile.c
@@ -26,6 +26,7 @@
void
vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
{
+ dbg(1,"%s:%d\n", attr_to_name(attr->type), attr->u.num);
switch (attr->type) {
case attr_flags:
this_->flags=attr->u.num;
@@ -34,7 +35,7 @@ vehicleprofile_set_attr_do(struct vehicleprofile *this_, struct attr *attr)
this_->flags_forward_mask=attr->u.num;
break;
case attr_flags_reverse_mask:
- this_->flags_forward_mask=attr->u.num;
+ this_->flags_reverse_mask=attr->u.num;
break;
case attr_maxspeed_handling:
this_->maxspeed_handling=attr->u.num;