From 8095c33bcddefebd16b7cb08b07690caf877f600 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 21 Feb 2017 17:14:37 +0100 Subject: Use qRadiansToDegrees() and qDegreesToRadians() more widely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Especially in examples, where we should show off our convenience functions, prefer calling these functions over doing arithmetic with M_PI (or approximations thereto) and 180 (give or take simple factors). This incidentally documents what's going on, just by the name of the function used (and reveals at least one place where variables were misnamed; the return from atan is in radians, *not* degrees). Task-number: QTBUG-58083 Change-Id: I6e5d66721cafab423378f970af525400423e971e Reviewed-by: Jüri Valdmann Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Marc Mutz --- examples/embedded/lightmaps/slippymap.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'examples/embedded/lightmaps') diff --git a/examples/embedded/lightmaps/slippymap.cpp b/examples/embedded/lightmaps/slippymap.cpp index 7e847c2501..0bd5f44075 100644 --- a/examples/embedded/lightmaps/slippymap.cpp +++ b/examples/embedded/lightmaps/slippymap.cpp @@ -48,15 +48,10 @@ ** ****************************************************************************/ -#include - #include #include #include "slippymap.h" - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#include "qmath.h" uint qHash(const QPoint& p) { @@ -68,10 +63,10 @@ const int tdim = 256; QPointF tileForCoordinate(qreal lat, qreal lng, int zoom) { + qreal radianLat = qDegreesToRadians(lat); qreal zn = static_cast(1 << zoom); qreal tx = (lng + 180.0) / 360.0; - qreal ty = (1.0 - log(tan(lat * M_PI / 180.0) + - 1.0 / cos(lat * M_PI / 180.0)) / M_PI) / 2.0; + qreal ty = 0.5 - log(tan(radianLat) + 1.0 / cos(radianLat)) / M_PI / 2.0; return QPointF(tx * zn, ty * zn); } @@ -86,8 +81,7 @@ qreal latitudeFromTile(qreal ty, int zoom) { qreal zn = static_cast(1 << zoom); qreal n = M_PI - 2 * M_PI * ty / zn; - qreal lng = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); - return lng; + return qRadiansToDegrees(atan(0.5 * (exp(n) - exp(-n)))); } -- cgit v1.2.3