summaryrefslogtreecommitdiff
path: root/src/location/maps
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-05-02 13:23:51 +0200
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-05-03 16:42:22 +0000
commit61bb8c49ec662adf1622cd0bf91de51a2305adb9 (patch)
tree5cf634a737be5436dbb317864377713a857f992c /src/location/maps
parent22c4a09a40ffaf298b361b9b99c4166ca4ec60d3 (diff)
downloadqtlocation-61bb8c49ec662adf1622cd0bf91de51a2305adb9.tar.gz
Evaluate the visible region lazily in QGeoProjectionWebMercator
This change optimizes QGeoProjectionWebMercator::setupCamera, factoring out the code that calculates the visible region, and replacing it with a dirty flag. The computation is deferred to the first time visibleRegion() gets called. This is done because the visible region is currently only used to render some types of map items, meaning that in a multi layer setup, only few layers might need it. Change-Id: I5dd75969581513eb60e3cf5d6ba649349bf25378 Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/location/maps')
-rw-r--r--src/location/maps/qgeoprojection.cpp22
-rw-r--r--src/location/maps/qgeoprojection_p.h3
2 files changed, 19 insertions, 6 deletions
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp
index 5aaf584b..319bf906 100644
--- a/src/location/maps/qgeoprojection.cpp
+++ b/src/location/maps/qgeoprojection.cpp
@@ -93,7 +93,9 @@ QGeoProjectionWebMercator::QGeoProjectionWebMercator()
m_farPlane(0.0),
m_halfWidth(0.0),
m_halfHeight(0.0),
- m_minimumUnprojectableY(0.0)
+ m_minimumUnprojectableY(0.0),
+ m_verticalEstateToSkip(0.0),
+ m_visibleRegionDirty(false)
{
}
@@ -299,6 +301,8 @@ bool QGeoProjectionWebMercator::isProjectable(const QDoubleVector2D &wrappedProj
QList<QDoubleVector2D> QGeoProjectionWebMercator::visibleRegion() const
{
+ if (m_visibleRegionDirty)
+ const_cast<QGeoProjectionWebMercator *>(this)->updateVisibleRegion();
return m_visibleRegion;
}
@@ -444,16 +448,22 @@ void QGeoProjectionWebMercator::setupCamera()
const double elevationUpperBound = 90.0 - upperBoundEpsilon;
const double maxRayElevation = qMin(elevationUpperBound - m_cameraData.tilt(), verticalHalfFOV);
double maxHalfAperture = 0;
- double verticalEstateToSkip = 0;
+ m_verticalEstateToSkip = 0;
if (maxRayElevation < verticalHalfFOV) {
maxHalfAperture = tan(QLocationUtils::radians(maxRayElevation));
- verticalEstateToSkip = 1.0 - maxHalfAperture / m_aperture;
+ m_verticalEstateToSkip = 1.0 - maxHalfAperture / m_aperture;
}
- m_minimumUnprojectableY = verticalEstateToSkip * 0.5 * m_viewportHeight; // verticalEstateToSkip is relative to half aperture
+ m_minimumUnprojectableY = m_verticalEstateToSkip * 0.5 * m_viewportHeight; // m_verticalEstateToSkip is relative to half aperture
+ m_visibleRegionDirty = true;
+}
+
+void QGeoProjectionWebMercator::updateVisibleRegion()
+{
+ m_visibleRegionDirty = false;
- QDoubleVector2D tl = viewportToWrappedMapProjection(QDoubleVector2D(-1, -1 + verticalEstateToSkip ));
- QDoubleVector2D tr = viewportToWrappedMapProjection(QDoubleVector2D( 1, -1 + verticalEstateToSkip ));
+ QDoubleVector2D tl = viewportToWrappedMapProjection(QDoubleVector2D(-1, -1 + m_verticalEstateToSkip ));
+ QDoubleVector2D tr = viewportToWrappedMapProjection(QDoubleVector2D( 1, -1 + m_verticalEstateToSkip ));
QDoubleVector2D bl = viewportToWrappedMapProjection(QDoubleVector2D(-1, 1 ));
QDoubleVector2D br = viewportToWrappedMapProjection(QDoubleVector2D( 1, 1 ));
diff --git a/src/location/maps/qgeoprojection_p.h b/src/location/maps/qgeoprojection_p.h
index b17392b1..3a0dec1d 100644
--- a/src/location/maps/qgeoprojection_p.h
+++ b/src/location/maps/qgeoprojection_p.h
@@ -131,6 +131,7 @@ public:
private:
void setupCamera();
+ void updateVisibleRegion();
public:
struct Line2D
@@ -187,6 +188,7 @@ private:
double m_halfWidth;
double m_halfHeight;
double m_minimumUnprojectableY;
+ double m_verticalEstateToSkip;
// For the clipping region
QDoubleVector3D m_centerMercator;
@@ -199,6 +201,7 @@ private:
Line2D m_nearPlaneMapIntersection;
QList<QDoubleVector2D> m_visibleRegion;
+ bool m_visibleRegionDirty;
Q_DISABLE_COPY(QGeoProjectionWebMercator)
};