Ejemplo n.º 1
0
        public IS2Region Clone()
        {
            var copy = new S2CellUnion();

            copy.InitRawCellIds(_cellIds);
            return(copy);
        }
Ejemplo n.º 2
0
        /**
         * Specialized version of GetIntersection() that gets the intersection of a
         * cell union with the given cell id. This can be useful for "splitting" a
         * cell union into chunks.
         */

        public void GetIntersection(S2CellUnion x, S2CellId id)
        {
            // assert (x != this);
            _cellIds.Clear();
            if (x.Contains(id))
            {
                _cellIds.Add(id);
            }
            else
            {
                var pos = x._cellIds.BinarySearch(id.RangeMin);

                if (pos < 0)
                {
                    pos = -pos - 1;
                }

                var idmax = id.RangeMax;
                var size  = x._cellIds.Count;
                while (pos < size && x._cellIds[pos] <= idmax)
                {
                    _cellIds.Add(x._cellIds[pos++]);
                }
            }
        }
Ejemplo n.º 3
0
        /**
         * Return a normalized cell union that is contained within the given region
         * and satisfies the restrictions *EXCEPT* for min_level() and level_mod().
         */

        public S2CellUnion GetInteriorCovering(IS2Region region)
        {
            var covering = new S2CellUnion();

            GetInteriorCovering(region, covering);
            return(covering);
        }
Ejemplo n.º 4
0
        public void GetUnion(S2CellUnion x, S2CellUnion y)
        {
            // assert (x != this && y != this);
            _cellIds.Clear();

            _cellIds.AddRange(x._cellIds);
            _cellIds.AddRange(y._cellIds);
            Normalize();
        }
Ejemplo n.º 5
0
 public bool Equals(S2CellUnion other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(_cellIds.SequenceEqual(other._cellIds));
 }
Ejemplo n.º 6
0
        /** This is a fast operation (logarithmic in the size of the cell union). */

        /**
         * Return true if this cell union contain/intersects the given other cell
         * union.
         */

        public bool Intersects(S2CellUnion union)
        {
            // TODO(kirilll?): A divide-and-conquer or alternating-skip-search approach
            // may be significantly faster in both the average and worst case.
            foreach (var id in union)
            {
                if (Intersects(id))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 7
0
        /**
         * Initialize this cell union to the union or intersection of the two given
         * cell unions. Requires: x != this and y != this.
         */

        public void GetIntersection(S2CellUnion x, S2CellUnion y)
        {
            // assert (x != this && y != this);

            // This is a fairly efficient calculation that uses binary search to skip
            // over sections of both input vectors. It takes constant time if all the
            // cells of "x" come before or after all the cells of "y" in S2CellId order.

            _cellIds.Clear();

            var i = 0;
            var j = 0;

            while (i < x._cellIds.Count && j < y._cellIds.Count)
            {
                var imin = x.CellId(i).RangeMin;
                var jmin = y.CellId(j).RangeMin;
                if (imin > jmin)
                {
                    // Either j->contains(*i) or the two cells are disjoint.
                    if (x.CellId(i) <= y.CellId(j).RangeMax)
                    {
                        _cellIds.Add(x.CellId(i++));
                    }
                    else
                    {
                        // Advance "j" to the first cell possibly contained by *i.
                        j = IndexedBinarySearch(y._cellIds, imin, j + 1);
                        // The previous cell *(j-1) may now contain *i.
                        if (x.CellId(i) <= y.CellId(j - 1).RangeMax)
                        {
                            --j;
                        }
                    }
                }
                else if (jmin >= imin)
                {
                    // Identical to the code above with "i" and "j" reversed.
                    if (y.CellId(j) <= x.CellId(i).RangeMax)
                    {
                        _cellIds.Add(y.CellId(j++));
                    }
                    else
                    {
                        i = IndexedBinarySearch(x._cellIds, jmin, i + 1);
                        if (y.CellId(j) <= x.CellId(i - 1).RangeMax)
                        {
                            --i;
                        }
                    }
                }
                else
                {
                    // "i" and "j" have the same range_min(), so one contains the other.
                    if (x.CellId(i) < y.CellId(j))
                    {
                        _cellIds.Add(x.CellId(i++));
                    }
                    else
                    {
                        _cellIds.Add(y.CellId(j++));
                    }
                }
            }
            // The output is generated in sorted order, and there should not be any
            // cells that can be merged (provided that both inputs were normalized).
            // assert (!normalize());
        }
Ejemplo n.º 8
0
 public void GetInteriorCovering(IS2Region region, S2CellUnion covering)
 {
     _interiorCovering = true;
     GetCoveringInternal(region);
     covering.InitSwap(_result);
 }