summaryrefslogtreecommitdiff
path: root/navit/maptool
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-07-20 16:13:13 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-07-20 16:13:13 +0000
commiteb50295a3ac34719bc188cecc687ac2214a59928 (patch)
treee827536b7783fbb845064ea1bd6949639a64feb0 /navit/maptool
parent6c38eb3ea1081ee19355b1bab830795b068e3aa5 (diff)
downloadnavit-eb50295a3ac34719bc188cecc687ac2214a59928.tar.gz
Fix:maptool:Better handling of broken polygons
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4648 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/maptool')
-rw-r--r--navit/maptool/boundaries.c28
-rw-r--r--navit/maptool/geom.c23
2 files changed, 40 insertions, 11 deletions
diff --git a/navit/maptool/boundaries.c b/navit/maptool/boundaries.c
index 4305bb79d..7c8df0fe4 100644
--- a/navit/maptool/boundaries.c
+++ b/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/maptool/geom.c b/navit/maptool/geom.c
index 7934b6187..642dd5f90 100644
--- a/navit/maptool/geom.c
+++ b/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 *