Marble

GeoDataLatLonBox.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2007 Andrew Manson <g.real.ate@gmail.com>
4// SPDX-FileCopyrightText: 2008-2009 Torsten Rahn <rahn@kde.org>
5//
6
7#ifndef MARBLE_GEODATALATLONBOX_H
8#define MARBLE_GEODATALATLONBOX_H
9
10#include "MarbleGlobal.h"
11
12#include "GeoDataCoordinates.h"
13#include "GeoDataObject.h"
14
15#include "geodata_export.h"
16
17namespace Marble
18{
19
20class GeoDataLatLonBoxPrivate;
21
22class GeoDataLineString;
23
24/**
25 * @short A class that defines a 2D bounding box for geographic data.
26 *
27 * GeoDataLatLonBox is a 2D bounding box that describes a geographic area
28 * in terms of latitude and longitude.
29 *
30 * The bounding box gets described by assigning the northern, southern,
31 * eastern and western boundary.
32 * So usually the value of the eastern boundary is bigger than the
33 * value of the western boundary.
34 *
35 * This is also true if the GeoDataLatLonBox covers the whole longitude
36 * range from 180 deg West to 180 deg East. Notably in this case
37 * the bounding box crosses the date line.
38 *
39 * If the GeoDataLatLonBox does not cover the whole longitude range but still
40 * crosses the date line then the eastern boundary has got a smaller value than
41 * the western one.
42 */
43
44class GEODATA_EXPORT GeoDataLatLonBox : public GeoDataObject
45{
46 friend bool GEODATA_EXPORT operator==(GeoDataLatLonBox const &lhs, GeoDataLatLonBox const &rhs);
47 friend bool GEODATA_EXPORT operator!=(GeoDataLatLonBox const &lhs, GeoDataLatLonBox const &rhs);
48
49public:
51 GeoDataLatLonBox(qreal north, qreal south, qreal east, qreal west, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
53 ~GeoDataLatLonBox() override;
54
55 GeoDataLatLonBox &operator=(const GeoDataLatLonBox &other);
56
57 /// Provides type information for downcasting a GeoData
58 const char *nodeType() const override;
59
60 /**
61 * @brief Get the northern boundary of the bounding box.
62 * @return the latitude of the northern boundary.
63 */
64 qreal north(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
65 void setNorth(const qreal north, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
66
67 /**
68 * @brief Get the southern boundary of the bounding box.
69 * @return the latitude of the southern boundary.
70 */
71 qreal south(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
72 void setSouth(const qreal south, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
73
74 /**
75 * @brief Get the eastern boundary of the bounding box.
76 * @return the longitude of the eastern boundary.
77 */
78 qreal east(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
79 void setEast(const qreal east, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
80
81 /**
82 * @brief Get the western boundary of the bounding box.
83 * @return the longitude of the western boundary.
84 */
85 qreal west(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
86 void setWest(const qreal west, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
87
88 /**
89 * @brief Get the rotation of the bounding box.
90 * @return the rotation of the bounding box.
91 */
92 qreal rotation(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
93 void setRotation(const qreal rotation, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
94
95 void boundaries(qreal &north, qreal &south, qreal &east, qreal &west, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
96 void setBoundaries(qreal north, qreal south, qreal east, qreal west, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
97
98 /**
99 * @brief Changes the differences between the boundaries and the center by the given factor, keeping the center unchanged
100 * @param verticalFactor Vertical scale factor (affects north and south boundaries)
101 * @param horizontalFactor Horizontal scale factor (affects west and east boundaries)
102 */
103 void scale(qreal verticalFactor, qreal horizontalFactor) const;
104 GeoDataLatLonBox scaled(qreal verticalFactor, qreal horizontalFactor) const;
105
106 /**
107 * @brief Get the width of the longitude interval
108 * @return the angle covered by the longitude range.
109 */
110 qreal width(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
111
112 /**
113 * @brief Get the width of the longitude interval. East and west parameters are in radians.
114 * @return the angle covered by the longitude range in given unit.
115 */
116 static qreal width(qreal east, qreal west, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
117
118 /**
119 * @brief Get the height of the latitude interval
120 * @return the angle covered by the latitude range.
121 */
122 qreal height(GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian) const;
123
124 /**
125 * @brief Get the height of the latitude interval. North and south parameters are in radians.
126 * @return the angle covered by the latitude range in given unit.
127 */
128 static qreal height(qreal north, qreal south, GeoDataCoordinates::Unit unit = GeoDataCoordinates::Radian);
129
130 /**
131 * @brief Detect whether the bounding box crosses the IDL.
132 * @return @c true the bounding box crosses the +/-180 deg longitude.
133 * @c false the bounding box doesn't cross the +/-180 deg longitude.
134 */
135 bool crossesDateLine() const;
136
137 /**
138 * @brief Detect whether the bounding box crosses the IDL.
139 * @param east radians east.
140 * @param west radians west.
141 * @return @c true the bounding box crosses the +/-180 deg longitude.
142 * @c false the bounding box doesn't cross the +/-180 deg longitude.
143 */
144 static bool crossesDateLine(qreal east, qreal west);
145
146 /**
147 * @brief returns the center of this box
148 * @return a coordinate, face-center of the box
149 */
150 virtual GeoDataCoordinates center() const;
151
152 /**
153 * @brief Detect whether the bounding box contains one of the poles.
154 * @return @c true the bounding box contains one of the poles.
155 * @c false the bounding box doesn't contain one of the poles.
156 */
157 bool containsPole(Pole pole = AnyPole) const;
158
159 virtual bool contains(const GeoDataCoordinates &) const;
160 bool contains(const GeoDataLatLonBox &) const;
161
162 /**
163 * @brief Detect whether the bounding box contains a point of given lon and lat.
164 * @param lon longitude in radians.
165 * @param lat latitude in radians.
166 * @return true if the box contains given point, false otherwise
167 */
168 bool contains(qreal lon, qreal lat) const; // Optimized version for overlay painting
169
170 virtual bool intersects(const GeoDataLatLonBox &) const;
171
172 /**
173 * @brief Returns the bounding LatLonBox of this box with the given one.
174 */
175 GeoDataLatLonBox united(const GeoDataLatLonBox &other) const;
176
177 /**
178 * @return Returns the smallest bounding box that contains this LatLonBox rotated with its given angle.
179 */
180 GeoDataLatLonBox toCircumscribedRectangle() const;
181
182 /**
183 * @brief Create the smallest bounding box from a line string.
184 * @return the smallest bounding box that contains the linestring.
185 */
186 static GeoDataLatLonBox fromLineString(const GeoDataLineString &lineString);
187
188 /**
189 * @brief Indicates whether the bounding box only contains a single 2D point ("singularity").
190 * @return Return value is true if the height and the width of the bounding box equal zero.
191 */
192 virtual bool isNull() const;
193
194 /**
195 * @brief Indicates whether the bounding box is not initialised (and contains nothing).
196 * @return Return value is true if bounding box is not initialised.
197 */
198 virtual bool isEmpty() const;
199
200 /**
201 * @brief Indicates whether two bounding boxes are roughly equal.
202 * The factor specifies the margin threshold relative to the left handside
203 * bounding box within which both bounding boxes are considered equal.
204 * @return Return value is true if both bounding box are approximately equal.
205 */
206 static bool fuzzyCompare(const GeoDataLatLonBox &lhs, const GeoDataLatLonBox &rhs, const qreal factor = 0.01);
207
208 /**
209 * @brief Resets the bounding box to its uninitialised state (and thus contains nothing).
210 */
211 virtual void clear();
212
213 GeoDataLatLonBox operator|(const GeoDataLatLonBox &other) const;
214
215 /**
216 * @brief Unites this bounding box with the given one.
217 * @return Returns a reference to self.
218 */
219 GeoDataLatLonBox &operator|=(const GeoDataLatLonBox &other);
220
221 /// Serialize the contents of the feature to @p stream.
222 void pack(QDataStream &stream) const override;
223 /// Unserialize the contents of the feature from @p stream.
224 void unpack(QDataStream &stream) override;
225
226private:
227 GeoDataLatLonBoxPrivate *const d;
228 static const GeoDataLatLonBox empty;
229};
230
231}
232
233Q_DECLARE_METATYPE(Marble::GeoDataLatLonBox)
234
235#endif
A 3d point representation.
Unit
enum used constructor to specify the units used
A class that defines a 2D bounding box for geographic data.
A LineString that allows to store a contiguous set of line segments.
A base class for all geodata objects.
Binds a QML item to a specific geodetic location in screen coordinates.
@ AnyPole
Any pole.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:04:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.