Example #1
0
        /// <summary>
        /// 将孔的点添加到PolygonData
        /// Add Points of a Hole to the PolygonData
        /// </summary>
        /// <param name="points">The Points that define the Hole in the Polygon</param>
        internal void AddHole(List <Point> points)
        {
            // Make Hole Clockwise
            if (SweepLinePolygonTriangulator.IsCCW(points))
            {
                points.Reverse();
            }
            // The Hole Points
            var polyPoints = points.Select(p => new PolygonPoint(p)).ToList();

            // If Endpoint equals Startpoint
            if (polyPoints[0].Equals(polyPoints[polyPoints.Count - 1]))
            {
                polyPoints.RemoveAt(polyPoints.Count - 1);
            }
            mHoles.Add(polyPoints);

            var cntBefore  = mPoints.Count;
            var pointCount = points.Count;

            // Add the PolygonPoints for this Polygon Object
            mPoints.AddRange(polyPoints);

            // Add the Indices
            for (int i = cntBefore; i < mPoints.Count; i++)
            {
                polyPoints[i - cntBefore].Index = i;
            }

            // Add Edges between the Points (to be able to navigate along the Polygon easily later)
            var cnt = mPoints.Count;

            for (int i = 0; i < pointCount; i++)
            {
                var lastIdx = (i + pointCount - 1) % pointCount;
                var edge    = new PolygonEdge(polyPoints[lastIdx], polyPoints[i]);
                polyPoints[lastIdx].EdgeTwo = edge;
                polyPoints[i].EdgeOne       = edge;
            }
        }
Example #2
0
 /// <summary>
 /// 使用扫掠线算法对多边形进行三角剖分
 /// Triangulate the polygon by using the sweep line algorithm
 /// </summary>
 /// <returns>An index collection.</returns>
 public Int32Collection Triangulate()
 {
     return(SweepLinePolygonTriangulator.Triangulate(this.points));
 }