PathFigure CalculateArrow(PathFigure pathfig, Point pt1, Point pt2)
        {
            Matrix matx = new Matrix();



            Vector vect = pt1 - pt2;

            vect.Normalize();
            vect *= ArrowLength;


            PolyLineSegment polyseg = pathfig.Segments[0] as PolyLineSegment;

            polyseg.Points.Clear();
            matx.Rotate(ArrowAngle / 2);

            //added code starts
            //places the position of the arrow on the midpoint
            pt2.X       = (pt2.X + pt1.X) / 2;
            pt2.Y       = (pt2.Y + pt1.Y) / 2;
            MiddlePoint = new Point(pt2.X + 5, pt2.Y);
            //added code ends

            pathfig.StartPoint = pt2 + vect * matx;
            polyseg.Points.Add(pt2);

            matx.Rotate(-ArrowAngle);
            polyseg.Points.Add(pt2 + vect * matx);
            pathfig.IsClosed = IsArrowClosed;

            return(pathfig);
        }
示例#2
0
        private static Geometry CreateUnitGeometry()
        {
            double       x        = 0.15;
            PathGeometry geometry = new PathGeometry();
            PathFigure   item     = new PathFigure {
                IsClosed   = true,
                StartPoint = new PointDouble(x, 0.0)
            };
            PolyLineSegment segment = new PolyLineSegment {
                IsSmoothJoin = false
            };

            segment.Points.Add(new PointDouble(0.5, 0.5 - x));
            segment.Points.Add(new PointDouble(1.0 - x, 0.0));
            segment.Points.Add(new PointDouble(1.0, x));
            segment.Points.Add(new PointDouble(0.5 + x, 0.5));
            segment.Points.Add(new PointDouble(1.0, 1.0 - x));
            segment.Points.Add(new PointDouble(1.0 - x, 1.0));
            segment.Points.Add(new PointDouble(0.5, 0.5 + x));
            segment.Points.Add(new PointDouble(x, 1.0));
            segment.Points.Add(new PointDouble(0.0, 1.0 - x));
            segment.Points.Add(new PointDouble(0.5 - x, 0.5));
            segment.Points.Add(new PointDouble(0.0, x));
            segment.Points.Add(new PointDouble(x, 0.0));
            item.Segments.Add(segment);
            geometry.Figures.Add(item);
            return(geometry);
        }
示例#3
0
        /// <summary>
        /// Altes original, sicherheitshalber noch behalten (zurzeit ungenutzt)
        /// </summary>
        /// <param name="allPointsContainer"></param>
        /// <returns></returns>
        private List <PolyLineSegment> OldPathGeometryToPlsList(PathGeometry allPointsContainer)
        {
            allPointsContainer = allPointsContainer.GetFlattenedPathGeometry(1.0, ToleranceType.Absolute);

            List <PolyLineSegment> allPolyLineSegments = new List <PolyLineSegment>();

            allPointsContainer = allPointsContainer.GetFlattenedPathGeometry(1.0, ToleranceType.Absolute);

            foreach (PathFigure figures in allPointsContainer.Figures)
            {
                List <Point> allPoints = new List <Point>();
                //allPoints.Add(figures.StartPoint);
                //isFirst = false;
                PolyLineSegment segment = (PolyLineSegment)figures.Segments[0];
                allPoints.Add(segment.Points[0]);

                foreach (PathSegment segments in figures.Segments)
                {
                    foreach (Point point in ((PolyLineSegment)segments).Points)
                    {
                        allPoints.Add(point);
                    }
                }
                allPoints.Add(segment.Points[0]); // fügt startpunkt hinzu damit der kreis geschlossen ist
                allPolyLineSegments.Add(new PolyLineSegment(allPoints, true));
            }

            return(allPolyLineSegments);
        }
示例#4
0
        /// <summary>
        /// Writes the specified ArcSegment to the content stream.
        /// </summary>
        internal void WriteSegment(ArcSegment seg)
        {
            if (!DevHelper.FlattenArcSegments)
            {
                int pieces;
                System.Windows.Media.PointCollection points =
                    GeometryHelper.ArcToBezier(this.currentPoint.X, this.currentPoint.Y, seg.Size.Width, seg.Size.Height, seg.RotationAngle, seg.IsLargeArc,
                                               seg.SweepDirection == SweepDirection.Clockwise, seg.Point.X, seg.Point.Y, out pieces);
                if (pieces == 0)
                {
                    // just draw single line
                    WriteLiteral("{0:0.####} {1:0.####} l\n", seg.Point.X, seg.Point.Y);
                    this.currentPoint = seg.Point;
                    return;
                }
                else if (pieces < 0)
                {
                    return;
                }

                int count = points.Count;
                Debug.Assert(count % 3 == 0);
                for (int idx = 0; idx < count - 2; idx += 3)
                {
                    WriteLiteral("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
                                 points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y, points[idx + 2].X, points[idx + 2].Y);
                    this.currentPoint = new Point(points[idx + 2].X, points[idx + 2].Y);
                }
            }
            else
            {
                PolyLineSegment lseg = WpfUtils.FlattenSegment(this.currentPoint, seg);
                WriteSegment(lseg);
            }
        }
