Commit ac2660dd authored by Dennis Nienhüser's avatar Dennis Nienhüser Committed by Friedrich W. H. Kossebau
Browse files

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.
parent e697a682
......@@ -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.
......
......@@ -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 )
};
......
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