Represents a cubic bezier segment drawn between two points.
Ejemplo n.º 1
0
 public void AddBeziers(BezierSegment[] beziers)
 {
     for (int index = 0; index < beziers.Length; ++index)
     {
         AddBezier(beziers[index]);
     }
 }
Ejemplo n.º 2
0
 public void AddBezier(BezierSegment bezier)
 {
     _buffer.AppendFormat("C {0},{1} {2},{3} {4},{5} ",
         bezier.Point1.X, bezier.Point1.Y,
         bezier.Point2.X, bezier.Point2.Y,
         bezier.Point3.X, bezier.Point3.Y);
 }
Ejemplo n.º 3
0
        public void BezierTo(double s1x, double s1y, double s2x, double s2y, double ex, double ey)
        {
            var bezier = new BezierSegment
            {
                Point1 = Import.Point(s1x, s1y),
                Point2 = Import.Point(s2x, s2y),
                Point3 = Import.Point(ex, ey)
            };

            _sink.AddBezier(bezier);
        }
Ejemplo n.º 4
0
 void SimplifiedGeometrySink.AddBeziers(BezierSegment[] beziers)
 {
     foreach(BezierSegment segment in beziers)
     {
         _GeometryBuilder.BezierCurveTo(
             segment.Point1.X,
             segment.Point1.Y,
             segment.Point2.X,
             segment.Point2.Y,
             segment.Point3.X,
             segment.Point3.Y);
     }
 }
Ejemplo n.º 5
0
 void SimplifiedGeometrySink.AddBeziers(BezierSegment[] beziers)
 {
     foreach(BezierSegment bezier in beziers)
     {
         _Builder.BezierCurveTo(
             bezier.Point1.X,
             bezier.Point1.Y,
             bezier.Point2.X,
             bezier.Point2.Y,
             bezier.Point3.X,
             bezier.Point3.Y);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Appends a Bézier segment from a curve.
        /// </summary>
        public static BezierSegment CreateCurveSegment(XPoint pt0, XPoint pt1, XPoint pt2, XPoint pt3, double tension3)
        {
#if !SILVERLIGHT && !NETFX_CORE
            return new BezierSegment(
                new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y)),
                new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y)),
                new SysPoint(pt2.X, pt2.Y), true);
#else
            BezierSegment bezierSegment = new BezierSegment();
            bezierSegment.Point1 = new SysPoint(pt1.X + tension3 * (pt2.X - pt0.X), pt1.Y + tension3 * (pt2.Y - pt0.Y));
            bezierSegment.Point2 = new SysPoint(pt2.X - tension3 * (pt3.X - pt1.X), pt2.Y - tension3 * (pt3.Y - pt1.Y));
            bezierSegment.Point3 = new SysPoint(pt2.X, pt2.Y);
            return bezierSegment;
#endif
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates the part.
 /// </summary>
 /// <returns>
 /// UIElement
 /// </returns>
 public override UIElement CreatePart()
 {
     SplinePath = new Path();
     PathFigure figure = new PathFigure();
     BezierSegment bezierPoints = new BezierSegment();
     PathGeometry pathGeometry = new PathGeometry();
     figure.StartPoint = StartPoint;
     bezierPoints.Point1 = FirstControlPoint;
     bezierPoints.Point2 = EndControlPoint;
     bezierPoints.Point3 = EndPoint;
     figure.Segments.Add(bezierPoints);
     pathGeometry.Figures = new PathFigureCollection() { figure };
     SplinePath.Data = pathGeometry;
     SetBindingForStrokeandStrokeThickness(SplinePath);
     return SplinePath;
 }
