コード例 #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);
        }