summaryrefslogtreecommitdiffstats
path: root/src/location/maps
diff options
context:
space:
mode:
authorPaolo Angelelli <paolo.angelelli@qt.io>2017-02-23 18:08:15 +0100
committerPaolo Angelelli <paolo.angelelli@qt.io>2017-03-06 21:09:54 +0000
commit9c2bf32b1185cdfcf448a76dbc4a9ba18ae68b05 (patch)
treeef7338aaaa9198b3d6b2bacd3ae16a11b9079a75 /src/location/maps
parent7a6c1a93a0c1f7305f861b2f717bf71f2c7eaae7 (diff)
Optimize QGeoProjectionWebMercator::wrappedMapProjectionToItemPosition
This patch bakes all the required linear transformations performed in the method inside a 4x4 double matrix, removing 4 of the 5 instructions previously performed. Autotest adaptations with compares instead of verifys have been necessary due to small epsilons in the results. Change-Id: I7795173a27812eb93a48e3175ad24fd546aeec04 Reviewed-by: Michal Klocek <michal.klocek@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/location/maps')
-rw-r--r--src/location/maps/qgeoprojection.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/location/maps/qgeoprojection.cpp b/src/location/maps/qgeoprojection.cpp
index 586dcb02..8cb7a748 100644
--- a/src/location/maps/qgeoprojection.cpp
+++ b/src/location/maps/qgeoprojection.cpp
@@ -185,12 +185,7 @@ QDoubleVector2D QGeoProjectionWebMercator::unwrapMapProjection(const QDoubleVect
QDoubleVector2D QGeoProjectionWebMercator::wrappedMapProjectionToItemPosition(const QDoubleVector2D &wrappedProjection) const
{
- QDoubleVector3D pos = wrappedProjection * m_sideLength;
- QDoubleVector2D res = (m_transformation * pos).toVector2D();
- res += QDoubleVector2D(1.0,1.0);
- res *= 0.5;
- res *= QDoubleVector2D(m_viewportWidth, m_viewportHeight);
- return res;
+ return (m_transformation * wrappedProjection).toVector2D();
}
QDoubleVector2D QGeoProjectionWebMercator::itemPositionToWrappedMapProjection(const QDoubleVector2D &itemPosition) const
@@ -384,7 +379,24 @@ void QGeoProjectionWebMercator::setupCamera()
QDoubleMatrix4x4 projectionMatrix;
projectionMatrix.frustum(-m_halfWidth, m_halfWidth, -m_halfHeight, m_halfHeight, m_nearPlane, m_farPlane);
- m_transformation = projectionMatrix * cameraMatrix;
+ /*
+ * The full transformation chain for m_transformation is:
+ * matScreen * matScreenFit * matShift * projectionMatrix * cameraMatrix * matZoomLevelScale
+ * where:
+ * matZoomLevelScale = scale(m_sideLength, m_sideLength, 1.0)
+ * matShift = translate(1.0, 1.0, 0.0)
+ * matScreenFit = scale(0.5, 0.5, 1.0)
+ * matScreen = scale(m_viewportWidth, m_viewportHeight, 1.0)
+ */
+
+ QDoubleMatrix4x4 matScreenTransformation;
+ matScreenTransformation.scale(0.5 * m_viewportWidth, 0.5 * m_viewportHeight, 1.0);
+ matScreenTransformation(0,3) = 0.5 * m_viewportWidth;
+ matScreenTransformation(1,3) = 0.5 * m_viewportHeight;
+
+ m_transformation = matScreenTransformation * projectionMatrix * cameraMatrix;
+ m_transformation.scale(m_sideLength, m_sideLength, 1.0);
+
m_centerNearPlane = m_eye + m_viewNormalized;
m_centerNearPlaneMercator = m_eyeMercator + m_viewNormalized * m_nearPlaneMercator;