示例#1
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));
        }
示例#2
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;
            }
        }
示例#3
0
        public void AppendLineSegment(Point p)
        {
            PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(this.path.Figures.Count - 1);

            if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
            {
                throw new InvalidOperationException(ExceptionStringTable.LastFigureMustBeOpenToAppendALineSegment);
            }
            pathFigureEditor.LineTo(p);
        }
示例#4
0
        public void CloseFigureWithCubicBezier(Point q, Point r, int figureIndex)
        {
            PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex);

            if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
            {
                throw new InvalidOperationException(ExceptionStringTable.FigureMustBeOpenToAppendACubicCurve);
            }
            pathFigureEditor.CubicCurveToAndCloseFigure(q, r);
        }
示例#5
0
        public static int TotalPointCount(PathGeometry geometry)
        {
            int num = 0;

            foreach (PathFigure figure in geometry.Figures)
            {
                num += PathFigureUtilities.PointCount(figure);
            }
            return(num);
        }
示例#6
0
        public void CloseFigureWithLineSegment(int figureIndex)
        {
            PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex);

            if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
            {
                throw new InvalidOperationException(ExceptionStringTable.FigureMustBeOpenToAppendALineSegment);
            }
            pathFigureEditor.CloseWithLineSegment();
        }
示例#7
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));
        }
示例#8
0
        public void AppendQuadraticBezier(Point q, Point r, int figureIndex)
        {
            PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex);

            if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
            {
                throw new InvalidOperationException(ExceptionStringTable.LastFigureMustBeOpenToAppendAQuadraticCurve);
            }
            pathFigureEditor.QuadraticCurveTo(q, r);
        }
示例#9
0
        public static Rect TightExtent(PathGeometry geometry, Matrix matrix)
        {
            if (geometry.Transform != null)
            {
                matrix = geometry.Transform.Value * matrix;
            }
            Rect empty = Rect.Empty;

            foreach (PathFigure figure in geometry.Figures)
            {
                empty.Union(PathFigureUtilities.TightExtent(figure, matrix));
            }
            return(empty);
        }
示例#10
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);
        }
示例#11
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);
     }
 }
示例#12
0
        public static bool CollapseSingleSegmentsToPolySegments(PathGeometry geometry)
        {
            if (geometry == null)
            {
                return(false);
            }
            bool flag = false;

            foreach (PathFigure original in geometry.Figures)
            {
                if (PathFigureUtilities.CollapseSingleSegmentsToPolySegments(original))
                {
                    flag = true;
                }
            }
            return(flag);
        }
示例#13
0
        public static bool EnsureOnlySingleSegmentsInGeometry(PathGeometry geometry)
        {
            if (geometry == null)
            {
                return(false);
            }
            bool flag = false;

            foreach (PathFigure original in geometry.Figures)
            {
                if (PathFigureUtilities.EnsureOnlySingleSegmentsInFigure(original))
                {
                    flag = true;
                }
            }
            return(flag);
        }
示例#14
0
        public static PathGeometry Copy(PathGeometry original, bool applyTransform)
        {
            PathGeometry pathGeometry = new PathGeometry();

            if (pathGeometry.FillRule != original.FillRule)
            {
                pathGeometry.FillRule = original.FillRule;
            }
            if (!applyTransform && original.Transform != null && !original.Transform.Value.IsIdentity)
            {
                pathGeometry.Transform = original.Transform.Clone();
            }
            Transform transformToApply = applyTransform ? original.Transform : (Transform)null;

            foreach (PathFigure original1 in original.Figures)
            {
                pathGeometry.Figures.Add(PathFigureUtilities.Copy(original1, transformToApply));
            }
            return(pathGeometry);
        }
示例#15
0
 public static Point GetPoint(PathFigure pathFigure, int index)
 {
     return(PathFigureUtilities.GetPoint(pathFigure, index, false));
 }
示例#16
0
 public static bool IsOpen(PathFigure figure)
 {
     return(!PathFigureUtilities.IsClosed(figure));
 }
示例#17
0
 public bool IsFigureOpen(int figureIndex)
 {
     return(PathFigureUtilities.IsOpen(this.path.Figures[figureIndex]));
 }