示例#5
0
 /// <summary>
 /// 页面加载
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     IsVirtualMark        = new SolidColorBrush(Properties.Settings.Default.MarkVirtualColor);
     NotVirtualMark       = new SolidColorBrush(Properties.Settings.Default.MarkNotColor);
     MarkDiameter         = Properties.Settings.Default.MarkDiameter;
     RouteColor           = new SolidColorBrush(Properties.Settings.Default.RouteColor);
     EVirtualMark.Fill    = IsVirtualMark;
     ENotVirtualMark.Fill = NotVirtualMark;
     RecRoute.Fill        = RouteColor;
     // Create the animation path.
     path                 = new Path();
     path.Stroke          = RouteColor;
     path.StrokeThickness = 3;
     animationPath        = new PathGeometry();
     pFigure              = new PathFigure();
     route                = new PolyLineSegment();
     path.Data            = animationPath;
     pFigure.Segments.Add(route);
     animationPath.Figures.Add(pFigure);
     MapInit();
     //修改日期:2013-12-1
     //修改日期:2013-12-30
     BindWorkLineCombox();
     BindLineCombox(cbRoute_WorkLine.Text.Trim());
     LoadAllMark();
 }
示例#6
0
        /// <summary>
        /// If the path is a single line with different start and end caps, convert the line into an area.
        /// </summary>
        private bool WriteSingleLineStrokeWithSpecialCaps(Path path)
        {
            if (path.StrokeStartLineCap == path.StrokeEndLineCap && path.StrokeStartLineCap != LineCap.Triangle)
            {
                return(false);
            }
            if (path.Data.Figures.Count != 1)
            {
                return(false);
            }
            PathFigure figure = path.Data.Figures[0];

            if (figure.Segments.Count != 1)
            {
                return(false);
            }
            PolyLineSegment polyLineSegment = figure.Segments[0] as PolyLineSegment;

            if (polyLineSegment.Points.Count != 1)
            {
                return(false);
            }

            // TODO: Create a new path that draws the line
            path.GetType();

            return(false);
        }
示例#7
0
 /// <summary>
 /// Writes the specified PolyQuadraticBezierSegment to the content stream.
 /// </summary>
 internal void WriteSegment(PolyQuadraticBezierSegment seg)
 {
     if (!DevHelper.FlattenPolyQuadraticBezierSegment)
     {
         int count = seg.Points.Count;
         PointStopCollection points = seg.Points;
         Point pt0 = this.currentPoint;
         for (int idx = 0; idx < count - 1;)
         {
             Point pt1 = points[idx++];
             Point pt2 = points[idx++];
             // Cannot believe it: I just guessed the formula and it works!
             WriteLiteral("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
                          pt1.X - (pt1.X - pt0.X) / 3, pt1.Y - (pt1.Y - pt0.Y) / 3,
                          pt1.X + (pt2.X - pt1.X) / 3, pt1.Y + (pt2.Y - pt1.Y) / 3,
                          pt2.X, pt2.Y);
             this.currentPoint = pt0 = pt2;
         }
     }
     else
     {
         PolyLineSegment lseg = WpfUtils.FlattenSegment(this.currentPoint, seg);
         WriteSegment(lseg);
     }
 }
        public void Load(byte[] audioData, AudioFormat format)
        {
            this.ClearGraph();
            this.format    = format;
            this.audioData = audioData;
            var graph = new PolyLineSegment();
            int step  = this.GetSampleStep();
            int index = 0;
            int count = 0;

            double yScale = (this.audioCanvas.Height / 2) / short.MaxValue;

            int leftSampleCount       = audioData.Length / 4; //assume 2 channels
            int actualLeftSampleCount = leftSampleCount / (step / 4);

            while (index < audioData.Length)
            {
                short sample = BitConverter.ToInt16(new byte[2] {
                    audioData[index], audioData[index + 1]
                }, 0);
                double yPoint = sample * yScale + (this.audioCanvas.Height / 2);
                double xPoint = count * this.audioCanvas.Width / actualLeftSampleCount;

                graph.Points.Add(new Point()
                {
                    X = xPoint, Y = yPoint
                });
                index += step;
                count++;
            }
            this.figure.Segments.Add(graph);
        }
示例#9
0
        private void draw_calibration()
        {
            Point[] currentWorkoutPoints = new Point[62];

            currentWorkoutPoints[0] = new Point(0, 1);
            for (int i = 0; i < 30; i++)
            {
                currentWorkoutPoints[i * 2 + 1] = new Point((double)i / 30, 1 - speedData[i] / 30);
                currentWorkoutPoints[i * 2 + 2] = new Point((double)(i + 1) / 30, 1 - speedData[i] / 30);
            }
            currentWorkoutPoints[61] = new Point(1, 1);


            var figure = new PathFigure
            {
                StartPoint = currentWorkoutPoints[0],
                IsClosed   = true
            };

            var segment = new PolyLineSegment(currentWorkoutPoints.Skip(1), true);

            figure.Segments.Add(segment);
            polyline.Figures.Clear();
            polyline.Figures.Add(figure);
        }
示例#10
0
        private void AddPolylineInternal(Point[] points, IFeature f, Brush fill, Brush stroke, double strokeWeight, bool addToFeatureList = true)
        {
            if (points.Length == 0) // newly 20131015
            {
                return;
            }
            PathGeometry geometry = new PathGeometry();
            PathFigure   figure   = new PathFigure {
                StartPoint = points.First()
            };
            PolyLineSegment segment = new PolyLineSegment(points, true);

            figure.Segments.Add(segment);
            geometry.Figures.Add(figure);
            GeometryDrawing drawing = new GeometryDrawing(fill, new Pen(stroke, strokeWeight)
            {
                LineJoin = PenLineJoin.Bevel
            }, geometry);

            _drawingGroup.Children.Add(drawing);
            if (addToFeatureList)
            {
                Features.Add(f, drawing);
            }
        }
