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,
29 #include "geocoordinate.h"
32 #include "scenecoordinate.h"
34 SceneCoordinate::SceneCoordinate() :
38 qDebug() << __PRETTY_FUNCTION__;
41 SceneCoordinate::SceneCoordinate(double x, double y) :
45 qDebug() << __PRETTY_FUNCTION__;
48 SceneCoordinate::SceneCoordinate(const GeoCoordinate &coordinate)
50 qDebug() << __PRETTY_FUNCTION__;
52 convertFrom(coordinate);
55 qreal SceneCoordinate::azimuthTo(const SceneCoordinate &to) const
57 QLineF line = QLineF(this->toPointF(), to.toPointF());
58 return -line.angle() + 90.0;
61 void SceneCoordinate::convertFrom(const GeoCoordinate &coordinate)
63 qDebug() << __PRETTY_FUNCTION__;
65 // calculate x & y positions in the map (0..1)
66 double worldX = static_cast<double>((coordinate.longitude() + 180.0) / 360.0);
67 double worldY = static_cast<double>((1.0 - log(tan(coordinate.latitude() * M_PI / 180.0) + 1.0
68 / cos(coordinate.latitude() * M_PI / 180.0)) / M_PI) / 2.0);
70 m_x = worldX * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_X;
71 m_y = worldY * OSM_TILES_PER_SIDE * OSM_TILE_SIZE_Y;
73 normalize(m_x, OSM_MAP_MIN_PIXEL_X, OSM_MAP_MAX_PIXEL_X);
76 bool SceneCoordinate::isNull() const
78 qDebug() << __PRETTY_FUNCTION__;
80 if (m_x == 0 && m_y == 0)
86 void SceneCoordinate::normalize(double &value, int min, int max)
88 qDebug() << __PRETTY_FUNCTION__;
89 Q_ASSERT_X(max >= min, "parameters", "max can't be smaller than min");
91 while (int(value) < min)
92 value += max - min + 1;
94 while (int(value) > max)
95 value -= max - min + 1;
98 void SceneCoordinate::setX(double x)
100 qDebug() << __PRETTY_FUNCTION__;
105 void SceneCoordinate::setY(double y)
107 qDebug() << __PRETTY_FUNCTION__;
112 QPointF SceneCoordinate::toPointF() const
114 qDebug() << __PRETTY_FUNCTION__;
116 return QPointF(m_x, m_y);
119 double SceneCoordinate::x() const
121 qDebug() << __PRETTY_FUNCTION__;
126 double SceneCoordinate::y() const
128 qDebug() << __PRETTY_FUNCTION__;
133 SceneCoordinate::operator QVariant() const
135 return QVariant::fromValue(*this);
138 QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate)
140 dbg.nospace() << "(" << coordinate.x() << ", " << coordinate.y() << ")";
145 SceneCoordinate & SceneCoordinate::operator*=(double factor)
152 SceneCoordinate & SceneCoordinate::operator+=(const SceneCoordinate &coordinate)
154 m_x += coordinate.x();
155 m_y += coordinate.y();
159 SceneCoordinate & SceneCoordinate::operator-=(const SceneCoordinate &coordinate)
161 m_x -= coordinate.x();
162 m_y -= coordinate.y();
166 const SceneCoordinate operator* (double factor, const SceneCoordinate &coordinate)
168 return SceneCoordinate(coordinate) *= factor;
171 const SceneCoordinate SceneCoordinate::operator+(const SceneCoordinate &other) const
173 return SceneCoordinate(*this) += other;
176 const SceneCoordinate SceneCoordinate::operator-(const SceneCoordinate &other) const
178 return SceneCoordinate(*this) -= other;