1 | // Copyright 2006 Google Inc. All Rights Reserved. |
---|---|
2 | |
3 | #ifndef UTIL_GEOMETRY_S2REGIONINTERSECTION_H__ |
4 | #define UTIL_GEOMETRY_S2REGIONINTERSECTION_H__ |
5 | |
6 | #include <vector> |
7 | using std::vector; |
8 | |
9 | #include "base/basictypes.h" |
10 | #include "base/logging.h" |
11 | #include "base/macros.h" |
12 | #include "s2region.h" |
13 | |
14 | class S2Cap; |
15 | class S2Cell; |
16 | class S2LatLngRect; |
17 | |
18 | // An S2RegionIntersection represents the intersection of a set of regions. |
19 | // It is convenient for computing a covering of the intersection of a set of |
20 | // regions. |
21 | class S2RegionIntersection : public S2Region { |
22 | public: |
23 | // Creates an empty intersection that should be initialized by calling Init(). |
24 | // Note: an intersection of no regions covers the entire sphere. |
25 | S2RegionIntersection(); |
26 | |
27 | // Create a region representing the intersection of the given regions. |
28 | // Takes ownership of all regions and clears the given vector. |
29 | S2RegionIntersection(vector<S2Region*>* regions); |
30 | |
31 | virtual ~S2RegionIntersection(); |
32 | |
33 | // Initialize region by taking ownership of the given regions. |
34 | void Init(vector<S2Region*>* regions); |
35 | |
36 | // Release ownership of the regions of this union, and appends them to |
37 | // "regions" if non-NULL. Resets the region to be empty. |
38 | void Release(vector<S2Region*>* regions); |
39 | |
40 | // Accessor methods. |
41 | int num_regions() const { return regions_.size(); } |
42 | inline S2Region* region(int i) const { return regions_[i]; } |
43 | |
44 | //////////////////////////////////////////////////////////////////////// |
45 | // S2Region interface (see s2region.h for details): |
46 | |
47 | virtual S2RegionIntersection* Clone() const; |
48 | virtual S2Cap GetCapBound() const; |
49 | virtual S2LatLngRect GetRectBound() const; |
50 | virtual bool VirtualContainsPoint(S2Point const& p) const; |
51 | bool Contains(S2Point const& p) const; |
52 | virtual bool Contains(S2Cell const& cell) const; |
53 | virtual bool MayIntersect(S2Cell const& cell) const; |
54 | virtual void Encode(Encoder* const encoder) const { |
55 | LOG(FATAL) << "Unimplemented"; |
56 | } |
57 | virtual bool Decode(Decoder* const decoder) { return false; } |
58 | |
59 | private: |
60 | // Internal constructor used only by Clone() that makes a deep copy of |
61 | // its argument. |
62 | S2RegionIntersection(S2RegionIntersection const* src); |
63 | |
64 | vector<S2Region*> regions_; |
65 | |
66 | DISALLOW_EVIL_CONSTRUCTORS(S2RegionIntersection); |
67 | }; |
68 | |
69 | #endif // UTIL_GEOMETRY_S2REGIONINTERSECTION_H__ |
70 |