示例#11
0
        public static PathGeometry MakeLines(List <Point> allPoints)
        {
            PathGeometry myPathGeometry   = new PathGeometry();
            bool         nextIsStartpoint = true;
            Point        startPoint       = new Point();
            PathFigure   pFigure          = new PathFigure();

            foreach (Point point in allPoints)
            {
                if (nextIsStartpoint)
                {
                    startPoint = point;
                }
                else
                {
                    //pFigure.Segments.Add(new LineSegment(point, true));
                    List <PathSegment> endPoint = new List <PathSegment>();
                    PolyLineSegment    myPls    = new PolyLineSegment();
                    myPls.Points.Add(point);
                    endPoint.Add(myPls);

                    myPathGeometry.Figures.Add(new PathFigure(startPoint, endPoint, false));
                    //line.Segments.RemoveAt(0);
                }

                nextIsStartpoint = !nextIsStartpoint;
            }

            return(myPathGeometry);
        }
示例#12
0
        protected override void ConnectFirstLastDataPoints()
        {
            IChartView view        = this.model.GetChartArea().view;
            double     scaleFactor = Math.Abs(view.ZoomWidth - view.ZoomHeight) / 2;

            PathFigure      figure      = null;
            PolyLineSegment lineSegment = null;

            foreach (Point point in SplineHelper.GetSplinePointsConnectingAbsoluteFirstLastDataPoints(this.renderPoints, scaleFactor))
            {
                if (lineSegment == null)
                {
                    figure            = new PathFigure();
                    figure.StartPoint = point;
                    lineSegment       = new PolyLineSegment();

                    continue;
                }

                lineSegment.Points.Add(point);
            }

            if (lineSegment != null)
            {
                figure.Segments.Add(lineSegment);
                this.shapeGeometry.Figures.Add(figure);
            }
        }
        private static Geometry Clip(Vector2 midpoint, Vector2 dir, Size size)
        {
            dir = (Vector2)((dir.Normalized * Math.Max(size.Width, size.Height)) * 2.0);
            Vector2              vector   = new Vector2(-dir.Y, dir.X);
            PathGeometry         geometry = new PathGeometry();
            PathFigureCollection figures  = new PathFigureCollection();
            PathFigure           figure   = new PathFigure();

            figure.IsClosed   = (true);
            figure.StartPoint = ((Point)midpoint);
            PathSegmentCollection segments = new PathSegmentCollection();
            PolyLineSegment       segment  = new PolyLineSegment();
            PointCollection       points   = new PointCollection();

            points.Add((Point)(midpoint + vector));
            points.Add((Point)((midpoint + vector) + dir));
            points.Add((Point)((midpoint - vector) + dir));
            points.Add((Point)(midpoint - vector));
            segment.Points = (points);
            segments.Add(segment);
            figure.Segments = (segments);
            figures.Add(figure);
            geometry.Figures = (figures);
            return(geometry);
        }
        protected override void UpdateData()
        {
            var geometry = (PathGeometry)Data;
            geometry.Figures.Clear();

            if (ParentMap != null && Locations != null && Locations.Any())
            {
                var points = Locations.Select(l => ParentMap.MapTransform.Transform(l));

                var figure = new PathFigure
                {
                    StartPoint = points.First(),
                    IsClosed = IsClosed,
                    IsFilled = IsClosed
                };

                var segment = new PolyLineSegment();

                foreach (var point in points.Skip(1))
                {
                    segment.Points.Add(point);
                }

                figure.Segments.Add(segment);
                geometry.Figures.Add(figure);
                geometry.Transform = ParentMap.ViewportTransform;
            }
            else
            {
                geometry.ClearValue(Geometry.TransformProperty);
            }
        }
示例#15
0
        public static PathFigure DrawArrowHead(Point startPoint, Point endPoint, double arrowLength = 10)
        {
            PathFigure pathFigure = new PathFigure()
            {
                StartPoint = endPoint,
            };
            double cos30 = 0.866;
            double sin30 = 0.5;
            double w     = arrowLength * cos30;
            double h     = arrowLength * sin30;

            double d  = Utility.DrawingAids.Distance(startPoint, endPoint);
            double Xn = (endPoint.X - startPoint.X) / d;
            double Yn = (endPoint.Y - startPoint.Y) / d;

            double X3 = endPoint.X - w * Xn - h * Yn;
            double Y3 = endPoint.Y - w * Yn + h * Xn;

            double X4 = endPoint.X - w * Xn + h * Yn;
            double Y4 = endPoint.Y - w * Yn - h * Xn;

            PolyLineSegment segment = new PolyLineSegment();

            pathFigure.Segments.Add(segment);

            segment.Points.Add(new Point(X3, Y3));
            segment.Points.Add(endPoint);
            segment.Points.Add(new Point(X4, Y4));
            segment.Points.Add(endPoint);

            return(pathFigure);
        }
