/// <summary> /// Parses a PolyQuadraticBezierSegment element. /// </summary> PolyQuadraticBezierSegment ParsePolyQuadraticBezierSegment() { Debug.Assert(reader.Name == "PolyQuadraticBezierSegment"); PolyQuadraticBezierSegment seg = new PolyQuadraticBezierSegment(); while (MoveToNextAttribute()) { switch (reader.Name) { case "IsStroked": seg.IsStroked = ParseBool(reader.Value); break; case "Points": seg.Points = Point.ParsePoints(reader.Value); break; default: UnexpectedAttribute(reader.Name); break; } } MoveBeyondThisElement(); return(seg); }
/// <summary> /// Returns new PolyQuadraticBezierSegment by easing startValue to endValue using a time percentage 0 -> 1. /// </summary> /// <example>XAML: Points="200,200 300,100 0,200 30,400"</example> /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.polyquadraticbeziersegment.aspx"/> public static PolyQuadraticBezierSegment EaseValue(PolyQuadraticBezierSegment startValue, PolyQuadraticBezierSegment endValue, double percent) { return(new PolyQuadraticBezierSegment { Points = EaseValue(startValue.Points, endValue.Points, percent), }); }
/// <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); }
/// <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); } }
private void TestPathPolyQuadratic_Click(object sender, RoutedEventArgs e) { PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = new PathFigureCollection(); PathFigure figure = new PathFigure() { IsClosed = false, IsFilled = false, StartPoint = new Point(10, 10) }; figure.Segments = new PathSegmentCollection(); polyQuadratic = new PolyQuadraticBezierSegment(); polyQuadratic.Points = new PointCollection(); polyQuadratic.Points.Add(new Point(50, 100)); polyQuadratic.Points.Add(new Point(150, 200)); polyQuadratic.Points.Add(new Point(250, 200)); polyQuadratic.Points.Add(new Point(150, 100)); figure.Segments.Add(polyQuadratic); pathGeometry.Figures.Add(figure); path1.Data = pathGeometry; PathArcButtons.Visibility = Visibility.Collapsed; PathBezierButtons.Visibility = Visibility.Collapsed; PathLineButtons.Visibility = Visibility.Collapsed; PathPolyBezierButtons.Visibility = Visibility.Collapsed; PathPolyLineButtons.Visibility = Visibility.Collapsed; PathPolyQuadraticButtons.Visibility = Visibility.Visible; PathQuadraticButtons.Visibility = Visibility.Collapsed; }
public void TestPolyQuadraticBezierSegmentConstructor(string points, int count) { var pointCollection = (PointCollection)_pointCollectionConverter.ConvertFromInvariantString(points); var polyQuadraticBezierSegment = new PolyQuadraticBezierSegment(pointCollection); Assert.IsNotNull(polyQuadraticBezierSegment); Assert.AreEqual(count, polyQuadraticBezierSegment.Points.Count); }
public override void quadTo(float cpx, float cpy, float x, float y) { PolyQuadraticBezierSegment segment = new PolyQuadraticBezierSegment(); segment.Points.Add(new Point(cpx, cpy)); segment.Points.Add(new Point(x, y)); _pathFigure.Segments.Add(segment); }
public static PathSegmentCollection GetSegments(IReadOnlyList <Point> controlPoints) { if (controlPoints.Count == 0) { return((PathSegmentCollection)null); } PathSegmentCollection segmentCollection = new PathSegmentCollection(); Point point1 = controlPoints[0]; double x1 = point1.X; point1 = controlPoints[0]; double y1 = point1.Y; if (controlPoints.Count <= 3) { LineSegment lineSegment = new LineSegment() { Point = new Point(x1 + 1.0, y1) }; segmentCollection.Add((PathSegment)lineSegment); } else { for (int index = 1; index < controlPoints.Count; ++index) { point1 = controlPoints[index - 1]; double x2 = point1.X; point1 = controlPoints[index - 1]; double y2 = point1.Y; point1 = controlPoints[index]; double x3 = point1.X; point1 = controlPoints[index]; double y3 = point1.Y; if (Math.Sqrt(Math.Pow(x3 - x2, 2.0) + Math.Pow(y3 - y2, 2.0)) < 2.0) { LineSegment lineSegment = new LineSegment() { Point = new Point(x3, y3) }; segmentCollection.Add((PathSegment)lineSegment); } else { PolyQuadraticBezierSegment quadraticBezierSegment1 = new PolyQuadraticBezierSegment(); PointCollection pointCollection = new PointCollection(); Point point2 = new Point(x2, y2); pointCollection.Add(point2); Point point3 = new Point((x2 + x3) / 2.0, (y2 + y3) / 2.0); pointCollection.Add(point3); quadraticBezierSegment1.Points = pointCollection; PolyQuadraticBezierSegment quadraticBezierSegment2 = quadraticBezierSegment1; segmentCollection.Add((PathSegment)quadraticBezierSegment2); } } } return(segmentCollection); }
/// <inheritdoc/> public override void PolyQuadraticBezierTo(ImmutableArray <PointShape> points, bool isStroked = true, bool isSmoothJoin = true) { var segment = PolyQuadraticBezierSegment.Create( points, isStroked, isSmoothJoin); _currentFigure.Segments = _currentFigure.Segments.Add(segment); }
public PolyQuadraticBezierSegmentExample() { // Create a PathFigure to be used for the PathGeometry of myPath. PathFigure myPathFigure = new PathFigure(); // Set the starting point for the PathFigure specifying that the // geometry starts at point 10,100. myPathFigure.StartPoint = new Point(10, 100); // Create a PointCollection that holds the Points used to specify // the points of the PolyQuadraticBezierSegment below. PointCollection myPointCollection = new PointCollection(4); myPointCollection.Add(new Point(200, 200)); myPointCollection.Add(new Point(300, 100)); myPointCollection.Add(new Point(0, 200)); myPointCollection.Add(new Point(30, 400)); // The PolyQuadraticBezierSegment specifies two Bezier curves. // The first curve is from 10,100 (start point specified above) // to 300,100 with a control point of 200,200. The second curve // is from 200,200 (end of the last curve) to 30,400 with a // control point of 0,200. PolyQuadraticBezierSegment myBezierSegment = new PolyQuadraticBezierSegment(); myBezierSegment.Points = myPointCollection; PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection(); myPathSegmentCollection.Add(myBezierSegment); myPathFigure.Segments = myPathSegmentCollection; PathFigureCollection myPathFigureCollection = new PathFigureCollection(); myPathFigureCollection.Add(myPathFigure); PathGeometry myPathGeometry = new PathGeometry(); myPathGeometry.Figures = myPathFigureCollection; // Create a path to draw a geometry with. Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 1; // specify the shape (quadratic Bezier curve) of the path using the StreamGeometry. myPath.Data = myPathGeometry; // Add path shape to the UI. StackPanel mainPanel = new StackPanel(); mainPanel.Children.Add(myPath); this.Content = mainPanel; }
private static void Points_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { //todo: find a way to know when the points changed in the collection PolyQuadraticBezierSegment segment = (PolyQuadraticBezierSegment)d; if (segment.ParentPath != null) { segment.ParentPath.ScheduleRedraw(); } }
public static PathSegmentImplementation Create(PolyQuadraticBezierSegment source) { if (source != null) { return new PolyQuadraticBezierSegmentImplementation { _segment = source } } ; return(null); }
public override void Draw(DrawingContext dc) { if (!IsVisible) { return; } // // https://en.wikipedia.org/wiki/B%C3%A9zier_curve // base.Draw(dc); Vector vector = EndPoint - StartPoint; if (vector.Length > 0) { // Bezier curve defined by StartPoint, EndPoint and BendingOffset // Drawing the curve is no problem, determining the EndConnectorPoint is more difficult. Vector endApproachVector = !DoubleUtility.AreClose(0.0, BendingOffset) ? GetDirectionVectorOnCurve(EndOffset) : vector; var v1 = endApproachVector * Utils.Rotation30Matrix; var v2 = endApproachVector * Utils.RotationMin30Matrix; v1.Normalize(); v2.Normalize(); var p3 = EndConnectorPoint - v1 * ArrowLength; var p4 = EndConnectorPoint - v2 * ArrowLength; dc.DrawLine(Utils.DefaultPen, EndConnectorPoint, p3); dc.DrawLine(Utils.DefaultPen, EndConnectorPoint, p4); //// https://books.google.nl/books?id=7MtkGjIgOxkC&pg=PA135&lpg=PA135&dq=drawingcontext+drawgeometry+bezier+wpf&source=bl&ots=TApW1D5bmd&sig=vlS5sD3lPpH3OfQfTeaRa3bsLxI&hl=nl&sa=X&ved=0CFcQ6AEwBmoVChMI0qXZ4YGSyAIV5afbCh1Jfgzd#v=onepage&q=drawingcontext%20drawgeometry%20bezier%20wpf&f=false if (!DoubleUtility.AreClose(0.0, BendingOffset)) { PathGeometry geo = new PathGeometry(); PathFigure figure = new PathFigure(); figure.StartPoint = StartPoint; PolyQuadraticBezierSegment bezier = new PolyQuadraticBezierSegment(); bezier.Points.Add(BendingPoint); bezier.Points.Add(EndPoint); figure.Segments.Add(bezier); geo.Figures.Add(figure); dc.DrawGeometry(null, GetMainLinePen(), geo); } else { dc.DrawLine(GetMainLinePen(), StartPoint, EndPoint); } } }
public static bool EnsureOnlySingleSegmentsInFigure(PathFigure original) { bool flag = false; PathSegmentCollection segmentCollection = new PathSegmentCollection(); foreach (PathSegment pathSegment in original.Segments) { PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; PolyQuadraticBezierSegment quadraticBezierSegment1 = pathSegment as PolyQuadraticBezierSegment; PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; if (polyLineSegment != null) { foreach (Point point in polyLineSegment.Points) { LineSegment lineSegment = PathSegmentUtilities.CreateLineSegment(point, polyLineSegment.IsStroked, new bool?(polyLineSegment.IsSmoothJoin)); segmentCollection.Add((PathSegment)lineSegment); } flag = true; } else if (quadraticBezierSegment1 != null) { int index = 0; while (index < quadraticBezierSegment1.Points.Count - 1) { QuadraticBezierSegment quadraticBezierSegment2 = PathSegmentUtilities.CreateQuadraticBezierSegment(quadraticBezierSegment1.Points[index], quadraticBezierSegment1.Points[index + 1], quadraticBezierSegment1.IsStroked, new bool?(quadraticBezierSegment1.IsSmoothJoin)); segmentCollection.Add((PathSegment)quadraticBezierSegment2); index += 2; } flag = true; } else if (polyBezierSegment != null) { int index = 0; while (index < polyBezierSegment.Points.Count - 2) { BezierSegment bezierSegment = PathSegmentUtilities.CreateBezierSegment(polyBezierSegment.Points[index], polyBezierSegment.Points[index + 1], polyBezierSegment.Points[index + 2], polyBezierSegment.IsStroked, new bool?(polyBezierSegment.IsSmoothJoin)); segmentCollection.Add((PathSegment)bezierSegment); index += 3; } flag = true; } else { segmentCollection.Add(pathSegment); } } if (flag) { original.Segments = segmentCollection; } return(flag); }
public void PolyQuadraticBezierTo(IList <Point> points, bool isStroked, bool isSmoothJoin) { CheckState(); PolyQuadraticBezierSegment seg = new PolyQuadraticBezierSegment(); PointCollection pts = new PointCollection(); foreach (Point p in points) { pts.Add(p); } seg.Points = pts; _Fig.Segments.Add(seg); }
public static PathSegment Clone(this PathSegment source) { if (source == null) { return((PathSegment)null); } ArcSegment source1 = source as ArcSegment; if (source1 != null) { return((PathSegment)GeometryExtensions.CloneArcSegment(source1)); } LineSegment source2 = source as LineSegment; if (source2 != null) { return((PathSegment)GeometryExtensions.CloneLineSegment(source2)); } PolyLineSegment source3 = source as PolyLineSegment; if (source3 != null) { return((PathSegment)GeometryExtensions.ClonePolyLineSegment(source3)); } BezierSegment source4 = source as BezierSegment; if (source4 != null) { return((PathSegment)GeometryExtensions.CloneBezierSegment(source4)); } PolyBezierSegment source5 = source as PolyBezierSegment; if (source5 != null) { return((PathSegment)GeometryExtensions.ClonePolyBezierSegment(source5)); } QuadraticBezierSegment source6 = source as QuadraticBezierSegment; if (source6 != null) { return((PathSegment)GeometryExtensions.CloneQuadraticBezierSegment(source6)); } PolyQuadraticBezierSegment source7 = source as PolyQuadraticBezierSegment; if (source7 != null) { return((PathSegment)GeometryExtensions.ClonePolyQuadraticBezierSegment(source7)); } throw new NotSupportedException("This type of segment is not supported by Clone extension method"); }
private void SetPolyQuadraticBezierSegmentUsingMinimalDiff(PolyQuadraticBezierSegment currentSegment, PolyQuadraticBezierSegment pathSegment, PropertyReference segmentReference) { PropertyReference propertyReference1 = segmentReference.Append(PathElement.PolyQuadraticBezierSegmentPointsProperty); for (int index = 0; index < currentSegment.Points.Count; ++index) { ReferenceStep step = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PointCollection, index); PropertyReference propertyReference2 = propertyReference1.Append(step); if (!VectorUtilities.ArePathPointsVeryClose(currentSegment.Points[index], pathSegment.Points[index])) { this.targetElement.SetValueAsWpf(propertyReference2, (object)pathSegment.Points[index]); } } }
public void ToString_Should_Return_Path_Markup() { var target = new PolyQuadraticBezierSegment(); target.Points = target.Points.Add(new PointShape()); target.Points = target.Points.Add(new PointShape()); target.Points = target.Points.Add(new PointShape()); target.Points = target.Points.Add(new PointShape()); target.Points = target.Points.Add(new PointShape()); var actual = target.ToString(); Assert.Equal("Q0,0 0,0 0,0 0,0 0,0", actual); }
public static PolyQuadraticBezierSegment ClonePolyQuadraticBezierSegment(this PolyQuadraticBezierSegment source) { if (source == null) { return((PolyQuadraticBezierSegment)null); } PolyQuadraticBezierSegment quadraticBezierSegment = new PolyQuadraticBezierSegment(); foreach (Point point in source.Points) { quadraticBezierSegment.Points.Add(point); } return(quadraticBezierSegment); }
private static void Points_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { //todo: find a way to know when the points changed in the collection PolyQuadraticBezierSegment segment = (PolyQuadraticBezierSegment)d; PointCollection oldCollection = (PointCollection)e.OldValue; PointCollection newCollection = (PointCollection)e.NewValue; if (oldCollection != newCollection) { if (e.NewValue != e.OldValue && segment.INTERNAL_parentPath != null && segment.INTERNAL_parentPath._isLoaded) { segment.INTERNAL_parentPath.ScheduleRedraw(); } } }
private static void ReplacePolySegments(PathSegmentCollection pathSegments) { for (int index1 = 0; index1 < pathSegments.Count; ++index1) { PathSegment pathSegment = pathSegments[index1]; PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment; if (polyLineSegment != null) { pathSegments.RemoveAt(index1); for (int index2 = 0; index2 < polyLineSegment.Points.Count; ++index2) { LineSegment lineSegment = PathSegmentUtilities.CreateLineSegment(polyLineSegment.Points[index2], polyLineSegment.IsStroked); pathSegments.Insert(index1, (PathSegment)lineSegment); ++index1; } --index1; } PolyQuadraticBezierSegment quadraticBezierSegment1 = pathSegment as PolyQuadraticBezierSegment; if (quadraticBezierSegment1 != null) { pathSegments.RemoveAt(index1); int index2 = 0; while (index2 < quadraticBezierSegment1.Points.Count - 1) { QuadraticBezierSegment quadraticBezierSegment2 = PathSegmentUtilities.CreateQuadraticBezierSegment(quadraticBezierSegment1.Points[index2], quadraticBezierSegment1.Points[index2 + 1], quadraticBezierSegment1.IsStroked); pathSegments.Insert(index1, (PathSegment)quadraticBezierSegment2); ++index1; index2 += 2; } --index1; } PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; if (polyBezierSegment != null) { pathSegments.RemoveAt(index1); int index2 = 0; while (index2 < polyBezierSegment.Points.Count - 2) { BezierSegment bezierSegment = PathSegmentUtilities.CreateBezierSegment(polyBezierSegment.Points[index2], polyBezierSegment.Points[index2 + 1], polyBezierSegment.Points[index2 + 2], polyBezierSegment.IsStroked); pathSegments.Insert(index1, (PathSegment)bezierSegment); ++index1; index2 += 3; } --index1; } } }
public void GetPoints_Should_Return_All_Segment_Points() { var segment = new PolyQuadraticBezierSegment(); segment.Points = segment.Points.Add(new PointShape()); segment.Points = segment.Points.Add(new PointShape()); segment.Points = segment.Points.Add(new PointShape()); segment.Points = segment.Points.Add(new PointShape()); segment.Points = segment.Points.Add(new PointShape()); var target = segment.GetPoints(); var count = target.Count(); Assert.Equal(5, count); Assert.Equal(segment.Points, target); }
void InitControls() { mPF = new PathFigure(); mPFC.Add(mPF); /* * int polyNum = 2 * mNodeNum - 4;//n+(n-2-1)-1polyStart * mPoints = new PointCollection(polyNum); * //for (int i = 0; i < polyNum; i++) * //{ * //mPoints.Add(new Point()); * //}//mPoints[index]返回的是copy值而不是引用,不宜修改,尤其元素是值类型时 * PolyQuadraticBezierSegment segment = new PolyQuadraticBezierSegment(); * segment.Points = mPoints; * mPF.Segments.Add(segment); */ mSegment = new PolyQuadraticBezierSegment(); mPF.Segments.Add(mSegment); }
private PathGeometry CreatePolyQuadraticBezierPathGeometry(List <List <PointInfo> > pointInfoListCollection) { PathFigureCollection pfc = new PathFigureCollection(); foreach (var pointInfoList in pointInfoListCollection) { Point[] pointArr = pointInfoList.Select(t => { return(t.Point); }).ToArray(); var polyQuadraticBezierSegment = new PolyQuadraticBezierSegment(); polyQuadraticBezierSegment.Points = new PointCollection(pointArr); var pathFigure = new PathFigure(); pathFigure.StartPoint = pointInfoList[0].Point; pathFigure.Segments.Add(polyQuadraticBezierSegment); pfc.Add(pathFigure); } return(new PathGeometry(pfc)); }
private bool DoesStructureMatch(PathSegment segment1, PathSegment segment2) { if (segment1.GetType() != segment2.GetType()) { return(false); } PolyBezierSegment polyBezierSegment1; if ((polyBezierSegment1 = segment1 as PolyBezierSegment) != null) { PolyBezierSegment polyBezierSegment2 = (PolyBezierSegment)segment2; if (polyBezierSegment1.Points.Count != polyBezierSegment2.Points.Count) { return(false); } } else { PolyQuadraticBezierSegment quadraticBezierSegment1; if ((quadraticBezierSegment1 = segment1 as PolyQuadraticBezierSegment) != null) { PolyQuadraticBezierSegment quadraticBezierSegment2 = (PolyQuadraticBezierSegment)segment2; if (quadraticBezierSegment1.Points.Count != quadraticBezierSegment2.Points.Count) { return(false); } } else { PolyLineSegment polyLineSegment1; if ((polyLineSegment1 = segment1 as PolyLineSegment) != null) { PolyLineSegment polyLineSegment2 = (PolyLineSegment)segment2; if (polyLineSegment1.Points.Count != polyLineSegment2.Points.Count) { return(false); } } } } return(true); }
private void DrawPoints(DrawingContext drawingContext, Point startPoint, IEnumerable <Point> points, Color color, bool bezier = true) { var figures = new PathSegmentCollection(); if (bezier) { var segment = new PolyQuadraticBezierSegment(points, true); figures.Add(segment); } else { var segment = new PolyLineSegment(points, true); figures.Add(segment); } var figure = new PathFigure(startPoint, figures, false); var geometry = new PathGeometry(); geometry.Figures.Add(figure); drawingContext.DrawGeometry(new SolidColorBrush(color), new Pen(new SolidColorBrush(Colors.Snow), 2), geometry); }
internal Stroke(Point point) { m_previousPoints[0] = point; m_previousPoints[1] = point; m_currentPoint = point; m_currentStroke = new Path(); m_currentGeometry = new PathGeometry(); m_currentStroke.Data = m_currentGeometry; m_currentStroke.Stroke = new SolidColorBrush(Colors.Yellow); m_currentStroke.StrokeThickness = 15.0; PathFigure figure = new PathFigure(); figure.StartPoint = m_currentPoint; m_currentLine = new PolyQuadraticBezierSegment(); m_currentLine.IsSmoothJoin = true; figure.Segments.Add(m_currentLine); m_currentGeometry.Figures.Add(figure); }
public static PolyQuadraticBezierSegment CreatePolyQuadraticBezierSegment(IList <Point> points, int start, int count, bool isStroked = true) { if (points == null) { throw new ArgumentNullException(nameof(points)); } count = count / 2 * 2; if (count < 0 || points.Count < start + count) { throw new ArgumentOutOfRangeException(nameof(count)); } var segment = new PolyQuadraticBezierSegment { Points = new PointCollection() }; for (var i = 0; i < count; i++) { segment.Points.Add(points[start + i]); } segment.SetIsStroked(isStroked); return(segment); }
public static PathData ToCGPath(this Geometry geometry, Transform renderTransform = null) { PathData pathData = new PathData { Data = new CGPath() }; CGAffineTransform transform; if (renderTransform == null) { transform = CGAffineTransform.MakeIdentity(); } else { transform = renderTransform.ToCGAffineTransform(); } if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; pathData.Data.MoveToPoint(transform, lineGeometry.StartPoint.ToPointF()); pathData.Data.AddLineToPoint(transform, lineGeometry.EndPoint.ToPointF()); } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; pathData.Data.AddRect(transform, new CGRect(rect.X, rect.Y, rect.Width, rect.Height)); } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; CGRect rect = new CGRect( ellipseGeometry.Center.X - ellipseGeometry.RadiusX, ellipseGeometry.Center.Y - ellipseGeometry.RadiusY, ellipseGeometry.RadiusX * 2, ellipseGeometry.RadiusY * 2); pathData.Data.AddEllipseInRect(transform, rect); } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; pathData.IsNonzeroFillRule = geometryGroup.FillRule == FillRule.Nonzero; foreach (Geometry child in geometryGroup.Children) { PathData pathChild = child.ToCGPath(renderTransform); pathData.Data.AddPath(pathChild.Data); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; pathData.IsNonzeroFillRule = pathGeometry.FillRule == FillRule.Nonzero; foreach (PathFigure pathFigure in pathGeometry.Figures) { pathData.Data.MoveToPoint(transform, pathFigure.StartPoint.ToPointF()); Point lastPoint = pathFigure.StartPoint; foreach (PathSegment pathSegment in pathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; pathData.Data.AddLineToPoint(transform, lineSegment.Point.ToPointF()); lastPoint = lineSegment.Point; } // PolyLineSegment else if (pathSegment is PolyLineSegment) { PolyLineSegment polylineSegment = pathSegment as PolyLineSegment; PointCollection points = polylineSegment.Points; for (int i = 0; i < points.Count; i++) { pathData.Data.AddLineToPoint(transform, points[i].ToPointF()); } lastPoint = points[points.Count - 1]; } // BezierSegment if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; pathData.Data.AddCurveToPoint( transform, bezierSegment.Point1.ToPointF(), bezierSegment.Point2.ToPointF(), bezierSegment.Point3.ToPointF()); lastPoint = bezierSegment.Point3; } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; PointCollection points = polyBezierSegment.Points; if (points.Count >= 3) { for (int i = 0; i < points.Count; i += 3) { pathData.Data.AddCurveToPoint( transform, points[i].ToPointF(), points[i + 1].ToPointF(), points[i + 2].ToPointF()); } } lastPoint = points[points.Count - 1]; } // QuadraticBezierSegment if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment; pathData.Data.AddQuadCurveToPoint( transform, new nfloat(bezierSegment.Point1.X), new nfloat(bezierSegment.Point1.Y), new nfloat(bezierSegment.Point2.X), new nfloat(bezierSegment.Point2.Y)); lastPoint = bezierSegment.Point2; } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment; PointCollection points = polyBezierSegment.Points; if (points.Count >= 2) { for (int i = 0; i < points.Count; i += 2) { pathData.Data.AddQuadCurveToPoint( transform, new nfloat(points[i + 0].X), new nfloat(points[i + 0].Y), new nfloat(points[i + 1].X), new nfloat(points[i + 1].Y)); } } lastPoint = points[points.Count - 1]; } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; List <Point> points = new List <Point>(); GeometryHelper.FlattenArc( points, lastPoint, arcSegment.Point, arcSegment.Size.Width, arcSegment.Size.Height, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == SweepDirection.CounterClockwise, 1); CGPoint[] cgpoints = new CGPoint[points.Count]; for (int i = 0; i < points.Count; i++) { cgpoints[i] = transform.TransformPoint(points[i].ToPointF()); } pathData.Data.AddLines(cgpoints); lastPoint = points.Count > 0 ? points[points.Count - 1] : Point.Zero; } } if (pathFigure.IsClosed) { pathData.Data.CloseSubpath(); } } } return(pathData); }
private static PathSegmentCollection Clone(PathSegmentCollection pathSegColl) { PathSegmentCollection collClone = new PathSegmentCollection(); foreach (PathSegment item in pathSegColl) { PathSegment clone = null; if (item is LineSegment) { LineSegment seg = item as LineSegment; clone = new LineSegment() { Point = seg.Point }; } else if (item is PolyLineSegment) { PolyLineSegment seg = item as PolyLineSegment; clone = new PolyLineSegment() { Points = getPoints(seg.Points) }; } else if (item is BezierSegment) { BezierSegment seg = item as BezierSegment; clone = new BezierSegment() { Point1 = seg.Point1, Point2 = seg.Point2, Point3 = seg.Point3 }; } else if (item is PolyBezierSegment) { PolyBezierSegment seg = item as PolyBezierSegment; clone = new PolyBezierSegment() { Points = getPoints(seg.Points) }; } else if (item is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment seg = item as PolyQuadraticBezierSegment; clone = new PolyQuadraticBezierSegment() { Points = getPoints(seg.Points) }; } else if (item is QuadraticBezierSegment) { QuadraticBezierSegment seg = item as QuadraticBezierSegment; clone = new QuadraticBezierSegment() { Point1 = seg.Point1, Point2 = seg.Point2 }; } else if (item is ArcSegment) { ArcSegment seg = item as ArcSegment; clone = new ArcSegment() { IsLargeArc = seg.IsLargeArc, Point = seg.Point, RotationAngle = seg.RotationAngle, Size = seg.Size, SweepDirection = seg.SweepDirection }; } collClone.Add(clone); } return(collClone); }
/// <summary> /// Returns new PolyQuadraticBezierSegment by easing startValue to endValue using a time percentage 0 -> 1. /// </summary> /// <example>XAML: Points="200,200 300,100 0,200 30,400"</example> /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.polyquadraticbeziersegment.aspx"/> public static PolyQuadraticBezierSegment EaseValue(PolyQuadraticBezierSegment startValue, PolyQuadraticBezierSegment endValue, double percent) { return new PolyQuadraticBezierSegment { Points = EaseValue(startValue.Points, endValue.Points, percent), }; }