return TRUE;
}
+gboolean osm_way_distance(gint lat, gint lon, osm_way_node *f, osm_way_node *t, gdouble *d)
+{
+if (!f || !t)
+ return FALSE;
+
+return distance_point_to_line(lon, lat, f->lon, f->lat, t->lon, t->lat, d);
+}
+
/**
* Search for the nearest way (road)
* - First search for ways with nearest node
case 0:
return NULL;
break;
- case 1:
- cw=w->data;
- break;
default:
{
gint dist=900000, ndist;
if ( (way->node_num==way->nodecnt) || (way->node_num==0)) {
wnt=g_list_nth_data(way->nodes, way->node_num==way->nodecnt ? way->nodecnt-1 : 1);
- if (!wnt) {
- osm_way_free(way);
- continue;
- }
- if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) {
+ if (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
osm_way_free(way);
continue;
}
} else {
wnt=g_list_nth_data(way->nodes, way->node_num-1);
- if (!wnt) {
- osm_way_free(way);
- continue;
- }
- if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) {
+ if (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
wnt=g_list_nth_data(way->nodes, way->node_num+1);
- if (!wnt) {
- osm_way_free(way);
- continue;
- }
- if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) {
+ if (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
osm_way_free(way);
continue;
}
if (pndist<pdist) {
g_printf("Found close way, distance: %f (Previous distance: %f)\n", pndist, pdist);
pdist=pndist;
+ way->node_f=wnf;
+ way->node_t=wnt;
+ way->distance=pndist;
cw=way;
} else {
g_printf("Way is not closer, freeing\n");
osm_way_free(way);
+ way=NULL;
}
}
}
osm_way_get_ref(cw);
}
-g_printf("BEST WAY: %d %d %d %d: %s %s %s\n",
- cw->id, cw->type, cw->flags,
- cw->nodes, cw->dist, cw->name,
- cw->ref, cw->int_ref);
+g_printf("BEST WAY(%d): %s (%s,%s)\n",
+ cw->id, cw->name, cw->ref, cw->int_ref);
+g_printf("\tT: %d F: %d N: %d D: %f\n",
+ cw->type, cw->flags, cw->nodes, cw->dist);
+g_printf("\tNF: %d NT: %d DT %f\n",
+ cw->node_f->num,
+ cw->node_t->num, cw->distance);
return cw;
}