示例#1
0
        public static PathFigure Copy(PathFigure original, Transform transformToApply)
        {
            PathFigure pathFigure = new PathFigure();

            if (pathFigure.IsFilled != original.IsFilled)
            {
                pathFigure.IsFilled = original.IsFilled;
            }
            if (pathFigure.IsClosed != original.IsClosed)
            {
                pathFigure.IsClosed = original.IsClosed;
            }
            int num = (int)original.GetValue(PathFigureUtilities.FigureMappingProperty);

            pathFigure.SetValue(PathFigureUtilities.FigureMappingProperty, (object)num);
            pathFigure.StartPoint = transformToApply == null ? original.StartPoint : original.StartPoint * transformToApply.Value;
            foreach (PathSegment pathSegment in original.Segments)
            {
                PathSegment segment = pathSegment.CloneCurrentValue();
                if (transformToApply != null)
                {
                    PathSegmentUtilities.TransformSegment(segment, transformToApply);
                }
                pathFigure.Segments.Add(segment);
            }
            return(pathFigure);
        }
 public static PathPointKind GetPointKind(PathSegment segment, int index)
 {
     if (index < 0 || index >= PathSegmentUtilities.GetPointCount(segment))
     {
         throw new ArgumentOutOfRangeException("index", (object)index, "Index must be between zero and the segment point count.");
     }
     if (segment is ArcSegment)
     {
         return(PathPointKind.Arc);
     }
     if (segment is LineSegment || segment is PolyLineSegment)
     {
         return(PathPointKind.Line);
     }
     if (segment is QuadraticBezierSegment || segment is PolyQuadraticBezierSegment)
     {
         return(index % 2 == 1 ? PathPointKind.Quadratic : PathPointKind.BezierHandle);
     }
     if (segment is BezierSegment || segment is PolyBezierSegment)
     {
         return(index % 3 == 2 ? PathPointKind.Cubic : PathPointKind.BezierHandle);
     }
     throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnknownPathSegmentType, new object[1]
     {
         (object)segment.GetType().Name
     }), "segment");
 }
示例#3
0
        public static Point GetPoint(PathFigure pathFigure, int index, bool correspondingPoint)
        {
            if (index == 0)
            {
                return(pathFigure.StartPoint);
            }
            PathSegmentCollection segments = pathFigure.Segments;
            int segmentIndex;
            int segmentPointIndex;

            PathFigureUtilities.GetSegmentFromPointIndex(pathFigure, index, out segmentIndex, out segmentPointIndex);
            PathSegment segment = segments[segmentIndex];

            if (correspondingPoint && segment is BezierSegment)
            {
                if (segmentPointIndex == 1)
                {
                    segmentPointIndex = 2;
                }
                else if (segmentPointIndex == 0)
                {
                    if (segmentIndex == 0)
                    {
                        return(pathFigure.StartPoint);
                    }
                    if (index > 0)
                    {
                        PathFigureUtilities.GetSegmentFromPointIndex(pathFigure, index - 1, out segmentIndex, out segmentPointIndex);
                        segment = segments[segmentIndex];
                    }
                }
            }
            return(PathSegmentUtilities.GetPoint(segment, segmentPointIndex));
        }
示例#4
0
        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 LineSegment CreateLineSegment(Point point, bool isStroked, bool?isSmoothJoin)
        {
            LineSegment lineSegment = new LineSegment();

            lineSegment.Point = point;
            PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)lineSegment, isStroked, isSmoothJoin);
            return(lineSegment);
        }
 public static void SetLastPoint(PathSegment segment, Point point)
 {
     if (PathSegmentUtilities.IsEmpty(segment))
     {
         throw new ArgumentException(ExceptionStringTable.CannotGetLastPointFromAnEmptySegment, "segment");
     }
     PathSegmentUtilities.SetPoint(segment, PathSegmentUtilities.GetPointCount(segment) - 1, point);
 }
        public static QuadraticBezierSegment CreateQuadraticBezierSegment(Point point1, Point point2, bool isStroked, bool?isSmoothJoin)
        {
            QuadraticBezierSegment quadraticBezierSegment = new QuadraticBezierSegment();

            quadraticBezierSegment.Point1 = point1;
            quadraticBezierSegment.Point2 = point2;
            PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)quadraticBezierSegment, isStroked, isSmoothJoin);
            return(quadraticBezierSegment);
        }
