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,
26 #include "geocoordinate.h"
29 #include "scenecoordinate.h"
31 SceneCoordinate::SceneCoordinate() :
35 qDebug() << __PRETTY_FUNCTION__;
38 SceneCoordinate::SceneCoordinate(double x, double y) :
42 qDebug() << __PRETTY_FUNCTION__;
45 SceneCoordinate::SceneCoordinate(GeoCoordinate &coordinate)
47 qDebug() << __PRETTY_FUNCTION__;
49 convertFrom(coordinate);
52 void SceneCoordinate::convertFrom(const GeoCoordinate &coordinate)
54 qDebug() << __PRETTY_FUNCTION__;
56 // calculate x & y positions in the map (0..1)
57 double worldX = static_cast<double>((coordinate.longitude() + 180.0) / 360.0);
58 double worldY = static_cast<double>((1.0 - log(tan(coordinate.latitude() * M_PI / 180.0) + 1.0
59 / cos(coordinate.latitude() * M_PI / 180.0)) / M_PI) / 2.0);
61 m_x = worldX * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_X;
62 m_y = worldY * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_Y;
64 normalize(m_x, OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X);
67 bool SceneCoordinate::isNull() const
69 qDebug() << __PRETTY_FUNCTION__;
71 if (m_x == 0 && m_y == 0)
77 void SceneCoordinate::normalize(double &value, int min, int max)
79 qDebug() << __PRETTY_FUNCTION__;
80 Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
82 while (int(value) < min)
83 value += max - min + 1;
85 while (int(value) > max)
86 value -= max - min + 1;
89 double SceneCoordinate::x() const
91 qDebug() << __PRETTY_FUNCTION__;
96 double SceneCoordinate::y() const
98 qDebug() << __PRETTY_FUNCTION__;
103 void SceneCoordinate::setX(double x)
105 qDebug() << __PRETTY_FUNCTION__;
110 void SceneCoordinate::setY(double y)
112 qDebug() << __PRETTY_FUNCTION__;
117 QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate)
119 dbg.nospace() << "(" << coordinate.x() << ", " << coordinate.y() << ")";