From 2dce0310b38aee3f7875122028e7df2a5196eb31 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 23 Jul 2007 13:43:24 +0300 Subject: [PATCH] Remove most debuging output. Free the way structures we don't need. --- src/osm-db.c | 116 ++++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/src/osm-db.c b/src/osm-db.c index c7656ee..8628f96 100644 --- a/src/osm-db.c +++ b/src/osm-db.c @@ -84,6 +84,39 @@ osm_init() return TRUE; } +/** + * Free way nodes list + */ +void +osm_way_nodes_free(osm_way *w) +{ +GList *iter; + +if (!w->nodes) + return; + +for (iter=w->nodes; iter!=NULL; iter=iter->next) + g_slice_free(osm_way_node, (osm_way_node*)iter->data); + +g_list_free(w->nodes); +} + +/** + * Free a osm_way structure + */ +void +osm_way_free(osm_way *w) +{ +osm_way_nodes_free(w); +if (w->name) + g_free(w->name); +if (w->ref) + g_free(w->ref); +if (w->int_ref) + g_free(w->int_ref); +g_slice_free(osm_way, w); +} + /** * Get place with given id and distance to current location */ @@ -172,7 +205,6 @@ if (SQLITE_ROW == sqlite3_step(sql.select_near_place)) { n->isin=sqlite3_column_int(sql.select_near_place, 5); n->type=type; - g_printf("Place(%d): %s distance: %f\n", type, place, n->dist); return TRUE; } return FALSE; @@ -223,33 +255,14 @@ return sqrt((x*x)+(y*y)); gboolean distance_point_to_line(gint x, gint y, gint x1, gint y1, gint x2, gint y2, gdouble *d) { -gdouble lm,u; +gdouble lm,u,tmp; gdouble ix,iy; -gdouble tmp,tx1,tx2,ty1,ty2; - -#if 0 -if (x1>x2) { - tx1=x2; - ty1=y2; - x2=x1; - y2=y1; - x1=tx1; - y1=ty1; -} -#endif lm=magnitude((gdouble)x1,(gdouble)y1,(gdouble)x2,(gdouble)y2); tmp=(gdouble)((x-x1)*(x2-x1))+((y-y1)*(y2-y1)); u=tmp/(lm*lm); -g_printf("DPL: tmp %f u %f lm %f\n", tmp, u, lm); - -g_printf("DPLX: (%d/%d) (%d %d)-(%d %d)\n", - x,y, - x1,y1, - x2,y2); - if (u<0.0f || u>1.0f) return FALSE; @@ -303,7 +316,7 @@ switch (g_list_length(w)) { osm_way *way=(osm_way*)iter->data; - g_printf("C*** WAY %d (%d) HAS %d NODES, nearest is %d\n", + g_printf("WAY %d (%d) HAS %d NODES, nearest is %d\n", way->id, way->type, way->nodecnt, way->node_num); if (osm_way_get_nodes(way)==FALSE) @@ -315,43 +328,47 @@ switch (g_list_length(w)) { } wnf=g_list_nth_data(way->nodes, way->node_num); - if (!wnf) + if (!wnf) { + osm_way_free(way); continue; + } - g_printf("----EVAL-START:\n"); - if (way->node_num==way->nodecnt) { - g_print(" <- Last\n"); - wnt=g_list_nth_data(way->nodes, way->nodecnt-1); - if (!wnt) - continue; - if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) + 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; - } else if (way->node_num==0) { - g_print(" First %d ->\n", wnf->num); - wnt=g_list_nth_data(way->nodes, 1); - if (!wnt) - continue; - if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) + } + if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) { + osm_way_free(way); continue; + } } else { - g_print(" <->\n"); wnt=g_list_nth_data(way->nodes, way->node_num-1); - if (!wnt) + if (!wnt) { + osm_way_free(way); continue; + } if (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) { wnt=g_list_nth_data(way->nodes, way->node_num+1); - if (!wnt) + 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 (distance_point_to_line(lon, lat, wnf->lon, wnf->lat, wnt->lon, wnt->lat, &pndist)==FALSE) { + osm_way_free(way); continue; + } } } - g_printf("----EVAL-DONE: %d <-> %d\n", wnf->num, wnt->num); - g_printf("WD: New: %f Prev:%f\n", pndist, pdist); if (pndisttype==WAY_MOTORWAY || cw->type==WAY_TRUNK || osm_way_get_ref(cw); } -g_printf("Way: %d %d %d %d: %s %s %s\n", +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); @@ -447,16 +464,3 @@ if (SQLITE_ROW == sqlite3_step(sql.select_way_ref)) { return FALSE; } -void -osm_way_free(osm_way *w) -{ -if (w->nodes) - g_list_free(w->nodes); -if (w->name) - g_free(w->name); -if (w->ref) - g_free(w->ref); -if (w->int_ref) - g_free(w->int_ref); -g_slice_free(osm_way, w); -} -- 2.39.5