示例#8
0
        public static bool IsCloseSegmentDegenerate(PathFigure figure)
        {
            if (figure.Segments.Count == 0)
            {
                return(false);
            }
            Point lastPoint = PathSegmentUtilities.GetLastPoint(figure.Segments[figure.Segments.Count - 1]);

            return(VectorUtilities.ArePathPointsVeryClose(PathFigureUtilities.FirstPoint(figure), lastPoint));
        }
        public static BezierSegment CreateBezierSegment(Point point1, Point point2, Point point3, bool isStroked, bool?isSmoothJoin)
        {
            BezierSegment bezierSegment = new BezierSegment();

            bezierSegment.Point1 = point1;
            bezierSegment.Point2 = point2;
            bezierSegment.Point3 = point3;
            PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)bezierSegment, isStroked, isSmoothJoin);
            return(bezierSegment);
        }
示例#10
0
        public static bool EnsureOnlySingleSegmentsInFigure(PathFigure original)
        {
            bool flag = false;
            PathSegmentCollection segmentCollection = new PathSegmentCollection();

            foreach (PathSegment pathSegment in original.Segments)
            {
                PolyLineSegment            polyLineSegment         = pathSegment as PolyLineSegment;
                PolyQuadraticBezierSegment quadraticBezierSegment1 = pathSegment as PolyQuadraticBezierSegment;
                PolyBezierSegment          polyBezierSegment       = pathSegment as PolyBezierSegment;
                if (polyLineSegment != null)
                {
                    foreach (Point point in polyLineSegment.Points)
                    {
                        LineSegment lineSegment = PathSegmentUtilities.CreateLineSegment(point, polyLineSegment.IsStroked, new bool?(polyLineSegment.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)lineSegment);
                    }
                    flag = true;
                }
                else if (quadraticBezierSegment1 != null)
                {
                    int index = 0;
                    while (index < quadraticBezierSegment1.Points.Count - 1)
                    {
                        QuadraticBezierSegment quadraticBezierSegment2 = PathSegmentUtilities.CreateQuadraticBezierSegment(quadraticBezierSegment1.Points[index], quadraticBezierSegment1.Points[index + 1], quadraticBezierSegment1.IsStroked, new bool?(quadraticBezierSegment1.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)quadraticBezierSegment2);
                        index += 2;
                    }
                    flag = true;
                }
                else if (polyBezierSegment != null)
                {
                    int index = 0;
                    while (index < polyBezierSegment.Points.Count - 2)
                    {
                        BezierSegment bezierSegment = PathSegmentUtilities.CreateBezierSegment(polyBezierSegment.Points[index], polyBezierSegment.Points[index + 1], polyBezierSegment.Points[index + 2], polyBezierSegment.IsStroked, new bool?(polyBezierSegment.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)bezierSegment);
                        index += 3;
                    }
                    flag = true;
                }
                else
                {
                    segmentCollection.Add(pathSegment);
                }
            }
            if (flag)
            {
                original.Segments = segmentCollection;
            }
            return(flag);
        }
示例#11
0
        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);
        }
示例#12
0
 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);
     }
 }
示例#13
0
 public static BezierSegment CreateBezierSegment(Point point1, Point point2, Point point3, bool isStroked)
 {
     return(PathSegmentUtilities.CreateBezierSegment(point1, point2, point3, isStroked, new bool?()));
 }
