Fix:Core:Made some performance critical parts a bit faster
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 2 Jan 2009 21:49:50 +0000 (21:49 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Fri, 2 Jan 2009 21:49:50 +0000 (21:49 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1882 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/graphics.c
navit/item.c
navit/item.h
navit/track.c

index c9b9e91..18ddf65 100644 (file)
@@ -1495,7 +1495,6 @@ static void do_draw_map(struct displaylist *displaylist, struct transformation *
        struct coord ca[max];
        struct attr attr;
        struct map_selection *sel;
-       struct coord_rect r;
 
        pro=map_projection(m);
        conv=map_requires_conversion(m);
@@ -1522,13 +1521,13 @@ 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_with_bbox(item, ca, item->type < type_line ? 1: max, &r);
+               count=item_coord_get_within_selection(item, ca, item->type < type_line ? 1: max, sel);
+               if (! count)
+                       continue;
                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])) {
@@ -1552,7 +1551,7 @@ static void do_draw_map(struct displaylist *displaylist, struct transformation *
 #endif
                }
                if (count == max) 
-                       dbg(0,"point count overflow\n", count);
+                       dbg(0,"point count overflow %d\n", count);
                if (!item_attr_get(item, attr_label, &attr))
                        attr.u.str=NULL;
                if (conv && attr.u.str && attr.u.str[0]) {
index 8cd20fe..7060eae 100644 (file)
@@ -54,30 +54,34 @@ 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)
+item_coord_get_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel)
 {
        int i,ret=it->meth->item_coord_get(it->priv_data, c, count);
-       struct coord_rect r2;
-       if (ret <= 0)
+       struct coord_rect r;
+       struct map_selection *curr;
+       if (ret <= 0 || !sel)
                return ret;
-       if (ret == 1) {
-               r->rl=r->lu=c[0];
-               return ret;     
-       }
-       r2.lu=c[0];
-       r2.rl=c[0];
+       r.lu=c[0];
+       r.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;
+               if (r.lu.x > c[i].x)
+                       r.lu.x=c[i].x;
+               if (r.rl.x < c[i].x)
+                       r.rl.x=c[i].x;
+               if (r.rl.y > c[i].y)
+                       r.rl.y=c[i].y;
+               if (r.lu.y < c[i].y)
+                       r.lu.y=c[i].y;
        }
-       *r=r2;
-       return ret;
+        curr=sel;
+       while (curr) {
+               struct coord_rect *sr=&curr->u.c_rect;
+               if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
+                   r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
+                       return ret;
+               curr=curr->next;
+       }
+        return 0;
 }
 
 int
index 3cff0f9..a3986ed 100644 (file)
@@ -77,9 +77,10 @@ struct attr;
 struct coord;
 struct item;
 struct item_hash;
+struct map_selection;
 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_within_selection(struct item *it, struct coord *c, int count, struct map_selection *sel);
 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);
index a5ae42c..071c98f 100644 (file)
@@ -130,6 +130,39 @@ tracking_get_angles(struct tracking_line *tl)
                tl->angle[i]=transform_get_angle_delta(&sd->c[i], &sd->c[i+1], 0);
 }
 
+static int
+street_data_within_selection(struct street_data *sd, struct map_selection *sel)
+{
+       struct coord_rect r;
+       struct map_selection *curr;
+       int i;
+
+       if (!sel)
+               return 1;
+       r.lu=sd->c[0];
+       r.rl=sd->c[0];
+       for (i = 1 ; i < sd->count ; i++) {
+               if (r.lu.x > sd->c[i].x)
+                       r.lu.x=sd->c[i].x;
+               if (r.rl.x < sd->c[i].x)
+                       r.rl.x=sd->c[i].x;
+               if (r.rl.y > sd->c[i].y)
+                       r.rl.y=sd->c[i].y;
+               if (r.lu.y < sd->c[i].y)
+                       r.lu.y=sd->c[i].y;
+       }
+        curr=sel;
+       while (curr) {
+               struct coord_rect *sr=&curr->u.c_rect;
+               if (r.lu.x <= sr->rl.x && r.rl.x >= sr->lu.x &&
+                   r.lu.y >= sr->rl.y && r.rl.y <= sr->lu.y)
+                       return 1;
+               curr=curr->next;
+       }
+        return 0;
+}
+
+
 static void
 tracking_doupdate_lines(struct tracking *tr, struct pcoord *pc)
 {
@@ -160,11 +193,14 @@ tracking_doupdate_lines(struct tracking *tr, struct pcoord *pc)
                while ((item=map_rect_get_item(mr))) {
                        if (item->type >= type_street_0 && item->type <= type_ferry) {
                                street=street_get_data(item);
-                               tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int));
-                               tl->street=street;
-                               tracking_get_angles(tl);
-                               tl->next=tr->lines;
-                               tr->lines=tl;
+                               if (street_data_within_selection(street, sel)) {
+                                       tl=g_malloc(sizeof(struct tracking_line)+(street->count-1)*sizeof(int));
+                                       tl->street=street;
+                                       tracking_get_angles(tl);
+                                       tl->next=tr->lines;
+                                       tr->lines=tl;
+                               } else
+                                       street_data_free(street);
                        }
                }
                map_selection_destroy(sel);