2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #include "geocoordinate.h"
25 #include "map/mapcommon.h"
27 #include "scenecoordinate.h"
29 SceneCoordinate::SceneCoordinate() :
33 qDebug() << __PRETTY_FUNCTION__;
36 SceneCoordinate::SceneCoordinate(double x, double y) :
40 qDebug() << __PRETTY_FUNCTION__;
43 SceneCoordinate::SceneCoordinate(GeoCoordinate &coordinate)
45 qDebug() << __PRETTY_FUNCTION__;
47 convertFrom(coordinate);
50 void SceneCoordinate::convertFrom(const GeoCoordinate &coordinate)
52 qDebug() << __PRETTY_FUNCTION__;
54 // calculate x & y positions in the map (0..1)
55 double worldX = static_cast<double>((coordinate.longitude() + 180.0) / 360.0);
56 double worldY = static_cast<double>((1.0 - log(tan(coordinate.latitude() * M_PI / 180.0) + 1.0
57 / cos(coordinate.latitude() * M_PI / 180.0)) / M_PI) / 2.0);
59 m_x = worldX * MAX_TILES_PER_SIDE * TILE_SIZE_X;
60 m_y = worldY * MAX_TILES_PER_SIDE * TILE_SIZE_Y;
62 normalize(m_x, MAP_MIN_PIXEL_X, MAP_MAX_PIXEL_X);
65 bool SceneCoordinate::isNull() const
67 qDebug() << __PRETTY_FUNCTION__;
69 if (m_x == 0 && m_y == 0)
75 void SceneCoordinate::normalize(double &value, int min, int max)
77 qDebug() << __PRETTY_FUNCTION__;
78 Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
80 while (int(value) < min)
81 value += max - min + 1;
83 while (int(value) > max)
84 value -= max - min + 1;
87 double SceneCoordinate::x() const
89 qDebug() << __PRETTY_FUNCTION__;
94 double SceneCoordinate::y() const
96 qDebug() << __PRETTY_FUNCTION__;
101 void SceneCoordinate::setX(double x)
103 qDebug() << __PRETTY_FUNCTION__;
108 void SceneCoordinate::setY(double y)
110 qDebug() << __PRETTY_FUNCTION__;
115 QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate)
117 dbg.nospace() << "(" << coordinate.x() << ", " << coordinate.y() << ")";