Marble

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

KDE's Doxygen guidelines are available online.