Ejemplo n.º 1
0
        public void Add(Point pt, long time)
        {
            if (this.current.points.Count > 0 && VectorUtilities.ArePathPointsVeryClose(this.current.points[this.current.points.Count - 1], pt))
            {
                return;
            }
            this.current.points.Add(pt);
            int count = this.current.points.Count;

            if (count >= 3)
            {
                this.current.endTangent.X = 0.0;
                this.current.endTangent.Y = 0.0;
                for (int index = Math.Max(0, count - 6); index < count - 1; ++index)
                {
                    this.current.endTangent += (this.current.points[count - 1] - this.current.points[index]) / (double)(count - 1 - Math.Max(0, count - 6));
                }
                if (this.IsSamplePointACorner(this.current.points[count - 3], this.current.points[count - 2], this.current.points[count - 1], Math.Cos(2.0 * Math.PI * (this.cornerTolerance / 360.0))))
                {
                    this.current.points.RemoveAt(this.current.points.Count - 1);
                    this.current.endTangent = new Vector(0.0, 0.0);
                    this.FitSegments(new PathGeometryEditor(this.path), this.current);
                    this.current.cornerSegment = true;
                    this.current.prevBezier    = (IncrementalFitter.IncrementalFittingData)null;
                    this.current.points.Clear();
                    this.current.points.Add(pt);
                }
            }
            if (this.current.points.Count < 4)
            {
                return;
            }
            Point[] bezierFit1 = this.ComputeBezierFit(this.current);
            if (this.ComputeMaxError(this.current.points, bezierFit1) <= this.curveTolerance)
            {
                return;
            }
            if (this.current.prevBezier != null)
            {
                PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(this.path);
                Point[]            bezierFit2         = this.ComputeBezierFit(this.current.prevBezier);
                if (PathGeometryUtilities.IsEmpty(pathGeometryEditor.PathGeometry))
                {
                    pathGeometryEditor.StartFigure(bezierFit2[0]);
                }
                pathGeometryEditor.AppendCubicBezier(bezierFit2[1], bezierFit2[2], bezierFit2[3]);
            }
            this.current.prevBezier            = (IncrementalFitter.IncrementalFittingData) this.current.Clone();
            this.current.prevBezier.prevBezier = (IncrementalFitter.IncrementalFittingData)null;
            this.current.cornerSegment         = false;
            this.current.startTangent          = bezierFit1[2] - bezierFit1[3];
            this.current.startTangent.Normalize();
            this.current.points.Clear();
            this.current.points.Add(pt);
        }
Ejemplo n.º 2
0
 private void FitSegments(PathGeometryEditor pathEditor, IncrementalFitter.IncrementalFittingData data)
 {
     Point[] pointArray = (Point[])null;
     if (data.points.Count > 3)
     {
         pointArray = this.ComputeBezierFit(data);
     }
     if (data.prevBezier != null)
     {
         Point[] bezierFit = this.ComputeBezierFit(data.prevBezier);
         if (PathGeometryUtilities.IsEmpty(pathEditor.PathGeometry))
         {
             pathEditor.StartFigure(bezierFit[0]);
         }
         pathEditor.AppendCubicBezier(bezierFit[1], bezierFit[2], bezierFit[3]);
     }
     if (data.points.Count == 2)
     {
         if (PathGeometryUtilities.IsEmpty(pathEditor.PathGeometry))
         {
             pathEditor.StartFigure(data.points[0]);
         }
         pathEditor.AppendLineSegment(data.points[1]);
     }
     else if (data.points.Count == 3)
     {
         if (PathGeometryUtilities.IsEmpty(pathEditor.PathGeometry))
         {
             pathEditor.StartFigure(data.points[0]);
         }
         pathEditor.AppendQuadraticBezier(data.points[1], data.points[2]);
     }
     else
     {
         if (data.points.Count <= 3)
         {
             return;
         }
         if (PathGeometryUtilities.IsEmpty(pathEditor.PathGeometry))
         {
             pathEditor.StartFigure(pointArray[0]);
         }
         pathEditor.AppendCubicBezier(pointArray[1], pointArray[2], pointArray[3]);
     }
 }
Ejemplo n.º 3
0
        public static PathGeometry RemoveMapping(PathGeometry original, bool preserveOriginal)
        {
            if (original == null || original.Figures.Count == 0)
            {
                return(original);
            }
            PathGeometry pathGeometry = preserveOriginal ? PathGeometryUtilities.Copy(original, false) : original;

            foreach (PathFigure pathFigure in pathGeometry.Figures)
            {
                pathFigure.ClearValue(PathFigureUtilities.FigureMappingProperty);
                foreach (DependencyObject dependencyObject in pathFigure.Segments)
                {
                    dependencyObject.ClearValue(PathFigureUtilities.SegmentMappingProperty);
                }
            }
            return(pathGeometry);
        }
Ejemplo n.º 4
0
 public static Rect TightExtent(PathGeometry geometry)
 {
     return(PathGeometryUtilities.TightExtent(geometry, Matrix.Identity));
 }