From 88e2c82d9833556a373cf08925e2224aa8e68983 Mon Sep 17 00:00:00 2001 From: martin-s Date: Wed, 20 Jul 2011 16:13:13 +0000 Subject: [PATCH] Fix:maptool:Better handling of broken polygons git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4648 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/maptool/boundaries.c | 28 ++++++++++++++++++++-------- navit/navit/maptool/geom.c | 23 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/navit/navit/maptool/boundaries.c b/navit/navit/maptool/boundaries.c index 4305bb7..7c8df0f 100644 --- a/navit/navit/maptool/boundaries.c +++ b/navit/navit/maptool/boundaries.c @@ -119,7 +119,7 @@ boundary_find_matches(GList *l, struct coord *c) while (l) { struct boundary *boundary=l->data; if (bbox_contains_coord(&boundary->r, c)) { - if (geom_poly_segments_point_inside(boundary->sorted_segments,c)) + if (geom_poly_segments_point_inside(boundary->sorted_segments,c) > 0) ret=g_list_prepend(ret, boundary); ret=g_list_concat(ret,boundary_find_matches(boundary->children, c)); } @@ -202,10 +202,11 @@ process_boundaries_finish(GList *boundaries_list) while (l) { struct boundary *boundary=l->data; int first=1; - FILE *f=NULL; + FILE *f=NULL,*fu=NULL; if (boundary->country) { char *name=g_strdup_printf("country_%s_poly",boundary->iso2); f=tempfile("",name,1); + g_free(name); } boundary->sorted_segments=geom_poly_segments_sort(boundary->segments, geom_poly_segment_type_way_right_side); sl=boundary->sorted_segments; @@ -227,21 +228,32 @@ process_boundaries_finish(GList *boundaries_list) item_bin_add_coord(ib, gs->first, gs->last-gs->first+1); item_bin_write(ib, f); } -#if 0 if (boundary->country) { - if (coord_is_equal(*gs->first,*gs->last)) { - fprintf(stderr,"closed\n"); - } else { - fprintf(stderr,"loose end\n"); + if (!coord_is_equal(*gs->first,*gs->last)) { + if (!fu) { + char *name=g_strdup_printf("country_%s_broken",boundary->iso2); + fu=tempfile("",name,1); + g_free(name); + } + struct item_bin *ib=item_bin; + item_bin_init(ib, type_selected_point); + item_bin_add_coord(ib, gs->first, 1); + item_bin_write(ib, fu); + item_bin_init(ib, type_selected_point); + item_bin_add_coord(ib, gs->last, 1); + item_bin_write(ib, fu); } } -#endif sl=g_list_next(sl); } ret=process_boundaries_insert(ret, boundary); l=g_list_next(l); if (f) fclose(f); + if (fu) { + osm_warning("relation",item_bin_get_relationid(boundary->ib),0,"Broken country polygon\n"); + fclose(fu); + } } #if 0 diff --git a/navit/navit/maptool/geom.c b/navit/navit/maptool/geom.c index 7934b61..642dd5f 100644 --- a/navit/navit/maptool/geom.c +++ b/navit/navit/maptool/geom.c @@ -353,15 +353,32 @@ geom_poly_segments_sort(GList *in, enum geom_poly_segment_type type) int geom_poly_segments_point_inside(GList *in, struct coord *c) { - int ret=0; + int open_matches=0,closed_matches=0; struct coord *cp; while (in) { struct geom_poly_segment *seg=in->data; cp=seg->first; - ret^=geom_poly_point_inside(seg->first, seg->last-seg->first+1, c); + if (geom_poly_point_inside(seg->first, seg->last-seg->first+1, c)) { + if (coord_is_equal(*seg->first,*seg->last)) + closed_matches++; + else + open_matches++; + } in=g_list_next(in); } - return ret; + if (closed_matches) { + if (closed_matches & 1) + return 0; + else + return 1; + } + if (open_matches) { + if (open_matches & 1) + return 0; + else + return -1; + } + return 0; } struct geom_poly_segment * -- 2.7.4