dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
rectlatlng.h
Go to the documentation of this file.
1 
13 /*
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
23 *
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, see <http://www.gnu.org/licenses/>
26 */
27 #ifndef RECTLATLNG_H
28 #define RECTLATLNG_H
29 
30 //#include "pointlatlng.h"
31 #include "../internals/pointlatlng.h"
32 #include "math.h"
33 #include <QString>
34 #include "sizelatlng.h"
35 
36 namespace internals {
37 struct RectLatLng
38 {
39 public:
40  static RectLatLng Empty;
41  friend uint qHash(RectLatLng const& rect);
42  friend bool operator==(RectLatLng const& left,RectLatLng const& right);
43  friend bool operator!=(RectLatLng const& left,RectLatLng const& right);
44  RectLatLng(double const& lat, double const& lng, double const& widthLng, double const& heightLat)
45  {
46  this->lng = lng;
47  this->lat = lat;
48  this->widthLng = widthLng;
49  this->heightLat = heightLat;
50  isempty=false;
51  }
52  RectLatLng(PointLatLng const& location, SizeLatLng const& size)
53  {
54  this->lng = location.Lng();
55  this->lat = location.Lat();
56  this->widthLng = size.WidthLng();
57  this->heightLat = size.HeightLat();
58  isempty=false;
59  }
61  {
62  this->lng = 0;
63  this->lat = 0;
64  this->widthLng = 0;
65  this->heightLat = 0;
66  isempty=true;
67  }
68 
69  static RectLatLng FromLTRB(double const& lng, double const& lat, double const& rightLng, double const& bottomLat)
70  {
71  return RectLatLng(lat, lng, rightLng - lng, lat - bottomLat);
72  }
74  {
75  return PointLatLng(this->lat, this->lng);
76  }
77  void SetLocationTopLeft(PointLatLng const& value)
78  {
79  this->lng = value.Lng();
80  this->lat = value.Lat();
81  isempty=false;
82  }
84  {
85 
86  PointLatLng ret = PointLatLng(this->lat, this->lng);
87  ret.Offset(HeightLat(), WidthLng());
88  return ret;
89  }
91  {
92  return SizeLatLng(this->HeightLat(), this->WidthLng());
93  }
94  void SetSize(SizeLatLng const& value)
95  {
96  this->widthLng = value.WidthLng();
97  this->heightLat = value.HeightLat();
98  isempty=false;
99  }
100  double Lng()const
101  {
102  return this->lng;
103  }
104  void SetLng(double const& value)
105  {
106  this->lng = value;
107  isempty=false;
108  }
109 
110 
111  double Lat()const
112  {
113  return this->lat;
114  }
115  void SetLat(double const& value)
116  {
117  this->lat = value;
118  isempty=false;
119  }
120 
121  double WidthLng()const
122  {
123  return this->widthLng;
124  }
125  void SetWidthLng(double const& value)
126  {
127  this->widthLng = value;
128  isempty=false;
129  }
130  double HeightLat()const
131  {
132  return this->heightLat;
133  }
134  void SetHeightLat(double const& value)
135  {
136  this->heightLat = value;
137  isempty=false;
138  }
139  double Left()const
140  {
141  return this->Lng();
142  }
143 
144  double Top()const
145  {
146  return this->Lat();
147  }
148 
149  double Right()const
150  {
151  return (this->Lng() + this->WidthLng());
152  }
153 
154  double Bottom()const
155  {
156  return (this->Lat() - this->HeightLat());
157  }
158  bool IsEmpty()const
159  {
160  return isempty;
161  }
162  bool Contains(double const& lat, double const& lng)
163  {
164  return ((((this->Lng() <= lng) && (lng < (this->Lng() + this->WidthLng()))) && (this->Lat() >= lat)) && (lat > (this->Lat() - this->HeightLat())));
165  }
166 
167  bool Contains(PointLatLng const& pt)
168  {
169  return this->Contains(pt.Lat(), pt.Lng());
170  }
171 
172  bool Contains(RectLatLng const& rect)
173  {
174  return ((((this->Lng() <= rect.Lng()) && ((rect.Lng() + rect.WidthLng()) <= (this->Lng() + this->WidthLng()))) && (this->Lat() >= rect.Lat())) && ((rect.Lat() - rect.HeightLat()) >= (this->Lat() - this->HeightLat())));
175  }
176  void Inflate(double const& lat, double const& lng)
177  {
178  this->lng -= lng;
179  this->lat += lat;
180  this->widthLng += (double)2 * lng;
181  this->heightLat +=(double)2 * lat;
182  }
183 
184  void Inflate(SizeLatLng const& size)
185  {
186  this->Inflate(size.HeightLat(), size.WidthLng());
187  }
188 
189  static RectLatLng Inflate(RectLatLng const& rect, double const& lat, double const& lng)
190  {
191  RectLatLng ef = rect;
192  ef.Inflate(lat, lng);
193  return ef;
194  }
195 
196  void Intersect(RectLatLng const& rect)
197  {
198  RectLatLng ef = Intersect(rect, *this);
199  this->lng = ef.Lng();
200  this->lat = ef.Lat();
201  this->widthLng = ef.WidthLng();
202  this->heightLat = ef.HeightLat();
203  }
204  static RectLatLng Intersect(RectLatLng const& a, RectLatLng const& b)
205  {
206  double lng = std::max(a.Lng(), b.Lng());
207  double num2 = std::min((double) (a.Lng() + a.WidthLng()), (double) (b.Lng() + b.WidthLng()));
208 
209  double lat = std::max(a.Lat(), b.Lat());
210  double num4 = std::min((double) (a.Lat() + a.HeightLat()), (double) (b.Lat() + b.HeightLat()));
211 
212  if((num2 >= lng) && (num4 >= lat))
213  {
214  return RectLatLng(lng, lat, num2 - lng, num4 - lat);
215  }
216  return Empty;
217  }
218  bool IntersectsWith(RectLatLng const& rect)
219  {
220  return ((((rect.Lng() < (this->Lng() + this->WidthLng())) && (this->Lng() < (rect.Lng() + rect.WidthLng()))) && (rect.Lat() < (this->Lat() + this->HeightLat()))) && (this->Lat() < (rect.Lat() + rect.HeightLat())));
221  }
222 
223  static RectLatLng Union(RectLatLng const& a, RectLatLng const& b)
224  {
225  double lng = std::min(a.Lng(), b.Lng());
226  double num2 = std::max((double) (a.Lng() + a.WidthLng()), (double) (b.Lng() + b.WidthLng()));
227  double lat = std::min(a.Lat(), b.Lat());
228  double num4 = std::max((double) (a.Lat() + a.HeightLat()), (double) (b.Lat() + b.HeightLat()));
229  return RectLatLng(lng, lat, num2 - lng, num4 - lat);
230  }
231  void Offset(PointLatLng const& pos)
232  {
233  this->Offset(pos.Lat(), pos.Lng());
234  }
235 
236  void Offset(double const& lat, double const& lng)
237  {
238  this->lng += lng;
239  this->lat -= lat;
240  }
241 
242  QString ToString() const
243  {
244  return ("{Lat=" + QString::number(this->Lat()) + ",Lng=" + QString::number(this->Lng()) + ",WidthLng=" + QString::number(this->WidthLng()) + ",HeightLat=" + QString::number(this->HeightLat()) + "}");
245  }
246 
247 private:
248  double lng;
249  double lat;
250  double widthLng;
251  double heightLat;
252  bool isempty;
253 };
254 
255 }
256 #endif // RECTLATLNG_H
257 
258 
259 
260 // static RectLatLng()
261 // {
262 // Empty = new RectLatLng();
263 // }
264 // }
double HeightLat() const
Definition: rectlatlng.h:130
void Inflate(SizeLatLng const &size)
Definition: rectlatlng.h:184
void SetLat(double const &value)
Definition: rectlatlng.h:115
QString ToString() const
Definition: rectlatlng.h:242
static RectLatLng Inflate(RectLatLng const &rect, double const &lat, double const &lng)
Definition: rectlatlng.h:189
static RectLatLng Union(RectLatLng const &a, RectLatLng const &b)
Definition: rectlatlng.h:223
void SetSize(SizeLatLng const &value)
Definition: rectlatlng.h:94
bool Contains(RectLatLng const &rect)
Definition: rectlatlng.h:172
void SetLocationTopLeft(PointLatLng const &value)
Definition: rectlatlng.h:77
double HeightLat() const
Definition: sizelatlng.h:84
void SetLng(double const &value)
Definition: rectlatlng.h:104
static RectLatLng Intersect(RectLatLng const &a, RectLatLng const &b)
Definition: rectlatlng.h:204
SizeLatLng Size()
Definition: rectlatlng.h:90
void Offset(PointLatLng const &pos)
Definition: pointlatlng.h:97
bool Contains(double const &lat, double const &lng)
Definition: rectlatlng.h:162
static RectLatLng FromLTRB(double const &lng, double const &lat, double const &rightLng, double const &bottomLat)
Definition: rectlatlng.h:69
double Lat() const
Definition: rectlatlng.h:111
friend bool operator!=(RectLatLng const &left, RectLatLng const &right)
Definition: rectlatlng.cpp:43
end a
Definition: OPPlots.m:98
bool Contains(PointLatLng const &pt)
Definition: rectlatlng.h:167
double Lng() const
Definition: pointlatlng.h:76
double Lat() const
Definition: pointlatlng.h:64
void Offset(PointLatLng const &pos)
Definition: rectlatlng.h:231
double Bottom() const
Definition: rectlatlng.h:154
double Left() const
Definition: rectlatlng.h:139
RectLatLng(double const &lat, double const &lng, double const &widthLng, double const &heightLat)
Definition: rectlatlng.h:44
double Top() const
Definition: rectlatlng.h:144
void Inflate(double const &lat, double const &lng)
Definition: rectlatlng.h:176
double Right() const
Definition: rectlatlng.h:149
void SetHeightLat(double const &value)
Definition: rectlatlng.h:134
friend bool operator==(RectLatLng const &left, RectLatLng const &right)
Definition: rectlatlng.cpp:38
double WidthLng() const
Definition: rectlatlng.h:121
double WidthLng() const
Definition: sizelatlng.h:74
bool IntersectsWith(RectLatLng const &rect)
Definition: rectlatlng.h:218
bool IsEmpty() const
Definition: rectlatlng.h:158
void Intersect(RectLatLng const &rect)
Definition: rectlatlng.h:196
PointLatLng LocationTopLeft() const
Definition: rectlatlng.h:73
static RectLatLng Empty
Definition: rectlatlng.h:40
void SetWidthLng(double const &value)
Definition: rectlatlng.h:125
double Lng() const
Definition: rectlatlng.h:100
RectLatLng(PointLatLng const &location, SizeLatLng const &size)
Definition: rectlatlng.h:52
friend uint qHash(RectLatLng const &rect)
Definition: rectlatlng.cpp:33
void Offset(double const &lat, double const &lng)
Definition: rectlatlng.h:236
PointLatLng LocationRightBottom()
Definition: rectlatlng.h:83