diff options
author | Stefan Wildemann <gta04@metalstrolche.de> | 2018-02-12 16:41:05 +0100 |
---|---|---|
committer | Stefan Wildemann <gta04@metalstrolche.de> | 2018-02-12 16:41:05 +0100 |
commit | 947b5a32d398cd7c53d299db429981ce6b6b2bc6 (patch) | |
tree | 6cdaef2da81ba8e2f8d61114a0bcc3cb3201a72e | |
parent | 02fa1f5b60bcc5a3ea891ffa4e2a0493b0f64c53 (diff) | |
download | navit-qt5_multipolygon.tar.gz |
Multipolygon quirk as suggested in issue #398qt5_multipolygon
This is the multipolygon drawing quirk detecting closed loops to
separate inner from outer loops on multi polygons.
Not a really good idea though, as there are many non multi polygons
having a node multiple times as well.
thanks @jandegr
-rw-r--r-- | navit/graphics/qt5/graphics_qt5.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/navit/graphics/qt5/graphics_qt5.cpp b/navit/graphics/qt5/graphics_qt5.cpp index f7ac15f43..f0ab7812e 100644 --- a/navit/graphics/qt5/graphics_qt5.cpp +++ b/navit/graphics/qt5/graphics_qt5.cpp @@ -413,14 +413,44 @@ draw_lines(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* static void draw_polygon(struct graphics_priv* gr, struct graphics_gc_priv* gc, struct point* p, int count) { - int i; + int i = 0; + int polygon_count = 0; QPolygon polygon; + struct point* start = NULL; // dbg(lvl_debug,"enter gr=%p, gc=%p, (%d, %d)\n", gr, gc, p->x, p->y); if (gr->painter == NULL) return; - for (i = 0; i < count; i++) - polygon.putPoints(i, 1, p[i].x, p[i].y); + while (i < count) { + int index = 0; + bool done = false; + QPolygon current; + /* read coordinates until loop is detected.*/ + while ((!done) && (i < count)) { + current.putPoints(index, 1, p[i].x, p[i].y); + index++; + /* don't have start point yet, so this is the start point */ + if (start == NULL) { + start = &(p[i]); + } else { + if ((start->x == p[i].x) && (start->y == p[i].y)) { + /* end of loop guessed */ + start = NULL; + done = true; + } + } + i++; + } + if (polygon_count == 0) { + /* outer loop. just use as is */ + polygon = current; + } else { + /* found a inner loop. Substract from what we already have */ + polygon = polygon.subtracted(current); + } + polygon_count++; + } + gr->painter->setPen(*gc->pen); gr->painter->setBrush(*gc->brush); /* if the polygon is transparent, we need to clear it first */ |