示例#14
0
        public static void TransformSegment(PathSegment segment, Transform transform)
        {
            if (transform == null)
            {
                return;
            }
            Matrix matrix = transform.Value;

            if (segment is ArcSegment)
            {
                throw new NotSupportedException(ExceptionStringTable.ArcSegmentIsNotSupported);
            }
            LineSegment lineSegment;

            if ((lineSegment = segment as LineSegment) != null)
            {
                lineSegment.Point *= matrix;
            }
            else
            {
                QuadraticBezierSegment quadraticBezierSegment1;
                if ((quadraticBezierSegment1 = segment as QuadraticBezierSegment) != null)
                {
                    quadraticBezierSegment1.Point1 *= matrix;
                    quadraticBezierSegment1.Point2 *= matrix;
                }
                else
                {
                    BezierSegment bezierSegment;
                    if ((bezierSegment = segment as BezierSegment) != null)
                    {
                        bezierSegment.Point1 *= matrix;
                        bezierSegment.Point2 *= matrix;
                        bezierSegment.Point3 *= matrix;
                    }
                    else
                    {
                        PolyLineSegment polyLineSegment;
                        if ((polyLineSegment = segment as PolyLineSegment) != null)
                        {
                            PathSegmentUtilities.TransformPoints(polyLineSegment.Points, matrix);
                        }
                        else
                        {
                            PolyQuadraticBezierSegment quadraticBezierSegment2;
                            if ((quadraticBezierSegment2 = segment as PolyQuadraticBezierSegment) != null)
                            {
                                PathSegmentUtilities.TransformPoints(quadraticBezierSegment2.Points, matrix);
                            }
                            else
                            {
                                PolyBezierSegment polyBezierSegment;
                                if ((polyBezierSegment = segment as PolyBezierSegment) != null)
                                {
                                    PathSegmentUtilities.TransformPoints(polyBezierSegment.Points, matrix);
                                }
                                else
                                {
                                    throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnknownPathSegmentType, new object[1]
                                    {
                                        (object)segment.GetType().Name
                                    }), "segment");
                                }
                            }
                        }
                    }
                }
            }
        }
