Add:core:Adaptive plyline generalization, resolves #1050.
authormdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 4 Jul 2012 15:06:59 +0000 (15:06 +0000)
committermdankov <mdankov@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 4 Jul 2012 15:06:59 +0000 (15:06 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@5178 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/graphics.c
navit/navit/navit.c
navit/navit/transform.c

index 8552c20..f2b5f3c 100644 (file)
@@ -394,6 +394,8 @@ struct graphics_font * graphics_named_font_new(struct graphics *gra, char *font,
 }
 
 void graphics_font_destroy(struct graphics_font *gra_font) {
+       if(!gra_font)
+               return;
        gra_font->meth.font_destroy(gra_font->priv);
        g_free(gra_font);
 }
@@ -1883,7 +1885,7 @@ displayitem_draw(struct displayitem *di, void *dummy, struct display_context *dc
                graphics_draw_polygon_clipped(gra, gc, pa, count);
                break;
        case element_polyline:
-               {
+               {       
                        gc->meth.gc_set_linewidth(gc->priv, 1);
                        if (e->u.polyline.width > 0 && e->u.polyline.dash_num > 0)
                                graphics_gc_set_dashes(gc, e->u.polyline.width,
@@ -2320,7 +2322,7 @@ void graphics_displaylist_draw(struct graphics *gra, struct displaylist *display
        if(displaylist->dc.trans!=trans)
                displaylist->dc.trans=transform_dup(trans);
        displaylist->dc.gra=gra;
-       displaylist->dc.mindist=transform_get_scale(trans)/2;
+       displaylist->dc.mindist=flags&512?15:2;
        // FIXME find a better place to set the background color
        if (l) {
                graphics_gc_set_background(gra->gc[0], &l->color);
@@ -2657,7 +2659,7 @@ int graphics_displayitem_within_dist(struct displaylist *displaylist, struct dis
        struct point *pa=g_alloca(sizeof(struct point)*displaylist->dc.maxlen);
        int count;
 
-       count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 1, 0, NULL);
+       count=transform(displaylist->dc.trans, displaylist->dc.pro, di->c, pa, di->count, 0, 0, NULL);
 
        if (di->item.type < type_line) {
                return within_dist_point(p, &pa[0], dist);
index 98ce268..66350a6 100644 (file)
@@ -540,7 +540,7 @@ navit_motion_timeout(struct navit *this_)
                graphics_displaylist_move(this_->displaylist, dx, dy);
 #endif
                graphics_draw_cancel(this_->gra, this_->displaylist);
-               graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
+               graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags|512);
                transform_destroy(tr);
                this_->moved=1;
        }
index 78c483c..d57c50b 100644 (file)
@@ -438,16 +438,8 @@ transform(struct transformation *t, enum projection pro, struct coord *c, struct
                        xc=c1.x;
                        yc=c1.y;
                }
-               if (i != 0 && i != count-1 && mindist) {
-                       if (xc > c[k].x-mindist && xc < c[k].x+mindist && yc > c[k].y-mindist && yc < c[k].y+mindist &&
-                               (c[i+1].x != c[0].x || c[i+1].y != c[0].y))
-                               continue;
-                       k=i;
-               }
                xm=xc;
                ym=yc;
-//             dbg(2,"0x%x, 0x%x - 0x%x,0x%x contains 0x%x,0x%x\n", t->r.lu.x, t->r.lu.y, t->r.rl.x, t->r.rl.y, c->x, c->y);
-//             ret=coord_rect_contains(&t->r, c);
                xc-=t->map_center.x;
                yc-=t->map_center.y;
                xc >>= t->scale_shift;
@@ -513,6 +505,18 @@ transform(struct transformation *t, enum projection pro, struct coord *c, struct
                }
                xc+=t->offx;
                yc+=t->offy;
+
+               if (i != 0 && i != count-1 && mindist) {
+                       /* We expect values of mindist to be within 0..5 pixels for nice looking screens. 
+                          That gives difference of about 1 pixel in worst case between abs(dx)+abs(dy) and sqrt(dx*dx+dy*dy).
+                          We expect significantly bigger values when drawing map while scrolling it. But it anyway will be ugly.
+                          Should anybody care about that inaccuracy? */
+                       if ( (abs(xc - p[k].x) + abs(yc - p[k].y)) < mindist &&
+                               (c[i+1].x != c[0].x || c[i+1].y != c[0].y))
+                               continue;
+                       k=j;
+               }               
+
                p[j].x=xc;
                p[j].y=yc;
                if (width_return) {