libosmscout
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
libosmscout
include
osmscout
util
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
23
#include <
osmscout/lib/CoreImportExport.h
>
24
25
#include <
osmscout/GeoCoord.h
>
26
27
#include <
osmscout/system/Compiler.h
>
28
#include <
osmscout/util/Distance.h
>
29
30
namespace
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
78
void
Invalidate
()
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
190
GeoCoord
GetMinCoord
()
const
191
{
192
return
minCoord;
193
}
194
198
GeoCoord
GetMaxCoord
()
const
199
{
200
return
maxCoord;
201
}
202
203
GeoCoord
GetCenter
()
const
;
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
266
GeoCoord
GetBottomLeft
()
const
267
{
268
return
minCoord;
269
}
270
274
GeoCoord
GetBottomRight
()
const
275
{
276
return
GeoCoord
(minCoord.GetLat(),
277
maxCoord.GetLon());
278
}
279
283
GeoCoord
GetTopLeft
()
const
284
{
285
return
GeoCoord
(maxCoord.GetLat(),
286
minCoord.GetLon());
287
}
288
292
GeoCoord
GetTopRight
()
const
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
Compiler.h
CoreImportExport.h
OSMSCOUT_API
#define OSMSCOUT_API
Definition
CoreImportExport.h:45
Distance.h
GeoCoord.h
osmscout::CLASS_FINAL
Definition
Area.h:88
osmscout::CLASS_FINAL::GetWidth
double GetWidth() const
Definition
GeoBox.h:240
osmscout::CLASS_FINAL::GetHeight
double GetHeight() const
Definition
GeoBox.h:248
osmscout::CLASS_FINAL::coord
const GeoCoord coord
Definition
RouteStateAgent.h:49
osmscout::CLASS_FINAL::GetMaxCoord
GeoCoord GetMaxCoord() const
Definition
GeoBox.h:198
osmscout::CLASS_FINAL::GetMinCoord
GeoCoord GetMinCoord() const
Definition
GeoBox.h:190
osmscout::CLASS_FINAL::GetBottomLeft
GeoCoord GetBottomLeft() const
Definition
GeoBox.h:266
osmscout::CLASS_FINAL::GetBottomRight
GeoCoord GetBottomRight() const
Definition
GeoBox.h:274
osmscout::CLASS_FINAL::GetMaxLon
double GetMaxLon() const
Definition
GeoBox.h:232
osmscout::CLASS_FINAL::GetMaxLat
double GetMaxLat() const
Definition
GeoBox.h:224
osmscout::CLASS_FINAL::operator=
GeoBox & operator=(const GeoBox &other)=default
osmscout::CLASS_FINAL::CropTo
GeoBox CropTo(const GeoBox &other) const
osmscout::CLASS_FINAL::GetMinLon
double GetMinLon() const
Definition
GeoBox.h:216
osmscout::CLASS_FINAL::operator==
bool operator==(const GeoBox &other) const
Definition
GeoBox.h:65
osmscout::CLASS_FINAL::GetCenter
GeoCoord GetCenter() const
osmscout::CLASS_FINAL::GetTopRight
GeoCoord GetTopRight() const
Definition
GeoBox.h:292
osmscout::CLASS_FINAL::GeoBox
GeoBox(const GeoBox &other)=default
osmscout::CLASS_FINAL::Includes
bool Includes(const P &coord, bool openInterval=true) const
Definition
GeoBox.h:113
osmscout::CLASS_FINAL::IsValid
bool IsValid() const
Definition
GeoBox.h:182
osmscout::CLASS_FINAL::GeoBox
GeoBox()=default
osmscout::CLASS_FINAL::Invalidate
void Invalidate()
Definition
GeoBox.h:78
osmscout::CLASS_FINAL::Include
void Include(const GeoBox &other)
osmscout::CLASS_FINAL::GeoCoord
GeoCoord()=default
osmscout::CLASS_FINAL::operator!=
bool operator!=(const GeoBox &other) const
Definition
GeoBox.h:70
osmscout::CLASS_FINAL::Intersects
bool Intersects(const GeoBox &other, bool openInterval=true) const
Definition
GeoBox.h:144
osmscout::CLASS_FINAL::GetMinLat
double GetMinLat() const
Definition
GeoBox.h:208
osmscout::CLASS_FINAL::Intersection
GeoBox Intersection(const GeoBox &other) const
osmscout::CLASS_FINAL::Include
void Include(const GeoCoord &point)
osmscout::CLASS_FINAL::GetTopLeft
GeoCoord GetTopLeft() const
Definition
GeoBox.h:283
osmscout::CLASS_FINAL::GetSize
double GetSize() const
Definition
GeoBox.h:258
osmscout::CLASS_FINAL::BoxByCenterAndRadius
static GeoBox BoxByCenterAndRadius(const GeoCoord ¢er, const Distance &radius)
osmscout::CLASS_FINAL::GetDisplayText
std::string GetDisplayText() const
osmscout::CLASS_FINAL::Set
void Set(const GeoCoord &coordA, const GeoCoord &coordB)
osmscout::CLASS_FINAL::GeoBox
GeoBox(const GeoCoord &coordA, const GeoCoord &coordB)
osmscout
Definition
Area.h:39
Generated by
1.17.0