From: Kaj-Michael Lang Date: Thu, 2 Aug 2007 09:03:50 +0000 (+0300) Subject: Remove switch { .. } structure as we don't need it anymore. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0dffebc9a70e0d92775671484db8f4296b0a2861;p=mapper Remove switch { .. } structure as we don't need it anymore. inline magnitude function --- diff --git a/src/osm-db.c b/src/osm-db.c index abff6cb..24019a8 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -364,7 +364,7 @@ g_printf("Query took: %f sec, found: %d ways\n", g_timer_elapsed(dbt, &tms), wc) 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; @@ -420,6 +420,7 @@ GList *iter; 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; @@ -428,70 +429,61 @@ while ((w=osm_find_nearest_way_nodes(lat, lon, range))==NULL && range<=65536) { 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 (pndistnode_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 (pndistnode_f=wnf; + way->node_t=wnt; + way->distance=pndist; + cw=way; + } else { + osm_way_free(way); + way=NULL; + } } g_list_free(w);