Created osm.h, re-factoring, unit test script bug fix
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Jul 2010 07:57:08 +0000 (10:57 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 15 Jul 2010 07:57:08 +0000 (10:57 +0300)
 - Created osm.h for OpenStreetMaps related constants and re-factored
   mapcommon.h

 - re-factored GeoCoordinate::convertFrom()

 - removed mapcommon.h dependency from GeoCoordinate and SceneCoordinate

 - bug fix for run_unit_tests.sh: finding and parsing the unit test
   project files was cutting "pro" also from the middle of the path
   and not just from the end as intented

19 files changed:
scripts/run_unit_tests.sh
src/coordinates/geocoordinate.cpp
src/coordinates/scenecoordinate.cpp
src/map/baselocationitem.cpp
src/map/frienditemshandler.cpp
src/map/mapcommon.h
src/map/mapengine.cpp
src/map/mapfetcher.cpp
src/map/mapscene.cpp
src/map/maptile.cpp
src/map/mapview.cpp
src/map/osm.h [new file with mode: 0644]
src/src.pro
tests/coordinates/geocoordinate/geocoordinate.pro
tests/coordinates/geocoordinate/testgeocoordinate.cpp
tests/coordinates/scenecoordinate/scenecoordinate.pro
tests/coordinates/scenecoordinate/testscenecoordinate.cpp
tests/map/mapengine/testmapengine.cpp
tests/tests.pro

index 3641427..dae1672 100755 (executable)
@@ -28,8 +28,8 @@ if [[ -d $REPORT_PATH && -d $UNIT_TESTS_ROOT_DIR ]]; then
     echo "##########################################" >> $REPORT
     echo "" >> $REPORT
 
-    # find all test .pro files pahts, cut .pro extension
-    UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep \.pro$ | sed -e s,[^/]pro,,g`)
+    # find all test .pro files paths, cut .pro extension
+    UNIT_TEST_PROJECTS=(`find $UNIT_TESTS_ROOT_DIR_ABSOLUTE | egrep \.pro$ | sed -e s,.pro$,,g`)
 
     echo "###################################################"
     echo "All unit test executables will be deleted"
index f58697a..a976f40 100644 (file)
     USA.
 */
 
+#include <cmath>
+
 #include <QDebug>
 
-/// @todo remove mapcommon.h include after refactored the convertFrom()
-#include "map/mapcommon.h"
+#include "map/osm.h"
 #include "scenecoordinate.h"
 
 #include "geocoordinate.h"
@@ -52,34 +53,17 @@ void GeoCoordinate::convertFrom(const SceneCoordinate &coordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    const int zoomLevel = 18; // replacing the parameter temporarily
-
-    double tileFactor = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
-    double xFactor = (coordinate.x() / (TILE_SIZE_X*tileFactor));
-    double yFactor = (coordinate.y() / (TILE_SIZE_Y*tileFactor));
+    const int MAP_PIXELS_Y = OSM_MAP_MAX_PIXEL_Y + 1;
 
-    tileFactor = 1 << zoomLevel;
-    double longitude = xFactor / tileFactor * 360.0 - 180;
+    double longitude = coordinate.x() / OMS_MAP_PIXELS_X * 360.0 - 180;
 
-    double n = M_PI - 2.0 * M_PI * yFactor / tileFactor;
+    double n = M_PI - 2.0 * M_PI * coordinate.y() / MAP_PIXELS_Y;
     double latitude = 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
 
-//    return QPointF(longitude, latitude);
     setLatitude(latitude);
     setLongitude(longitude);
 }
 
-//double tilex2long(int x, int z)
-//{
-//     return x / pow(2.0, z) * 360.0 - 180;
-//}
-
-//double tiley2lat(int y, int z)
-//{
-//     double n = M_PI - 2.0 * M_PI * y / pow(2.0, z);
-//     return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n)));
-//}
-
 bool GeoCoordinate::isNull() const
 {
     qDebug() << __PRETTY_FUNCTION__;
index 923ad90..14965e6 100644 (file)
     USA.
 */
 
+#include <cmath>
+
 #include <QDebug>
 
 #include "geocoordinate.h"
-#include "map/mapcommon.h"
+#include "map/osm.h"
 
 #include "scenecoordinate.h"
 
@@ -56,10 +58,10 @@ void SceneCoordinate::convertFrom(const GeoCoordinate &coordinate)
     double worldY = static_cast<double>((1.0 - log(tan(coordinate.latitude() * M_PI / 180.0) + 1.0
                                 / cos(coordinate.latitude() * M_PI / 180.0)) / M_PI) / 2.0);
 
-    m_x = worldX * MAX_TILES_PER_SIDE * TILE_SIZE_X;
-    m_y = worldY * MAX_TILES_PER_SIDE * TILE_SIZE_Y;
+    m_x = worldX * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_X;
+    m_y = worldY * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_Y;
 
-    normalize(m_x, MAP_MIN_PIXEL_X, MAP_MAX_PIXEL_X);
+    normalize(m_x, OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X);
 }
 
 bool SceneCoordinate::isNull() const
index 2acafd6..8dbc8d5 100644 (file)
@@ -41,7 +41,7 @@ QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
     // picture side length used for collision detection
     const int IMAGE_SIDE = 58;
 
-    int multiplier = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
+    int multiplier = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
     int side = multiplier * IMAGE_SIDE;
 
     QPoint center = pos().toPoint();
@@ -49,10 +49,10 @@ QRect BaseLocationItem::sceneTransformedBoundingRect(int zoomLevel) const
     QRect rect = QRect(topLeft, QSize(side, side));
 
     // normalize rect's center point to be inside the map
-    if (center.x() < MAP_MIN_PIXEL_X)
-        rect.translate(MAP_PIXELS_X, 0);
-    else if (center.x() > MAP_MAX_PIXEL_X)
-        rect.translate(-MAP_PIXELS_X, 0);
+    if (center.x() < OSM_MAP_MIN_PIXEL_X)
+        rect.translate(OMS_MAP_PIXELS_X, 0);
+    else if (center.x() > OSM_MAP_MAX_PIXEL_X)
+        rect.translate(-OMS_MAP_PIXELS_X, 0);
 
     return rect;
 }
index 55fd84a..cfc10b2 100644 (file)
@@ -107,12 +107,12 @@ bool FriendItemsHandler::collides(BaseLocationItem *item1, BaseLocationItem *ite
     if (item1Rect.intersects(item2Rect))
         return true;
 
-    if (item1Rect.left() < (MAP_MIN_PIXEL_X + item1Rect.width() / 2)) {
-        QRect translated = item1Rect.translated(MAP_PIXELS_X, 0);
+    if (item1Rect.left() < (OSM_MAP_MIN_PIXEL_X + item1Rect.width() / 2)) {
+        QRect translated = item1Rect.translated(OMS_MAP_PIXELS_X, 0);
         if (translated.intersects(item2Rect))
             return true;
-    } else if (item1Rect.right() > (MAP_MAX_PIXEL_X  - item1Rect.width() / 2)) {
-        QRect translated = item1Rect.translated(-MAP_PIXELS_X, 0);
+    } else if (item1Rect.right() > (OSM_MAP_MAX_PIXEL_X  - item1Rect.width() / 2)) {
+        QRect translated = item1Rect.translated(-OMS_MAP_PIXELS_X, 0);
         if (translated.intersects(item2Rect))
             return true;
     }
index 710d2a7..71f3819 100644 (file)
 
 #include <QtCore>
 
-const int TILE_SIZE_X = 256;      ///< Tile image size in x direction
-const int TILE_SIZE_Y = 256;      ///< Tile image size in y direction
+#include "osm.h"
+
 const int MAP_TILE_MIN_INDEX = 0; ///< First index number of map tiles
 
-const int MIN_MAP_ZOOM_LEVEL = 0; ///< Minimum zoom level
-const int MAX_MAP_ZOOM_LEVEL = 18; ///< Maximum zoom level
-const int MIN_VIEW_ZOOM_LEVEL = 2; ///< Minimum zoom level for MapView
+const int MAP_VIEW_MIN_ZOOM_LEVEL = 2; ///< Minimum zoom level for MapView
 
 /**
-* @var MIN_MAP_SCENE_NORMAL_LEVEL
+* @var MAP_SCENE_MIN_NORMAL_LEVEL
 * @brief Used for shifting zValues of MapTiles
 */
-const int MIN_MAP_SCENE_NORMAL_LEVEL = MAX_MAP_ZOOM_LEVEL + 1;
-
-const int MAX_TILES_PER_SIDE = (1 << MAX_MAP_ZOOM_LEVEL);  ///< Amount of tiles per side
-const int MAP_PIXELS_X = MAX_TILES_PER_SIDE * TILE_SIZE_X; ///< Amount of horizontal pixels in map
-
-const int MAP_MIN_PIXEL_X = 0;                ///< First map horizontal pixel index
-const int MAP_MAX_PIXEL_X = MAP_PIXELS_X - 1; ///< Last map horizontal pixel index
-
-const int MAP_MIN_PIXEL_Y = 0;                                   ///< First map vertical pixel index
-const int MAP_MAX_PIXEL_Y = MAX_TILES_PER_SIDE * TILE_SIZE_Y - 1; ///< Last map vertical pixel index
+const int MAP_SCENE_MIN_NORMAL_LEVEL = OSM_MAX_ZOOM_LEVEL + 1;
 
 const double MAP_SCENE_VERTICAL_OVERSIZE_FACTOR = 0.5; ///< MapScene vertical oversize ( * map size)
 
@@ -54,25 +43,31 @@ const double MAP_SCENE_VERTICAL_OVERSIZE_FACTOR = 0.5; ///< MapScene vertical ov
 * @var MAP_SCENE_MIN_PIXEL_X
 * @brief First scene horizontal pixel
 */
-const int MAP_SCENE_MIN_PIXEL_X = -MAP_PIXELS_X * MAP_SCENE_VERTICAL_OVERSIZE_FACTOR;
+const int MAP_SCENE_MIN_PIXEL_X = -OMS_MAP_PIXELS_X * MAP_SCENE_VERTICAL_OVERSIZE_FACTOR;
 
 /**
 * @var MAP_SCENE_MAX_PIXEL_X
 * @brief Last scene horizontal pixel
 */
-const int MAP_SCENE_MAX_PIXEL_X = MAP_PIXELS_X * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR) - 1;
+const int MAP_SCENE_MAX_PIXEL_X = OMS_MAP_PIXELS_X * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR) - 1;
 
+////////////////////////////////////////////////////////////////////////////////
+// DEFAULT VALUES
+////////////////////////////////////////////////////////////////////////////////
 /**
-* @var DEFAULT_START_ZOOM_LEVEL
+* @var MAP_DEFAULT_ZOOM_LEVEL
 * @brief Maps Default zoom level, used when latest zoom level is not available.
 */
-const int DEFAULT_START_ZOOM_LEVEL = MIN_VIEW_ZOOM_LEVEL;
+const int MAP_DEFAULT_ZOOM_LEVEL = MAP_VIEW_MIN_ZOOM_LEVEL;
+
+const qreal MAP_DEFAULT_LONGITUDE = 0.0000;  ///< Default longitude value
+const qreal MAP_DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
 
 /**
 * @var FRIEND_LOCATION_ICON_Z_LEVEL
 * @brief layer of friend location icon
 */
-const int FRIEND_LOCATION_ICON_Z_LEVEL = MIN_MAP_SCENE_NORMAL_LEVEL + MAX_MAP_ZOOM_LEVEL + 1;
+const int FRIEND_LOCATION_ICON_Z_LEVEL = MAP_SCENE_MIN_NORMAL_LEVEL + OSM_MAX_ZOOM_LEVEL + 1;
 
 const int GROUP_ITEM_FRIENDS_COUNT_X = 13;  ///< Group item friends count x value
 const int GROUP_ITEM_FRIENDS_COUNT_Y = 13;  ///< Group item friends count y value
@@ -87,18 +82,12 @@ const int PRESS_MANHATTAN_LENGTH = 30;   ///< Friend/group item press manhattan
 */
 const int OWN_LOCATION_ICON_Z_LEVEL = FRIEND_LOCATION_ICON_Z_LEVEL + 1;
 
-const double MAX_LATITUDE = 85.05112877980659237802;  ///< Maximum latitude value
-const double MIN_LATITUDE = -MAX_LATITUDE; ///< Minimum latitude value
 const double MIN_LONGITUDE = -180.0;  ///< Minimum longitude value
 const double MAX_LONGITUDE = 180.0;  ///< Maximum longitude value
 
-const int DEFAULT_ZOOM_LEVEL = 14;       ///< Default zoom level
-const qreal DEFAULT_LONGITUDE = 0.0000;  ///< Default longitude value
-const qreal DEFAULT_LATITUDE = 0.0000; ///< Default latitude value
-
 const qreal EARTH_RADIUS = 6371.01;         ///< Earth radius in km
 
-const int GRID_PADDING = 0;  ///< Grid padding used in tile grid calculation
+const int MAP_GRID_PADDING = 0;  ///< Grid padding used in tile grid calculation
 
 const QString OSM_LICENSE = QString::fromUtf8("© OpenStreetMap contributors, CC-BY-SA");
 
index 66fb041..ced4e52 100644 (file)
@@ -54,7 +54,7 @@ MapEngine::MapEngine(QObject *parent)
       m_scrollStartedByGps(false),
       m_smoothScrollRunning(false),
       m_zoomedIn(false),
-      m_zoomLevel(DEFAULT_ZOOM_LEVEL),
+      m_zoomLevel(MAP_DEFAULT_ZOOM_LEVEL),
       m_centerTile(QPoint(UNDEFINED, UNDEFINED)),
       m_lastAutomaticPosition(QPoint(0, 0)),
       m_tilesGridSize(QSize(0, 0)),
@@ -150,25 +150,25 @@ QPoint MapEngine::convertLatLonToSceneCoordinate(QPointF latLonCoordinate)
 
     if ((longitude > MAX_LONGITUDE) || (longitude < MIN_LONGITUDE))
         return QPoint(UNDEFINED, UNDEFINED);
-    if ((latitude > MAX_LATITUDE) || (latitude < MIN_LATITUDE))
+    if ((latitude > OSM_MAX_LATITUDE) || (latitude < OSM_MIN_LATITUDE))
         return QPoint(UNDEFINED, UNDEFINED);
 
-    qreal z = static_cast<qreal>(MapEngine::tilesPerSide(MAX_MAP_ZOOM_LEVEL));
+    qreal z = static_cast<qreal>(MapEngine::tilesPerSide(OSM_MAX_ZOOM_LEVEL));
 
     qreal x = static_cast<qreal>((longitude + 180.0) / 360.0);
     qreal y = static_cast<qreal>((1.0 - log(tan(latitude * M_PI / 180.0) + 1.0
                                 / cos(latitude * M_PI / 180.0)) / M_PI) / 2.0);
 
-    return QPointF(x * z * TILE_SIZE_X, y * z * TILE_SIZE_Y).toPoint();
+    return QPointF(x * z * OSM_TILE_SIZE_X, y * z * OSM_TILE_SIZE_Y).toPoint();
 }
 
 QPointF MapEngine::convertSceneCoordinateToLatLon(int zoomLevel, QPoint sceneCoordinate)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    double tileFactor = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
-    double xFactor = (sceneCoordinate.x() / (TILE_SIZE_X*tileFactor));
-    double yFactor = (sceneCoordinate.y() / (TILE_SIZE_Y*tileFactor));
+    double tileFactor = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
+    double xFactor = (sceneCoordinate.x() / (OSM_TILE_SIZE_X*tileFactor));
+    double yFactor = (sceneCoordinate.y() / (OSM_TILE_SIZE_Y*tileFactor));
 
     tileFactor = 1 << zoomLevel;
     double longitude = xFactor / tileFactor * 360.0 - 180;
@@ -183,9 +183,9 @@ QPoint MapEngine::convertSceneCoordinateToTileNumber(int zoomLevel, QPoint scene
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
-    int x = static_cast<int>(sceneCoordinate.x() / (TILE_SIZE_X * pow));
-    int y = static_cast<int>(sceneCoordinate.y() / (TILE_SIZE_Y * pow));
+    int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
+    int x = static_cast<int>(sceneCoordinate.x() / (OSM_TILE_SIZE_X * pow));
+    int y = static_cast<int>(sceneCoordinate.y() / (OSM_TILE_SIZE_Y * pow));
 
     return QPoint(x, y);
 }
@@ -194,9 +194,9 @@ QPoint MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileN
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    int pow = 1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel);
-    int x = tileNumber.x() * TILE_SIZE_X * pow;
-    int y = tileNumber.y() * TILE_SIZE_Y * pow;
+    int pow = 1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel);
+    int x = tileNumber.x() * OSM_TILE_SIZE_X * pow;
+    int y = tileNumber.y() * OSM_TILE_SIZE_Y * pow;
 
     return QPoint(x, y);
 }
@@ -204,7 +204,7 @@ QPoint MapEngine::convertTileNumberToSceneCoordinate(int zoomLevel, QPoint tileN
 void MapEngine::disableAutoCenteringIfRequired(QPoint sceneCoordinate)
 {
     if (isAutoCenteringEnabled()) {
-        int zoomFactor = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+        int zoomFactor = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
 
         QPoint oldPixelValue = QPoint(m_lastAutomaticPosition.x() / zoomFactor,
                                       m_lastAutomaticPosition.y() / zoomFactor);
@@ -294,8 +294,8 @@ void MapEngine::init()
         == ERROR_VALUE_NOT_FOUND_ON_SETTINGS || settings.value(MAP_LAST_ZOOMLEVEL,
         ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toString() == ERROR_VALUE_NOT_FOUND_ON_SETTINGS) {
 
-        startLocation = QPointF(DEFAULT_LONGITUDE, DEFAULT_LATITUDE);
-        m_zoomLevel = qBound(MIN_VIEW_ZOOM_LEVEL, DEFAULT_START_ZOOM_LEVEL, MAX_MAP_ZOOM_LEVEL);
+        startLocation = QPointF(MAP_DEFAULT_LONGITUDE, MAP_DEFAULT_LATITUDE);
+        m_zoomLevel = qBound(MAP_VIEW_MIN_ZOOM_LEVEL, MAP_DEFAULT_ZOOM_LEVEL, OSM_MAX_ZOOM_LEVEL);
     } else {
         m_zoomLevel = settings.value(MAP_LAST_ZOOMLEVEL, ERROR_VALUE_NOT_FOUND_ON_SETTINGS).toInt();
         startLocation = settings.value(MAP_LAST_POSITION,
@@ -328,7 +328,7 @@ qreal MapEngine::sceneResolution()
 
     const int SHIFT = 200;
     const int KM_TO_M = 1000;
-    qreal scale = (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+    qreal scale = (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
     QPointF centerCoordinate = centerGeoCoordinate();
     QPoint shiftedSceneCoordinate = QPoint(m_sceneCoordinate.x() + SHIFT*scale
                                            , m_sceneCoordinate.y());
@@ -349,13 +349,13 @@ void MapEngine::mapImageReceived(int zoomLevel, int x, int y, const QPixmap &ima
     int tilesGridWidthHalf = (m_viewTilesGrid.width() + 1) / 2;
 
     // duplicate to east side? (don't need to duplicate over padding)
-    if (tileNumber.x() < (tilesGridWidthHalf - GRID_PADDING)) {
+    if (tileNumber.x() < (tilesGridWidthHalf - MAP_GRID_PADDING)) {
         QPoint adjustedTileNumber(tileNumber.x() + tileMaxIndex(zoomLevel) + 1, tileNumber.y());
         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
     }
 
     // duplicate to west side? (don't need to duplicate over padding)
-    if (tileNumber.x() > (tileMaxIndex(zoomLevel) - tilesGridWidthHalf + GRID_PADDING)) {
+    if (tileNumber.x() > (tileMaxIndex(zoomLevel) - tilesGridWidthHalf + MAP_GRID_PADDING)) {
         QPoint adjustedTileNumber(tileNumber.x() - tileMaxIndex(zoomLevel) - 1, tileNumber.y());
         m_mapScene->addTile(zoomLevel, adjustedTileNumber, image, m_zoomLevel);
     }
@@ -442,10 +442,10 @@ void MapEngine::setCenterPosition(QPoint scenePosition)
     qDebug() << __PRETTY_FUNCTION__;
 
     // jump to opposite side of the world if world horizontal limit is exceeded
-    scenePosition.setX(normalize(scenePosition.x(), MAP_MIN_PIXEL_X, MAP_MAX_PIXEL_X));
+    scenePosition.setX(normalize(scenePosition.x(), OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X));
 
     // don't allow vertical scene coordinates go out of the map
-    scenePosition.setY(qBound(MAP_MIN_PIXEL_Y, scenePosition.y(), MAP_MAX_PIXEL_Y));
+    scenePosition.setY(qBound(OSM_MAP_MIN_PIXEL_Y, scenePosition.y(), OSM_MAP_MAX_PIXEL_Y));
 
     if (!m_smoothScrollRunning)
         disableAutoCenteringIfRequired(scenePosition);
@@ -488,10 +488,10 @@ void MapEngine::setTilesGridSize(const QSize &viewSize)
     // converting scene tile to tile number does cause grid centering inaccuracy of one tile
     const int CENTER_TILE_INACCURACY = 1;
 
-    int gridWidth = ceil(qreal(viewSize.width()) / TILE_SIZE_X + SCROLLING_RESERVE)
-                    + CENTER_TILE_INACCURACY + (GRID_PADDING * 2);
-    int gridHeight = ceil(qreal(viewSize.height()) / TILE_SIZE_Y + SCROLLING_RESERVE)
-                     + CENTER_TILE_INACCURACY + (GRID_PADDING * 2);
+    int gridWidth = ceil(qreal(viewSize.width()) / OSM_TILE_SIZE_X + SCROLLING_RESERVE)
+                    + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
+    int gridHeight = ceil(qreal(viewSize.height()) / OSM_TILE_SIZE_Y + SCROLLING_RESERVE)
+                     + CENTER_TILE_INACCURACY + (MAP_GRID_PADDING * 2);
 
     m_mapFetcher->setDownloadQueueSize(gridWidth * gridHeight);
 
@@ -562,9 +562,9 @@ void MapEngine::viewZoomFinished()
         m_mapScene->removeOutOfViewTiles(m_viewTilesGrid, m_zoomLevel);
     }
 
-    if (m_zoomLevel == MAX_MAP_ZOOM_LEVEL)
+    if (m_zoomLevel == OSM_MAX_ZOOM_LEVEL)
         emit maxZoomLevelReached();
-    else if (m_zoomLevel == MIN_VIEW_ZOOM_LEVEL)
+    else if (m_zoomLevel == MAP_VIEW_MIN_ZOOM_LEVEL)
         emit minZoomLevelReached();
 }
 
@@ -583,7 +583,7 @@ void MapEngine::zoomIn()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_zoomLevel < MAX_MAP_ZOOM_LEVEL) {
+    if (m_zoomLevel < OSM_MAX_ZOOM_LEVEL) {
         m_zoomLevel++;
         m_zoomedIn = true;
         zoomed();
@@ -594,7 +594,7 @@ void MapEngine::zoomOut()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_zoomLevel > MIN_VIEW_ZOOM_LEVEL) {
+    if (m_zoomLevel > MAP_VIEW_MIN_ZOOM_LEVEL) {
         m_zoomLevel--;
         zoomed();
     }
index 8a601b3..15f8aa8 100644 (file)
@@ -239,7 +239,7 @@ bool MapFetcher::translateIndexesToUpperLevel(int &zoomLevel, int &x, int &y)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (zoomLevel > MIN_MAP_ZOOM_LEVEL) {
+    if (zoomLevel > OSM_MIN_ZOOM_LEVEL) {
         zoomLevel--;
         x /= 2;
         y /= 2;
index 33e0278..556ac85 100644 (file)
@@ -35,8 +35,8 @@ MapScene::MapScene(QObject *parent)
     qDebug() << __PRETTY_FUNCTION__;
 
     setBackgroundBrush(Qt::lightGray);
-    setSceneRect(QRect(QPoint(MAP_SCENE_MIN_PIXEL_X, MAP_MIN_PIXEL_Y),
-                       QPoint(MAP_SCENE_MAX_PIXEL_X, MAP_MAX_PIXEL_Y)));
+    setSceneRect(QRect(QPoint(MAP_SCENE_MIN_PIXEL_X, OSM_MAP_MIN_PIXEL_Y),
+                       QPoint(MAP_SCENE_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y)));
 }
 
 void MapScene::addTile(int tileZoomLevel, QPoint tileNumber, const QPixmap &image, int viewZoomLevel)
@@ -144,9 +144,9 @@ void MapScene::removeOutOfViewTiles(QRect tilesGrid, int zoomLevel)
 
     // if view is near east limit of the map, then there is duplicate tiles also on the opposite
     // side of the world which are removed from allTiles
-    if (tilesGrid.right() > (MapEngine::tileMaxIndex(zoomLevel) - tilesGridWidthHalf + GRID_PADDING)) {
+    if (tilesGrid.right() > (MapEngine::tileMaxIndex(zoomLevel) - tilesGridWidthHalf + MAP_GRID_PADDING)) {
         QRect oppositeRect = m_tilesSceneRect;
-        oppositeRect.translate(-MAP_PIXELS_X, 0);
+        oppositeRect.translate(-OMS_MAP_PIXELS_X, 0);
         QList<QGraphicsItem *> oppositeItems = items(oppositeRect, Qt::IntersectsItemBoundingRect);
         foreach (QGraphicsItem *item, oppositeItems)
             allItems.removeOne(item);
@@ -154,9 +154,9 @@ void MapScene::removeOutOfViewTiles(QRect tilesGrid, int zoomLevel)
 
     // if view is near west limit of the map, then there is duplicate tiles also on the opposite
     // side of the world which are removed from allTiles
-    if (tilesGrid.left() < (tilesGridWidthHalf - GRID_PADDING)) {
+    if (tilesGrid.left() < (tilesGridWidthHalf - MAP_GRID_PADDING)) {
         QRect oppositeRect = m_tilesSceneRect;
-        oppositeRect.translate(MAP_PIXELS_X, 0);
+        oppositeRect.translate(OMS_MAP_PIXELS_X, 0);
         QList<QGraphicsItem *> oppositeItems = items(oppositeRect, Qt::IntersectsItemBoundingRect);
         foreach (QGraphicsItem *item, oppositeItems)
             allItems.removeOne(item);
@@ -209,11 +209,11 @@ void MapScene::setSceneVerticalOverlap(int viewHeight, int zoomLevel)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    int overlap = viewHeight / 2 * (1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel));
+    int overlap = viewHeight / 2 * (1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel));
 
     QRect rect = sceneRect().toRect();
-    rect.setTop(MAP_MIN_PIXEL_Y - overlap);
-    rect.setBottom(MAP_MAX_PIXEL_Y + overlap);
+    rect.setTop(OSM_MAP_MIN_PIXEL_Y - overlap);
+    rect.setBottom(OSM_MAP_MAX_PIXEL_Y + overlap);
     setSceneRect(rect);
 }
 
@@ -250,27 +250,27 @@ void MapScene::spanItems(int zoomLevel, QPoint sceneCoordinate, QSize viewSize)
 
     // create rects for left and right side
     QRect leftRect = sceneRect().toRect(); // this way we get the horizontal limits of the scene
-    leftRect.setTop(MAP_MIN_PIXEL_Y);
-    leftRect.setBottom(MAP_MAX_PIXEL_Y);
+    leftRect.setTop(OSM_MAP_MIN_PIXEL_Y);
+    leftRect.setBottom(OSM_MAP_MAX_PIXEL_Y);
     QRect rightRect = leftRect;
 
     // calculate current horizontal area shown on the view
-    int viewSceneWidth = (1 << (MAX_MAP_ZOOM_LEVEL - zoomLevel)) * viewSize.width();
+    int viewSceneWidth = (1 << (OSM_MAX_ZOOM_LEVEL - zoomLevel)) * viewSize.width();
     int viewSceneLeft = sceneCoordinate.x() - viewSceneWidth / 2;
     int viewSceneRight = sceneCoordinate.x() + viewSceneWidth / 2;
 
     // limit rects to include only area which really must be moved
-    leftRect.setRight(-1 - (MAP_PIXELS_X - 1 - viewSceneRight));
-    rightRect.setLeft(MAP_PIXELS_X + viewSceneLeft);
+    leftRect.setRight(-1 - (OMS_MAP_PIXELS_X - 1 - viewSceneRight));
+    rightRect.setLeft(OMS_MAP_PIXELS_X + viewSceneLeft);
 
     Q_ASSERT_X(leftRect.right() < viewSceneLeft, "spanning rect right value", "move rect is in the view area");
     Q_ASSERT_X(rightRect.left() > viewSceneRight, "spanning rect left value", "move rect is in the view area");
 
     // move all items which intersects the rects
     if (leftRect.left() < leftRect.right())
-        moveIntersectingItemsHorizontally(leftRect, MAP_PIXELS_X);
+        moveIntersectingItemsHorizontally(leftRect, OMS_MAP_PIXELS_X);
     if (rightRect.left() < rightRect.right())
-        moveIntersectingItemsHorizontally(rightRect, -MAP_PIXELS_X);
+        moveIntersectingItemsHorizontally(rightRect, -OMS_MAP_PIXELS_X);
 }
 
 void MapScene::tilesSceneRectUpdated(QRect tilesSceneRect)
index 90ce801..290f4f6 100644 (file)
@@ -52,7 +52,7 @@ void MapTile::setZoomLevel(int tileZoomLevel, int currentViewZoomLevel)
 
     setSceneLevel(currentViewZoomLevel);
 
-    qreal zoomFactor = static_cast<qreal>(1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+    qreal zoomFactor = static_cast<qreal>(1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
     setScale(zoomFactor);
 }
 
@@ -61,12 +61,12 @@ void MapTile::setSceneLevel(int currentZoomLevel)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (currentZoomLevel < m_zoomLevel) {
-        qreal z = static_cast<qreal>(MIN_MAP_SCENE_NORMAL_LEVEL + currentZoomLevel
+        qreal z = static_cast<qreal>(MAP_SCENE_MIN_NORMAL_LEVEL + currentZoomLevel
                                      - (m_zoomLevel - currentZoomLevel)) + 0.5;
         setZValue(z);
     }
     else
-        setZValue(static_cast<qreal>(MIN_MAP_SCENE_NORMAL_LEVEL + m_zoomLevel));
+        setZValue(static_cast<qreal>(MAP_SCENE_MIN_NORMAL_LEVEL + m_zoomLevel));
 }
 
 QPoint MapTile::tileNumber()
@@ -98,7 +98,7 @@ void MapTile::setPosition()
                                   * (1 + MAP_SCENE_VERTICAL_OVERSIZE_FACTOR)
                                   - INDEX_0_TILE;
 
-    if ((m_zoomLevel >= MIN_MAP_ZOOM_LEVEL) && (m_zoomLevel <= MAX_MAP_ZOOM_LEVEL)
+    if ((m_zoomLevel >= OSM_MIN_ZOOM_LEVEL) && (m_zoomLevel <= OSM_MAX_ZOOM_LEVEL)
         && (m_tileNumber.x() >= MIN_TILE_NUMBER_X) && (m_tileNumber.x() <= MAX_TILE_NUMBER_X)
         && (m_tileNumber.y() >= 0) && (m_tileNumber.y() <= MAX_TILE_NUMBER)) {
             setPos(MapEngine::convertTileNumberToSceneCoordinate(m_zoomLevel, m_tileNumber));
index 0fbaa90..9e45304 100644 (file)
@@ -84,7 +84,7 @@ void MapView::mouseDoubleClickEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_zoomLevel + 1 <= MAX_MAP_ZOOM_LEVEL) {
+    if (m_zoomLevel + 1 <= OSM_MAX_ZOOM_LEVEL) {
         QPoint pressPosition = mapToScene(event->pos()).toPoint();
         QPoint viewCenterPosition = mapToScene(width() / 2 - 1, height() / 2 - 1).toPoint();
         QPoint zoomPosition = viewCenterPosition - ((viewCenterPosition - pressPosition) / 2);
@@ -100,7 +100,7 @@ void MapView::mouseDoubleClickEvent(QMouseEvent *event)
         m_zoomAnimation->setEasingCurve(QEasingCurve::InQuad);
         m_zoomAnimation->setDuration(ZOOM_TIME_MS);
         m_zoomAnimation->setStartValue(viewScale());
-        m_zoomAnimation->setEndValue(pow(2, m_zoomLevel+1 - MAX_MAP_ZOOM_LEVEL));
+        m_zoomAnimation->setEndValue(pow(2, m_zoomLevel+1 - OSM_MAX_ZOOM_LEVEL));
 
         m_scrollAndZoomAnimation->start();
     }
@@ -187,7 +187,7 @@ void MapView::mouseReleaseEvent(QMouseEvent *event)
                 effectViewDistance /= biggerDistance / m_kineticMaxViewDistance;
 
             QPointF effectSceneDistance = effectViewDistance
-                                          * (1 << (MAX_MAP_ZOOM_LEVEL - m_zoomLevel));
+                                          * (1 << (OSM_MAX_ZOOM_LEVEL - m_zoomLevel));
 
             m_scroller->setEasingCurve(QEasingCurve::OutCirc);
             m_scroller->setDuration(KINETIC_SCROLL_TIME_MS);
@@ -227,7 +227,7 @@ void MapView::setZoomLevel(int zoomLevel)
         m_zoomAnimation->setEasingCurve(QEasingCurve::InQuad);
         m_zoomAnimation->setDuration(ZOOM_TIME_MS);
         m_zoomAnimation->setStartValue(viewScale());
-        m_zoomAnimation->setEndValue(pow(2, zoomLevel - MAX_MAP_ZOOM_LEVEL));
+        m_zoomAnimation->setEndValue(pow(2, zoomLevel - OSM_MAX_ZOOM_LEVEL));
 
         m_zoomAnimation->start();
     }
diff --git a/src/map/osm.h b/src/map/osm.h
new file mode 100644 (file)
index 0000000..66a2b64
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+    Situare - A location system for Facebook
+    Copyright (C) 2010  Ixonos Plc. Authors:
+
+        Sami Rämö - sami.ramo@ixonos.com
+
+    Situare is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License
+    version 2 as published by the Free Software Foundation.
+
+    Situare is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Situare; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+    USA.
+*/
+
+
+#ifndef OSM_H
+#define OSM_H
+
+// ZOOM LEVELS
+const int OSM_MIN_ZOOM_LEVEL = 0;   ///< Minimum zoom level
+const int OSM_MAX_ZOOM_LEVEL = 18;  ///< Maximum zoom level
+
+// TILES
+const int OSM_TILE_SIZE_X = 256;                            ///< Tile image size in x direction
+const int OSM_TILE_SIZE_Y = 256;                            ///< Tile image size in y direction
+const int OSM_TILES_PER_SIDE = (1 << OSM_MAX_ZOOM_LEVEL);   ///< Amount of tiles per side
+
+// LATITUDE COORDINATE LIMITS
+/**
+* @var OSM_MAX_LATITUDE
+* @brief Maximum latitude value ( = arctan(sinh(pi))
+*/
+const double OSM_MAX_LATITUDE = 85.05112877980659237802;
+const double OSM_MIN_LATITUDE = -OSM_MAX_LATITUDE;          ///< Minimum latitude value
+
+// MAP PIXELS
+/**
+* @var OMS_MAP_PIXELS_X
+* @brief Amount of horizontal pixels in map
+*/
+const int OMS_MAP_PIXELS_X = OSM_TILES_PER_SIDE * OSM_TILE_SIZE_X;
+
+const int OSM_MAP_MIN_PIXEL_X = 0;                ///< First map horizontal pixel index
+const int OSM_MAP_MIN_PIXEL_Y = 0;                ///< First map vertical pixel index
+
+const int OSM_MAP_MAX_PIXEL_X = OMS_MAP_PIXELS_X - 1; ///< Last map horizontal pixel index
+/**
+* @var OSM_MAP_MAX_PIXEL_Y
+* @brief Last map vertical pixel index
+*/
+const int OSM_MAP_MAX_PIXEL_Y = OSM_TILES_PER_SIDE * OSM_TILE_SIZE_Y - 1;
+
+#endif // OSM_H
index 1469bca..75ecd82 100644 (file)
@@ -106,7 +106,8 @@ HEADERS += application.h \
     ui/zoombuttonpanel.h \
     user/user.h \
     ui/fullscreenbutton.h \
-    engine/mce.h
+    engine/mce.h \
+    map/osm.h
 QT += network \
     webkit
 
index ab0685c..b4f7958 100644 (file)
@@ -25,6 +25,6 @@ INCLUDEPATH += . \
 HEADERS += \
     ../../../src/coordinates/geocoordinate.h \
     ../../../src/coordinates/scenecoordinate.h \
-    ../../../src/map/mapcommon.h
+    ../../../src/map/osm.h
 
 DEFINES += QT_NO_DEBUG_OUTPUT
index 0c95012..6efc36f 100644 (file)
@@ -86,14 +86,14 @@ void TestGeoCoordinate::conversion_data()
     QTest::addColumn<SceneCoordinate>("sceneCoordinate");
     QTest::addColumn<GeoCoordinate>("result");
 
-    QTest::newRow("top left") << SceneCoordinate(MAP_MIN_PIXEL_X, MAP_MIN_PIXEL_Y)
-                              << GeoCoordinate(MAX_LATITUDE, MIN_LONGITUDE);
+    QTest::newRow("top left") << SceneCoordinate(OSM_MAP_MIN_PIXEL_X, OSM_MAP_MIN_PIXEL_Y)
+                              << GeoCoordinate(OSM_MAX_LATITUDE, MIN_LONGITUDE);
 
     const double LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE = MAX_LONGITUDE
                                                          - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES;
 
-    QTest::newRow("bottom right") << SceneCoordinate(MAP_MAX_PIXEL_X, MAP_MAX_PIXEL_Y)
-                                  << GeoCoordinate(MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE);
+    QTest::newRow("bottom right") << SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y)
+                                  << GeoCoordinate(OSM_MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE);
 }
 
 void TestGeoCoordinate::isNull()
index 06a39ab..2065d3d 100644 (file)
@@ -22,7 +22,7 @@ DEFINES += SRCDIR=\\\"$$PWD/\\\"
 HEADERS += \
     ../../../src/coordinates/scenecoordinate.h \
     ../../../src/coordinates/geocoordinate.h \
-    ../../../src/map/mapcommon.h
+    ../../../src/map/osm.h
 
 INCLUDEPATH += . \
     ../../../src/
index 6767e25..2a261f8 100644 (file)
@@ -85,23 +85,23 @@ void TestSceneCoordinate::conversion_data()
     QTest::addColumn<GeoCoordinate>("geoCoordinate");
     QTest::addColumn<SceneCoordinate>("result");
 
-    QTest::newRow("top left pixel") << GeoCoordinate(MAX_LATITUDE, MIN_LONGITUDE)
+    QTest::newRow("top left pixel") << GeoCoordinate(OSM_MAX_LATITUDE, MIN_LONGITUDE)
                                     << SceneCoordinate(0, 0);
 
     const double ONE_SCENE_PIXEL_WIDTH_IN_DEGREES = 0.00000536441802978516;
     const double LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE = MAX_LONGITUDE
                                                          - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES;
     QTest::newRow("bottom right pixel")
-            << GeoCoordinate(MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE)
-            << SceneCoordinate(MAP_MAX_PIXEL_X, MAP_MAX_PIXEL_Y);
+            << GeoCoordinate(OSM_MIN_LATITUDE, LAST_SCENE_HORIZONTAL_PIXEL_LONGITUDE)
+            << SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
 
     QTest::newRow("southeast corner with 180 degrees longitude")
-            << GeoCoordinate(MIN_LATITUDE, MAX_LONGITUDE)
-            << SceneCoordinate(MAP_MIN_PIXEL_X, MAP_MAX_PIXEL_Y);
+            << GeoCoordinate(OSM_MIN_LATITUDE, MAX_LONGITUDE)
+            << SceneCoordinate(OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
 
     QTest::newRow("southeast corner just little over west edge of the map")
-            << GeoCoordinate(MIN_LATITUDE, MIN_LONGITUDE - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES)
-            << SceneCoordinate(MAP_MAX_PIXEL_X, MAP_MAX_PIXEL_Y);
+            << GeoCoordinate(OSM_MIN_LATITUDE, MIN_LONGITUDE - ONE_SCENE_PIXEL_WIDTH_IN_DEGREES)
+            << SceneCoordinate(OSM_MAP_MAX_PIXEL_X, OSM_MAP_MAX_PIXEL_Y);
 }
 
 void TestSceneCoordinate::isNull()
index 3cdb973..bad3b73 100644 (file)
@@ -68,11 +68,11 @@ void TestMapEngine::convertLatLonToSceneCoordinate_data()
     QTest::addColumn<QPointF>("coordinate");
     QTest::addColumn<QPoint>("result");
 
-    QTest::newRow("top left") << QPointF(MIN_LONGITUDE, MAX_LATITUDE) << QPoint(0, 0);
+    QTest::newRow("top left") << QPointF(MIN_LONGITUDE, OSM_MAX_LATITUDE) << QPoint(0, 0);
 
-    int x = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_X;
-    int y = (1 << MAX_MAP_ZOOM_LEVEL) * TILE_SIZE_Y;
-    QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, MIN_LATITUDE) << QPoint(x, y);
+    int x = (1 << OSM_MAX_ZOOM_LEVEL) * OSM_TILE_SIZE_X;
+    int y = (1 << OSM_MAX_ZOOM_LEVEL) * OSM_TILE_SIZE_Y;
+    QTest::newRow("bottom right") << QPointF(MAX_LONGITUDE, OSM_MIN_LATITUDE) << QPoint(x, y);
 }
 
 /**
@@ -105,7 +105,7 @@ void TestMapEngine::setLocationNewTilesCount()
 
     // move one tile to east and south, only most right one column and most bottom one row tiles
     // should be downloaded
-    emit setCenterPosition(QPoint((1220+TILE_SIZE_X)*16, (1220+TILE_SIZE_Y)*16));
+    emit setCenterPosition(QPoint((1220+OSM_TILE_SIZE_X)*16, (1220+OSM_TILE_SIZE_Y)*16));
     QTest::qWait(1000);
     QCOMPARE(fetchImageSpy.count(), 4 + 4);
     fetchImageSpy.clear();
@@ -208,7 +208,7 @@ void TestMapEngine::usingLastLocation()
     QVERIFY(parameters.at(0).toInt() == DEFAULT_TEST_ZOOMLEVEL);
 
     parameters = mapEngineSpy.takeFirst();
-    QVERIFY(parameters.at(0).toInt() == DEFAULT_START_ZOOM_LEVEL);
+    QVERIFY(parameters.at(0).toInt() == MAP_DEFAULT_ZOOM_LEVEL);
 
     // Call set location with know parameter to get location changed
     // Store new location and zoomlevel to settings
index f355b75..728c8b1 100644 (file)
@@ -1,5 +1,7 @@
 TEMPLATE = subdirs
-SUBDIRS = map/mapengine \
+SUBDIRS = coordinates/geocoordinate \
+          coordinates/scenecoordinate \
+          map/mapengine \
           map/mapview \
           map/ownlocationitem \
           map/gpslocationitem \
@@ -7,9 +9,9 @@ SUBDIRS = map/mapengine \
           map/friendgroupitem \
           map/mapscene \
           map/friendlocationitem \
-          user \
           ui/friendlist \
           ui/sidepanel \
           ui/avatarimage \
+          user \
           routing/route \
           routing/routesegment