protected override Size ArrangeOverride(Size finalSize) { if (this.Children.Count > 0) { foreach (var item in Children) { // Arrangement needs to happen. // Measurement needs to be checked. item.Arrange(new Rect(pointCollection.First().X, pointCollection.First().Y, finalSize.Width, finalSize.Height)); break; } } return(finalSize); }
private void DrawShape() { Polygon polygon = new Polygon(); polygon.Fill = Brushes.Blue; polygon.Stroke = Brushes.Red; polygon.StrokeThickness = 2; polygon.Points = points; polygon.MouseMove += ShapeMouseMove; canvas.Children.Add(polygon); Canvas.SetLeft(polygon, 10); Canvas.SetTop(polygon, 10); FirstPoint.Content = points.First().X.ToString() + ", " + points.First().Y.ToString(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var readings = (List <TemperatureReading>)value; var figures = new PathFigureCollection(); var cleanHistory = readings.Where(r => !double.IsNegativeInfinity(r.Temperature)); if (cleanHistory.Count() > 0) { var startTime = cleanHistory.First().Time; var endTime = cleanHistory.Last().Time; var dataHeight = GraphSettings.Max - GraphSettings.Min; var dataWidth = (int)(endTime - startTime).TotalSeconds; var points = new PointCollection(cleanHistory.Select(r => new Point(((r.Time - startTime).TotalSeconds / dataWidth) * GraphSettings.Width, (1 - ((r.Temperature - GraphSettings.Min) / dataHeight)) * GraphSettings.Height))); var figure = new PathFigure() { StartPoint = points.First() }; figure.Segments.Add(new PolyLineSegment(points, true)); figures.Add(figure); } return(figures); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { Point result = new Point(); PointCollection collection = value as PointCollection; if (collection != null && parameter != null && collection.Count > 0) { string converterParameter = parameter.ToString().ToUpper(); int index; if (int.TryParse(converterParameter, out index) && collection.Count < index) { result = collection[index]; } else { switch (converterParameter) { case FirstIndexer: result = collection.First(); break; case LastIndexer: result = collection.Last(); break; } } } return(result); }
// construct a pathfigure from the line segments static PathFigure FromPointCollection(LineSegments ls) { var pc = new PointCollection(ls); var pls = new PolyLineSegment(pc, true); var psc = new PathSegmentCollection(); psc.Add(pls); return(new PathFigure(pc.First(), psc, false)); }
private IEnumerable <Point> GetPolyLineRegion(PointCollection points) { var result = new List <Point>(); var prev = points.First(); for (int i = 1; i < points.Count; i++) { result.AddRange(GetLineRegion(prev, points[i])); prev = points[i]; } return(result.Distinct()); }
public override bool AddEdge(EdgePointID GraphEdge) { if (PointCollection.Contains(GraphEdge.StartPoint) && PointCollection.Contains(GraphEdge.EndPoint)) { // Переназначаем вершины графа на те, что точно содержаться в списке графа. GraphEdge.StartPoint = PointCollection.First(i1 => i1.Name == GraphEdge.StartPoint.Name); GraphEdge.EndPoint = PointCollection.First(i1 => i1.Name == GraphEdge.EndPoint.Name); return base.HashSetEdges.Add(GraphEdge); } else throw new Exception("Graph not contains this combination of points: " + GraphEdge.StartPoint.ToString() + ", " + GraphEdge.EndPoint.ToString()); }
/// <summary> /// Draw Polygon /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void DrawPolygon(object sender, RoutedEventArgs e) { if (lines.Count > 1) { lines.Add(DrawLine(points.First())); CreateNewPolygon(); points.Clear(); foreach (var line in lines) { MainCanvas.Children.Remove(line); } lines.Clear(); return; } }
public MainWindow() { InitializeComponent(); //Node filled Polyline var pointsCollection = new PointCollection(); pointsCollection.Add(new Point(300, 350)); pointsCollection.Add(new Point(330, 300)); pointsCollection.Add(new Point(370, 300)); pointsCollection.Add(new Point(400, 350)); pointsCollection.Add(new Point(370, 400)); pointsCollection.Add(new Point(330, 400)); var pathFigure = new PathFigure() { StartPoint = pointsCollection.First(), Segments = new PathSegmentCollection() { new PolyLineSegment() { Points = pointsCollection } } }; var pathGeometry = new PathGeometry() { Figures = new PathFigureCollection() { pathFigure } }; NodeViewModel node = new NodeViewModel() { ID = "NodeID", OffsetX = 300, OffsetY = 400, UnitWidth = 100, UnitHeight = 100, Shape = pathGeometry, }; (diagram.Nodes as NodeCollection).Add(node); }
public static void DrawSpline(this DrawingContext dc, PointCollection pointCollection, double offsetX, double offsetY, Format format) { pointCollection = PointCollection.Parse( string.Join(" ", pointCollection .Select(x => new Point(x.X + offsetX, x.Y + offsetY)) .Select(x => $"{x.X},{x.Y}")) ); StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext gcx = streamGeometry.Open()) { gcx.BeginFigure(pointCollection.First(), true, true); gcx.PolyLineTo(pointCollection, true, true); } dc.DrawGeometry(format.brushBackground, new Pen(format.brushForeground, format.penWidth), streamGeometry); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { PointCollection pc = value as PointCollection; string symbol = parameter as string; PathGeometry pathgeom = new PathGeometry(); PolyLineSegment ps = new PolyLineSegment() { Points = pc }; PathFigure pf = new PathFigure() { StartPoint = pc.First() }; pf.Segments.Add(ps); pathgeom.Figures.Add(pf); Geometry geom = SymbolMgr.GetStrokeSymbol(symbol).Create(pathgeom); return(geom); }
public Polyline GetCanvasSpline(netDxf.Entities.Spline InputSpline, Vector3 startVector, double canvasHeight) { var transformedControlPointsList = new PointCollection(); foreach (var item in InputSpline.PolygonalVertexes(chordVariable)) { transformedControlPointsList.Add(new Point(item.X - startVector.X, -item.Y + canvasHeight + startVector.Y)); } var g = new StreamGeometry(); StreamGeometryContext gc; using (gc = g.Open()) { gc.BeginFigure( transformedControlPointsList.First(), false, false); gc.PolyLineTo(transformedControlPointsList, false, false); } var path = new Path { Stroke = Brushes.Black, StrokeThickness = 1, Data = g }; //return path; var temp = new Polyline(); temp.Stroke = Brushes.Black; temp.StrokeThickness = 1; temp.Points = transformedControlPointsList; return(temp); }
private static PathFigure CreateSpline(PointCollection points, PointCollection previousPoints) { PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = points[0]; var bezierSegment = new PolyLineSegment(points, true); pathFigure.Segments.Add(bezierSegment); if (previousPoints != null) { var lineSegment = new LineSegment(previousPoints.First(), false); pathFigure.Segments.Add(lineSegment); if (previousPoints.Count > 2) { bezierSegment = new PolyLineSegment(previousPoints, false); pathFigure.Segments.Add(bezierSegment); } else { var polyLineSegment = new PolyLineSegment(previousPoints, false); pathFigure.Segments.Add(polyLineSegment); } lineSegment = new LineSegment(points[0], false); pathFigure.Segments.Add(lineSegment); pathFigure.IsClosed = true; pathFigure.IsFilled = true; } return(pathFigure); }
public static PathGeometry Reposition(ref PointCollection Points) { Random Chance = new Random(); PathGeometry G = new PathGeometry(); PathFigure F = new PathFigure(); PointCollection NewPoints = new PointCollection(); int xMin = Const.MAX_X; int xMax = Const.MIN_X; int yMin = Const.MAX_Y; int yMax = Const.MIN_Y; foreach (Point P in Points) { if (P.X < xMin) { xMin = (int)P.X; } if (P.X > xMax) { xMax = (int)P.X; } if (P.Y < yMin) { yMin = (int)P.Y; } if (P.Y > yMax) { yMax = (int)P.Y; } } int xShift, yShift; bool Left = Chance.Next(0, 1) == 1 ? true : false; if (Left) { xShift = Chance.Next(0, xMin - Const.MIN_X); yShift = Chance.Next(0, yMin - Const.MIN_Y); xShift = 0 - xShift; yShift = 0 - yShift; } else { xShift = Chance.Next(0, Const.MAX_X - xMax); yShift = Chance.Next(0, Const.MAX_Y - yMax); } foreach (Point P in Points) { Point NP = new Point(P.X + xShift, P.Y + yShift); if (NP.X < Const.MIN_X || NP.X > Const.MAX_X || NP.Y < Const.MIN_Y || NP.Y > Const.MAX_Y) { return(null); } if (P == Points.First <Point>()) { F.StartPoint = NP; } else { F.Segments.Add(new LineSegment(NP, false)); } NewPoints.Add(NP); } Points = NewPoints; G.Figures.Add(F); return(G); }