diff options
| author | mdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-07-09 08:40:05 +0000 |
|---|---|---|
| committer | mdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-07-09 08:40:05 +0000 |
| commit | 87ee6230ea82f05bd7a19daf8c8f5d104f979c95 (patch) | |
| tree | 5a8fcb143b9142b122b3e50e3107ab3520334ac5 | |
| parent | 84e48fff09e171506dcca40b6eba079c8561f37f (diff) | |
| download | navit-87ee6230ea82f05bd7a19daf8c8f5d104f979c95.tar.gz | |
Fix:maptool:Move icons and labels for way2poi generated items to polygon border if centroid is outside the polygon
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4604 ffa7fe5e-494d-0410-b361-a75ebd5db220
| -rw-r--r-- | navit/maptool/geom.c | 29 | ||||
| -rw-r--r-- | navit/maptool/maptool.h | 1 | ||||
| -rw-r--r-- | navit/maptool/osm.c | 18 |
3 files changed, 37 insertions, 11 deletions
diff --git a/navit/maptool/geom.c b/navit/maptool/geom.c index 88f0c177e..f5627b19a 100644 --- a/navit/maptool/geom.c +++ b/navit/maptool/geom.c @@ -148,6 +148,28 @@ geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coo return vertex; } +/** + * Check if point is inside polgone. + * @param in *cp array of polygon vertex coordinates + * @param in count count of polygon vertexes + * @param in *c point coordinates + * @returns 1 - inside, 0 - outside + */ +int +geom_poly_point_inside(struct coord *cp, int count, struct coord *c) +{ + int ret=0; + struct coord *last=cp+count-1; + while (cp < last) { + if ((cp[0].y > c->y) != (cp[1].y > c->y) && + c->x < (cp[1].x-cp[0].x)*(c->y-cp[0].y)/(cp[1].y-cp[0].y)+cp[0].x) + ret=!ret; + cp++; + } + return ret; +} + + GList * geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third) @@ -294,12 +316,7 @@ geom_poly_segments_point_inside(GList *in, struct coord *c) while (in) { struct geom_poly_segment *seg=in->data; cp=seg->first; - while (cp < seg->last) { - if ((cp[0].y > c->y) != (cp[1].y > c->y) && - c->x < (cp[1].x-cp[0].x)*(c->y-cp[0].y)/(cp[1].y-cp[0].y)+cp[0].x) - ret=!ret; - cp++; - } + ret^=geom_poly_point_inside(seg->first, seg->last-seg->first+1, c); in=g_list_next(in); } return ret; diff --git a/navit/maptool/maptool.h b/navit/maptool/maptool.h index 85d26c460..2f5b50b76 100644 --- a/navit/maptool/maptool.h +++ b/navit/maptool/maptool.h @@ -145,6 +145,7 @@ void geom_coord_copy(struct coord *from, struct coord *to, int count, int revers void geom_coord_revert(struct coord *c, int count); long long geom_poly_area(struct coord *c, int count); int geom_poly_centroid(struct coord *c, int count, struct coord *r); +int geom_poly_point_inside(struct coord *cp, int count, struct coord *c); int geom_poly_closest_point(struct coord *pl, int count, struct coord *p, struct coord *c); GList *geom_poly_segments_insert(GList *list, struct geom_poly_segment *first, struct geom_poly_segment *second, struct geom_poly_segment *third); void geom_poly_segment_destroy(struct geom_poly_segment *seg); diff --git a/navit/maptool/osm.c b/navit/maptool/osm.c index 6454ffde8..ef1cf8db6 100644 --- a/navit/maptool/osm.c +++ b/navit/maptool/osm.c @@ -2138,15 +2138,23 @@ process_way2poi(FILE *in, FILE *out) { struct item_bin *ib; while ((ib=read_item(in))) { - if(ib->clen>2 && ib->type<type_line) { - struct coord *c=(struct coord *)(ib+1); - if(ib->clen/2>2) { - if(!geom_poly_centroid(c,ib->clen/2,c)) { + int count=ib->clen/2; + if(count>1 && ib->type<type_line) { + struct coord *c=(struct coord *)(ib+1), c1, c2; + if(count>2) { + if(!geom_poly_centroid(c, count, &c1)) { // we have poly with zero area // Falling back to coordinates of its first vertex... osm_warning("way",item_bin_get_wayid(ib),0,"Broken polygon, area is 0\n"); + } else { + if(geom_poly_point_inside(c, count, &c1)) { + c[0]=c1; + } else { + geom_poly_closest_point(c, count, &c1, &c2); + c[0]=c2; + } } - } else if (ib->clen/2==2) { + } else if (count==2) { osm_warning("way",item_bin_get_wayid(ib),0, "Expected polygon, but only two points defined\n"); c[0].x=(c[0].x+c[1].x)/2; c[0].y=(c[0].y+c[1].y)/2; |
