summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-10-22 13:04:39 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-11-05 16:47:11 (GMT)
commitac2660dd2fc7ef85db47f9a06fe9b144d51c7536 (patch)
treeeb01c7877e7adec0177d95d0ca3efcbb88b82fce
parente697a6824a516d584272df7be3381cb26a41512a (diff)
Cache one of the two expensive gdInv calls
Viewport center changes infrequently compared to the number of calls to screenCoordinates. Therefore this has a cache hit ratio of more than 99.99% even during panning and zooming for vector intensive areas.
-rw-r--r--src/lib/marble/projections/MercatorProjection.cpp10
-rw-r--r--src/lib/marble/projections/MercatorProjection.h3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/lib/marble/projections/MercatorProjection.cpp b/src/lib/marble/projections/MercatorProjection.cpp
index 72beb86..62dcef0 100644
--- a/src/lib/marble/projections/MercatorProjection.cpp
+++ b/src/lib/marble/projections/MercatorProjection.cpp
@@ -28,7 +28,9 @@
using namespace Marble;
MercatorProjection::MercatorProjection()
- : CylindricalProjection()
+ : CylindricalProjection(),
+ m_lastCenterLat(200.0),
+ m_lastCenterLatInv(0.0)
{
setMinLat( minValidLat() );
setMaxLat( maxValidLat() );
@@ -86,10 +88,14 @@ bool MercatorProjection::screenCoordinates( const GeoDataCoordinates &geopoint,
const qreal centerLon = viewport->centerLongitude();
const qreal centerLat = viewport->centerLatitude();
+ if (centerLat != m_lastCenterLat) {
+ m_lastCenterLatInv = gdInv(centerLat);
+ m_lastCenterLat = centerLat;
+ }
// Let (x, y) be the position on the screen of the placemark..
x = ( width / 2 + rad2Pixel * ( lon - centerLon ) );
- y = ( height / 2 - rad2Pixel * ( gdInv( lat ) - gdInv( centerLat ) ) );
+ y = ( height / 2 - rad2Pixel * ( gdInv( lat ) - m_lastCenterLatInv ) );
// Return true if the calculated point is inside the screen area,
// otherwise return false.
diff --git a/src/lib/marble/projections/MercatorProjection.h b/src/lib/marble/projections/MercatorProjection.h
index 582e592..fe3ab8f 100644
--- a/src/lib/marble/projections/MercatorProjection.h
+++ b/src/lib/marble/projections/MercatorProjection.h
@@ -109,6 +109,9 @@ class MercatorProjection : public CylindricalProjection
bool mapCoversViewport( const ViewportParams *viewport ) const;
private:
+ mutable qreal m_lastCenterLat;
+ mutable qreal m_lastCenterLatInv;
+
Q_DISABLE_COPY( MercatorProjection )
};