コード例 #1
0
        /**
         * Like AssembleLoops, but normalizes all the loops so that they enclose less
         * than half the sphere, and then assembles the loops into a polygon.
         *
         *  For this method to succeed, there should be no duplicate edges in the
         * input. If this is not known to be true, then the "xor_edges" option should
         * be set (which is true by default).
         *
         *  Note that S2Polygons cannot represent arbitrary regions on the sphere,
         * because of the limitation that no loop encloses more than half of the
         * sphere. For example, an S2Polygon cannot represent a 100km wide band around
         * the equator. In such cases, this method will return the *complement* of the
         * expected region. So for example if all the world's coastlines were
         * assembled, the output S2Polygon would represent the land area (irrespective
         * of the input edge or loop orientations).
         */

        public bool AssemblePolygon(S2Polygon polygon, System.Collections.Generic.IList <S2Edge> unusedEdges)
        {
            var loops   = new List <S2Loop>();
            var success = AssembleLoops(loops, unusedEdges);

            // If edges are undirected, then all loops are already CCW. Otherwise we
            // need to make sure the loops are normalized.
            if (!_options.UndirectedEdges)
            {
                for (var i = 0; i < loops.Count; ++i)
                {
                    loops[i].Normalize();
                }
            }
            if (_options.Validate && !S2Polygon.IsValidPolygon(loops))
            {
                if (unusedEdges != null)
                {
                    foreach (var loop in loops)
                    {
                        RejectLoop(loop, loop.NumVertices, unusedEdges);
                    }
                }
                return(false);
            }
            polygon.Init(loops);
            return(success);
        }
コード例 #2
0
        /**
         * Add all loops in the given polygon. Shells and holes are added with
         * opposite orientations as described for AddLoop(). This method does not take
         * ownership of the polygon.
         */

        public void AddPolygon(S2Polygon polygon)
        {
            for (var i = 0; i < polygon.NumLoops; ++i)
            {
                AddLoop(polygon.Loop(i));
            }
        }
コード例 #3
0
        /**
         * Convenience method for when you don't care about unused edges.
         */

        public S2Polygon AssemblePolygon()
        {
            var polygon     = new S2Polygon();
            var unusedEdges = new List <S2Edge>();

            AssemblePolygon(polygon, unusedEdges);

            return(polygon);
        }
コード例 #4
0
            private static int[] GetVertices(S2Polygon poly)
            {
                var vertices = new int[poly.NumLoops];

                for (var i = 0; i < vertices.Length; i++)
                {
                    vertices[i] = poly.Loop(i).NumVertices;
                }
                return(vertices);
            }
コード例 #5
0
 public S2PolygonIndex(S2Polygon poly, bool reverse) : base(GetVertices(poly))
 {
     _poly    = poly;
     _reverse = reverse;
 }