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,
23 #ifndef SCENECOORDINATE_H
24 #define SCENECOORDINATE_H
32 * @brief Scene coordinate
34 * @author Sami Rämö - sami.ramo@ixonos.com
40 * @brief Constructs a null coordinate
45 * @brief Constructs a coordinate with given x and y
50 SceneCoordinate(double x, double y);
53 * @brief Constructs a coordinate with values converted from the given GeoCoordinate
55 * Uses convertFrom() method.
57 * @param coordinate Geological coordinate
59 SceneCoordinate(const GeoCoordinate &coordinate);
61 /*******************************************************************************
62 * MEMBER FUNCTIONS AND SLOTS
63 ******************************************************************************/
66 * @brief Returns the azimuth from this coordinate to other coordinate
68 * @param to Target coordinate
69 * @returns Azimuth in degrees
71 qreal azimuthTo(const SceneCoordinate &to) const;
74 * @brief Check if coordinate is (0.0, 0.0)
76 * @returns True if both X and Y are 0.0, otherwise false
81 * @brief Sets the latitude
88 * @brief Sets the longitude
95 * @brief Convert to QPointF
97 * @returns a QPointF object
99 QPointF toPointF() const;
102 * @brief Returns the x value
109 * @brief Returns the y value
117 * @brief Convert values from GeoCoordinate
119 * Does run normalize() for the x value after the conversion to make sure that the result
120 * is inside the allowed map pixel values.
122 * In horizontal direction:
123 * -180º equals scene pixel 0 (first scene pixel)
126 * scene has 2^18 * 256 - 1 = 67108864 pixels per side
127 * one pixel width is 360º / 67108864 = 0.00000536441802978516º
128 * so the last scene pixel is 180º - 0.00000536441802978516º = 179.99999463558197021484º
130 * @param coordinate Geological coordinate
132 void convertFrom(const GeoCoordinate &coordinate);
135 * @brief Translate integer part of the given value between min and max
137 * If given value is not inside the given range (min <= value <= max), then the allowed range
138 * is adder or subtracted until the value does fit in the range. Only integer part is compared.
140 * @param value Value to be normalized
141 * @param min Minimum allowed value
142 * @param max Maximum allowed value
144 void normalize(double &value, int min, int max);
146 /*******************************************************************************
148 ******************************************************************************/
150 double m_x; ///< X value
151 double m_y; ///< Y value
153 /*******************************************************************************
155 ******************************************************************************/
158 * @brief Operator for creating QVariant
160 operator QVariant() const;
163 * @brief Multiplies this coordinate's values by the given factor, and returns a reference
164 * to this coordinate.
166 SceneCoordinate & operator*=(double factor);
169 * @brief Adds the given coordinate to this coordinate and returns a reference to this
172 SceneCoordinate & operator+=(const SceneCoordinate &coordinate);
175 * @brief Subtracts the given coordinate from this coordinate and returns a reference to this
178 SceneCoordinate & operator-=(const SceneCoordinate &coordinate);
181 * @brief Returns a SceneCoordinate object that is the sum of the coordinates.
183 const SceneCoordinate operator+(const SceneCoordinate &other) const;
186 * @brief Returns a SceneCoordinate object that is formed by subtracting the coordinates.
188 const SceneCoordinate operator-(const SceneCoordinate &other) const;
192 * @brief Operator for writing the coordinate to QDebug stream.
194 QDebug operator<<(QDebug dbg, const SceneCoordinate &coordinate);
197 * @brief Returns a SceneCoordinate object that is multiplied by the given factor.
199 const SceneCoordinate operator*(double factor, const SceneCoordinate &coordinate);
201 Q_DECLARE_METATYPE(SceneCoordinate)
203 #endif // SCENECOORDINATE_H