Creates an empty cell union.
Constructs a cell union with the given S2CellIds, then calls Normalize() to sort them, remove duplicates, and merge cells when possible. (See FromNormalized if your vector is already normalized.)
Calculates this cell union's area in steradians by summing the exact area for each contained cell, using the Exact method from the S2Cell class.
Approximates this cell union's area in steradians by summing the average area of each contained cell's average area, using the AverageArea method from the S2Cell class. This is equivalent to the number of leaves covered, multiplied by the average area of a leaf. Note that AverageArea does not take into account distortion of cell, and thus may be off by up to a factor of up to 1.7.
Standard begin/end methods, to allow range-based for loops:
Direct access to the underlying vector for STL algorithms.
Clears the contents of the cell union and minimizes memory usage.
/////////////////////////////////////////////////////////////////////
Returns true if the cell union contains the given cell id. Containment is defined with respect to regions, e.g. a cell contains its 4 children. This is a fast operation (logarithmic in the size of the cell union).
This is a fast operation (logarithmic in the size of the cell union).
The point 'p' does not need to be normalized. This is a fast operation (logarithmic in the size of the cell union).
Decodes an S2CellUnion encoded with Encode(). Returns true on success.
Replaces "output" with an expanded version of the cell union where any cells whose level is less than "min_level" or where (level - min_level) is not a multiple of "level_mod" are replaced by their children, until either both of these conditions are satisfied or the maximum level is reached.
Returns the difference of the two given cell unions.
Appends a serialized representation of the S2CellUnion to "encoder".
Expands the cell union by adding a buffer of cells at "expand_level" around the union boundary.
Expands the cell union such that it contains all points whose distance to the cell union is at most "min_radius", but do not use cells that are more than "max_level_diff" levels higher than the largest cell in the input. The second parameter controls the tradeoff between accuracy and output size when a large region is being expanded by a small amount (e.g. expanding Canada by 1km). For example, if max_level_diff == 4 the region will always be expanded by approximately 1/16 the width of its largest cell. Note that in the worst case, the number of cells in the output can be up to 4 * (1 + 2 ** max_level_diff) times larger than the number of cells in the input.
initialize() methods corresponding to the constructors/factory methods above. TODO(ericv): Consider deprecating these methods in favor of using the constructors and move assignment operator.
Returns true if the cell union intersects the given cell id. This is a fast operation (logarithmic in the size of the cell union).
Returns true if the cell union is normalized, meaning that it is satisfies IsValid() and that no four cells have a common parent. Certain operations such as Contains(S2CellUnion) will return a different result if the cell union is not normalized.
Returns true if the cell union is valid, meaning that the S2CellIds are valid, non-overlapping, and sorted in increasing order.
The number of leaf cells covered by the union. This will be no more than 6*2^60 for the whole sphere.
This is a fast operation (logarithmic in the size of the cell union).
Normalizes the cell union by discarding cells that are contained by other cells, replacing groups of 4 child cells by their parent cell whenever possible, and sorting all the cell ids in increasing order.
Convenience methods for accessing the individual cell ids.
Return true if two cell unions are identical.
If there are more than "excess" elements of the cell_ids() vector that are allocated but unused, reallocates the array to eliminate the excess space. This reduces memory usage when many cell unions need to be held in memory at once.
Gives ownership of the vector data to the client without copying, and clears the content of the cell union. The original data in cell_ids is lost if there was any.
Vector-like methods for accessing the individual cell ids.
Like FromMinMax() except that the union covers the range of leaf cells from "begin" (inclusive) to "end" (exclusive), as with Python ranges or STL iterator ranges. If (begin == end) the result is empty.
Constructs a cell union that corresponds to a continuous range of cell ids. The output is a normalized collection of cell ids that covers the leaf cells between "min_id" and "max_id" inclusive.
Constructs a cell union from S2CellIds that have already been normalized (typically because they were extracted from another S2CellUnion).
Constructs a cell union from a vector of sorted, non-overlapping S2CellIds. Unlike the other constructors, FromVerbatim does not require that groups of 4 child cells have been replaced by their parent cell. In other words, "cell_ids" must satisfy the requirements of IsValid() but not necessarily IsNormalized().
Like GetIntersection(), but works directly with vectors of S2CellIds, Equivalent to:
Like Normalize(), but works with a vector of S2CellIds. Equivalent to: *cell_ids = S2CellUnion(std::move(*cell_ids)).Release();
Returns a deep copy of the region.
Returns a bounding spherical cap that contains the region. The bound may not be tight.
Returns a bounding latitude-longitude rectangle that contains the region. The bound may not be tight.
Returns a small collection of S2CellIds whose union covers the region. The cells are not sorted, may have redundancies (such as cells that contain other cells), and may cover much more area than necessary.
Returns true if the region completely contains the given cell, otherwise returns false.
If this method returns false, the region does not intersect the given cell. Otherwise, either region intersects the cell, or the intersection relationship could not be determined.
Returns true if and only if the given point is contained by the region. The point 'p' is generally required to be unit length, although some subtypes may relax this restriction.
An S2CellUnion is a region consisting of cells of various sizes. Typically a cell union is used to approximate some other shape. There is a tradeoff between the accuracy of the approximation and how many cells are used. Unlike polygons, cells have a fixed hierarchical structure. This makes them more suitable for optimizations based on preprocessing.
An S2CellUnion is represented as a vector of sorted, non-overlapping S2CellIds. By default the vector is also "normalized", meaning that groups of 4 child cells have been replaced by their parent cell whenever possible. S2CellUnions are not required to be normalized, but certain operations will return different results if they are not (e.g., Contains(S2CellUnion).)
S2CellUnion is movable and copyable.