From 3bae1744c7c500698721c78552108dd1786c73f7 Mon Sep 17 00:00:00 2001 From: martin-s Date: Fri, 2 Jan 2009 21:18:55 +0000 Subject: [PATCH] Fix:Core:Made some performance critical parts a bit faster git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1881 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/graphics.c | 45 ++++++++++++++++++++++++++------------------- navit/navit/item.c | 27 +++++++++++++++++++++++++++ navit/navit/item.h | 1 + 3 files changed, 54 insertions(+), 19 deletions(-) diff --git a/navit/navit/graphics.c b/navit/navit/graphics.c index 04a89ea..c9b9e91 100644 --- a/navit/navit/graphics.c +++ b/navit/navit/graphics.c @@ -771,12 +771,14 @@ draw_circle(struct point *pnt, int diameter, int scale, int start, int len, stru end+=1024; } while (end > 0) { - for (i = 0 ; i < 16 ; i++) { - if (c[i].fowler > start && c[i].fowler < end) { - res[*pos].x=pnt->x+c[i].x*diameter/20; - res[*pos].y=pnt->y+c[i].y*diameter/20; - (*pos)+=dir; - } + i=0; + while (i < 16 && c[i].fowler <= start) + i++; + while (i < 16 && c[i].fowler < end) { + res[*pos].x=pnt->x+c[i].x*diameter/20; + res[*pos].y=pnt->y+c[i].y*diameter/20; + (*pos)+=dir; + i++; } end-=1024; start-=1024; @@ -787,12 +789,14 @@ draw_circle(struct point *pnt, int diameter, int scale, int start, int len, stru end-=1024; } while (end < 1024) { - for (i = 15 ; i >= 0 ; i--) { - if (c[i].fowler < start && c[i].fowler > end) { - res[*pos].x=pnt->x+c[i].x*diameter/20; - res[*pos].y=pnt->y+c[i].y*diameter/20; - (*pos)+=dir; - } + i=15; + while (i >= 0 && c[i].fowler >= end) + i--; + while (i >= 0 && c[i].fowler > start) { + res[*pos].x=pnt->x+c[i].x*diameter/20; + res[*pos].y=pnt->y+c[i].y*diameter/20; + (*pos)+=dir; + i--; } start+=1024; end+=1024; @@ -1491,7 +1495,7 @@ static void do_draw_map(struct displaylist *displaylist, struct transformation * struct coord ca[max]; struct attr attr; struct map_selection *sel; - int num=0; + struct coord_rect r; pro=map_projection(m); conv=map_requires_conversion(m); @@ -1510,7 +1514,6 @@ static void do_draw_map(struct displaylist *displaylist, struct transformation * return; } while ((item=map_rect_get_item(mr))) { - num++; #if 0 if (num < 7599 || num > 7599) continue; @@ -1519,33 +1522,37 @@ static void do_draw_map(struct displaylist *displaylist, struct transformation * if (item->id_hi != 0xb0031 || item->id_lo != 0x20c9aeea) continue; #endif - count=item_coord_get(item, ca, item->type < type_line ? 1: max); + count=item_coord_get_with_bbox(item, ca, item->type < type_line ? 1: max, &r); if (item->type >= type_line && count < 2) { dbg(1,"poly from map has only %d points\n", count); continue; } + if (! map_selection_contains_rect(sel, &r)) + continue; if (item->type < type_line) { +#if 0 if (! map_selection_contains_point(sel, &ca[0])) { dbg(1,"point not visible\n"); continue; } +#endif } else if (item->type < type_area) { +#if 0 if (! map_selection_contains_polyline(sel, ca, count)) { dbg(1,"polyline not visible\n"); continue; } +#endif } else { +#if 0 if (! map_selection_contains_polygon(sel, ca, count)) { dbg(1,"polygon not visible\n"); continue; } +#endif } if (count == max) dbg(0,"point count overflow\n", count); - if (item->type >= type_line && count < 2) { - dbg(1,"poly from transform has only %d points\n", count); - continue; - } if (!item_attr_get(item, attr_label, &attr)) attr.u.str=NULL; if (conv && attr.u.str && attr.u.str[0]) { diff --git a/navit/navit/item.c b/navit/navit/item.c index 5de4bf7..8cd20fe 100644 --- a/navit/navit/item.c +++ b/navit/navit/item.c @@ -54,6 +54,33 @@ item_coord_get(struct item *it, struct coord *c, int count) } int +item_coord_get_with_bbox(struct item *it, struct coord *c, int count, struct coord_rect *r) +{ + int i,ret=it->meth->item_coord_get(it->priv_data, c, count); + struct coord_rect r2; + if (ret <= 0) + return ret; + if (ret == 1) { + r->rl=r->lu=c[0]; + return ret; + } + r2.lu=c[0]; + r2.rl=c[0]; + for (i = 1 ; i < ret ; i++) { + if (r2.lu.x > c[i].x) + r2.lu.x=c[i].x; + if (r2.rl.x < c[i].x) + r2.rl.x=c[i].x; + if (r2.rl.y > c[i].y) + r2.rl.y=c[i].y; + if (r2.lu.y < c[i].y) + r2.lu.y=c[i].y; + } + *r=r2; + return ret; +} + +int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection to) { int ret=item_coord_get(it, c, count); diff --git a/navit/navit/item.h b/navit/navit/item.h index 7e25e6b..3cff0f9 100644 --- a/navit/navit/item.h +++ b/navit/navit/item.h @@ -79,6 +79,7 @@ struct item; struct item_hash; void item_coord_rewind(struct item *it); int item_coord_get(struct item *it, struct coord *c, int count); +int item_coord_get_with_bbox(struct item *it, struct coord *c, int count, struct coord_rect *r); int item_coord_get_pro(struct item *it, struct coord *c, int count, enum projection pro); /* does the next returned coordinate mark a node */ int item_coord_is_node(struct item *it); -- 2.7.4