示例#18
0
        private void OpenFit2DFromTo(int first, Vector unitTangentFirst, int last, Vector unitTangentLast, bool onlyCubics)
        {
            int length = last - first + 1;
            int num1   = length - 1;
            PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure);

            if (length == 2)
            {
                if (onlyCubics)
                {
                    double num2 = VectorUtilities.Distance(this.sample[first], this.sample[last]) / 3.0;
                    Point  p1   = this.sample[first] + unitTangentFirst * num2;
                    Point  p2   = this.sample[last] - unitTangentLast * num2;
                    pathFigureEditor.CubicCurveTo(p1, p2, this.sample[last]);
                }
                else
                {
                    pathFigureEditor.LineTo(this.sample[last]);
                }
            }
            else if (length == 3)
            {
                int    index1  = first + 1;
                Vector vector1 = this.sample[first] - this.sample[index1];
                Vector vector2 = this.sample[last] - this.sample[index1];
                Vector vector3 = vector1;
                vector3.Normalize();
                Vector vector4 = vector2;
                vector4.Normalize();
                Vector vector5 = vector3 + vector4;
                Vector vector6;
                if (VectorUtilities.IsZero(vector5))
                {
                    vector6 = this.sample[last] - this.sample[first];
                    vector6.Normalize();
                }
                else
                {
                    vector6 = VectorUtilities.UnitNormal(vector5);
                }
                if (VectorUtilities.Dot(vector6, this.sample[last] - this.sample[first]) < 0.0)
                {
                    vector6 *= -1.0;
                }
                this.OpenFit2DFromTo(first, unitTangentFirst, index1, vector6, onlyCubics);
                int index2 = PathFigureUtilities.PointCount(this.figure) - 1;
                this.OpenFit2DFromTo(index1, vector6, last, unitTangentLast, onlyCubics);
                this.SetupCollinearHandlesConstraint(index2, onlyCubics);
            }
            else
            {
                double[][] numArray1 = new double[length][];
                for (int index = 0; index < length; ++index)
                {
                    numArray1[index] = new double[4];
                }
                double   num2      = 1.0 / (this.chordLength[last] - this.chordLength[first]);
                double[] numArray2 = new double[length];
                for (int index = 0; index <= num1; ++index)
                {
                    numArray2[index] = (this.chordLength[first + index] - this.chordLength[first]) * num2;
                }
                double[] numArray3 = new double[4];
                numArray3[0] = 1.0;
                for (int index1 = 0; index1 <= num1; ++index1)
                {
                    numArray3[1] = 1.0 - numArray2[index1];
                    for (int index2 = 2; index2 <= 3; ++index2)
                    {
                        numArray3[index2] = numArray3[index2 - 1] * numArray3[1];
                    }
                    numArray1[index1][0] = numArray3[3];
                    double num3   = numArray2[index1];
                    int    index3 = 1;
                    while (index3 <= 3)
                    {
                        numArray1[index1][index3] = (double)BezierCurveFitter.pascalTriangle[3][index3] * num3 * numArray3[3 - index3];
                        ++index3;
                        num3 *= numArray2[index1];
                    }
                }
                double[][] numArray4 = new double[4][];
                for (int index = 0; index < 4; ++index)
                {
                    numArray4[index] = new double[4];
                }
                for (int index1 = 0; index1 <= 3; ++index1)
                {
                    for (int index2 = 0; index2 <= index1; ++index2)
                    {
                        for (int index3 = 0; index3 <= num1; ++index3)
                        {
                            numArray4[index1][index2] += numArray1[index3][index2] * numArray1[index3][index1];
                        }
                        if (index1 != index2)
                        {
                            numArray4[index2][index1] = numArray4[index1][index2];
                        }
                    }
                }
                double[][] m = new double[2][]
                {
                    new double[2]
                    {
                        numArray4[1][1],
                        numArray4[1][2] * VectorUtilities.Dot(unitTangentFirst, unitTangentLast)
                    },
                    new double[2]
                    {
                        numArray4[1][2],
                        numArray4[2][2]
                    }
                };
                double[] v           = new double[2];
                Vector[] vectorArray = new Vector[4];
                for (int index1 = 0; index1 < 4; ++index1)
                {
                    for (int index2 = 0; index2 <= num1; ++index2)
                    {
                        vectorArray[index1].X += numArray1[index2][index1] * this.sample[index2 + first].X;
                        vectorArray[index1].Y += numArray1[index2][index1] * this.sample[index2 + first].Y;
                    }
                }
                Vector vector1 = new Vector(this.sample[first].X, this.sample[first].Y);
                Vector vector2 = new Vector(this.sample[last].X, this.sample[last].Y);
                Vector b1      = (numArray4[1][0] + numArray4[1][1]) * vector1 + (numArray4[1][2] + numArray4[1][3]) * vector2 - vectorArray[1];
                v[0] = -VectorUtilities.Dot(unitTangentFirst, b1);
                Vector b2 = (numArray4[2][0] + numArray4[2][1]) * vector1 + (numArray4[2][2] + numArray4[2][3]) * vector2 - vectorArray[2];
                v[1] = -VectorUtilities.Dot(unitTangentLast, b2);
                bool flag = BezierCurveFitter.Solve2By2LinearSystem(m, v);
                int  firstBadVertexInQ = 0;
                if (flag && v[0] > 0.0 && v[1] < 0.0)
                {
                    Point[] controlPoints = new Point[4];
                    controlPoints[0] = this.sample[first];
                    controlPoints[1] = controlPoints[0] + v[0] * unitTangentFirst;
                    controlPoints[3] = this.sample[last];
                    controlPoints[2] = controlPoints[3] + v[1] * unitTangentLast;
                    List <Point> list = new List <Point>(128);
                    BezierCurveFlattener.FlattenCubic(controlPoints, this.distanceTolerance, list, false);
                    double[] cumulatedChordLength = VectorUtilities.GetCumulatedChordLength(list, 0, list.Count - 1);
                    if (VectorUtilities.ArePolylinesClose(list, cumulatedChordLength, 0, list.Count - 1, this.sample, this.chordLength, first, last, this.distanceTolerance, ref firstBadVertexInQ))
                    {
                        pathFigureEditor.CubicCurveTo(controlPoints[1], controlPoints[2], controlPoints[3]);
                        return;
                    }
                }
                int    num4 = (first + last) / 2;
                Vector tangentVectorAtSplit = this.GetUnitTangentVectorAtSplit(num4);
                this.OpenFit2DFromTo(first, unitTangentFirst, num4, tangentVectorAtSplit, onlyCubics);
                int index4 = PathFigureUtilities.PointCount(this.figure) - 1;
                this.OpenFit2DFromTo(num4, tangentVectorAtSplit, last, unitTangentLast, onlyCubics);
                this.SetupCollinearHandlesConstraint(index4, onlyCubics);
            }
        }
示例#19
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);
        }