Commit 53a9f2b6 authored by Dennis Nienhüser's avatar Dennis Nienhüser
Browse files

Avoid intersects() call when the result can be determined easier.

Inner tiles of the pyramid always intersect with the viewport, so
the check can be simplified. Also moves the intersection calculation
to the items() method where it should have been done in the first
place. The idea for this patch is from Lars Grønning, see
https://phabricator.kde.org/D3176. Thanks!
parent 116108b7
......@@ -110,13 +110,7 @@ QList< GeoGraphicsItem* > GeoGraphicsScene::items( const GeoDataLatLonBox &box,
right.setNorth( box.north() );
right.setSouth( box.south() );
QList< GeoGraphicsItem* > allItems = items( left, zoomLevel );
foreach( GeoGraphicsItem* item, items( right, zoomLevel ) ) {
if ( !allItems.contains( item ) ) {
allItems << item;
}
}
return allItems;
return items(left, zoomLevel) + items(right, zoomLevel);
}
QList< GeoGraphicsItem* > result;
......@@ -141,11 +135,15 @@ QList< GeoGraphicsItem* > GeoGraphicsScene::items( const GeoDataLatLonBox &box,
int x1, y1, x2, y2;
coords.getCoords( &x1, &y1, &x2, &y2 );
for ( int x = x1; x <= x2; ++x ) {
bool const isBorderX = x == x1 || x == x2;
for ( int y = y1; y <= y2; ++y ) {
bool const isBorder = isBorderX || y == y1 || y == y2;
const TileId tileId = TileId( 0, level, x, y );
foreach(GeoGraphicsItem *object, d->m_items.value( tileId )) {
if (object->minZoomLevel() <= zoomLevel && object->visible()) {
result.push_back(object);
if (!isBorder || object->latLonAltBox().intersects(box)) {
result.push_back(object);
}
}
}
}
......
......@@ -131,30 +131,25 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
typedef QPair<QString, GeoGraphicsItem*> LayerItem;
QList<LayerItem> defaultLayer;
int paintedItems = 0;
QHash<QString, QVector<GeoGraphicsItem*> > paintedFragments;
QSet<QString> const knownLayers = QSet<QString>::fromList(d->m_styleBuilder->renderOrder());
auto const viewLatLonAltBox = viewport->viewLatLonAltBox();
foreach( GeoGraphicsItem* item, items ) {
if ( item->latLonAltBox().intersects(viewLatLonAltBox) ) {
QStringList paintLayers = item->paintLayers();
if (paintLayers.isEmpty()) {
mDebug() << item << " provides no paint layers, so I force one onto it.";
paintLayers << QString();
}
foreach(const auto &layer, paintLayers) {
if (knownLayers.contains(layer)) {
paintedFragments[layer] << item;
} else {
defaultLayer << LayerItem(layer, item);
static QSet<QString> missingLayers;
if (!missingLayers.contains(layer)) {
mDebug() << "Missing layer " << layer << ", in render order, will render it on top";
missingLayers << layer;
}
QStringList paintLayers = item->paintLayers();
if (paintLayers.isEmpty()) {
mDebug() << item << " provides no paint layers, so I force one onto it.";
paintLayers << QString();
}
foreach(const auto &layer, paintLayers) {
if (knownLayers.contains(layer)) {
paintedFragments[layer] << item;
} else {
defaultLayer << LayerItem(layer, item);
static QSet<QString> missingLayers;
if (!missingLayers.contains(layer)) {
mDebug() << "Missing layer " << layer << ", in render order, will render it on top";
missingLayers << layer;
}
}
++paintedItems;
}
}
......@@ -174,9 +169,8 @@ bool GeometryLayer::render( GeoPainter *painter, ViewportParams *viewport,
}
painter->restore();
d->m_runtimeTrace = QStringLiteral("Geometries: %1 Drawn: %2 Zoom: %3")
d->m_runtimeTrace = QStringLiteral("Geometries: %1 Zoom: %2")
.arg( items.size() )
.arg( paintedItems )
.arg( maxZoomLevel );
return true;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment