return ways;
}
-static gdouble magnitude(gdouble x1, gdouble y1, gdouble x2, gdouble y2)
+inline gdouble magnitude(gdouble x1, gdouble y1, gdouble x2, gdouble y2)
{
gdouble x,y;
x=x2-x1;
GList *w=NULL;
guint range=8192;
osm_way *cw=NULL;
+gdouble pdist=900000.0, pndist=9000000.0;
while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=65536) {
range=range<<1;
g_printf("Found ways: %d\n", g_list_length(w));
-switch (g_list_length(w)) {
- case 0:
- return NULL;
- break;
- default:
- {
- gdouble pdist=900000.0, pndist=9000000.0;
-
- for (iter=w; iter!=NULL; iter=iter->next) {
- osm_way_node *wnf;
- osm_way_node *wnt;
+if (g_list_length(w)==0)
+ return NULL;
- osm_way *way=(osm_way*)iter->data;
+for (iter=w; iter!=NULL; iter=iter->next) {
+ osm_way_node *wnf;
+ osm_way_node *wnt;
+ osm_way *way=(osm_way*)iter->data;
#ifdef DEBUG_OSM
- g_printf("WAY %d (%d) HAS %d NODES, nearest is %d\n",
- way->id, way->type, way->nodecnt, way->node_num);
+ g_printf("WAY %d (%d) HAS %d NODES, nearest is %d\n",
+ way->id, way->type, way->nodecnt, way->node_num);
#endif
- if (osm_way_get_nodes(way)==FALSE)
- continue;
-
- if (way->nodes==0) {
- g_printerr("Way with 0 nodes ? Skipping\n");
- continue;
- }
+ if (osm_way_get_nodes(way)==FALSE)
+ continue;
- wnf=g_list_nth_data(way->nodes, way->node_num);
- if (!wnf) {
- osm_way_free(way);
- continue;
- }
+ if (way->nodes==0) {
+ g_printerr("Way with 0 nodes ? Skipping\n");
+ continue;
+ }
- 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 (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 (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
- wnt=g_list_nth_data(way->nodes, way->node_num+1);
- if (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
- osm_way_free(way);
- continue;
- }
- }
- }
+ wnf=g_list_nth_data(way->nodes, way->node_num);
+ if (!wnf) {
+ 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 {
+ 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 (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 (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
+ wnt=g_list_nth_data(way->nodes, way->node_num+1);
+ if (osm_way_distance(lat, lon, wnf, wnt, &pndist)==FALSE) {
osm_way_free(way);
- way=NULL;
+ continue;
}
}
}
- break;
+
+ 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 {
+ osm_way_free(way);
+ way=NULL;
+ }
}
g_list_free(w);