1 | // Copyright 2005 Google Inc. All Rights Reserved. |
2 | |
3 | #ifndef UTIL_GEOMETRY_S2REGIONUNION_H__ |
4 | #define UTIL_GEOMETRY_S2REGIONUNION_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 S2RegionUnion represents a union of possibly overlapping regions. |
19 | // It is convenient for computing a covering of a set of regions. |
20 | class S2RegionUnion : public S2Region { |
21 | public: |
22 | // Create an empty region. Can be made non-empty by calling Init() or Add(). |
23 | S2RegionUnion(); |
24 | |
25 | // Create a region representing the union of the given regions. |
26 | // Takes ownership of all regions and clears the given vector. |
27 | S2RegionUnion(vector<S2Region*>* regions); |
28 | |
29 | virtual ~S2RegionUnion(); |
30 | |
31 | // Initialize region by taking ownership of the given regions. |
32 | void Init(vector<S2Region*>* regions); |
33 | |
34 | // Release ownership of the regions of this union, and appends them to |
35 | // "regions" if non-NULL. Resets the region to be empty. |
36 | void Release(vector<S2Region*>* regions); |
37 | |
38 | // Add the given region to the union. This method can be called repeatedly |
39 | // as an alternative to Init(). |
40 | // Takes ownership of the pointer. |
41 | void Add(S2Region* region); |
42 | |
43 | // Accessor methods. |
44 | int num_regions() const { return regions_.size(); } |
45 | inline S2Region* region(int i) const { return regions_[i]; } |
46 | |
47 | //////////////////////////////////////////////////////////////////////// |
48 | // S2Region interface (see s2region.h for details): |
49 | |
50 | virtual S2RegionUnion* Clone() const; |
51 | virtual S2Cap GetCapBound() const; |
52 | virtual S2LatLngRect GetRectBound() const; |
53 | virtual bool VirtualContainsPoint(S2Point const& p) const; |
54 | bool Contains(S2Point const& p) const; |
55 | virtual bool Contains(S2Cell const& cell) const; |
56 | virtual bool MayIntersect(S2Cell const& cell) const; |
57 | virtual void Encode(Encoder* const encoder) const { |
58 | LOG(FATAL) << "Unimplemented" ; |
59 | } |
60 | virtual bool Decode(Decoder* const decoder) { return false; } |
61 | |
62 | private: |
63 | // Internal constructor used only by Clone() that makes a deep copy of |
64 | // its argument. |
65 | S2RegionUnion(S2RegionUnion const* src); |
66 | |
67 | vector<S2Region*> regions_; |
68 | |
69 | DISALLOW_EVIL_CONSTRUCTORS(S2RegionUnion); |
70 | }; |
71 | |
72 | #endif // UTIL_GEOMETRY_S2REGIONUNION_H__ |
73 | |