コード例 #1
0
        const float PRECISION = 1000;         //000000000.0f;

        public PolygonClipper(WPMF.Region regionSubject, WPMF.Region regionClipping)
        {
            // Setup subject and clipping polygons
            this.regionSubject = regionSubject;
            subject            = new Polygon();
            Contour scont = new Contour();

            scont.AddRange(regionSubject.points);
            for (int k = 0; k < scont.points.Count; k++)
            {
                scont.points[k] *= PRECISION;
            }
            subject.AddContour(scont);
            clipping = new Polygon();
            Contour ccont = new Contour();

            ccont.AddRange(regionClipping.points);
            for (int k = 0; k < ccont.points.Count; k++)
            {
                ccont.points[k] *= PRECISION;
            }
            clipping.AddContour(ccont);

            // Init event queue
            eventQueue = new EventQueue();
        }
コード例 #2
0
ファイル: Polygon.cs プロジェクト: VadimCat/Map-project
        public Polygon Clone()
        {
            Polygon poly = new Polygon();

            foreach (Contour cont in this.contours)
            {
                Contour c = new Contour();
                c.AddRange(cont.points);
                poly.AddContour(c);
            }
            return(poly);
        }
コード例 #3
0
        /// <summary>
        /// Since polygons from countries and provinces are not perfectly aligned in all cases, this method will take the largest contour and assume this is the resulting polygon
        /// (even if it's not closed...)
        /// </summary>
        public Polygon ToPolygonFromLargestLineStrip()
        {
            // Check for empty result
            if ((closedPolygons.Count == 0 ||
                 (closedPolygons.Count == 1 && closedPolygons[0].pointList.Count == 0)) &&
                (openPolygons.Count == 0 ||
                 (openPolygons.Count == 1 && openPolygons[0].pointList.Count == 0)))
            {
                return(null);
            }

            // Get the largest contour (open or closed)
            int        maxPoints         = -1;
            PointChain largestPointChain = null;

            foreach (PointChain pointChain in closedPolygons)
            {
                if (pointChain.pointList.Count > maxPoints)
                {
                    maxPoints         = pointChain.pointList.Count;
                    largestPointChain = pointChain;
                }
            }
            foreach (PointChain pointChain in openPolygons)
            {
                if (pointChain.pointList.Count > maxPoints)
                {
                    maxPoints         = pointChain.pointList.Count;
                    largestPointChain = pointChain;
                }
            }

            // ... and create a new polygon from that
            if (maxPoints < 0)
            {
                return(null);
            }
            Polygon polygon = new Polygon();
            Contour c       = new Contour();

            c.AddRange(largestPointChain.pointList);
            polygon.AddContour(c);
            FixOrientation(polygon);
            return(polygon);
        }
コード例 #4
0
        public Polygon ToPolygon()
        {
            // Check for empty result
            if ((closedPolygons.Count == 0 ||
                 (closedPolygons.Count == 1 && closedPolygons[0].pointList.Count == 0)) &&
                (openPolygons.Count == 0 ||
                 (openPolygons.Count == 1 && openPolygons[0].pointList.Count == 0)))
            {
                return(null);
            }

            Polygon polygon = new Polygon();

            foreach (PointChain pointChain in closedPolygons)
            {
                Contour c = new Contour();
                c.AddRange(pointChain.pointList);
                polygon.AddContour(c);
            }
            FixOrientation(polygon);
            return(polygon);
        }