コード例 #1
0
    private static object CoerceGeometry(DependencyObject d, object baseValue)
    {
        PortionPath portionPath = (PortionPath)d;
        int         firstPoint  = (int)(portionPath.PointCollection.Length * portionPath.From);
        int         lastPoint   = (int)(portionPath.PointCollection.Length * portionPath.To);

        if (firstPoint == 0 && lastPoint == portionPath.PointCollection.Length)
        {
            return(portionPath.Data);
        }
        if (firstPoint == lastPoint)
        {
            return(Geometry.Empty);
        }
        PathFigure pathFigure      = new PathFigure();
        var        pointCollection = portionPath.PointCollection.Skip(firstPoint).Take(lastPoint - firstPoint).ToArray();

        if (pointCollection.Length > 0)
        {
            pathFigure.StartPoint = pointCollection[0];
            if (pointCollection.Length > 1)
            {
                Point[] array = new Point[pointCollection.Length - 1];
                for (int i = 1; i < pointCollection.Length; i++)
                {
                    array[i - 1] = pointCollection[i];
                }
                pathFigure.Segments.Add(new PolyLineSegment(array, true));
            }
        }
        PathGeometry polylineGeometry = new PathGeometry();

        polylineGeometry.Figures.Add(pathFigure);
        return(polylineGeometry);
    }
コード例 #2
0
    private static object CoercePointCollection(DependencyObject d, object baseValue)
    {
        PortionPath  portionPath     = (PortionPath)d;
        var          path            = portionPath.Data;
        var          steps           = portionPath.Steps;
        var          g               = path.GetFlattenedPathGeometry(portionPath.Tolerance, ToleranceType.Absolute);
        List <Point> pointCollection = new List <Point>();
        var          step            = 1.0 / steps;

        for (double i = 0; i <= 1; i += step)
        {
            g.GetPointAtFractionLength(i, out Point p, out _);
            pointCollection.Add(p);
        }
        return(pointCollection.ToArray());
    }