From: mdankov Date: Sat, 9 Jul 2011 08:40:05 +0000 (+0000) Subject: Fix:maptool:Move icons and labels for way2poi generated items to polygon border if... X-Git-Tag: navit-0.5.0.5194svn~591 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7b6fc1e84d40588bc66ae3d9221844f3a7a42afc;p=profile%2Fivi%2Fnavit.git Fix:maptool:Move icons and labels for way2poi generated items to polygon border if centroid is outside the polygon git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4604 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/navit/maptool/geom.c b/navit/navit/maptool/geom.c index 88f0c17..f5627b1 100644 --- a/navit/navit/maptool/geom.c +++ b/navit/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/navit/maptool/maptool.h b/navit/navit/maptool/maptool.h index 85d26c4..2f5b50b 100644 --- a/navit/navit/maptool/maptool.h +++ b/navit/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/navit/maptool/osm.c b/navit/navit/maptool/osm.c index 6454ffd..ef1cf8d 100644 --- a/navit/navit/maptool/osm.c +++ b/navit/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->typeclen/2>2) { - if(!geom_poly_centroid(c,ib->clen/2,c)) { + int count=ib->clen/2; + if(count>1 && ib->type2) { + 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;