コード例 #1
0
        // Given an array of points that define a path, add a new bend into it at the "right" place where it fits.
        // The oldPoints array may be null or empty.
        public static PointF[] AddPointToArray(PointF[] oldPoints, PointF newPoint)
        {
            if (oldPoints == null || oldPoints.Length == 0)
            {
                // Simple case -- no old path.
                return(new PointF[1] {
                    newPoint
                });
            }
            else
            {
                // Complex case. We need to figure out where the newPoint goes by finding the closest point
                // on the path.
                PointF  closestPoint;
                SymPath path = new SymPath(oldPoints);
                path.DistanceFromPoint(newPoint, out closestPoint);

                // On which segment does the closest point lie?
                int segmentStart, segmentEnd;
                path.FindSegmentWithPoint(closestPoint, 0.01F, out segmentStart, out segmentEnd);

                // Insert the point in that segment.
                List <PointF> list = new List <PointF>(oldPoints);
                list.Insert(segmentEnd, newPoint);
                return(list.ToArray());
            }
        }