示例#16
0
        private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            PointListPair plp         = (PointListPair)e.UserState;
            List <Point>  points1     = plp.points1;
            List <Point>  points2     = plp.points2;
            GeometryGroup geomGroup   = new GeometryGroup();
            Point         startPoint1 = points1[0];

            points1.RemoveAt(0);
            PolyLineSegment polyLnSeg1 = new PolyLineSegment(points1, true);
            PathFigure      pathFig1   = new PathFigure(startPoint1, new PathSegment[] { polyLnSeg1 }, false);
            PathGeometry    pathGeom1  = new PathGeometry(new PathFigure[] { pathFig1 });

            geomGroup.Children.Add(pathGeom1);
            if (points2 != null && points2.Count > 1)
            {
                Point startPoint2 = points2[0];
                points2.RemoveAt(0);
                PolyLineSegment polyLnSeg2 = new PolyLineSegment(points2, true);
                PathFigure      pathFig2   = new PathFigure(startPoint2, new PathSegment[] { polyLnSeg2 }, false);
                PathGeometry    pathGeom2  = new PathGeometry(new PathFigure[] { pathFig2 });
                geomGroup.Children.Add(pathGeom2);
            }
            GeometryDrawing geomDrawing = new GeometryDrawing(null, OscilloscopePen, geomGroup);

            host.DrawDrawing(geomDrawing);
        }
示例#17
0
        private void DrawPass()
        {
            bezie = new PolyLineSegment();
            if (start == finish)
            {
                return;
            }
            List <Station> currentLine = map[start.Line];

            int GoFrom, GoTo;

            if (start.Line == finish.Line)
            {
                GoFrom = currentLine.IndexOf(start);
                GoTo   = currentLine.IndexOf(finish);
                MoveByLine(currentLine, GoFrom, GoTo, bezie);
            }
            else
            {
                string passLine = start.Line + '_' + finish.Line;
                string point    = passStations.Find(s => s.Line == passLine).Name; //Name of passage station in starting Line
                GoFrom = currentLine.IndexOf(start);
                GoTo   = currentLine.FindIndex(s => s.Name == point);
                MoveByLine(currentLine, GoFrom, GoTo, bezie);



                currentLine = map[finish.Line];
                passLine    = finish.Line + '_' + start.Line;
                point       = passStations.Find(s => s.Line == passLine).Name;
                GoFrom      = currentLine.FindIndex(s => s.Name == point);
                GoTo        = currentLine.IndexOf(finish);
                MoveByLine(currentLine, GoFrom, GoTo, bezie);
            }
        }
示例#18
0
        /// <summary>
        /// Creates the geometry for the path from the given GeneralPath.
        /// </summary>
        private Geometry CreateGeometry(GeneralPath gp)
        {
            PolyLineSegment pl     = new PolyLineSegment();
            PathFigure      figure = new PathFigure {
                Segments = { pl }
            };

            // create path
            if (gp != null)
            {
                var cursor = gp.CreateCursor();
                if (cursor.MoveNext())
                {
                    figure.StartPoint = cursor.CurrentEndPoint;
                }
                // loop all bends of the edge
                while (cursor.MoveNext())
                {
                    pl.Points.Add(cursor.CurrentEndPoint);
                }
            }

            return(new PathGeometry {
                Figures = { figure }
            });
        }
        /// <summary>
        /// Creates a brush to paint half-filled mod annotations, to denote mod localization ambiguity
        /// </summary>
        private static TileBrush GetPatternedTileBrush(SolidColorBrush brushColor)
        {
            PolyLineSegment triangleLinesSegment = new PolyLineSegment();

            triangleLinesSegment.Points.Add(new Point(50, 0));
            triangleLinesSegment.Points.Add(new Point(0, 50));
            PathFigure triangleFigure = new PathFigure();

            triangleFigure.IsClosed   = true;
            triangleFigure.StartPoint = new Point(0, 0);
            triangleFigure.Segments.Add(triangleLinesSegment);
            PathGeometry triangleGeometry = new PathGeometry();

            triangleGeometry.Figures.Add(triangleFigure);

            GeometryDrawing triangleDrawing = new GeometryDrawing();

            triangleDrawing.Geometry = triangleGeometry;
            triangleDrawing.Brush    = brushColor;
            Pen trianglePen = new Pen(Brushes.Black, 2);

            triangleDrawing.Pen    = trianglePen;
            trianglePen.MiterLimit = 0;
            triangleDrawing.Freeze();

            DrawingBrush tileBrushWithTiling = new DrawingBrush();

            tileBrushWithTiling.Drawing  = triangleDrawing;
            tileBrushWithTiling.TileMode = TileMode.None;

            //tileBrushWithTiling.Viewport = new Rect(0, 0, 0.5, 0.5);

            return(tileBrushWithTiling);
        }
示例#20
0
        public Visual Draw(Curve item, Axis xAxis, Axis yAxis, string side)
        {
            var dv      = new DrawingVisual();
            var dc      = dv.RenderOpen();
            var pointXs = xAxis.Map(item.F);
            var pointYs = yAxis.Map(item.V);

            var pathFigure = new PathFigure
            {
                StartPoint = new Point(pointXs[0], pointYs[0]),
                IsClosed   = false,
                IsFilled   = false
            };
            var polyLine = new PolyLineSegment();

            for (int i = 0; i < pointXs.Length; i++)
            {
                polyLine.Points.Add(new Point(pointXs[i], pointYs[i]));
            }
            pathFigure.Segments.Add(polyLine);

            var pathGeometry = new PathGeometry();

            pathGeometry.Figures.Add(pathFigure);

            var brush     = this.resourceProvider.GetCurveBrush(item, side);
            var thickness = this.resourceProvider.GetCurveThickness(item, side);

            dc.DrawGeometry(brush, new Pen(brush, thickness), pathGeometry);
            dc.Close();

            return(dv);
        }
