public static void GetSegmentFromPointIndex(PathFigure pathFigure, int pointIndex, out int segmentIndex, out int segmentPointIndex) { PathSegmentCollection segments = pathFigure.Segments; if (pointIndex == 0) { if (pathFigure.IsClosed && PathFigureUtilities.IsCloseSegmentDegenerate(pathFigure)) { segmentIndex = pathFigure.Segments.Count - 1; segmentPointIndex = PathSegmentUtilities.GetPointCount(segments[segmentIndex]) - 1; } else { segmentIndex = 0; segmentPointIndex = -1; } } else { segmentIndex = 0; segmentPointIndex = 0; int num = 1; int pointCount = PathSegmentUtilities.GetPointCount(segments[segmentIndex]); while (pointCount < pointIndex) { num = pointCount + 1; pointCount += PathSegmentUtilities.GetPointCount(segments[++segmentIndex]); } segmentPointIndex = pointIndex - num; } }
public static int PointCount(PathFigure figure) { int num = 1; foreach (PathSegment segment in figure.Segments) { num += PathSegmentUtilities.GetPointCount(segment); } if (PathFigureUtilities.IsClosed(figure) && PathFigureUtilities.IsCloseSegmentDegenerate(figure)) { --num; } return(num); }
public static void SetPoint(PathFigure pathFigure, int pointIndex, Point point) { if (pointIndex == 0 || pointIndex == PathFigureUtilities.PointCount(pathFigure) && PathFigureUtilities.IsClosed(pathFigure) && !PathFigureUtilities.IsCloseSegmentDegenerate(pathFigure)) { pathFigure.StartPoint = point; } else { PathSegmentCollection segments = pathFigure.Segments; int segmentIndex; int segmentPointIndex; PathFigureUtilities.GetSegmentFromPointIndex(pathFigure, pointIndex, out segmentIndex, out segmentPointIndex); PathSegmentUtilities.SetPoint(segments[segmentIndex], segmentPointIndex, point); } }