]> err.no Git - mapper/commitdiff
Remove switch { .. } structure as we don't need it anymore.
authorKaj-Michael Lang <milang@onion.tal.org>
Thu, 2 Aug 2007 09:03:50 +0000 (12:03 +0300)
committerKaj-Michael Lang <milang@onion.tal.org>
Thu, 2 Aug 2007 09:03:50 +0000 (12:03 +0300)
inline magnitude function

src/osm-db.c

index abff6cb2170a94f9cd46109c7ff8c1f1ff2b99ab..24019a821a9cf4556a3ee1e2aa40ff62d5cd530a 100644 (file)
@@ -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 (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);