示例#15
0
        public static void SetPoint(PathSegment segment, int index, Point point)
        {
            if (index < 0 || index >= PathSegmentUtilities.GetPointCount(segment))
            {
                throw new ArgumentOutOfRangeException("index", (object)index, "Index must be between zero and the segment point count.");
            }
            ArcSegment arcSegment;

            if ((arcSegment = segment as ArcSegment) != null)
            {
                arcSegment.Point = point;
            }
            else
            {
                LineSegment lineSegment;
                if ((lineSegment = segment as LineSegment) != null)
                {
                    lineSegment.Point = point;
                }
                else
                {
                    QuadraticBezierSegment quadraticBezierSegment1;
                    if ((quadraticBezierSegment1 = segment as QuadraticBezierSegment) != null)
                    {
                        if (index == 0)
                        {
                            quadraticBezierSegment1.Point1 = point;
                        }
                        else
                        {
                            quadraticBezierSegment1.Point2 = point;
                        }
                    }
                    else
                    {
                        BezierSegment bezierSegment;
                        if ((bezierSegment = segment as BezierSegment) != null)
                        {
                            if (index == 0)
                            {
                                bezierSegment.Point1 = point;
                            }
                            else if (index == 1)
                            {
                                bezierSegment.Point2 = point;
                            }
                            else
                            {
                                bezierSegment.Point3 = point;
                            }
                        }
                        else
                        {
                            PolyLineSegment polyLineSegment;
                            if ((polyLineSegment = segment as PolyLineSegment) != null)
                            {
                                polyLineSegment.Points[index] = point;
                            }
                            else
                            {
                                PolyQuadraticBezierSegment quadraticBezierSegment2;
                                if ((quadraticBezierSegment2 = segment as PolyQuadraticBezierSegment) != null)
                                {
                                    quadraticBezierSegment2.Points[index] = point;
                                }
                                else
                                {
                                    PolyBezierSegment polyBezierSegment;
                                    if ((polyBezierSegment = segment as PolyBezierSegment) != null)
                                    {
                                        polyBezierSegment.Points[index] = point;
                                    }
                                    else
                                    {
                                        throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnknownPathSegmentType, new object[1]
                                        {
                                            (object)segment.GetType().Name
                                        }), "segment");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#16
0
 public static LineSegment CreateLineSegment(Point point, bool isStroked)
 {
     return(PathSegmentUtilities.CreateLineSegment(point, isStroked, new bool?()));
 }
示例#17
0
 public static bool IsEmpty(PathSegment segment)
 {
     return(PathSegmentUtilities.GetPointCount(segment) == 0);
 }
示例#18
0
        public static bool CollapseSingleSegmentsToPolySegments(PathFigure original)
        {
            bool flag = false;
            PathSegmentCollection segmentCollection = new PathSegmentCollection();

            for (int index = 0; index < original.Segments.Count; ++index)
            {
                LineSegment            lineSegment             = original.Segments[index] as LineSegment;
                QuadraticBezierSegment quadraticBezierSegment1 = original.Segments[index] as QuadraticBezierSegment;
                BezierSegment          bezierSegment1          = original.Segments[index] as BezierSegment;
                int num = index;
                if (lineSegment != null)
                {
                    PointCollection pointCollection = (PointCollection)null;
                    for (; index + 1 < original.Segments.Count && original.Segments[index + 1] is LineSegment && !PathFigureUtilities.IsSignificantChangeBetweenSegments((PathSegment)lineSegment, original.Segments[index + 1]); ++index)
                    {
                        if (pointCollection == null)
                        {
                            pointCollection = new PointCollection();
                            pointCollection.Add(lineSegment.Point);
                        }
                        pointCollection.Add(((LineSegment)original.Segments[index + 1]).Point);
                    }
                    if (index != num)
                    {
                        PolyLineSegment polyLineSegment = new PolyLineSegment();
                        polyLineSegment.Points = pointCollection;
                        PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)polyLineSegment, lineSegment.IsStroked, new bool?(lineSegment.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)polyLineSegment);
                        flag = true;
                    }
                    else
                    {
                        segmentCollection.Add((PathSegment)lineSegment);
                    }
                }
                else if (quadraticBezierSegment1 != null)
                {
                    PointCollection        pointCollection = (PointCollection)null;
                    QuadraticBezierSegment quadraticBezierSegment2;
                    for (; index + 1 < original.Segments.Count && (quadraticBezierSegment2 = original.Segments[index + 1] as QuadraticBezierSegment) != null && !PathFigureUtilities.IsSignificantChangeBetweenSegments((PathSegment)quadraticBezierSegment1, (PathSegment)quadraticBezierSegment2); ++index)
                    {
                        if (pointCollection == null)
                        {
                            pointCollection = new PointCollection();
                            pointCollection.Add(quadraticBezierSegment1.Point1);
                            pointCollection.Add(quadraticBezierSegment1.Point2);
                        }
                        pointCollection.Add(quadraticBezierSegment2.Point1);
                        pointCollection.Add(quadraticBezierSegment2.Point2);
                    }
                    if (index != num)
                    {
                        PolyQuadraticBezierSegment quadraticBezierSegment3 = new PolyQuadraticBezierSegment();
                        quadraticBezierSegment3.Points = pointCollection;
                        PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)quadraticBezierSegment3, quadraticBezierSegment1.IsStroked, new bool?(quadraticBezierSegment1.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)quadraticBezierSegment3);
                        flag = true;
                    }
                    else
                    {
                        segmentCollection.Add((PathSegment)quadraticBezierSegment1);
                    }
                }
                else if (bezierSegment1 != null)
                {
                    PointCollection pointCollection = (PointCollection)null;
                    BezierSegment   bezierSegment2;
                    for (; index + 1 < original.Segments.Count && (bezierSegment2 = original.Segments[index + 1] as BezierSegment) != null && !PathFigureUtilities.IsSignificantChangeBetweenSegments((PathSegment)bezierSegment1, (PathSegment)bezierSegment2); ++index)
                    {
                        if (pointCollection == null)
                        {
                            pointCollection = new PointCollection();
                            pointCollection.Add(bezierSegment1.Point1);
                            pointCollection.Add(bezierSegment1.Point2);
                            pointCollection.Add(bezierSegment1.Point3);
                        }
                        pointCollection.Add(bezierSegment2.Point1);
                        pointCollection.Add(bezierSegment2.Point2);
                        pointCollection.Add(bezierSegment2.Point3);
                    }
                    if (index != num)
                    {
                        PolyBezierSegment polyBezierSegment = new PolyBezierSegment();
                        polyBezierSegment.Points = pointCollection;
                        PathSegmentUtilities.SetStrokeAndJoinOnSegment((PathSegment)polyBezierSegment, bezierSegment1.IsStroked, new bool?(bezierSegment1.IsSmoothJoin));
                        segmentCollection.Add((PathSegment)polyBezierSegment);
                        flag = true;
                    }
                    else
                    {
                        segmentCollection.Add((PathSegment)bezierSegment1);
                    }
                }
                else
                {
                    segmentCollection.Add(original.Segments[index]);
                }
            }
            if (flag)
            {
                original.Segments = segmentCollection;
            }
            return(flag);
        }