/// <summary> Gets the geometry from string. /// </summary> /// <param name="text">The text.</param> /// <returns></returns> public static Geometry GetGeometry(string text) { if (String.IsNullOrEmpty(text)) { return(null); } if (text.StartsWith(GeometryType.Path.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Path.ToString().Length + 1); GeometryConverter conv = new GeometryConverter(); StreamGeometry streamGeometry = (StreamGeometry)conv.ConvertFrom(content); PathGeometry geometry = streamGeometry.GetFlattenedPathGeometry(); return(geometry); } else if (text.StartsWith(GeometryType.Rectangle.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Rectangle.ToString().Length + 1); string[] contents = content.Split(','); RectangleGeometry geometry = new RectangleGeometry(); geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS), Convert.ToDouble(contents[1], enUS), Convert.ToDouble(contents[2], enUS), Convert.ToDouble(contents[3], enUS) ); return(geometry); } else if (text.StartsWith(GeometryType.Ellipse.ToString(), StringComparison.Ordinal)) { string content = text.Substring(GeometryType.Ellipse.ToString().Length + 1); string[] contents = content.Split(','); EllipseGeometry geometry = new EllipseGeometry(); geometry.Center = new Point(Convert.ToDouble(contents[0], enUS) + Convert.ToDouble(contents[2], enUS) / 2.0, Convert.ToDouble(contents[1], enUS) + Convert.ToDouble(contents[3], enUS) / 2.0); geometry.RadiusX = Convert.ToDouble(contents[2], enUS) / 2.0; geometry.RadiusY = Convert.ToDouble(contents[3], enUS) / 2.0; return(geometry); } else if (text.StartsWith("Text:", StringComparison.Ordinal)) { string content = text.Substring("Text:".Length); string[] contents = content.Split(','); RectangleGeometry geometry = new RectangleGeometry(); geometry.Rect = new Rect(Convert.ToDouble(contents[0], enUS), Convert.ToDouble(contents[1], enUS), Convert.ToDouble(contents[2], enUS), Convert.ToDouble(contents[3], enUS) ); return(geometry); } else { throw new InvalidOperationException("This is not a valid geometry object in string"); } }
private void SetUpPathPoints() { StreamGeometry streamGeo1 = (StreamGeometry)tempoPath.Data.Clone(); PathGeometry pg = streamGeo1.GetFlattenedPathGeometry(); PathFigure pf = pg.Figures[0]; PolyLineSegment pls = (PolyLineSegment)pf.Segments[0]; this.points = pls.Points; //this.midPoint = points[points.Count / 2]; var midY = (Bottom.Y + Top.Y) / 2; this.midPoint = Helpers.GetPointClosestToY(points, midY); }
public Object Convert(Object value, Type targetType, Object parameter, CultureInfo culture) { if (value == null || value == DependencyProperty.UnsetValue) { return value; } var line = (MandlBrot.Line)value; var points = line.Point; var i = 0; var newPath = new StreamGeometry(); using (var context = newPath.Open()) { var begun = false; for (i = 0; i < points.Count; i++) { var current = points[i]; if (!begun) { begun = true; context.BeginFigure(current, true, false); } else { context.ArcTo(current, new Size(1, 1), 1, false, SweepDirection.Counterclockwise, true, true); } } } newPath.Freeze(); return newPath.GetFlattenedPathGeometry(); }
public static Telerik.Windows.Documents.Fixed.Model.Graphics.PathGeometry ConvertStreamGeometry(StreamGeometry streamGeometry) { PathGeometry pathGeometry = streamGeometry.GetFlattenedPathGeometry(); return(ConvertPathGeometry(pathGeometry)); }