示例#21
0
        private DrawingVisual Create()
        {
            countCreate++;

            var square = new DrawingVisualFx();

            using (DrawingContext dc = square.RenderOpen())
            {
                dc.DrawEllipse(null, Stroke, new Point(Width / 2, Height / 2), Width / 2 + Stroke.Thickness / 2, Height / 2 + Stroke.Thickness / 2);

                if (Angle.HasValue)
                {
                    dc.PushTransform(new RotateTransform(Angle.Value, Width / 2, Height / 2));
                    {
                        PolyLineSegment polySeg = new PolyLineSegment(new Point[] { new Point(Width * 0.2, Height * 0.3), new Point(Width * 0.8, Height * 0.3) }, true);
                        PathFigure      pathFig = new PathFigure(new Point(Width * 0.5, -Height * 0.22), new PathSegment[] { polySeg }, true);
                        PathGeometry    pathGeo = new PathGeometry(new PathFigure[] { pathFig });
                        dc.DrawGeometry(Brushes.AliceBlue, StrokeArrow, pathGeo);
                    }
                    dc.Pop();
                }

                dc.DrawEllipse(Background, null, new Point(Width / 2, Height / 2), Width / 2, Height / 2);
                dc.DrawText(FText, new Point(Width / 2 - FText.Width / 2, Height / 2 - FText.Height / 2));
            }

            return(square);
        }
示例#22
0
        private void CreateProgressIndicator()
        {
            if (progressCanvas == null)
            {
                return;
            }

            const double xLocation = 0.0d;

            progressLine.X1 = xLocation;
            progressLine.X2 = xLocation;
            progressLine.Y1 = timelineCanvas.RenderSize.Height;
            progressLine.Y2 = progressCanvas.RenderSize.Height;

            PolyLineSegment indicatorPolySegment = new PolyLineSegment();

            indicatorPolySegment.Points.Add(new Point(xLocation, timelineCanvas.RenderSize.Height));
            indicatorPolySegment.Points.Add(new Point(xLocation - indicatorTriangleWidth, timelineCanvas.RenderSize.Height - indicatorTriangleWidth));
            indicatorPolySegment.Points.Add(new Point(xLocation + indicatorTriangleWidth, timelineCanvas.RenderSize.Height - indicatorTriangleWidth));
            indicatorPolySegment.Points.Add(new Point(xLocation, timelineCanvas.RenderSize.Height));
            PathGeometry indicatorGeometry = new PathGeometry();
            PathFigure   indicatorFigure   = new PathFigure();

            indicatorFigure.Segments.Add(indicatorPolySegment);
            indicatorGeometry.Figures.Add(indicatorFigure);

            progressIndicator.Data = indicatorGeometry;
            UpdateProgressIndicator();
        }
示例#23
0
        /// <summary>
        /// Creates List of geometries for underline
        /// </summary>
        /// <returns>List of Geometries</returns>
        public Geometry  BottomEdgeRectangleGeometry()
        {
            PathGeometry  pg = (PathGeometry)mOrginalGeometry;
            GeometryGroup gg = new GeometryGroup();

            foreach (PathFigure fg in pg.Figures)
            {
                PolyLineSegment       pls       = (PolyLineSegment)fg.Segments[0];
                PointCollectionHelper pch       = new PointCollectionHelper(pls.Points, fg.StartPoint);
                List <double>         distinctY = pch.DistinctY;
                for (int i = 0; i < distinctY.Count - 1; i++)
                {
                    double bottom = distinctY[i + 1] - 3;
                    double top    = bottom + 2;
                    // ordered values of X that are present for both Y values
                    List <double> rlMatches = pch.XAtY(distinctY[i], distinctY[i + 1]);
                    double        left      = rlMatches[0];
                    double        right     = rlMatches[rlMatches.Count - 1];

                    PathGeometry rpg = CreateGeometry(top, bottom, left, right);
                    gg.Children.Add(rpg);
                }
            }
            return(gg);
        }
示例#24
0
        private void ReadLines(string pathAsString, ref int currentIndex, ref Point lastAbsolutePosition, PathFigure currentFigure, bool relative)
        {
            PointCollection points = new PointCollection();

            while (true)
            {
                while (currentIndex < pathAsString.Length && pathAsString[currentIndex] == ' ')
                {
                    ++currentIndex;
                }
                if (currentIndex < pathAsString.Length && !_commandCharacters.Contains(pathAsString[currentIndex]))
                {
                    Point point = GetPoint(pathAsString, currentIndex, out currentIndex);
                    if (relative)
                    {
                        point.X = point.X + lastAbsolutePosition.X;
                        point.Y = point.Y + lastAbsolutePosition.Y;
                    }
                    points.Add(point);
                    lastAbsolutePosition.X = point.X;
                    lastAbsolutePosition.Y = point.Y;
                }
                else
                {
                    break;
                }
            }
            if (points.Count > 0)
            {
                PolyLineSegment polyLineSegment = new PolyLineSegment();
                polyLineSegment.Points = new PointCollection();
                polyLineSegment.Points = points;
                currentFigure.Segments.Add(polyLineSegment);
            }
        }
        protected override void UpdateData()
        {
            var geometry = (PathGeometry)Data;

            geometry.Figures.Clear();

            if (ParentMap != null && Locations != null && Locations.Any())
            {
                var points = Locations.Select(l => ParentMap.MapProjection.LocationToPoint(l));

                var figure = new PathFigure
                {
                    StartPoint = points.First(),
                    IsClosed   = IsClosed,
                    IsFilled   = IsClosed
                };

                var segment = new PolyLineSegment();

                foreach (var point in points.Skip(1))
                {
                    segment.Points.Add(point);
                }

                figure.Segments.Add(segment);
                geometry.Figures.Add(figure);
            }
        }
