| 1 | // Copyright 2005 Google Inc. All Rights Reserved. |
|---|---|
| 2 | |
| 3 | #ifndef UTIL_GEOMETRY_S2POINTREGION_H__ |
| 4 | #define UTIL_GEOMETRY_S2POINTREGION_H__ |
| 5 | |
| 6 | #include "base/logging.h" |
| 7 | #include "base/macros.h" |
| 8 | #include "s2.h" |
| 9 | #include "s2region.h" |
| 10 | |
| 11 | // An S2PointRegion is a region that contains a single point. It is more |
| 12 | // expensive than the raw S2Point type and is useful mainly for completeness. |
| 13 | class S2PointRegion : public S2Region { |
| 14 | public: |
| 15 | // Create a region containing the given point, which must be unit length. |
| 16 | inline explicit S2PointRegion(S2Point const& point); |
| 17 | |
| 18 | ~S2PointRegion(); |
| 19 | |
| 20 | S2Point const& point() const { return point_; } |
| 21 | |
| 22 | //////////////////////////////////////////////////////////////////////// |
| 23 | // S2Region interface (see s2region.h for details): |
| 24 | |
| 25 | virtual S2PointRegion* Clone() const; |
| 26 | virtual S2Cap GetCapBound() const; |
| 27 | virtual S2LatLngRect GetRectBound() const; |
| 28 | virtual bool Contains(S2Cell const& cell) const { return false; } |
| 29 | virtual bool MayIntersect(S2Cell const& cell) const; |
| 30 | virtual bool VirtualContainsPoint(S2Point const& p) const { |
| 31 | return Contains(p); |
| 32 | } |
| 33 | bool Contains(S2Point const& p) const { return (point_ == p); } |
| 34 | virtual void Encode(Encoder* const encoder) const; |
| 35 | virtual bool Decode(Decoder* const decoder); |
| 36 | |
| 37 | private: |
| 38 | S2Point point_; |
| 39 | |
| 40 | DISALLOW_EVIL_CONSTRUCTORS(S2PointRegion); |
| 41 | }; |
| 42 | |
| 43 | S2PointRegion::S2PointRegion(S2Point const& point) : point_(point) { |
| 44 | DCHECK(S2::IsUnitLength(point)); |
| 45 | } |
| 46 | |
| 47 | #endif // UTIL_GEOMETRY_S2POINTREGION_H__ |
| 48 |