libosmscout 1.1.1
Loading...
Searching...
No Matches
GeoBox.h
Go to the documentation of this file.
1#ifndef OSMSCOUT_UTIL_GEOBOX_H
2#define OSMSCOUT_UTIL_GEOBOX_H
3
4/*
5 This source is part of the libosmscout library
6 Copyright (C) 2015 Tim Teulings
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*/
22
24
25#include <osmscout/GeoCoord.h>
26
29
30namespace osmscout {
31
40 class OSMSCOUT_API GeoBox CLASS_FINAL
41 {
42 private:
43 GeoCoord minCoord=GeoCoord(0.0,0.0);
44 GeoCoord maxCoord=GeoCoord(0.0,0.0);
45 bool valid=false;
46
47 public:
51 GeoBox() = default;
52
56 GeoBox(const GeoBox& other) = default;
57
62 GeoBox(const GeoCoord& coordA,
63 const GeoCoord& coordB);
64
65 bool operator==(const GeoBox& other) const {
66 return GetMinCoord()==other.GetMinCoord() &&
67 GetMaxCoord()== other.GetMaxCoord();
68 }
69
70 bool operator!=(const GeoBox& other) const {
71 return GetMinCoord()!=other.GetMinCoord() ||
72 GetMaxCoord()!= other.GetMaxCoord();
73 }
74
79 {
80 valid=false;
81 minCoord.Set(0.0,0.0);
82 maxCoord.Set(0.0,0.0);
83 }
84
88 void Set(const GeoCoord& coordA,
89 const GeoCoord& coordB);
90
94 void Include(const GeoBox& other);
95
99 void Include(const GeoCoord& point);
100
112 template<typename P>
113 bool Includes(const P& coord,
114 bool openInterval=true) const
115 {
116 if (!valid){
117 return false;
118 }
119
120 if (openInterval) {
121 return minCoord.GetLat()<=coord.GetLat() &&
122 maxCoord.GetLat()>coord.GetLat() &&
123 minCoord.GetLon()<=coord.GetLon() &&
124 maxCoord.GetLon()>coord.GetLon();
125 }
126
127 return minCoord.GetLat()<=coord.GetLat() &&
128 maxCoord.GetLat()>=coord.GetLat() &&
129 minCoord.GetLon()<=coord.GetLon() &&
130 maxCoord.GetLon()>=coord.GetLon();
131 }
132
144 bool Intersects(const GeoBox& other,
145 bool openInterval=true) const
146 {
147 if (!valid || !other.valid) {
148 return false;
149 }
150
151 if (openInterval) {
152 return !(other.GetMaxLon()<minCoord.GetLon() ||
153 other.GetMinLon()>=maxCoord.GetLon() ||
154 other.GetMaxLat()<minCoord.GetLat() ||
155 other.GetMinLat()>=maxCoord.GetLat());
156 }
157
158 return !(other.GetMaxLon()<minCoord.GetLon() ||
159 other.GetMinLon()>maxCoord.GetLon() ||
160 other.GetMaxLat()<minCoord.GetLat() ||
161 other.GetMinLat()>maxCoord.GetLat());
162 }
163
169 GeoBox Intersection(const GeoBox& other) const;
170
175 GeoBox CropTo(const GeoBox& other) const;
176
182 bool IsValid() const
183 {
184 return valid;
185 }
186
191 {
192 return minCoord;
193 }
194
199 {
200 return maxCoord;
201 }
202
204
208 double GetMinLat() const
209 {
210 return minCoord.GetLat();
211 }
212
216 double GetMinLon() const
217 {
218 return minCoord.GetLon();
219 }
220
224 double GetMaxLat() const
225 {
226 return maxCoord.GetLat();
227 }
228
232 double GetMaxLon() const
233 {
234 return maxCoord.GetLon();
235 }
236
240 double GetWidth() const
241 {
242 return maxCoord.GetLon()-minCoord.GetLon();
243 }
244
248 double GetHeight() const
249 {
250 return maxCoord.GetLat()-minCoord.GetLat();
251 }
252
258 double GetSize() const
259 {
260 return GetWidth()*GetHeight();
261 }
262
267 {
268 return minCoord;
269 }
270
275 {
276 return GeoCoord(minCoord.GetLat(),
277 maxCoord.GetLon());
278 }
279
284 {
285 return GeoCoord(maxCoord.GetLat(),
286 minCoord.GetLon());
287 }
288
293 {
294 return maxCoord;
295 }
296
300 std::string GetDisplayText() const;
301
305 GeoBox& operator=(const GeoBox& other) = default;
306
311 static GeoBox BoxByCenterAndRadius(const GeoCoord& center,const Distance& radius);
312 };
313}
314
315#endif
#define OSMSCOUT_API
Definition CoreImportExport.h:45
Definition Area.h:88
double GetWidth() const
Definition GeoBox.h:240
double GetHeight() const
Definition GeoBox.h:248
const GeoCoord coord
Definition RouteStateAgent.h:49
GeoCoord GetMaxCoord() const
Definition GeoBox.h:198
GeoCoord GetMinCoord() const
Definition GeoBox.h:190
GeoCoord GetBottomLeft() const
Definition GeoBox.h:266
GeoCoord GetBottomRight() const
Definition GeoBox.h:274
double GetMaxLon() const
Definition GeoBox.h:232
double GetMaxLat() const
Definition GeoBox.h:224
GeoBox & operator=(const GeoBox &other)=default
GeoBox CropTo(const GeoBox &other) const
double GetMinLon() const
Definition GeoBox.h:216
bool operator==(const GeoBox &other) const
Definition GeoBox.h:65
GeoCoord GetCenter() const
GeoCoord GetTopRight() const
Definition GeoBox.h:292
GeoBox(const GeoBox &other)=default
bool Includes(const P &coord, bool openInterval=true) const
Definition GeoBox.h:113
bool IsValid() const
Definition GeoBox.h:182
void Invalidate()
Definition GeoBox.h:78
void Include(const GeoBox &other)
bool operator!=(const GeoBox &other) const
Definition GeoBox.h:70
bool Intersects(const GeoBox &other, bool openInterval=true) const
Definition GeoBox.h:144
double GetMinLat() const
Definition GeoBox.h:208
GeoBox Intersection(const GeoBox &other) const
void Include(const GeoCoord &point)
GeoCoord GetTopLeft() const
Definition GeoBox.h:283
double GetSize() const
Definition GeoBox.h:258
static GeoBox BoxByCenterAndRadius(const GeoCoord &center, const Distance &radius)
std::string GetDisplayText() const
void Set(const GeoCoord &coordA, const GeoCoord &coordB)
GeoBox(const GeoCoord &coordA, const GeoCoord &coordB)
Definition Area.h:39