示例#26
0
        private static void ProcessFigure(List <Point> points, GeneralTransform transform, PathGeometry geometry)
        {
            if (points.Count == 0)
            {
                return;
            }
            var result = new PolyLineSegment();
            var prev   = points[0];

            for (int i = 1; i < points.Count; ++i)
            {
                var current = points[i];
                if (current == prev)
                {
                    continue;
                }
                result.Points.Add(transform.Transform(current));
                prev = current;
            }
            if (result.Points.Count == 0)
            {
                return;
            }
            geometry.Figures.Add(new PathFigure(transform.Transform(points[0]), new PathSegment[] { result }, true));
        }
示例#27
0
 public Star()
 {
     pg  = new PathGeometry();
     pf  = new PathFigure();
     pls = new PolyLineSegment();
     pg.Figures.Add(pf);
 }
示例#28
0
        private static List <Point> GetOrdinateOnPathFigureByAbscissa(PathFigure figure, double abscissa)
        {
            List <Point> outputPoints = new List <Point>();
            Point        current      = figure.StartPoint;

            foreach (PathSegment s in figure.Segments)
            {
                PolyLineSegment segment = s as PolyLineSegment;
                LineSegment     line    = s as LineSegment;
                Point[]         points;
                if (segment != null)
                {
                    points = segment.Points.ToArray();
                }
                else if (line != null)
                {
                    points = new[] { line.Point };
                }
                else
                {
                    throw new InvalidOperationException();
                }
                foreach (Point next in points)
                {
                    if (TryGetOrdinateOnVectorByAbscissa(current, next, abscissa, out double ordinate))
                    {
                        outputPoints.Add(new Point(abscissa, ordinate));
                    }
                    current = next;
                }
            }
            return(outputPoints);
        }
示例#29
0
        private static Tuple <Point, double> GetClosestPointOnPathFigure(PathFigure figure, Point p)
        {
            List <Tuple <Point, double> > closePoints = new List <Tuple <Point, double> >();
            Point current = figure.StartPoint;

            foreach (PathSegment s in figure.Segments)
            {
                PolyLineSegment segment = s as PolyLineSegment;
                LineSegment     line    = s as LineSegment;
                Point[]         points;
                if (segment != null)
                {
                    points = segment.Points.ToArray();
                }
                else if (line != null)
                {
                    points = new[] { line.Point };
                }
                else
                {
                    throw new InvalidOperationException();
                }
                foreach (Point next in points)
                {
                    Point  closestPoint = GetClosestPointOnLine(current, next, p);
                    double d            = (closestPoint - p).LengthSquared;
                    closePoints.Add(new Tuple <Point, double>(closestPoint, d));
                    current = next;
                }
            }
            return(closePoints.OrderBy(t => t.Item2).First());
        }
示例#30
0
        protected virtual void DrawLine(Canvas canvas)
        {
            Path path = new Path();

            path.Style = this.PathStyle;

            PolyLineSegment pls = new PolyLineSegment();

            for (int i = 0; i < this.xAxis.Count; i++)
            {
                double x = this.xAxis[i];

                double y = this.Data[i];

                y = this.GetMapY(i, y);

                //  Do :添加曲线
                pls.Points.Add(new Point(this.GetX(x), this.GetY(y)));
            }

            PathFigure pf = new PathFigure();

            pf.StartPoint = pls.Points.FirstOrDefault();
            pf.Segments.Add(pls);

            PathGeometry pg = new PathGeometry(new List <PathFigure>()
            {
                pf
            });

            path.Data = pg;

            this.Children.Add(path);
        }
示例#31
0
        /// <summary>
        /// Converts a PolyQuadraticBezierSegment into a PolyLineSegment because I currently have no muse to calculate
        /// the correct Bézier curves.
        /// </summary>
        public static PolyLineSegment FlattenSegment(
            Point startPoint,
            PolyQuadraticBezierSegment seg)
        {
            var geo = new PathGeometry();
            var fig = new PathFigure();

            geo.Figures.Add(fig);
            fig.StartPoint = new Point(startPoint.X, startPoint.Y);
            int count  = seg.Points.Count;
            var points = new Point[count];

            for (int idx = 0; idx < count - 1; idx += 2)
            {
                var qbseg = new QuadraticBezierSegment(
                    new Point(seg.Points[idx].X, seg.Points[idx].Y),
                    new Point(seg.Points[idx + 1].X, seg.Points[idx + 1].Y), seg.IsStroked);
                fig.Segments.Add(qbseg);
            }
            geo = geo.GetFlattenedPathGeometry();
            fig = geo.Figures[0];
            var lineSeg   = (PolyLineSegment)fig.Segments[0];
            var resultSeg = new PolyLineSegment();

            foreach (var point in lineSeg.Points)
            {
                resultSeg.Points.Add(new Point(point.X, point.Y));
            }
            return(resultSeg);
        }
