1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

A much better area Z-level algorithm

O(n^2) -> O(1)
This commit is contained in:
Martin Tůma 2022-01-27 00:26:28 +01:00
parent 1f0bd76f67
commit 0b3e54abf2
2 changed files with 3 additions and 21 deletions

View File

@ -34,20 +34,6 @@
#define COORDINATES_OFFSET SCALE_OFFSET
template<typename T>
static void updateZValues(T &items)
{
for (int i = 0; i < items.size(); i++) {
const QGraphicsItem *ai = items.at(i);
for (int j = 0; j < items.size(); j++) {
QGraphicsItem *aj = items[j];
if (aj->boundingRect().contains(ai->boundingRect()))
aj->setZValue(qMin(ai->zValue() - 1, aj->zValue()));
}
}
}
MapView::MapView(Map *map, POI *poi, QGeoPositionInfoSource *source,
QWidget *parent) : QGraphicsView(parent)
{
@ -226,6 +212,7 @@ void MapView::addArea(const Area &area)
ai->setOpacity(_areaOpacity);
ai->setDigitalZoom(_digitalZoom);
ai->setVisible(_showAreas);
ai->setZValue(-area.boundingRect().area());
_scene->addItem(ai);
_ar |= ai->bounds();
@ -266,6 +253,7 @@ MapItem *MapView::addMap(MapAction *map)
mi->setOpacity(_areaOpacity);
mi->setDigitalZoom(_digitalZoom);
mi->setVisible(_showAreas);
mi->setZValue(-mi->bounds().area());
_scene->addItem(mi);
_ar |= mi->bounds();
@ -299,9 +287,6 @@ QList<PathItem *> MapView::loadData(const Data &data)
else
updatePOIVisibility();
if (!data.areas().isEmpty())
updateZValues(_areas);
centerOn(contentCenter());
return paths;
@ -319,8 +304,6 @@ void MapView::loadMaps(const QList<MapAction *> &maps)
else
updatePOIVisibility();
updateZValues(_areas);
centerOn(contentCenter());
}
@ -336,8 +319,6 @@ void MapView::loadDEMs(const QList<Area> &dems)
else
updatePOIVisibility();
updateZValues(_areas);
centerOn(contentCenter());
}

View File

@ -30,6 +30,7 @@ public:
return (left() > right()) ? 360.0 - res : res;
}
double height() const {return (top() - bottom());}
double area() const {return qAbs(width()) * qAbs(height());}
double top() const {return _tl.lat();}
double bottom() const {return _br.lat();}