1 | // Copyright 2005 Google Inc. All Rights Reserved. |
---|---|
2 | |
3 | #include "s2pointregion.h" |
4 | #include "base/logging.h" |
5 | #include "util/coding/coder.h" |
6 | #include "s2cap.h" |
7 | #include "s2cell.h" |
8 | #include "s2latlngrect.h" |
9 | |
10 | static const unsigned char kCurrentEncodingVersionNumber = 1; |
11 | |
12 | S2PointRegion::~S2PointRegion() { |
13 | } |
14 | |
15 | S2PointRegion* S2PointRegion::Clone() const { |
16 | return new S2PointRegion(point_); |
17 | } |
18 | |
19 | S2Cap S2PointRegion::GetCapBound() const { |
20 | return S2Cap::FromAxisHeight(point_, 0); |
21 | } |
22 | |
23 | S2LatLngRect S2PointRegion::GetRectBound() const { |
24 | S2LatLng ll(point_); |
25 | return S2LatLngRect(ll, ll); |
26 | } |
27 | |
28 | bool S2PointRegion::MayIntersect(S2Cell const& cell) const { |
29 | return cell.Contains(point_); |
30 | } |
31 | |
32 | void S2PointRegion::Encode(Encoder* encoder) const { |
33 | encoder->Ensure(30); // sufficient |
34 | |
35 | encoder->put8(kCurrentEncodingVersionNumber); |
36 | for (int i = 0; i < 3; ++i) { |
37 | encoder->putdouble(point_[i]); |
38 | } |
39 | DCHECK_GE(encoder->avail(), 0); |
40 | } |
41 | |
42 | bool S2PointRegion::Decode(Decoder* decoder) { |
43 | unsigned char version = decoder->get8(); |
44 | if (version > kCurrentEncodingVersionNumber) return false; |
45 | |
46 | for (int i = 0; i < 3; ++i) { |
47 | point_[i] = decoder->getdouble(); |
48 | } |
49 | DCHECK(S2::IsUnitLength(point_)); |
50 | |
51 | return decoder->avail() >= 0; |
52 | } |
53 |