示例#32
0
        /// <summary>
        /// Generate PathGeometry object with curved Path using supplied route points
        /// </summary>
        /// <param name="points">Route points</param>
        /// <param name="tension"></param>
        /// <param name="tolerance"></param>
        /// <returns></returns>
        public static PolyLineSegment GetCurveThroughPoints(Point[] points, Double tension, Double tolerance)
        {
            Debug.Assert(points != null);
            Debug.Assert(points.Length >= 2);
            Debug.Assert(tolerance > 0);

            var oPolyLineSegment = new PolyLineSegment();

            if (points.Length == 2)
            {
                AddPointsToPolyLineSegment(oPolyLineSegment, points[0], points[0],
                    points[1], points[1], tension, tolerance);
            }
            else
            {
                var iPoints = points.Length;

                for (var i = 0; i < iPoints; i++)
                {
                    if (i == 0)
                    {
                        AddPointsToPolyLineSegment(oPolyLineSegment, points[0],
                            points[0], points[1], points[2], tension, tolerance);
                    }

                    else if (i == iPoints - 2)
                    {
                        AddPointsToPolyLineSegment(oPolyLineSegment, points[i - 1],
                            points[i], points[i + 1], points[i + 1], tension,
                            tolerance);
                    }
                    else if (i != iPoints - 1)
                    {
                        AddPointsToPolyLineSegment(oPolyLineSegment, points[i - 1],
                            points[i], points[i + 1], points[i + 2], tension,
                            tolerance);
                    }
                }
                oPolyLineSegment.Points.Insert(0, points[0]);
            }

            return oPolyLineSegment;
        }
        protected override void UpdateData()
        {
            var geometry = (PathGeometry)Data;
            var locations = Locations;
            Location first;

            if (ParentMap != null && locations != null && (first = locations.FirstOrDefault()) != null)
            {
                var figure = new PathFigure
                {
                    StartPoint = ParentMap.MapTransform.Transform(first),
                    IsClosed = IsClosed,
                    IsFilled = IsClosed
                };

                var segment = new PolyLineSegment();

                foreach (var location in locations.Skip(1))
                {
                    segment.Points.Add(ParentMap.MapTransform.Transform(location));
                }

                if (segment.Points.Count > 0)
                {
                    figure.Segments.Add(segment);
                }

                geometry.Figures.Clear();
                geometry.Figures.Add(figure);
                geometry.Transform = ParentMap.ViewportTransform;
            }
            else
            {
                geometry.Figures.Clear();
                geometry.ClearValue(Geometry.TransformProperty);
            }
        }
示例#34
0
        /// <summary>
        /// Adds a polygon to this path.
        /// </summary>
        public void AddPolygon(XPoint[] points)
        {
#if CORE
            int count = points.Length;
            if (count == 0)
                return;

            _corePath.MoveTo(points[0].X, points[0].Y);
            for (int idx = 0; idx < count - 1; idx++)
                _corePath.LineTo(points[idx].X, points[idx].Y, false);
            _corePath.LineTo(points[count - 1].X, points[count - 1].Y, true);
            _corePath.CloseSubpath();
#endif
#if GDI
            try
            {
                Lock.EnterGdiPlus();
                _gdipPath.AddPolygon(XGraphics.MakePointFArray(points));
            }
            finally { Lock.ExitGdiPlus(); }
#endif
#if WPF || NETFX_CORE
#if !SILVERLIGHT && !NETFX_CORE
            _pathGeometry.AddGeometry(GeometryHelper.CreatePolygonGeometry(XGraphics.MakePointArray(points), XFillMode.Alternate, true));
#else
            var figure = new PathFigure();
            figure.StartPoint = new SysPoint(points[0].X, points[0].Y);
            figure.IsClosed = true;

            PolyLineSegment segment = new PolyLineSegment();
            int count = points.Length;
            // For correct drawing the start point of the segment must not be the same as the first point.
            for (int idx = 1; idx < count; idx++)
                segment.Points.Add(new SysPoint(points[idx].X, points[idx].Y));
#if !SILVERLIGHT && !NETFX_CORE
            seg.IsStroked = true;
#endif
            figure.Segments.Add(segment);
            _pathGeometry.Figures.Add(figure);
#endif
            // TODO: NOT NEEDED
            //CloseFigure(); // StartFigure() isn't needed because AddGeometry() implicitly starts a new figure, but CloseFigure() is needed for the next adding not to continue this figure.
#endif
        }
 /// <summary>
 /// Returns new PolyLineSegment by easing startValue to endValue using a time percentage 0 -> 1.
 /// </summary>
 /// <example>XAML: Points="50,100 50,150"</example>
 /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.polylinesegment.aspx"/>
 public static PolyLineSegment EaseValue(PolyLineSegment startValue, PolyLineSegment endValue, double percent)
 {
     return new PolyLineSegment
     {
         Points = EaseValue(startValue.Points, endValue.Points, percent),
     };
 }
