-
Notifications
You must be signed in to change notification settings - Fork 523
Expand file tree
/
Copy pathcodearea.cc
More file actions
51 lines (38 loc) · 1.58 KB
/
codearea.cc
File metadata and controls
51 lines (38 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "codearea.h"
#include <algorithm>
namespace openlocationcode {
namespace {
const double kLatitudeMaxDegrees = 90;
const double kLongitudeMaxDegrees = 180;
const CodeArea kInvalidCodeArea(0.0, 0.0, 0.0, 0.0, 0);
} // anonymous namespace
CodeArea::CodeArea(double latitude_lo, double longitude_lo, double latitude_hi,
double longitude_hi, size_t code_length) {
latitude_lo_ = latitude_lo;
longitude_lo_ = longitude_lo;
latitude_hi_ = latitude_hi;
longitude_hi_ = longitude_hi;
code_length_ = code_length;
}
double CodeArea::GetLatitudeLo() const { return latitude_lo_; }
double CodeArea::GetLongitudeLo() const { return longitude_lo_; }
double CodeArea::GetLatitudeHi() const { return latitude_hi_; }
double CodeArea::GetLongitudeHi() const { return longitude_hi_; }
size_t CodeArea::GetCodeLength() const { return code_length_; }
LatLng CodeArea::GetCenter() const {
const double latitude_center = std::min(
latitude_lo_ + (latitude_hi_ - latitude_lo_) / 2, kLatitudeMaxDegrees);
const double longitude_center =
std::min(longitude_lo_ + (longitude_hi_ - longitude_lo_) / 2,
kLongitudeMaxDegrees);
const LatLng center = {latitude_center, longitude_center};
return center;
}
bool CodeArea::IsValid() const {
return code_length_ > 0 && latitude_lo_ < latitude_hi_ &&
longitude_lo_ < longitude_hi_ && latitude_lo_ >= -90.0 &&
latitude_hi_ <= 90.0 && longitude_lo_ >= -180.0 &&
longitude_hi_ <= 180.0;
}
const CodeArea& CodeArea::InvalidCodeArea() { return kInvalidCodeArea; }
} // namespace openlocationcode