Ejemplo n.º 8
0
        public Wire()
        {
            InitializeComponent();

            flow              = new LinearGradientBrush(Colors.White, Colors.Red, 0);
            flow.MappingMode  = BrushMappingMode.Absolute;
            flow.SpreadMethod = GradientSpreadMethod.Repeat;

            pf = new PathFigure();
            bz = new BezierSegment();
            pf.Segments.Add(bz);
            PathGeometry pg = new PathGeometry(new PathFigure[] { pf });

            Inner.Data = pg;
            Outer.Data = pg;

            Inner.Stroke = Brushes.White;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Generates a black spline outline, typically used to overlay on a space element.
        /// </summary>
        /// <param name="p0">
        /// The first point for the spline.
        /// </param>
        /// <param name="p1">
        /// The second point for the spline.
        /// </param>
        /// <param name="p2">
        /// The third point for the spline.
        /// </param>
        /// <param name="p3">
        /// The fourth point for the spline.
        /// </param>
        /// <returns>
        /// A Path that incorporates the spline.
        /// </returns>
        private static Path GenerateBlackSpline(Point p0, Point p1, Point p2, Point p3)
        {
            var p = new Path {
                Fill = new SolidColorBrush(Colors.Black)
            };
            var pg = new PathGeometry();
            var pf = new PathFigure {
                StartPoint = p0
            };
            var bs = new BezierSegment {
                Point1 = p1, Point2 = p2, Point3 = p3
            };

            pf.Segments.Add(bs);
            pg.Figures.Add(pf);
            p.Data = pg;
            return(p);
        }
Ejemplo n.º 10
0
        public void Bezier(CubicBezier bezier)
        {
            if (Stroking)
            {
                drawOpenPath(Import.Point(bezier.Start),
                             sink =>
                {
                    var bezierSegment = new BezierSegment()
                    {
                        Point1 = Import.Point(bezier.Span1),
                        Point2 = Import.Point(bezier.Span2),
                        Point3 = Import.Point(bezier.End)
                    };

                    sink.AddBezier(bezierSegment);
                });
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 在已经设置信息的情况下初始化
        /// </summary>
        protected void InitLineInformation()
        {
            ///实例化
            connectorGeometry = new PathGeometry();
            connectorPoints   = new PathFigure();
            connectorCurve    = new BezierSegment();

            ///设置贝塞尔曲线的开始点
            //connectorPoints.StartPoint = StartPoint.position;

            connectorPoints.Segments.Add(connectorCurve);
            connectorGeometry.Figures.Add(connectorPoints);
            geometryData = connectorGeometry;

            vpLeftCoverter.ValueChangedCallBack  += VpLeftCoverter_ValueChangedCallBack;
            vpRightCoverter.ValueChangedCallBack += VpRightCoverter_ValueChangedCallBack;
            Stroke = new SolidColorBrush(Colors.White);
        }
Ejemplo n.º 12
0
    public void UnselectBezierSegment()
    {
        if (_currentHoveredObject == null)
        {
            return;
        }

        _currentSelectionMode = SelectionMode.NoSelection;

        for (int i = 0; i < _segments.Count; i++)
        {
            _selectedSegments[i].PointSelected = false;
        }
        _currentBezierSegment = null;

        //if(_currentPathObject != null)
        _currentPathObject.UpdatePointsHandlesRenderer();
    }
Ejemplo n.º 13
0
    public void MovePoint()
    {
        BezierSegment current = _currentHoverData.HoveredBeziersegment;

        current.PointSelected = true;

        Vector2 newPosition = _program.GetMouseCanvasPosition() - current.Point;

        for (int i = 0; i < _segments.Count; i++)
        {
            if (_segments[i].PointSelected)
            {
                _segments[i].MovePoints(newPosition);
            }
        }

        _currentPathObject.UpdatePointsHandlesRenderer();
    }
        private static PathGeometry CloneDeep(PathGeometry pathGeometry)
        {
            var newPathGeometry = new PathGeometry();

            foreach (var figure in pathGeometry.Figures)
            {
                var newFigure = new PathFigure();
                newFigure.StartPoint = figure.StartPoint;
                foreach (var segment in figure.Segments)
                {
                    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 segmentLineSegment = segment as LineSegment;
                    if (segmentLineSegment != null)
                    {
                        var newSegment = new LineSegment();
                        newSegment.Point = new Point(segmentLineSegment.Point.X, segmentLineSegment.Point.Y);
                        newFigure.Segments.Add(newSegment);
                    }

                    var segmentBezierSegment = segment as BezierSegment;
                    if (segmentBezierSegment != null)
                    {
                        var newSegment = new BezierSegment();
                        newSegment.Point1 = new Point(segmentBezierSegment.Point1.X, segmentBezierSegment.Point1.Y);
                        newSegment.Point2 = new Point(segmentBezierSegment.Point2.X, segmentBezierSegment.Point2.Y);
                        newSegment.Point3 = new Point(segmentBezierSegment.Point3.X, segmentBezierSegment.Point3.Y);
                        newFigure.Segments.Add(newSegment);
                    }
                }

                newPathGeometry.Figures.Add(newFigure);
            }
            return(newPathGeometry);
        }
Ejemplo n.º 15
0
        private void pat_Click(object sender, RoutedEventArgs e)
        {
            path.Stroke          = Brushes.DarkOliveGreen;
            path.StrokeThickness = 2;
            //кисть для заполнения прямоугольника изображением
            ImageBrush ib = new ImageBrush();

            ib.AlignmentX = AlignmentX.Left;
            ib.AlignmentY = AlignmentY.Top;
            //загрузка изображения и назначение кисти
            ib.ImageSource = new BitmapImage(new Uri(@"D:\sib\WpfApp5\WpfApp5\img\jUUQ0lfsUM8.jpg", UriKind.Absolute));
            path.Fill      = ib;
            //создание двух сегментов пути при помощи кривых Безье
            //параметры - (первая контрольная точка, вторая контрольная точка, конец кривой)
            BezierSegment bezierCurve1 = new BezierSegment(new Point(400, 0), new Point(400, 50), new Point(450, 90),
                                                           true);
            BezierSegment bezierCurve2 = new BezierSegment(new Point(500, 50), new Point(500, 0), new Point(450, 30), true);
            //создание коллекции сегментов и добавление к ней кривых
            PathSegmentCollection psc = new PathSegmentCollection();

            psc.Add(bezierCurve1);
            psc.Add(bezierCurve2);
            //создание объекта фигуры и установка начальной точки пути
            PathFigure pf = new PathFigure();

            pf.Segments   = psc;
            pf.StartPoint = new Point(450, 30);
            //создание коллекции фигур
            PathFigureCollection pfc = new PathFigureCollection();

            pfc.Add(pf);
            //создание геометрии пути
            PathGeometry pg = new PathGeometry();

            pg.Figures = pfc;
            //создание набора геометрий
            GeometryGroup pathGeometryGroup = new GeometryGroup();

            pathGeometryGroup.Children.Add(pg);
            //
            path.Data = pathGeometryGroup;
            //добавление объекта путь в сцену
            scene.Children.Add(path);
        }
Ejemplo n.º 16
0
        private void DrawMainPolygon(Canvas canvas, List <Point> points)
        {
            if (points.Count < 3)
            {
                return;
            }
            var          path = new Path();
            var          pathSegmentCollection = new PathSegmentCollection();
            var          pathFigure            = new PathFigure();
            List <Point> processedPoints       = JarvisAlgorithm.ConvexHull(points);

            for (int i = 0; i < processedPoints.Count; i++)
            {
                processedPoints[i] = new Point(processedPoints[i].X + 100, processedPoints[i].Y + 100);
            }
            pathFigure.StartPoint = PointMapper.fromMyPointToSystemPoint(processedPoints.First());

            var beizerSegments = InterpolationUtils.InterpolatePointWithBeizerCurves(processedPoints, true);

            foreach (var beizerCurveSegment in beizerSegments)
            {
                var segment = new BezierSegment
                {
                    Point1 = PointMapper.fromMyPointToSystemPoint(beizerCurveSegment.FirstControlPoint),
                    Point2 = PointMapper.fromMyPointToSystemPoint(beizerCurveSegment.SecondControlPoint),
                    Point3 = PointMapper.fromMyPointToSystemPoint(beizerCurveSegment.EndPoint)
                };
                pathSegmentCollection.Add(segment);
            }

            pathFigure.Segments = pathSegmentCollection;
            var pathFigureCollection = new PathFigureCollection {
                pathFigure
            };

            var pathGeometry = new PathGeometry {
                Figures = pathFigureCollection
            };

            path.Data            = pathGeometry;
            path.Stroke          = Brushes.Black;
            path.StrokeThickness = 1;
            canvas.Children.Add(path);
        }
Ejemplo n.º 17
0
        public override void MouseDownHandle(object sender, MouseButtonEventArgs e)
        {
            base.MouseDownHandle(sender, e);

            Point currentPosition = Mouse.GetPosition(this.CurrentWindow.Canvas);

            if (ContainerClass.LastGrid == null)
            {
                if (BezierDots.Count != 4)
                {
                    BezierDots.Add(currentPosition);
                    CreateTemporaryDot(currentPosition);
                }

                if (BezierDots.Count == 4)
                {
                    DeleteTemporaryDots();

                    BezierSegment bezier = new BezierSegment
                    {
                        Point1 = BezierDots[1],
                        Point2 = BezierDots[2],
                        Point3 = BezierDots[3]
                    };

                    PathFigure figure = new PathFigure();
                    figure.StartPoint = BezierDots[0];
                    figure.Segments.Add(bezier);

                    Path path = new Path();
                    path.Stroke          = new SolidColorBrush(Colors.Black);
                    path.StrokeThickness = 2;
                    path.Data            = new PathGeometry(new PathFigure[] { figure });

                    Grid grid = GetPackedGrid <Path>(path);

                    this.Publish <CurrentGrid>(new CurrentGrid(grid));

                    ContainerClass.LastGrid      = grid;
                    ContainerClass.LastShape     = path;
                    ContainerClass.MousePosition = currentPosition;
                }
            }
        }
Ejemplo n.º 18
0
        public void AutoTurnPage(CornerOrigin fromCorner, int duration)
        {
            if (Status != PageStatus.None)
            {
                return;
            }
            if (duration <= 0)
            {
                return;
            }
            Status = PageStatus.TurnAnimation;

            UIElement source = this as UIElement;

            this.BeginAnimation(BookPage.CornerPointProperty, null);

            Point startPoint = OriginToPoint(this, fromCorner);
            Point endPoint   = OriginToOppositePoint(this, fromCorner);

            CornerPoint = startPoint;
            origin      = fromCorner;

            BezierSegment bs =
                new BezierSegment(startPoint, new Point(endPoint.X + (startPoint.X - endPoint.X) / 3, 250), endPoint, true);

            PathGeometry path   = new PathGeometry();
            PathFigure   figure = new PathFigure();

            figure.StartPoint = startPoint;
            figure.Segments.Add(bs);
            figure.IsClosed = false;
            path.Figures.Add(figure);

            PointAnimationUsingPath anim =
                new PointAnimationUsingPath();

            anim.PathGeometry      = path;
            anim.Duration          = new Duration(TimeSpan.FromMilliseconds(duration));
            anim.AccelerationRatio = 0.6;

            anim.CurrentTimeInvalidated += anim_CurrentTimeInvalidated;
            anim.Completed += anim_Completed;
            this.BeginAnimation(BookPage.CornerPointProperty, anim);
        }
Ejemplo n.º 19
0
        private PathFigure DrawCurveLine(Point startPoint, Point endpoint, double waveWith, double xRadius, double yRadius)
        {
            double PILine = GetRadian(startPoint, endpoint);

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = startPoint;

            Point pt = GetCurvePoint();

            BezierSegment bezierSegment = new BezierSegment();

            bezierSegment.Point1 = startPoint;
            bezierSegment.Point2 = pt;
            bezierSegment.Point3 = endpoint;
            pathFigure.Segments.Add(bezierSegment);

            return(pathFigure);
        }
Ejemplo n.º 20
0
        public void DrawBezier(Pen pen, float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2)
        {
            var rt = RenderTarget;

            using (var path = new PathGeometry(rt.Factory)) {
                using (var s = path.Open()) {
                    s.BeginFigure(new RawVector2(x1, y1), FigureBegin.Filled);
                    var segment = new BezierSegment {
                        Point1 = new RawVector2(cx1, cy1),
                        Point2 = new RawVector2(cx2, cy2),
                        Point3 = new RawVector2(x2, y2)
                    };
                    s.AddBezier(segment);
                    s.EndFigure(FigureEnd.Open);
                    s.Close();
                }
                rt.DrawGeometry(path, pen.Brush, pen.StrokeWidth, pen.StrokeStyle);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Refreshes this instance.
 /// </summary>
 public override void Refresh()
 {
     if (SplinePath != null)
     {
         PathFigure    figure       = new PathFigure();
         BezierSegment bezierPoints = new BezierSegment();
         PathGeometry  pathGeometry = new PathGeometry();
         figure.StartPoint   = StartPoint;
         bezierPoints.Point1 = FirstControlPoint;
         bezierPoints.Point2 = EndControlPoint;
         bezierPoints.Point3 = EndPoint;
         figure.Segments.Add(bezierPoints);
         pathGeometry.Figures = new PathFigureCollection()
         {
             figure
         };
         SplinePath.Data = pathGeometry;
     }
 }
        public void HighlightErrors(FormattedText text, List <SyntaxError> Errors,
                                    List <InnerTextBlock> blocks)
        {
            Pen path_pen = new Pen(ErrorColor, 0.5)
            {
                EndLineCap   = PenLineCap.Square,
                StartLineCap = PenLineCap.Square
            };
            Point         path_start   = new Point(0, 1);
            BezierSegment path_segment = new BezierSegment(new Point(1, 0),
                                                           new Point(2, 2), new Point(3, 1), true);
            PathFigure path_figure = new PathFigure(path_start,
                                                    new PathSegment[] { path_segment }, false);
            PathGeometry path_geometry  = new PathGeometry(new[] { path_figure });
            DrawingBrush squiggly_brush = new DrawingBrush
            {
                Viewport      = new Rect(0, 0, 6, 4),
                ViewportUnits = BrushMappingMode.Absolute,
                TileMode      = TileMode.Tile,
                Drawing       = new GeometryDrawing(null, path_pen, path_geometry)
            };
            TextDecoration squiggly = new TextDecoration {
                Pen = new Pen(squiggly_brush, 6)
            };
            TextDecorationCollection collection = new TextDecorationCollection {
                squiggly
            };

            foreach (SyntaxError error in Errors)
            {
                string tag    = error.Tag ?? "";
                int    Line   = error.Line ?? -1;
                int    Column = error.Column ?? -1;
                //Check if a block with this line and column exists
                int TagPos = CodeHelper.getStartCharOfPos(text.Text, Line, Column);
                //If cannot find a block for this error
                if (TagPos < 0)
                {
                    continue;
                }
                text.SetTextDecorations(collection, TagPos, TagPos + tag.Length);
            }
        }
Ejemplo n.º 23
0
        private Path[] getLips4()
        {
            Path[] lipsParts = new Path[1];

            BezierSegment bezierSegment1 = new BezierSegment(
                new Point(CentrePoint.X - Radius * 0.6, CentrePoint.Y + Radius * 0.7),
                new Point(CentrePoint.X, CentrePoint.Y - Radius * 0.2),
                new Point(CentrePoint.X + Radius * 0.6, CentrePoint.Y + Radius * 0.7),
                false
                );

            BezierSegment bezierSegment2 = new BezierSegment(
                new Point(CentrePoint.X - Radius * 0.5, CentrePoint.Y + Radius * 0.7),
                new Point(CentrePoint.X, CentrePoint.Y),
                new Point(CentrePoint.X + Radius * 0.5, CentrePoint.Y + Radius * 0.7),
                false
                );

            LineSegment line1 = new LineSegment(new Point(CentrePoint.X - Radius * 0.5, CentrePoint.Y + Radius * 0.7), false);

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = new Point(CentrePoint.X - Radius * 0.6, CentrePoint.Y + Radius * 0.7);
            pathFigure.Segments.Add(bezierSegment1);
            pathFigure.Segments.Add(line1);
            pathFigure.Segments.Add(bezierSegment2);

            PathFigureCollection pathFigureCollection = new PathFigureCollection();

            pathFigureCollection.Add(pathFigure);

            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry.Figures = pathFigureCollection;

            lipsParts[0]                 = new Path();
            lipsParts[0].Data            = pathGeometry;
            lipsParts[0].StrokeThickness = 1;
            lipsParts[0].Stroke          = new SolidColorBrush(Colors.Black);
            lipsParts[0].Fill            = new SolidColorBrush(Colors.Black);

            return(lipsParts);
        }
        /// <summary>
        /// 在已经设置信息的情况下初始化
        /// </summary>
        protected void InitLineInformation()
        {
            ///赋予笔刷
            connector.Stroke = new SolidColorBrush(StartPoint.LinkAribute.BorderColor);
            ///赋予笔触
            connector.StrokeThickness = _strokeThickness;
            ///实例化
            connectorGeometry = new PathGeometry();
            connectorPoints   = new PathFigure();
            connectorCurve    = new BezierSegment();

            ///设置贝塞尔曲线的开始点
            connectorPoints.StartPoint = StartPoint.position;
            AdjustBezierLine();

            connectorPoints.Segments.Add(connectorCurve);
            connectorGeometry.Figures.Add(connectorPoints);
            connector.Data = connectorGeometry;
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Creates the part.
        /// </summary>
        /// <returns>
        /// UIElement
        /// </returns>
        public override UIElement CreatePart()
        {
            SplinePath = new Path();
            PathFigure    figure       = new PathFigure();
            BezierSegment bezierPoints = new BezierSegment();
            PathGeometry  pathGeometry = new PathGeometry();

            figure.StartPoint   = StartPoint;
            bezierPoints.Point1 = FirstControlPoint;
            bezierPoints.Point2 = EndControlPoint;
            bezierPoints.Point3 = EndPoint;
            figure.Segments.Add(bezierPoints);
            pathGeometry.Figures = new PathFigureCollection()
            {
                figure
            };
            SplinePath.Data = pathGeometry;
            SetBindingForStrokeandStrokeThickness(SplinePath);
            return(SplinePath);
        }
Ejemplo n.º 26
0
        protected override Geometry getGeometry(double left = 0.0f, double top = 0.0f)
        {
            Point              p  = new Point(left, top);
            Point              p1 = _addpoint(p, Point1);
            Point              p2 = _addpoint(p, Point2);
            Point              p3 = _addpoint(p, Point3);
            Point              p0 = _addpoint(p, Point0);
            PathSegment        ps = new BezierSegment(p1, p2, p3, true);
            List <PathSegment> l  = new List <PathSegment>();

            l.Clear();
            l.Add(ps);
            PathFigure pf = new PathFigure(p0, l, false);

            pf.Segments.Add(ps);
            PathGeometry pg = new PathGeometry();

            pg.Figures.Add(pf);
            return(pg);
        }
    public void FlipSegment_FlipsPointsOrder()
    {
        var points = new Vector2[4];

        for (int i = 0; i < points.Length; ++i)
        {
            points[i] = Vector2.one * i;
        }

        var seg = new BezierSegment()
        {
            P0 = points[0], P1 = points[1], P2 = points[2], P3 = points[3]
        };
        var flipped = VectorUtils.FlipSegment(seg);

        Assert.AreEqual(points[3], flipped.P0);
        Assert.AreEqual(points[2], flipped.P1);
        Assert.AreEqual(points[1], flipped.P2);
        Assert.AreEqual(points[0], flipped.P3);
    }
Ejemplo n.º 28
0
    public void CloseCurve()
    {
        BezierSegment first = _segments[0];

        first.isFirst      = false;
        first.SegmentCount = _program.SEGMENTS_PER_CURVE;
        first.Delete();
        first.AddCurvePoints();
        BezierSegment last = _segments[_segments.Count - 1];

        OrganizeNeighbors(last, _segments[0]);
        first.Update();

        first.PointSelected         = false;
        last.PointSelected          = false;
        _currentPathObject.IsClosed = true;

        _currentPathObject.UpdatePointsHandlesRenderer();
        _program.AllowPathObjectUpdate();
    }
Ejemplo n.º 29
0
        private void SetBezierSegmentUsingMinimalDiff(BezierSegment currentSegment, BezierSegment pathSegment, PropertyReference segmentReference)
        {
            PropertyReference propertyReference1 = segmentReference.Append(PathElement.BezierSegmentPoint1Property);
            PropertyReference propertyReference2 = segmentReference.Append(PathElement.BezierSegmentPoint2Property);
            PropertyReference propertyReference3 = segmentReference.Append(PathElement.BezierSegmentPoint3Property);

            if (!VectorUtilities.ArePathPointsVeryClose(currentSegment.Point1, pathSegment.Point1))
            {
                this.targetElement.SetValueAsWpf(propertyReference1, (object)pathSegment.Point1);
            }
            if (!VectorUtilities.ArePathPointsVeryClose(currentSegment.Point2, pathSegment.Point2))
            {
                this.targetElement.SetValueAsWpf(propertyReference2, (object)pathSegment.Point2);
            }
            if (VectorUtilities.ArePathPointsVeryClose(currentSegment.Point3, pathSegment.Point3))
            {
                return;
            }
            this.targetElement.SetValueAsWpf(propertyReference3, (object)pathSegment.Point3);
        }
Ejemplo n.º 30
0
        //CaliDiagramAndRaft
        public static PathGeometry GetBezierGeometry(List <Point> points)
        {
            var myPathFigure = new PathFigure {
                StartPoint = points.FirstOrDefault()
            };
            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();

            BezierSegment segment = null;

            if (points.Count == 3)
            {
                segment = new BezierSegment
                {
                    Point1 = points[1],
                    Point2 = points[1],
                    Point3 = points[2],
                }
            }
            ;
            else if (points.Count == 4)
            {
                segment = new BezierSegment
                {
                    Point1 = points[1],
                    Point2 = points[2],
                    Point3 = points[3],
                };
            }
            myPathSegmentCollection.Add(segment);


            myPathFigure.Segments = myPathSegmentCollection;

            var myPathFigureCollection = new PathFigureCollection {
                myPathFigure
            };

            return(new PathGeometry {
                Figures = myPathFigureCollection
            });
        }
Ejemplo n.º 31
0
        private void DrawPath(Point source, Point destination, Line path)
        {
            float magic    = 8;
            var   segments = new List <PathSegment>();

            if (destination.X > source.X)
            {
                Point c1 = new Point(source.X + (magic - 1) * (destination.X - source.X) / magic, source.Y + (destination.Y - source.Y) / magic);
                Point c2 = new Point(source.X + (destination.X - source.X) / magic, source.Y + (magic - 1) * (destination.Y - source.Y) / magic);
                var   bs = new BezierSegment();
                bs.Point1 = c1;
                bs.Point2 = c2;
                bs.Point3 = destination;
                segments.Add(bs);
            }
            else
            {
                double distanceX = Math.Abs(source.X - destination.X) / 3;
                Point  c1        = new Point(source.X + Math.Min((magic - 1) * (source.X - destination.X) / magic, distanceX) + 20, source.Y + (magic - 1) * (destination.Y - source.Y) / magic);
                Point  c2        = new Point(destination.X - Math.Min((magic - 1) * (source.X - destination.X) / magic, distanceX) - 20, destination.Y - (magic - 1) * (destination.Y - source.Y) / magic);
                var    bs        = new BezierSegment();
                bs.Point1 = c1;
                bs.Point2 = c2;
                bs.Point3 = destination;
                segments.Add(bs);
            }

            var geo = new PathGeometry();
            var pf  = new PathFigure()
            {
                StartPoint = source, IsClosed = false
            };

            foreach (var s in segments)
            {
                pf.Segments.Add(s);
            }
            geo.Figures.Add(pf);
            path.Data = geo;
            Canvas.SetZIndex(path, -2);
        }
Ejemplo n.º 32
0
        public override void DrawShape(gView gv, gPath data, Boolean bfirst)
        {
            if (bfirst)
            {
                shapeLib.Data.Status = "rest";
                shapeLib.Data.bfirst = false;
                BezierSegment bezier = new BezierSegment();
                bezier.Point3 = data.controlBtn3;
                PathFigure figure = new PathFigure();
                figure.StartPoint = data.controlBtn1;
                bezier.Point1     = figure.StartPoint;
                bezier.Point2     = bezier.Point3;
                figure.Segments.Add(bezier);
                PathGeometry geometry = new PathGeometry();
                geometry.Figures.Add(figure);
                Path            myPath            = new System.Windows.Shapes.Path();
                SolidColorBrush mySolidColorBrush = new SolidColorBrush();
                // Describes the brush's color using RGB values.
                // Each value has a range of 0-255.

                myPath.Stroke          = new SolidColorBrush(Color.FromRgb(data.state.colorR, data.state.colorG, data.state.colorB));
                myPath.StrokeThickness = data.state.strokeT;

                /*myPath.MouseLeftButtonDown += data.myLine_MouseLeftButtonDown;
                 * myPath.MouseEnter += data.myLine_MouseEnter;
                 * myPath.MouseLeave += data.myLine_MouseLeave; */
                myPath.Data = geometry;
                shapeLib.Data.mygrid.Children.Add(myPath);
                gv.baseShape.Add(myPath);
            }
            else
            {
                Path         myPath   = (Path)gv.baseShape[0];// =(Line) currPath.getDrawShape();
                PathGeometry geometry = (PathGeometry)myPath.Data;
                geometry.Figures[0].StartPoint = data.controlBtn1;
                BezierSegment bs = (BezierSegment)geometry.Figures[0].Segments[0];
                bs.Point1 = data.controlBtn2;
                bs.Point2 = data.controlBtn3;
                bs.Point3 = data.controlBtn4;
            }
        }
Ejemplo n.º 33
0
        public static void RefreshSectionNodes()
        {
            int count = BuilderData.Data.bezierHandles.Count;

            for (int i = 0; i < count; i++)
            {
                GameObject o = BuilderData.Data.bezierHandles [0].gameObject;
                BuilderData.Data.bezierHandles.RemoveAt(0);
                DestroyImmediate(o);
            }
            count = BuilderData.Data.sectionNodes.Count;
            for (int i = 0; i < count; i++)
            {
                GameObject o = BuilderData.Data.sectionNodes [0].gameObject;
                BuilderData.Data.sectionNodes.RemoveAt(0);
                DestroyImmediate(o);
            }

            BuilderData.Data.bezierSetMap.Clear();

            foreach (LineSet ls in BuilderData.Data.lineSetMap)
            {
                float      distance = Vector3.Distance(ls.startNode.transform.position, ls.endNode.transform.position);
                int        segment  = (int)(distance / BuilderTool.Settings.sectionLength);
                Vector3    dir      = ls.endNode.transform.position - ls.startNode.transform.position;
                GameObject handle   = new GameObject("Handle " + ls.startNode.name + " <-> " + ls.endNode.name,
                                                     new System.Type[] { typeof(BezierHandle) });
                handle.transform.SetParent(BuilderData.Data.handleParent);
                BuilderData.Data.bezierHandles.Add(handle);
                BezierSegment bSeg = new BezierSegment(ls.startNode, ls.endNode, handle);
                BuilderData.Data.bezierSetMap.Add(bSeg);
                for (int i = 1; i < segment; i++)
                {
                    GameObject newSection = new GameObject("Section");
                    newSection.transform.SetParent(BuilderData.Data.sectionParent);
                    BuilderData.Data.sectionNodes.Add(newSection.AddComponent <SectionNode> ());
                    bSeg.sectionNodes.Add(newSection);
                    newSection.transform.position = ls.startNode.transform.position + dir.normalized * i * BuilderTool.Settings.sectionLength;
                }
            }
        }
Ejemplo n.º 34
0
        public static Shape SetBezier(Brush brush, Point firstDot, Point controlDot1, Point controlDot2, Point lastDot, Canvas canvas)
        {
            Path myPath = new Path();

            myPath.MinHeight       = 5;
            myPath.Stroke          = brush;
            myPath.StrokeThickness = OptionDrawLine.strokeThickness;
            PathGeometry  myPathGeometry = new PathGeometry();
            PathFigure    myPathFigure   = new PathFigure();
            BezierSegment myArcSegment   = new BezierSegment();

            myPathFigure.StartPoint = firstDot;
            myArcSegment.Point1     = controlDot1;
            myArcSegment.Point2     = controlDot2;
            myArcSegment.Point3     = lastDot;
            myPathFigure.Segments.Add(myArcSegment);
            myPathGeometry.Figures.Add(myPathFigure);
            myPath.Data = myPathGeometry;
            canvas.Children.Add(myPath);
            return(myPath);
        }
    public void BezierSegmentToPath_ReturnsBezierPathSegments()
    {
        var points = new Vector2[4];

        for (int i = 0; i < points.Length; ++i)
        {
            points[i] = Vector2.one * i;
        }

        var seg = new BezierSegment()
        {
            P0 = points[0], P1 = points[1], P2 = points[2], P3 = points[3]
        };
        var pathSeg = VectorUtils.BezierSegmentToPath(seg);

        Assert.AreEqual(2, pathSeg.Length);
        Assert.AreEqual(points[0], pathSeg[0].P0);
        Assert.AreEqual(points[1], pathSeg[0].P1);
        Assert.AreEqual(points[2], pathSeg[0].P2);
        Assert.AreEqual(points[3], pathSeg[1].P0);
    }
Ejemplo n.º 36
0
            public VisualConnection(NodeConnector _connector1, NodeConnector _connector2, Canvas _nodeEditor)
            {
                connector1 = _connector1;
                connector2 = _connector2;
                nodeEditor = _nodeEditor;

                Ellipse e1 = connector1.ellipse;
                Ellipse e2 = connector2.ellipse;

                connectionPath = new Path
                {
                    Stroke = new SolidColorBrush(Properties.Settings.Default.ConnectionPathColor),
                };

                Point p1 = new Point(e1.TransformToAncestor(nodeEditor).Transform(new Point(0, 0)).X + e1.ActualWidth / 2, (e1.TransformToAncestor(nodeEditor).Transform(new Point(0, 0)).Y + e1.ActualHeight / 2));
                Point p2 = new Point(e2.TransformToAncestor(nodeEditor).Transform(new Point(0, 0)).X + e2.ActualWidth / 2, (e2.TransformToAncestor(nodeEditor).Transform(new Point(0, 0)).Y + e2.ActualHeight / 2));

                BezierSegment spline = new BezierSegment()
                {
                    Point1 = new Point(p1.X + (p2.X - p1.X) * 0.66, p1.Y),
                    Point2 = new Point(p2.X + (p1.X - p2.X) * 0.66, p2.Y),
                    Point3 = p2,
                };

                PathFigure pathFigure = new PathFigure
                {
                    StartPoint = p1
                };

                pathFigure.Segments.Add(spline);

                PathGeometry connectionGeometry = new PathGeometry();

                connectionGeometry.Figures.Add(pathFigure);

                connectionPath.Data = connectionGeometry;

                connection = pathFigure;
                nodeEditor.Children.Add(connectionPath);
            }
Ejemplo n.º 37
0
        /// <summary>
        /// Updates the segments based on its data point value. This method is not
        /// intended to be called explicitly outside the Chart but it can be overridden by
        /// any derived class.
        /// </summary>
        /// <param name="transformer">Represents the view port of chart control.(refer <see cref="IChartTransformer"/>)</param>
        public override void Update(IChartTransformer transformer)
        {
            PathFigure figure = new PathFigure();

            if (AreaPoints.Count > 1)
            {
                int endIndex = AreaPoints.Count - 1;
                WindowsLineSegment lineSegment = new WindowsLineSegment();
                figure.StartPoint = transformer.TransformToVisible(AreaPoints[0].X, AreaPoints[0].Y);
                lineSegment.Point = transformer.TransformToVisible(AreaPoints[1].X, AreaPoints[1].Y);
                figure.Segments.Add(lineSegment);

                for (int i = 2; i < AreaPoints.Count - 1; i += 6)
                {
                    BezierSegment segment = new BezierSegment();
                    segment.Point1 = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    segment.Point2 = transformer.TransformToVisible(AreaPoints[i + 1].X, AreaPoints[i + 1].Y);
                    segment.Point3 = transformer.TransformToVisible(AreaPoints[i + 2].X, AreaPoints[i + 2].Y);
                    figure.Segments.Add(segment);
                }

                lineSegment       = new WindowsLineSegment();
                lineSegment.Point = transformer.TransformToVisible(AreaPoints[endIndex].X, AreaPoints[endIndex].Y);
                figure.Segments.Add(lineSegment);

                for (int i = endIndex - 1; i > 1; i -= 6)
                {
                    BezierSegment segment = new BezierSegment();
                    segment.Point1 = transformer.TransformToVisible(AreaPoints[i].X, AreaPoints[i].Y);
                    segment.Point2 = transformer.TransformToVisible(AreaPoints[i - 1].X, AreaPoints[i - 1].Y);
                    segment.Point3 = transformer.TransformToVisible(AreaPoints[i - 2].X, AreaPoints[i - 2].Y);
                    figure.Segments.Add(segment);
                }
            }

            PathGeometry segmentGeometry = new PathGeometry();

            segmentGeometry.Figures.Add(figure);
            this.segPath.Data = segmentGeometry;
        }
Ejemplo n.º 38
0
	public void Add(BezierNode Node){
		if (closed){
			if (mapped){
				length -= Curve[Curve.Count - 1].Length;
			}
			Curve.RemoveAt(Curve.Count - 1);
			closed = false;
		}
		if (Curve.Count > 0){
			BezierSegment segment = new BezierSegment(Curve[Curve.Count - 1].End, Node);
			Curve.Add(segment);
		}
		else if (firstNode != null) {
			BezierSegment segment = new BezierSegment(firstNode, Node);
			Curve.Add(segment);
		}
		else {
			firstNode = Node;
		}
		if (mapped){
			Curve[Curve.Count - 1].Map(resolution);
			length += Curve[Curve.Count - 1].Length;
		}
	}
Ejemplo n.º 39
0
        /// <summary>
        /// Draws a Bézier spline defined by four System.Drawing.PointF structures</summary>
        /// <param name="pt1">Represents the starting point of the curve</param>
        /// <param name="pt2">Represents the first control point for the curve</param>
        /// <param name="pt3">Represents the second control point for the curve</param>
        /// <param name="pt4">Represents the ending point of the curve</param>
        /// <param name="brush">The brush used to paint the curve's stroke</param>
        /// <param name="strokeWidth">The thickness of the geometry's stroke. The stroke is centered on the geometry's outline.</param>
        /// <param name="strokeStyle">The style of stroke to apply to the geometry's outline or null to draw a solid line</param>
        public void DrawBezier(PointF pt1, PointF pt2, PointF pt3, PointF pt4, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            using (var geom = new PathGeometry(D2dFactory.NativeFactory))
            {
                var sink = geom.Open();
                sink.BeginFigure(pt1.ToSharpDX(), FigureBegin.Hollow);
                var seg = new BezierSegment
                {
                    Point1 = pt2.ToSharpDX(),
                    Point2 = pt3.ToSharpDX(),
                    Point3 = pt4.ToSharpDX()
                };
                sink.AddBezier(seg);
                sink.EndFigure(FigureEnd.Open);
                sink.Close();
                sink.Dispose();

                var stroke = strokeStyle == null ? null : strokeStyle.NativeStrokeStyle;
                m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth, stroke);
            }
        }
 public UserControlEditBezier()
 {
     InitializeComponent();
     BezierSegment Segment = new BezierSegment();
     DataContext = m_Segments;
 }
Ejemplo n.º 41
0
 void GeometrySink.AddBezier(BezierSegment bezier)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 42
0
 private void PathBetween(Anchor a1, Anchor a2, CurveMode interpMode = CurveMode.CIM_Linear)
 {
     Line line;
     BezierSegment bez;
     switch (interpMode)
     {
         case CurveMode.CIM_Linear:
             line = new Line();
             line.bind(Line.X1Property, a1, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             break;
         case CurveMode.CIM_Constant:
             line = new Line();
             line.bind(Line.X1Property, a1, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a1, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             line = new Line();
             line.bind(Line.X1Property, a2, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             break;
         case CurveMode.CIM_CurveAuto:
         case CurveMode.CIM_CurveUser:
         case CurveMode.CIM_CurveBreak:
         case CurveMode.CIM_CurveAutoClamped:
             bez = new BezierSegment(this);
             bez.Slope1 = a1.point.Value.LeaveTangent;
             bez.Slope2 = a2.point.Value.ArriveTangent;
             bez.bind(BezierSegment.X1Property, a1, "X");
             bez.bind(BezierSegment.Y1Property, a1, "Y");
             bez.bind(BezierSegment.X2Property, a2, "X");
             bez.bind(BezierSegment.Y2Property, a2, "Y");
             graph.Children.Add(bez);
             a1.rightBez = bez;
             a2.leftBez = bez;
             break;
         default:
             break;
     }
 }
 /// <summary>
 /// Returns new BezierSegment  by easing startValue to endValue using a time percentage 0 -> 1.
 /// </summary>
 /// <example>XAML: Data="M 10,100 C 100,0 200,200 300,100"</example>
 /// <seealso cref="http://msdn.microsoft.com/en-us/library/system.windows.media.beziersegment.aspx"/>
 public static BezierSegment EaseValue(BezierSegment startValue, BezierSegment endValue, double percent)
 {
     return new BezierSegment 
     {
         Point1 = EaseValue(startValue.Point1, endValue.Point1, percent),
         Point2 = EaseValue(startValue.Point2, endValue.Point2, percent),
         Point3 = EaseValue(startValue.Point3, endValue.Point3, percent)
     };
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Adds a sequence of connected cubic Bézier curves to the current figure.
        /// </summary>
        public void AddBeziers(XPoint[] points)
        {
            if (points == null)
                throw new ArgumentNullException("points");

            int count = points.Length;
            if (count < 4)
                throw new ArgumentException("At least four points required for bezier curve.", "points");

            if ((count - 1) % 3 != 0)
                throw new ArgumentException("Invalid number of points for bezier curve. Number must fulfil 4+3n.",
                    "points");

#if CORE
            _corePath.MoveOrLineTo(points[0].X, points[0].Y);
            for (int idx = 1; idx < count; idx += 3)
            {
                _corePath.BezierTo(points[idx].X, points[idx].Y, points[idx + 1].X, points[idx + 1].Y,
                    points[idx + 2].X, points[idx + 2].Y, false);
            }
#endif
#if GDI
            try
            {
                Lock.EnterGdiPlus();
                _gdipPath.AddBeziers(XGraphics.MakePointFArray(points));
            }
            finally { Lock.ExitGdiPlus(); }
#endif
#if WPF
            PathFigure figure = CurrentPathFigure;
            if (figure.Segments.Count == 0)
                figure.StartPoint = new SysPoint(points[0].X, points[0].Y);
            else
            {
                // figure.Segments.Add(new LineSegment(new SysPoint(points[0].x, points[0].y), true));
#if !SILVERLIGHT
                LineSegment lineSegment = new LineSegment(new SysPoint(points[0].X, points[0].Y), true);
#else
                LineSegment lineSegment = new LineSegment();
                lineSegment.Point = new Point(points[0].X, points[0].Y);
#endif
                figure.Segments.Add(lineSegment);
            }
            for (int idx = 1; idx < count; idx += 3)
            {
                //figure.Segments.Add(new BezierSegment(
                //                      new SysPoint(points[idx].x, points[idx].y),
                //                      new SysPoint(points[idx + 1].x, points[idx + 1].y),
                //                      new SysPoint(points[idx + 2].x, points[idx + 2].y), true));
#if !SILVERLIGHT
                BezierSegment bezierSegment = new BezierSegment(
                                      new SysPoint(points[idx].X, points[idx].Y),
                                      new SysPoint(points[idx + 1].X, points[idx + 1].Y),
                                      new SysPoint(points[idx + 2].X, points[idx + 2].Y), true);
#else
                BezierSegment bezierSegment = new BezierSegment();
                bezierSegment.Point1 = new Point(points[idx].X, points[idx].Y);
                bezierSegment.Point2 = new Point(points[idx + 1].X, points[idx + 1].Y);
                bezierSegment.Point3 = new Point(points[idx + 2].X, points[idx + 2].Y);
#endif
                figure.Segments.Add(bezierSegment);
            }
#endif
        }
Ejemplo n.º 45
0
 public void AddBezier(BezierSegment bezier)
 {
 }
Ejemplo n.º 46
0
        /// <summary>
        /// Draws a path defined by an enumeration of EdgeStyleData structures</summary>
        /// <param name="path">The enumeration of drawing primitives that describes the contents of the path</param>
        /// <param name="brush">The brush used to paint the path's stroke</param>
        /// <param name="strokeWidth">A value greater than or equal to 0.0f that specifies the width of the stroke</param>
        /// <remarks>Assume the end point of one primitive be coincident with the start point of the following primitive in a path</remarks>
        /// <param name="strokeStyle">The style of the rounded rectangle's stroke, or null to paint a solid stroke</param>
        public void DrawPath(IEnumerable<EdgeStyleData> path, D2dBrush brush, float strokeWidth = 1.0f, D2dStrokeStyle strokeStyle = null)
        {
            using (var geom = new PathGeometry(D2dFactory.NativeFactory))
            {
                var sink = geom.Open();
                var firstPoint = true;
                foreach (var edge in path)
                {
                    if (edge.ShapeType == EdgeStyleData.EdgeShape.Line)
                    {
                        var line = edge.EdgeData.As<PointF[]>();
                        if (firstPoint)
                        {
                            sink.BeginFigure(line[0].ToSharpDX(), FigureBegin.Hollow);
                            firstPoint = false;
                        }
                        for (var i = 1; i < line.Length; ++i)
                            sink.AddLine(line[i].ToSharpDX());

                    }
                    else if (edge.ShapeType == EdgeStyleData.EdgeShape.Bezier)
                    {
                        var curve = edge.EdgeData.As<BezierCurve2F>();
                        if (firstPoint)
                        {
                            sink.BeginFigure(curve.P1.ToSharpDX(), FigureBegin.Hollow);
                            firstPoint = false;
                        }
                        var seg = new BezierSegment
                        {
                            Point1 = curve.P2.ToSharpDX(),
                            Point2 = curve.P3.ToSharpDX(),
                            Point3 = curve.P4.ToSharpDX()
                        };
                        sink.AddBezier(seg);
                    }
                }
                sink.EndFigure(FigureEnd.Open);
                sink.Close();
                sink.Dispose();

                m_renderTarget.DrawGeometry(geom, brush.NativeBrush, strokeWidth,
                    strokeStyle != null ? strokeStyle.NativeStrokeStyle : null);
            }
        }
Ejemplo n.º 47
0
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(@"c:\users\ken\desktop\drawing.svg");

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
            nsmgr.AddNamespace("svg", "http://www.w3.org/2000/svg");

            XmlNodeList selection = doc.SelectNodes("//svg:path", nsmgr);

            Factory factory = new Factory(FactoryType.SingleThreaded);
            PathGeometry pathGeometry = new PathGeometry(factory);

            GeometrySink sink = pathGeometry.Open();

            sink.SetSegmentFlags(PathSegment.ForceRoundLineJoin);
            sink.SetFillMode(FillMode.Winding);

            PointF currentPoint = new PointF(0, 0);

            foreach (XmlNode n in selection)
            {
                XmlAttribute attribute = n.Attributes["d"];
                string d = attribute.Value;

                string[] data = d.Split(' ');

                Command command = Command.MoveTo;
                PointF relativePoint = currentPoint;
                bool isBegun = false;
                FigureEnd figureEndStyle = FigureEnd.Open;

                for (int i = 0; i < data.Length; i++)
                {
                    string arg = data[i];

                    switch (arg.ToUpper())
                    {
                        case "M":
                            command = Command.MoveTo;
                            relativePoint = arg.ToUpper() == arg ? new PointF(0, 0) : currentPoint;
                            break;

                        case "C":
                            command = Command.CurveTo;
                            relativePoint = arg.ToUpper() == arg ? new PointF(0, 0) : currentPoint;
                            break;

                        case "L":
                            command = Command.LineTo;
                            relativePoint = arg.ToUpper() == arg ? new PointF(0, 0) : currentPoint;
                            break;

                        case "V":
                        case "H":
                            break;

                        case "Z":
                            figureEndStyle = FigureEnd.Closed;
                            break;

                        default:
                            currentPoint = CoordinateToPointF(arg, relativePoint);

                            switch (command)
                            {
                                case Command.MoveTo:
                                    if (isBegun)
                                    {
                                        sink.EndFigure(figureEndStyle);
                                    }

                                    sink.BeginFigure(currentPoint, FigureBegin.Filled);
                                    isBegun = true;

                                    break;

                                case Command.LineTo:
                                    sink.AddLine(currentPoint);
                                    break;

                                case Command.CurveTo:
                                    BezierSegment bezier = new BezierSegment();

                                    bezier.Point1 = currentPoint;
                                    bezier.Point2 = CoordinateToPointF(data[i + 1], relativePoint);
                                    bezier.Point3 = CoordinateToPointF(data[i + 2], relativePoint);

                                    i += 2;

                                    sink.AddBezier(bezier);
                                    break;
                            }

                            break;
                    }
                }

                sink.EndFigure(figureEndStyle);
                sink.Close();

                var pathGeometryNew = new PathGeometry(factory);
                var newSink = pathGeometryNew.Open();
                pathGeometry.Widen(4, newSink);
                newSink.Close();

                // Now do Tessellation
                using (FileStream fs = File.OpenWrite(@"c:\Users\ken\desktop\my.triangles"))
                {
                    MyTessellationSink tessellationSink = new MyTessellationSink(fs);
                    var result = pathGeometryNew.Tessellate(tessellationSink);
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 48
0
    public void init(LevelInstance inst)
    {
        levels [inst] = this;

        //load the configuration stuff
        this.Costume = "Levels/" + sprites[inst];
        this.levelName = names[inst];
        nodes = nodeSets[inst];

        segments = new Dictionary<float, BezierSegment> ();
        orderedKeys = new List<float> ();

        //build the bezier segments from the nodes
        totalLength = 0;
        for (int i = 0; i < nodes.Length; i++) {
            Vector3 midpointBefore = i == 0 ? nodes[i] : (nodes[i-1] + nodes[i])/2f;
            Vector3 midpointAfter = i == nodes.Length - 1 ? nodes[i] : (nodes[i+1] + nodes[i])/2f;
            var bez = new BezierSegment(midpointBefore, nodes[i], midpointAfter);
            segments[totalLength] = bez;
            orderedKeys.Add(totalLength);
            totalLength += bez.Length;
        }

        sprite.sortingLayerName = "Map";
    }
Ejemplo n.º 49
0
        public void Bezier(CubicBezier bezier)
        {
            if (Stroking)
            {
                drawOpenPath(Import.Point(bezier.Start),
                    sink =>
                        {
                            var bezierSegment = new BezierSegment()
                            {
                                Point1 = Import.Point(bezier.Span1),
                                Point2 = Import.Point(bezier.Span2),
                                Point3 = Import.Point(bezier.End)
                            };

                            sink.AddBezier(bezierSegment);
                        });
            }
        }
Ejemplo n.º 50
0
 /// <summary>
 /// Refreshes this instance.
 /// </summary>
 public override void Refresh()
 {
     if (SplinePath != null)
     {
         PathFigure figure = new PathFigure();
         BezierSegment bezierPoints = new BezierSegment();
         PathGeometry pathGeometry = new PathGeometry();
         figure.StartPoint = StartPoint;
         bezierPoints.Point1 = FirstControlPoint;
         bezierPoints.Point2 = EndControlPoint;
         bezierPoints.Point3 = EndPoint;
         figure.Segments.Add(bezierPoints);
         pathGeometry.Figures = new PathFigureCollection() { figure };
         SplinePath.Data = pathGeometry;
     }
 }
Ejemplo n.º 51
0
        /// <summary>
        /// Adds a cubic Bézier curve to the current figure.
        /// </summary>
        public void AddBezier(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
        {
#if CORE
            _corePath.MoveOrLineTo(x1, y1);
            _corePath.BezierTo(x2, y2, x3, y3, x4, y4, false);
#endif
#if GDI
            try
            {
                Lock.EnterGdiPlus();
                _gdipPath.AddBezier((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3, (float)x4, (float)y4);
            }
            finally { Lock.ExitGdiPlus(); }
#endif
#if WPF
            PathFigure figure = CurrentPathFigure;
            if (figure.Segments.Count == 0)
                figure.StartPoint = new SysPoint(x1, y1);
            else
            {
                // figure.Segments.Add(new LineSegment(new SysPoint(x1, y1), true));
#if !SILVERLIGHT
                LineSegment lineSegment = new LineSegment(new SysPoint(x1, y1), true);
#else
                LineSegment lineSegment = new LineSegment();
                lineSegment.Point = new Point(x1, y1);
#endif
                figure.Segments.Add(lineSegment);
            }
            //figure.Segments.Add(new BezierSegment(
            //  new SysPoint(x2, y2),
            //  new SysPoint(x3, y3),
            //  new SysPoint(x4, y4), true));
#if !SILVERLIGHT
            BezierSegment bezierSegment = new BezierSegment(
                new SysPoint(x2, y2),
                new SysPoint(x3, y3),
                new SysPoint(x4, y4), true);
#else
            BezierSegment bezierSegment = new BezierSegment();
            bezierSegment.Point1 = new Point(x2, y2);
            bezierSegment.Point2 = new Point(x3, y3);
            bezierSegment.Point3 = new Point(x4, y4);
#endif
            figure.Segments.Add(bezierSegment);
#endif
        }
Ejemplo n.º 52
0
        /// <summary>
        /// Fills the interior of a path defined by an enumeration of EdgeStyleData structures</summary>
        /// <param name="path">The enumeration of drawing primitives that describes the contents of the path</param>
        /// <param name="brush">The brush used to paint the path's stroke</param>
        /// <remarks>Assume the end point of one primitive be coincident with the start point of the following primitive in a path</remarks>
        public void FillPath(IEnumerable<EdgeStyleData> path, D2dBrush brush)
        {
            using (var geom = new PathGeometry(D2dFactory.NativeFactory))
            {
                var sink = geom.Open();
                var firstPoint = true;
                foreach (var edge in path)
                {
                    if (edge.ShapeType == EdgeStyleData.EdgeShape.Line)
                    {
                        var line = edge.EdgeData.As<PointF[]>();
                        if (firstPoint)
                        {
                            sink.BeginFigure(new DrawingPointF(line[0].X, line[0].Y), FigureBegin.Filled);
                            firstPoint = false;
                        }
                        for (var i = 1; i < line.Length; ++i)
                            sink.AddLine(new DrawingPointF(line[i].X, line[i].Y));

                    }
                    else if (edge.ShapeType == EdgeStyleData.EdgeShape.Bezier)
                    {
                        var curve = edge.EdgeData.As<BezierCurve2F>();
                        if (firstPoint)
                        {
                            sink.BeginFigure(new DrawingPointF(curve.P1.X, curve.P1.Y), FigureBegin.Hollow);
                            firstPoint = false;
                        }
                        var seg = new BezierSegment
                        {
                            Point1 = new DrawingPointF(curve.P2.X, curve.P2.Y),
                            Point2 = new DrawingPointF(curve.P3.X, curve.P3.Y),
                            Point3 = new DrawingPointF(curve.P4.X, curve.P4.Y)
                        };
                        sink.AddBezier(seg);
                    }
                }
                sink.EndFigure(FigureEnd.Closed);
                sink.Close();
                sink.Dispose();

                m_renderTarget.FillGeometry(geom, brush.NativeBrush);
            }
        }
Ejemplo n.º 53
0
 public void AddBeziers(BezierSegment[] beziers)
 {
 }
Ejemplo n.º 54
0
        public Anchor(CurveGraph g, LinkedListNode<CurvePoint> p)
        {
            graph = g;
            point = p;
            X = graph.localX(point.Value.InVal);
            Y = graph.localY(point.Value.OutVal);
            this.DragDelta += OnDragDelta;
            this.DragStarted += OnDragStarted;
            this.MouseDown += Anchor_MouseDown;

            leftHandle = new Handle(this, true);
            graph.graph.Children.Add(leftHandle);
            rightHandle = new Handle(this, false);
            graph.graph.Children.Add(rightHandle);

            leftBez = null;
            rightBez = null;
        }
 /// <summary>
 /// Creates a sequence of cubic Bezier curves and adds them to the geometry sink.
 /// </summary>
 /// <param name="beziers">An array of Bezier segments that describes the Bezier curves to create. A curve is drawn from the geometry sink's current point (the end point of the last segment drawn or the location specified by <strong>BeginFigure</strong>) to the end point of the first Bezier segment in the array. If the array contains additional Bezier segments, each subsequent Bezier segment uses the end point of the preceding Bezier segment as its start point.</param>
 public void AddBeziers(BezierSegment[] beziers)
 {
     AddBeziers_(beziers, beziers.Length);
 }
Ejemplo n.º 56
0
 public void AddBezier(BezierSegment bezier)
 {
     AddBezier_(ref bezier);
 }