示例#36
0
        /// <summary>
        /// Creates a path geometry from a polygon.
        /// </summary>
        public static PathGeometry CreatePolygonGeometry(SysPoint[] points, XFillMode fillMode, bool closed)
        {
            PolyLineSegment seg = new PolyLineSegment();
            int count = points.Length;
            // For correct drawing the start point of the segment must not be the same as the first point.
            for (int idx = 1; idx < count; idx++)
                seg.Points.Add(new SysPoint(points[idx].X, points[idx].Y));
#if !SILVERLIGHT &&  !NETFX_CORE
            seg.IsStroked = true;
#endif
            PathFigure fig = new PathFigure();
            fig.StartPoint = new SysPoint(points[0].X, points[0].Y);
            fig.Segments.Add(seg);
            fig.IsClosed = closed;
            PathGeometry geo = new PathGeometry();
            geo.FillRule = fillMode == XFillMode.Winding ? FillRule.Nonzero : FillRule.EvenOdd;
            geo.Figures.Add(fig);
            return geo;
        }
示例#37
0
        /// <summary>
        /// Creates a path geometry from a polygon.
        /// </summary>
        public static PolyLineSegment CreatePolyLineSegment(SysPoint[] points, XFillMode fillMode, bool closed)
        {
            PolyLineSegment seg = new PolyLineSegment();
            int count = points.Length;
            // For correct drawing the start point of the segment must not be the same as the first point.
            for (int idx = 1; idx < count; idx++)
                seg.Points.Add(new SysPoint(points[idx].X, points[idx].Y));
#if !SILVERLIGHT && !NETFX_CORE
            seg.IsStroked = true;
#endif
            return seg;
        }
示例#38
0
        private static void AddPointsToPolyLineSegment(PolyLineSegment oPolyLineSegment, Point oPoint0, Point oPoint1, Point oPoint2, Point oPoint3, Double dTension, Double dTolerance)
        {
            Debug.Assert(oPolyLineSegment != null);
            Debug.Assert(dTolerance > 0);

            var iPoints = (Int32)((Math.Abs(oPoint1.X - oPoint2.X) +
                Math.Abs(oPoint1.Y - oPoint2.Y)) / dTolerance);

            var oPolyLineSegmentPoints = oPolyLineSegment.Points;

            if (iPoints <= 2)
            {
                oPolyLineSegmentPoints.Add(oPoint2);
            }
            else
            {
                var dSx1 = dTension * (oPoint2.X - oPoint0.X);
                var dSy1 = dTension * (oPoint2.Y - oPoint0.Y);
                var dSx2 = dTension * (oPoint3.X - oPoint1.X);
                var dSy2 = dTension * (oPoint3.Y - oPoint1.Y);

                var dAx = dSx1 + dSx2 + 2 * oPoint1.X - 2 * oPoint2.X;
                var dAy = dSy1 + dSy2 + 2 * oPoint1.Y - 2 * oPoint2.Y;
                var dBx = -2 * dSx1 - dSx2 - 3 * oPoint1.X + 3 * oPoint2.X;
                var dBy = -2 * dSy1 - dSy2 - 3 * oPoint1.Y + 3 * oPoint2.Y;

                var dCx = dSx1;
                var dCy = dSy1;
                var dDx = oPoint1.X;
                var dDy = oPoint1.Y;

                // Note that this starts at 1, not 0.

                for (var i = 1; i < iPoints; i++)
                {
                    var t = (Double)i / (iPoints - 1);

                    var oPoint = new Point(
                        dAx * t * t * t + dBx * t * t + dCx * t + dDx,
                        dAy * t * t * t + dBy * t * t + dCy * t + dDy
                        );

                    oPolyLineSegmentPoints.Add(oPoint);
                }

            }
        }
示例#39
-1
        public PathGeometry CloneDeep(PathGeometry pathGeometry)
        {
            var newPathGeometry = new PathGeometry();
            foreach (var figure in pathGeometry.Figures)
            {
                var newFigure = new PathFigure();
                newFigure.StartPoint = figure.StartPoint;
                // Even figures have to be deep cloned. Assigning them directly will result in
                //  an InvalidOperationException being thrown with the message "Element is already the child of another element."
                foreach (var segment in figure.Segments)
                {
                    // I only impemented cloning the abstract PathSegments to one implementation, 
                    //  the PolyLineSegment class. If your paths use other kinds of segments, you'll need
                    //  to implement that kind of coding yourself.
                    var segmentAsPolyLineSegment = segment as PolyLineSegment;
                    if (segmentAsPolyLineSegment != null)
                    {
                        var newSegment = new PolyLineSegment();
                        foreach (var point in segmentAsPolyLineSegment.Points)
                        {
                            newSegment.Points.Add(point);
                        }
                        newFigure.Segments.Add(newSegment);
                    }

                    var segmentAsLineSegment = segment as LineSegment;
                    if (segmentAsLineSegment != null)
                    {
                        var newSegment = new LineSegment();
                        newSegment.Point = segmentAsLineSegment.Point;
                        newFigure.Segments.Add(newSegment);
                    }

                    var segmentAsArcSegment = segment as ArcSegment;
                    if (segmentAsArcSegment != null)
                    {
                        var newSegment = new ArcSegment();
                        newSegment.Point = segmentAsArcSegment.Point;
                        newSegment.SweepDirection = segmentAsArcSegment.SweepDirection;
                        newSegment.RotationAngle = segmentAsArcSegment.RotationAngle;
                        newSegment.IsLargeArc = segmentAsArcSegment.IsLargeArc;
                        newSegment.Size = segmentAsArcSegment.Size;
                        newFigure.Segments.Add(newSegment);
                    }
                }
                newPathGeometry.Figures.Add(newFigure);
            }
            return newPathGeometry;
        }