public void Setup()
        {
            m_StartSegment = Substitute.For <ITurnCircleArcSegment>();
            m_MiddleSegment = Substitute.For <ITurnCircleArcSegment>();
            m_EndSegment = Substitute.For <ITurnCircleArcSegment>();

            m_Path = Substitute.For <IPath>();
            var segments = new List <IPolylineSegment>
                           {
                               m_StartSegment,
                               m_MiddleSegment,
                               m_EndSegment
                           };

            m_Path.Segments.Returns(segments);

            m_ArcSegmentOne = new ArcSegment(new Point(10.0,
                                                       10.0),
                                             new Size(10.0,
                                                      10.0),
                                             45.0,
                                             false,
                                             SweepDirection.Clockwise,
                                             false);

            m_LineSegment = new LineSegment(new Point(20.0,
                                                      20.0),
                                            false);

            m_ArcSegmentTwo = new ArcSegment(new Point(30.0,
                                                       30.0),
                                             new Size(30.0,
                                                      30.0),
                                             90.0,
                                             false,
                                             SweepDirection.Counterclockwise,
                                             false);

            m_ArcSegmentThree = new ArcSegment(new Point(40.0,
                                                         40.0),
                                               new Size(40.0,
                                                        40.0),
                                               135.0,
                                               false,
                                               SweepDirection.Counterclockwise,
                                               false);


            m_Point = new Point(10.0,
                                10.0);

            m_Helper = Substitute.For <IPathSegmentHelper>();
            m_Helper.SegmentToLineSegment(Line.Unknown).ReturnsForAnyArgs(m_LineSegment);
            m_Helper.SegmentToArcSegment(TurnCircleArcSegment.Unknown).ReturnsForAnyArgs(m_ArcSegmentOne,
                                                                                         m_ArcSegmentTwo,
                                                                                         m_ArcSegmentThree);
            m_Helper.PointRelativeToOrigin(null).ReturnsForAnyArgs(m_Point);

            m_Converter = new RacetrackPathUTurnToFiguresConverter(m_Helper);
        }
Exemple #2
0
        public WpfArc(IArc arc)
        {
            _xarc = arc;

            _fillBrush = new SolidColorBrush(_xarc.Fill.ToNativeColor());
            _fillBrush.Freeze();
            _strokeBrush = new SolidColorBrush(_xarc.Stroke.ToNativeColor());
            _strokeBrush.Freeze();

            _path = new Path();
            _path.Tag = this;
            _path.Fill = _fillBrush;
            _path.Stroke = _strokeBrush;
            _path.StrokeThickness = arc.StrokeThickness;
            _pg = new PathGeometry();
            _pf = new PathFigure();
            _pf.IsFilled = arc.IsFilled;
            _pf.IsClosed = arc.IsClosed;
            _start = new Point();
            _as = new ArcSegment();
            SetArcSegment(_as, arc, out _start);
            _pf.StartPoint = _start;
            _pf.Segments.Add(_as);
            _pg.Figures.Add(_pf);
            _path.Data = _pg;

            Native = _path;
        }
Exemple #3
0
 public static Tuple<Path, PathFigure, ArcSegment> CreateArcShape()
 {
     var arcSegment = new ArcSegment()
     {
         SweepDirection = SweepDirection.Counterclockwise,
         RotationAngle = 0
     };
     var figure = new PathFigure()
     {
         IsClosed = false,
         IsFilled = false,
         Segments = new PathSegmentCollection()
         {
             arcSegment
         }
     };
     var path = new Path()
     {
         Data = new PathGeometry()
         {
             Figures = new PathFigureCollection()
             {
                 figure
             }
         },
         Stroke = new SolidColorBrush(Colors.Black),
         StrokeThickness = 1
     };
     return Tuple.Create(path, figure, arcSegment);
 }
Exemple #4
0
        public PathFigure AddArc(int start, int end)
        {
            int horizontalPostion = 100;

            var startPoint = new Point(horizontalPostion, start);
            var endPoint = new Point(horizontalPostion, end);

            PathFigure pathFigure = new PathFigure();
            pathFigure.StartPoint = startPoint;

            ArcSegment arcSeg = new ArcSegment();
            arcSeg.Point = endPoint;
            arcSeg.Size = new Size(25, 25);
            arcSeg.IsLargeArc = true;
            arcSeg.SweepDirection = SweepDirection.Clockwise;
            arcSeg.RotationAngle = 90;

            var arrowhead = new Polygon();
            arrowhead.Stroke = Brushes.Black;
            arrowhead.StrokeThickness = 2;
            arrowhead.Points.Add(new Point(endPoint.X - 4, endPoint.Y));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y + 3));
            arrowhead.Points.Add(new Point(endPoint.X + 4, endPoint.Y - 3));
            arrowhead.Fill = Brushes.Black;

            PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
            myPathSegmentCollection.Add(arcSeg);
            pathFigure.Segments = myPathSegmentCollection;

            _pathFigureCollection.Add(pathFigure);

            _root.Children.Add(arrowhead);

            return pathFigure;
        }
        private void RenderArc(double Angle, Path pathRoot, PathFigure pathFigure, ArcSegment arcSegment)
        {
            Point startPoint = new Point(Radius, 0);
            Point endPoint = ComputeCartesianCoordinate(Angle, Radius);
            endPoint.X += Radius;
            endPoint.Y += Radius;

            pathRoot.Width = Radius * 2 + StrokeThickness;
            pathRoot.Height = Radius * 2 + StrokeThickness;
            pathRoot.Margin = new Thickness(StrokeThickness, StrokeThickness, 0, 0);

            bool largeArc = Angle > 180.0;

            Size outerArcSize = new Size(Radius, Radius);

            pathFigure.StartPoint = startPoint;

            if (startPoint.X == Math.Round(endPoint.X) && startPoint.Y == Math.Round(endPoint.Y))
            {
                endPoint.X -= 0.01;
            }

            arcSegment.Point = endPoint;
            arcSegment.Size = outerArcSize;
            arcSegment.IsLargeArc = largeArc;
        }
		private void AddCircularArcGraph(Point startPoint, Point endPoint, Size size)
		{
			PathFigure pf = new PathFigure();
			pf.StartPoint = new Point(startPoint.X, startPoint.Y);

			ArcSegment arcSegment = new ArcSegment();
			arcSegment.Point = new Point(endPoint.X, endPoint.Y);
			arcSegment.Size = size;
			arcSegment.SweepDirection = SweepDirection.Counterclockwise;

			PathSegmentCollection psc = new PathSegmentCollection();
			psc.Add(arcSegment);

			pf.Segments = psc;

			PathFigureCollection pfc = new PathFigureCollection();
			pfc.Add(pf);

			PathGeometry pg = new PathGeometry();
			pg.Figures = pfc;

			var path = new Path();
			path.Stroke = Brushes.Black;
			path.StrokeThickness = 1;
			path.Data = pg;
			path.Fill = Brushes.Orange;
			path.Stretch = Stretch.Fill;

			var viewportPanel = new ViewportHostPanel();
			ViewportPanel.SetViewportBounds(path, new DataRect(0, 0, 50, 50));
			viewportPanel.Children.Add(path);
			plotter.Children.Add(viewportPanel);
		}
        private void DefineGeometry()
        {
            PointCollection points = Points;
            if (points == null)
            {
                _geometry = Geometry.Empty;
                return;
            }

            PathFigure figure = new PathFigure();
            if (points.Count > 0)
            {
                // start point
                figure.StartPoint = points[0];

                if (points.Count > 1)
                {
                    // points between
                    double desiredRadius = Radius;
                    for (int i = 1; i < (points.Count - 1); i++)
                    {
                        // adjust radius if points are too close
                        Vector v1 = points[i] - points[i - 1];
                        Vector v2 = points[i + 1] - points[i];
                        double radius = Math.Min(Math.Min(v1.Length, v2.Length) / 2, desiredRadius);

                        // draw the line, and stop before the next point
                        double len = v1.Length;
                        v1.Normalize();
                        v1 *= (len - radius);
                        LineSegment line = new LineSegment(points[i - 1] + v1, true);
                        figure.Segments.Add(line);

                        // draw the arc to the next point
                        v2.Normalize();
                        v2 *= radius;
                        SweepDirection direction = (Vector.AngleBetween(v1, v2) > 0) ? SweepDirection.Clockwise : SweepDirection.Counterclockwise;
                        ArcSegment arc = new ArcSegment(points[i] + v2, new Size(radius, radius), 0, false, direction, true);
                        figure.Segments.Add(arc);
                    }

                    // last point
                    figure.Segments.Add(new LineSegment(points[points.Count - 1], true));
                }
            }
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(figure);
            geometry.FillRule = FillRule;
            if (geometry.Bounds == Rect.Empty)
            {
                _geometry = Geometry.Empty;
            }
            else
            {
                _geometry = geometry;
            }
        }
 void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) {
     switch (connectionId)
     {
     case 1:
     this.arc = ((System.Windows.Media.ArcSegment)(target));
     return;
     }
     this._contentLoaded = true;
 }
Exemple #9
0
 public Arc(Path path, LineSegment lineSegment, ArcSegment arcSegment, Point zeroPos, Color color)
 {
     Path = path;
     LineSegment = lineSegment;
     ArcSegment = arcSegment;
     ZeroPos = zeroPos;
     Path.Stroke = ToBrush(color);
     Path.Fill = ToBrush(color);
 }
        public ArcSegment CreateArcSegment(Point point,
                                           Size size,
                                           SweepDirection sweepDirection,
                                           bool isLargeArc = false)
        {
            const double rotationAngle = 0.0;
            const bool isStroked = true;

            var arcSegment = new ArcSegment(point,
                                            size,
                                            rotationAngle,
                                            isLargeArc,
                                            sweepDirection,
                                            isStroked);

            return arcSegment;
        }
Exemple #11
0
 public override void OnApplyTemplate()
 {
     base.OnApplyTemplate();
     this.Root = base.GetTemplateChild("Root") as Border;
     this.ArrowRow = base.GetTemplateChild("ArrowRow") as RowDefinition;
     this.ToolTipPathFigure = base.GetTemplateChild("ToolTipPathFigure") as PathFigure;
     this.BottomCenterLeft = base.GetTemplateChild("BottomCenterLeft") as LineSegment;
     this.BottomLeftCorner1 = base.GetTemplateChild("BottomLeftCorner1") as LineSegment;
     this.BottomLeftCorner2 = base.GetTemplateChild("BottomLeftCorner2") as ArcSegment;
     this.TopLeftCorner1 = base.GetTemplateChild("TopLeftCorner1") as LineSegment;
     this.TopLeftCorner2 = base.GetTemplateChild("TopLeftCorner2") as ArcSegment;
     this.TopRightCorner1 = base.GetTemplateChild("TopRightCorner1") as LineSegment;
     this.TopRightCorner2 = base.GetTemplateChild("TopRightCorner2") as ArcSegment;
     this.BottomRightCorner1 = base.GetTemplateChild("BottomRightCorner1") as LineSegment;
     this.BottomRightCorner2 = base.GetTemplateChild("BottomRightCorner2") as ArcSegment;
     this.BottomCenterRight = base.GetTemplateChild("BottomCenterRight") as LineSegment;
 }
Exemple #12
0
        void ClippedGrid_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            double w = this.ActualWidth;
            double h = this.ActualHeight;

            PathFigure figure = new PathFigure();
            figure.StartPoint = new Point(0, h);

            LineSegment left = new LineSegment();
            left.Point = new Point(0, _arcSizeY + _offsetY);
            figure.Segments.Add(left);

            ArcSegment topLeftRounding = new ArcSegment();
            topLeftRounding.Size = new Size(_arcSizeX, _arcSizeY);
            topLeftRounding.RotationAngle = 0;
            topLeftRounding.IsLargeArc = false;
            topLeftRounding.SweepDirection = SweepDirection.Clockwise;
            topLeftRounding.Point = new Point(_arcSizeX, _offsetY);
            figure.Segments.Add(topLeftRounding);

            LineSegment top = new LineSegment();
            top.Point = new Point(w - _arcSizeX, _offsetY);
            figure.Segments.Add(top);

            ArcSegment topRightRounding = new ArcSegment();
            topRightRounding.Size = new Size(_arcSizeX, _arcSizeY);
            topRightRounding.RotationAngle = 0;
            topRightRounding.IsLargeArc = false;
            topRightRounding.SweepDirection = SweepDirection.Clockwise;
            topRightRounding.Point = new Point(w, _arcSizeY + _offsetY);
            figure.Segments.Add(topRightRounding);

            LineSegment right = new LineSegment();
            right.Point = new Point(w, h);
            figure.Segments.Add(right);

            LineSegment bottom = new LineSegment();
            bottom.Point = new Point(0, h);
            figure.Segments.Add(bottom);

            PathGeometry clip = new PathGeometry();
            clip.Figures.Add(figure);

            this.Clip = clip;
        }
        public Path Draw(double X, double Y)
        {
            Path path = new Path();
            Canvas.SetTop(path, Y);
            Canvas.SetLeft(path, X);
            //Make Geometry
            _arcSeg = new ArcSegment(new Point(X+800, Y+800), new Size(1000, 2000), 0.0, true, SweepDirection.Clockwise, true);
            PathSegmentCollection psc = new PathSegmentCollection(){_arcSeg};
            _pathFig = new PathFigure(new Point(X, Y), psc, false);
            PathFigureCollection pfc = new PathFigureCollection(){_pathFig};
            PathGeometry pgeo = new PathGeometry(pfc);
            path.Data = pgeo;

            path.StrokeThickness = 200;
            path.Fill = Brushes.White;
            path.Stroke = Brushes.Black;

            return path;
        }
        /// <summary>
        /// Calculates the midpoint of the arc passed as a parameter, as well as whether the arc is small.
        /// </summary>
        /// <param name="center">The center of the pie chart.</param>
        /// <param name="startPoint">The start point of the arc segment.</param>
        /// <param name="arcSegment">The arc of the pie wedge itself.</param>
        /// <param name="arcMidpoint">he midpoint of the arc in the pie wedge.</param>
        /// <param name="isArcSmall">True if the arc is small, false otherwise.</param>
        private static void CalculateArcInfo(Point center, Point startPoint, ArcSegment arcSegment, out Point arcMidpoint, out bool isArcSmall)
        {
            // Note: we assume a valid arcSegment with equal radii.
            Debug.Assert(arcSegment != null);
            Debug.Assert(arcSegment.Size.Width == arcSegment.Size.Height);

            Point endPoint = arcSegment.Point;
            Point chordMidpoint = new Point(0.5 * (startPoint.X + endPoint.X), 0.5 * (startPoint.Y + endPoint.Y));
            Vector chordDirection = endPoint - startPoint;
            double chordLength = chordDirection.Length;
            double radius = arcSegment.Size.Width;

            isArcSmall = chordLength < DistanceSmallArc;

            // If the chord length is less than the distance tolerance, just use the chord midpoint
            // or the point on the opposite side of the circle as appropriate.
            if (chordLength < DistanceTolerance)
            {
                arcMidpoint = arcSegment.IsLargeArc ? center - (chordMidpoint - center) : chordMidpoint;
            }
            else
            {
                chordDirection /= chordLength;
                Vector radialDirection = new Vector(-chordDirection.Y, chordDirection.X);
                double halfChordLength = 0.5 * chordLength;
                double radialOffset;
                if (radius >= halfChordLength)
                {
                    double sectorRadius = Math.Sqrt(radius * radius - halfChordLength * halfChordLength);
                    radialOffset = -radius + (arcSegment.IsLargeArc ? -sectorRadius : sectorRadius);
                }
                else
                {
                    radialOffset = -halfChordLength;
                }
                if (arcSegment.SweepDirection == SweepDirection.Counterclockwise)
                {
                    radialOffset = -radialOffset;
                }
                arcMidpoint = chordMidpoint + radialOffset * radialDirection;
            }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        public SurfaceWindow1()
        {
            InitializeComponent();
            Path myShape = new Path();
            myShape.StrokeThickness = 3.0;
            myShape.Fill = System.Windows.Media.Brushes.Wheat;
            myShape.Stroke = System.Windows.Media.Brushes.BlueViolet;
            PathGeometry myGeometry = new PathGeometry();
            PathFigure figure = new PathFigure();

            //Figure draws the segments upside down (this the coordinate system in negatives to draw objects)
            Double width = 200;
            Double height = 100;
            figure.SetValue(PathFigure.StartPointProperty, new Point(height, 0));
            ArcSegment arc = new ArcSegment(new Point(height, height), new Size(height / 2, height / 2), 0.0, true, SweepDirection.Counterclockwise, true);
            //Note: LineSegments take end point as the constructor, Their Start point will be the end point of previous segment(the order you added into path figure(Source API))
            LineSegment arcVertical1 = new LineSegment(new Point(height, height - 25), true);
            LineSegment horizontal1 = new LineSegment(new Point(height + 275, height - 25), true);
            LineSegment vertical = new LineSegment(new Point(height + 275, 25), true);
            LineSegment horizontal2 = new LineSegment(new Point(height, 25), true);
            LineSegment arcVertical2 = new LineSegment(new Point(height, 0), true);

            figure.Segments.Add(arc);
            figure.Segments.Add(arcVertical1);
            figure.Segments.Add(horizontal1);
            figure.Segments.Add(vertical);
            figure.Segments.Add(horizontal2);
            figure.Segments.Add(arcVertical2);
            myGeometry.Figures.Add(figure);

            myShape.Data = myGeometry;
            myCanvas.Children.Add(myShape);

            //****************************** Register for Stroke change events*************************
            // This is how we can get the currently being drawn stroke information
            inkCanvas.Strokes.StrokesChanged += new StrokeCollectionChangedEventHandler(canvasStrokesChanged);

            // Add handlers for window availability events
            AddWindowAvailabilityHandlers();
        }
 public override void DrawEquation(DrawingContext dc)
 {
     LineSegment line;
     ArcSegment arc;
     Point pathFigureStart;
     if (IsInverted)
     {
         pathFigureStart = new Point(ParentEquation.Right, Bottom - StandardRoundPen.Thickness /2);
         line = new LineSegment(new Point(Left, Bottom - StandardRoundPen.Thickness / 2), true);
         arc = new ArcSegment(Location, new Size(Width * 4.5, Height), 0, false, SweepDirection.Counterclockwise, true);
     }
     else
     {
         pathFigureStart = new Point(ParentEquation.Right, Top);
         line = new LineSegment(Location, true);
         arc = new ArcSegment(new Point(Left, Bottom), new Size(Width * 4.5, Height), 0, false, SweepDirection.Clockwise, true);
     }
     PathGeometry pathGeometry = new PathGeometry();
     PathFigure pathFigure = new PathFigure(pathFigureStart, new PathSegment[] { line, arc }, false);
     pathGeometry.Figures.Add(pathFigure);
     dc.DrawGeometry(null, StandardRoundPen, pathGeometry);
 }
        public static Geometry CreateArcGeometry(double minAngle, double maxAngle, double radius, int thickness, SweepDirection sweepDirection)
        {
            //the range will have 4 segments (arc, line, arc, line)
            //if the sweep angle is bigger than 180 use the large arc
            //first use the same sweep direction as the control. invert for the second arc.
            PathFigure figure = new PathFigure();
            figure.IsClosed = true;
            figure.StartPoint = new Point((radius - thickness) * Math.Sin(minAngle * Math.PI / 180),
                -(radius - thickness) * Math.Cos(minAngle * Math.PI / 180));

            //first arc segment
            ArcSegment arc = new ArcSegment();
            arc.Point = new Point((radius - thickness) * Math.Sin(maxAngle * Math.PI / 180),
                -(radius - thickness) * Math.Cos(maxAngle * Math.PI / 180));
            arc.Size = new Size(radius - thickness, radius - thickness);
            arc.SweepDirection = sweepDirection;
            if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true;
            figure.Segments.Add(arc);
            //first line segment
            LineSegment line = new LineSegment();
            line.Point = new Point(radius * Math.Sin(maxAngle * Math.PI / 180),
                -radius * Math.Cos(maxAngle * Math.PI / 180));
            figure.Segments.Add(line);
            //second arc segment
            arc = new ArcSegment();
            arc.Point = new Point(radius * Math.Sin(minAngle * Math.PI / 180),
                -radius * Math.Cos(minAngle * Math.PI / 180));
            arc.Size = new Size(radius, radius);
            arc.SweepDirection = SweepDirection.Counterclockwise;
            if (sweepDirection == SweepDirection.Counterclockwise)
                arc.SweepDirection = SweepDirection.Clockwise;
            if (Math.Abs(maxAngle - minAngle) > 180) arc.IsLargeArc = true;
            figure.Segments.Add(arc);

            PathGeometry path = new PathGeometry();
            path.Figures.Add(figure);
            return path;
        }
Exemple #18
0
 /// <summary>
 /// Converts an ArcSegment into a PolyLineSegment because I currently have no muse to calculate
 /// the correct Bézier curves.
 /// </summary>
 public static PdfSharp.Xps.XpsModel.PolyLineSegment FlattenSegment(PdfSharp.Xps.XpsModel.Point startPoint,
   PdfSharp.Xps.XpsModel.ArcSegment seg)
 {
   PathGeometry geo = new PathGeometry();
   PathFigure fig = new PathFigure();
   geo.Figures.Add(fig);
   fig.StartPoint = new Point(startPoint.X, startPoint.Y);
   ArcSegment aseg = new ArcSegment(new Point(seg.Point.X, seg.Point.Y), new Size(seg.Size.Width, seg.Size.Height), seg.RotationAngle,
     seg.IsLargeArc, (SweepDirection)seg.SweepDirection, seg.IsStroked);
   fig.Segments.Add(aseg);
   geo = geo.GetFlattenedPathGeometry();
   fig = geo.Figures[0];
   //PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0];
   PdfSharp.Xps.XpsModel.PolyLineSegment resultSeg = new PdfSharp.Xps.XpsModel.PolyLineSegment();
   int count = fig.Segments.Count;
   for (int idx = 0; idx < count; idx++)
   {
     PathSegment pathSeg = fig.Segments[idx];
     if (pathSeg is PolyLineSegment)
     {
       PolyLineSegment plseg = (PolyLineSegment)pathSeg;
       foreach (Point point in plseg.Points)
         resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(point.X, point.Y));
     }
     else if (pathSeg is LineSegment)
     {
       LineSegment lseg = (LineSegment)pathSeg;
       resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(lseg.Point.X, lseg.Point.Y));
     }
     else
     {
       Debugger.Break();
     }
   }
   return resultSeg;
 }
Exemple #19
0
		/// <summary>
		/// Transforms the specified path segment and returns the result.
		/// </summary>
		/// <param name="pathSegment">The path segment.</param>
		/// <param name="transform">The transform.</param>
		/// <returns></returns>
        public static PathSegment Transform(this PathSegment pathSegment, TransformGroup transform)
		{
			PathSegment ret;
			if (pathSegment is LineSegment)
				ret = new LineSegment { Point = ((LineSegment)pathSegment).Point.Transform(transform) };
			else if (pathSegment is ArcSegment)
			{
				var arcSegment = (ArcSegment) pathSegment;
			    var scaleTransform = transform.Children.OfType<ScaleTransform>().FirstOrDefault();
                var rotateTransform = transform.Children.OfType<RotateTransform>().FirstOrDefault();
                var size = new Size { Height = arcSegment.Size.Height * scaleTransform.ScaleY, Width = arcSegment.Size.Width * scaleTransform.ScaleX };
                ret = new ArcSegment { Point = arcSegment.Point.Transform(transform), Size = size, IsLargeArc = arcSegment.IsLargeArc, RotationAngle = rotateTransform.Angle };
			}
			else if (pathSegment is BezierSegment)
			{
				var bezierSegment = (BezierSegment)pathSegment;
				ret = new BezierSegment
				{
					Point1 = bezierSegment.Point1.Transform(transform),
					Point2 = bezierSegment.Point2.Transform(transform),
					Point3 = bezierSegment.Point3.Transform(transform),
				};
			}
			else if (pathSegment is QuadraticBezierSegment)
			{
				var bezierSegment = (QuadraticBezierSegment)pathSegment;
				ret = new QuadraticBezierSegment
				{
					Point1 = bezierSegment.Point1.Transform(transform),
					Point2 = bezierSegment.Point2.Transform(transform),
				};
			}
			else
				throw new Exception("Transform To implement");
			return ret;
		}
        public void arc(double x, double y, double width, double height, double start, double stop)
        {
            Path p = new Path ();
            PathGeometry pg = new PathGeometry ();
            // FIXME: moonlight should be fixed to automatically ceate Figures.
            pg.Figures = new PathFigureCollection ();

            PathFigure pf = new PathFigure ();
            pf.StartPoint = new Point (x, y);
            ArcSegment ars = new ArcSegment ();
            ars.Size = new Size (width, height);
            ars.SweepDirection = SweepDirection.Counterclockwise;
            ars.IsLargeArc = (stop - start > PI);

            pf.Segments.Add (ars);
            pg.Figures.Add (pf);

            p.Stroke = stroke_brush;
            p.StrokeThickness = stroke_weight;
            p.StrokeLineJoin = stroke_join;
            p.StrokeStartLineCap = p.StrokeEndLineCap = stroke_cap;
            p.Data = pg;
            Host.Children.Add (p);
        }
Exemple #21
0
        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 System.Windows.Media.ArcSegment)
                {
                    System.Windows.Media.ArcSegment seg = item as System.Windows.Media.ArcSegment;
                    clone = new System.Windows.Media.ArcSegment()
                    {
                        IsLargeArc     = seg.IsLargeArc,
                        Point          = seg.Point,
                        RotationAngle  = seg.RotationAngle,
                        Size           = seg.Size,
                        SweepDirection = seg.SweepDirection
                    };
                }

                collClone.Add(clone);
            }
            return(collClone);
        }
Exemple #22
0
        public DisplayCircularSurface( SlopeCanvas canvas , Point enter , Point exit , double radius )
        {
            this.canvas = canvas;

            surface = new System.Windows.Shapes.Path();
            surface.Stroke = Brushes.Black;
            surface.StrokeThickness = 1;
            surface.Fill = Brushes.Transparent;
            surface.Opacity = 0.8;
            surface.StrokeDashArray.Add( 5 );
            surface.StrokeDashArray.Add( 5 );

            PathGeometry surfaceGeom = new PathGeometry();
            surfaceGeom.FillRule = FillRule.Nonzero;
            surface.Data = surfaceGeom;

            surfaceFigure = new PathFigure();
            surfaceFigure.StartPoint = enter;
            surfaceGeom.Figures.Add( surfaceFigure );

            surfaceArc = new ArcSegment();
            surfaceArc.Size = new Size( radius , radius );
            surfaceArc.Point = exit;
            surfaceArc.SweepDirection = SweepDirection.Counterclockwise;
            surfaceArc.IsLargeArc = false;
            surfaceFigure.Segments.Add( surfaceArc );

            canvas.Children.Add( surface );
        }
Exemple #23
0
 /// <summary>
 /// Adds the corner.
 /// </summary>
 /// <param name="figure">The figure.</param>
 /// <param name="x">The x.</param>
 /// <param name="y">The y.</param>
 /// <param name="cornerRadius">The corner radius.</param>
 private static void AddCorner(PathFigure figure, double x, double y, double cornerRadius)
 {
     var cornerArc = new ArcSegment
     {
         Point = new Point(x, y),
         Size = new Size(cornerRadius, cornerRadius),
         SweepDirection = SweepDirection.Clockwise
     };
     figure.Segments.Add(cornerArc);
 }
Exemple #24
0
        private static PathGeometry CreateGeometry(Size contentDesiredSize)
        {
            //TODO Make better :)  do some funky beziers or summit
            const double cheapRadiusBig = 6.0;
            const double cheapRadiusSmall = cheapRadiusBig/2;
            
            const int angle = 20;
            const double radians = angle * (Math.PI / 180);

            var startPoint = new Point(0, contentDesiredSize.Height + cheapRadiusSmall + cheapRadiusSmall);

            //clockwise starting at bottom left
            var bottomLeftSegment = new ArcSegment(new Point(startPoint.X + cheapRadiusSmall, startPoint.Y - cheapRadiusSmall),
                new Size(cheapRadiusSmall, cheapRadiusSmall), 315, false, SweepDirection.Counterclockwise, true);
            var triangleX = Math.Tan(radians) * (contentDesiredSize.Height);
            var leftSegment = new LineSegment(new Point(bottomLeftSegment.Point.X + triangleX, bottomLeftSegment.Point.Y - contentDesiredSize.Height), true);
            var topLeftSegment = new ArcSegment(new Point(leftSegment.Point.X + cheapRadiusBig, leftSegment.Point.Y - cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 120, false, SweepDirection.Clockwise, true);
            var topSegment = new LineSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig, 0), true);
            var topRightSegment = new ArcSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig + cheapRadiusBig, cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 40, false, SweepDirection.Clockwise, true);

            triangleX = Math.Tan(radians) * (contentDesiredSize.Height);
            //triangleX = Math.Tan(radians)*(contentDesiredSize.Height - topRightSegment.Point.Y);
            var rightSegment =
                new LineSegment(new Point(topRightSegment.Point.X + triangleX,
                    topRightSegment.Point.Y + contentDesiredSize.Height), true);

            var bottomRightPoint = new Point(rightSegment.Point.X + cheapRadiusSmall,
                rightSegment.Point.Y + cheapRadiusSmall);
            var bottomRightSegment = new ArcSegment(bottomRightPoint,
                new Size(cheapRadiusSmall, cheapRadiusSmall), 25, false, SweepDirection.Counterclockwise, true);
            var bottomLeftPoint = new Point(0, bottomRightSegment.Point.Y);
            var bottomSegment = new LineSegment(bottomLeftPoint, true);            

            var pathSegmentCollection = new PathSegmentCollection
            {
                bottomLeftSegment, leftSegment, topLeftSegment, topSegment, topRightSegment, rightSegment, bottomRightSegment, bottomSegment
            };
            var pathFigure = new PathFigure(startPoint, pathSegmentCollection, true)
            {
                IsFilled = true
            };
            var pathFigureCollection = new PathFigureCollection
            {
                pathFigure
            };
            var geometryGroup = new PathGeometry(pathFigureCollection);            
            geometryGroup.Freeze();                        

            return geometryGroup;
        }
Exemple #25
0
        /// <summary>
        /// Returns a path geometry
        /// </summary>
        /// <param name="fillRule">FillRule</param>
        /// <param name="startPoint">Start point</param>
        /// <param name="pathGeometryParams">List of path geometry parameters</param>
        /// <returns>PathGeometry</returns>
        private static PathGeometry GetPathGeometryFromList(FillRule fillRule, Point startPoint, List<PathGeometryParams> pathGeometryParams, Boolean isClosed)
        {
            PathGeometry pathGeometry = new PathGeometry();

            pathGeometry.FillRule = fillRule;
            pathGeometry.Figures = new PathFigureCollection();

            PathFigure pathFigure = new PathFigure();

            pathFigure.StartPoint = startPoint;
            pathFigure.Segments = new PathSegmentCollection();
            pathFigure.IsClosed = isClosed;

            foreach (PathGeometryParams param in pathGeometryParams)
            {
                switch (param.GetType().Name)
                {
                    case "LineSegmentParams":
                        LineSegment lineSegment = new LineSegment();
                        lineSegment.Point = param.EndPoint;
                        pathFigure.Segments.Add(lineSegment);
                        break;

                    case "ArcSegmentParams":
                        ArcSegment arcSegment = new ArcSegment();

                        arcSegment.Point = param.EndPoint;
                        arcSegment.IsLargeArc = (param as ArcSegmentParams).IsLargeArc;
                        arcSegment.RotationAngle = (param as ArcSegmentParams).RotationAngle;
                        arcSegment.SweepDirection = (param as ArcSegmentParams).SweepDirection;
                        arcSegment.Size = (param as ArcSegmentParams).Size;
                        pathFigure.Segments.Add(arcSegment);

                        break;
                }
            }

            pathGeometry.Figures.Add(pathFigure);

            return pathGeometry;
        }
Exemple #26
0
        private void Paint()
        {
            //相隔距离
            //_Line.X1 =_Line.X2 =
            _LineLeft.Y1 = _LineLeft.Y2 = this.Height / 2; ;
            _LineLeft.X1 = this.Width*0.75;
            _LineLeft.X2 = this.Width;

            PointCollection pc = new PointCollection();
            pc.Add(new Point(0, this.Height/2));
            pc.Add(new Point(this.Width / 2, this.Height / 2));
            pc.Add(new Point(this.Width/2, this.Height));
            plRight.Points = pc;

            Size arcsSize = new Size(this.Width / 4, this.Height / 2);

            psc.Clear();

            pf.StartPoint = new Point(this.Width * 0.75, this.Height / 2);

            ArcSegment arcs = new ArcSegment();
            arcs.Point = new Point(this.Width * 0.5, 0);

            arcs.Size = arcsSize;
            psc.Add(arcs);

            arcs = new ArcSegment();
            arcs.Point = new Point(this.Width * 0.25, this.Height / 2);
            arcs.Size = arcsSize;
            psc.Add(arcs);

            arcs = new ArcSegment();
            arcs.Point = new Point(this.Width * 0.5, this.Height);
            arcs.Size = arcsSize;
            psc.Add(arcs);
        }
        public KeyValuePair<Point, Point> Ellipse(Point at, double alpha, double beta, Size radiuses)
        {
            //alpha = Math.Abs(alpha) % 360;
            //beta = Math.Abs(beta) % 360;

            //if (beta - alpha >= 360d) beta = alpha + 360d;

            Point from = new Point((at.X + Math.Cos(ToRadians(alpha)) * radiuses.Width), (at.Y - Math.Sin(ToRadians(alpha)) * radiuses.Height));
            Point to = new Point((at.X + Math.Cos(ToRadians(beta)) * radiuses.Width), (at.Y - Math.Sin(ToRadians(beta)) * radiuses.Height));

            Path tmpPath = new Path();

            ArcSegment tmpArc = new ArcSegment();
            tmpArc.Point = to;
            tmpArc.Size = radiuses;
            tmpArc.SweepDirection = SweepDirection.Counterclockwise;
            tmpArc.IsLargeArc = (Math.Abs(beta - alpha) > 180d ? true : false);

            PathFigure tmpFigure = new PathFigure();
            tmpFigure.StartPoint = from;
            tmpFigure.Segments.Add(tmpArc);

            PathGeometry tmpGeometry = new PathGeometry();
            tmpGeometry.Figures.Add(tmpFigure);

            CombinedGeometry tmpCombined = new CombinedGeometry();
            tmpCombined.GeometryCombineMode = GeometryCombineMode.Exclude;
            tmpCombined.Geometry1 = tmpGeometry;

            tmpFigure = new PathFigure();
            tmpFigure.StartPoint = from;
            tmpFigure.Segments.Add(new LineSegment(at, false));
            tmpFigure.Segments.Add(new LineSegment(to, false));
            tmpFigure.IsClosed = true;
            tmpGeometry = new PathGeometry();
            tmpGeometry.Figures.Add(tmpFigure);

            tmpCombined.Geometry2 = tmpGeometry;

            tmpPath.Data = tmpCombined;
            tmpPath.Stroke = brush;
            tmpPath.StrokeThickness = LineThickness;
            tmpPath.StrokeDashArray = LineStyle;
            tmpPath.StrokeDashCap = LineCapStyle;
            tmpPath.StrokeLineJoin = LineJoinStyle;
            tmpPath.Fill = brush;

            buffer.Add(tmpPath);

            return new KeyValuePair<Point, Point>(from, to);
        }
		private void ConvertPart(PathThumb senderThumb, PathPartConvertType convertType)
		{
			if (senderThumb.PathPoint.ParentObject is PathFigure)
			{
				var pathFigure = senderThumb.PathPoint.ParentObject as PathFigure;
				var pathSegment = senderThumb.PathPoint.Object as PathSegment;

				var idx = pathFigure.Segments.IndexOf(pathSegment);

				var point = senderThumb.PathPoint.Point;

				if (pathSegment is PolyLineSegment) {
					var poly = pathSegment as PolyLineSegment;
					var lst = poly.Points.Take(senderThumb.PathPoint.PolyLineIndex);
					var lst2 = poly.Points.Skip(senderThumb.PathPoint.PolyLineIndex + 1);
					var p = poly.Points[senderThumb.PathPoint.PolyLineIndex];
					pathFigure.Segments.RemoveAt(idx);
					var p1 = new PolyLineSegment();
					p1.Points.AddRange(lst);
					pathFigure.Segments.Insert(idx, p1);
					pathSegment =  new LineSegment() {Point = p};
					pathFigure.Segments.Insert(idx+1, pathSegment);
					var p2 = new PolyLineSegment();
					p2.Points.AddRange(lst2);
					pathFigure.Segments.Insert(idx+2, p2);
					idx++;
				} else if (pathSegment is PolyBezierSegment) {
					//TODO
				} else if (pathSegment is PolyQuadraticBezierSegment) {
					//TODO
				}

				pathFigure.Segments.RemoveAt(idx);

				var midp = senderThumb.PathPoint.ParentPathPoint.Point - ((senderThumb.PathPoint.ParentPathPoint.Point - point) / 2);
				
				PathSegment newSegment = null;
				switch (convertType)
				{
					case PathPartConvertType.ToBezierSegment:
						newSegment = new BezierSegment() { Point1 = midp - new Vector(40, 40), Point2 = midp + new Vector(-40, 40), Point3 = point };
						break;
					case PathPartConvertType.ToQuadricBezierSegment:
						newSegment = new QuadraticBezierSegment() { Point1 = point - new Vector(40, 40), Point2 = point  };
						break;
					case PathPartConvertType.ToArcSegment:
						newSegment = new ArcSegment() { Point = point, Size = new Size(20, 20) };
						break;
					case PathPartConvertType.insertPoint:
						pathFigure.Segments.Insert(idx, pathSegment);
						newSegment = new LineSegment() { Point = midp, };
						break;
					default:
						newSegment = new LineSegment() { Point = point };
						break;
				}

				pathFigure.Segments.Insert(idx, newSegment);
			}

			this.ExtendedItem.ReapplyAllExtensions();
		}
Exemple #29
0
        private void Paint()
        {
            pf.StartPoint = new Point(0, 0);
            psc.Clear();
            //直线
            ArcSegment arcs = new ArcSegment();
            arcs.Point = new Point(this.Width * 0.75, 0);
            psc.Add(arcs);

            arcs = new ArcSegment();
            arcs.Point = new Point(this.Width, this.Height / 2);
            arcs.Size = new Size()
            {
                Height = this.Height / 2,
                Width = this.Width * 0.25
            };
            arcs.SweepDirection = SweepDirection.Clockwise;
            psc.Add(arcs);

            //下面
            arcs = new ArcSegment();
            arcs.Point = new Point(this.Width * 0.75, this.Height);
            arcs.Size = new Size()
            {
                Height = this.Height / 2,
                Width = this.Width * 0.25
            };
            arcs.SweepDirection = SweepDirection.Clockwise;
            psc.Add(arcs);
            //中间最右边线
            arcs = new ArcSegment();
            arcs.Point = new Point(0, this.Height);
            psc.Add(arcs);
        }
		ArcSegment MakeArc(double x, double y, SweepDirection dir)
		{
			ArcSegment arc = new ArcSegment(
				new Point(x, y),
				new Size(cornerRadius, cornerRadius),
				0, false, dir, true);
			arc.Freeze();
			return arc;
		}
        public void ArcUpdate()
        {
            // 線の太さ
            double thick = this.ViewModel.StrokeThickness;

            // 入力値切捨て
            double inputValue = Math.Floor(this.ViewModel.Percentage * 100.0);

            // 角度の計算
            double angle = (inputValue * 3.6);

            if(angle < 0)
            {
                angle += 360;
            }
            if(angle > 360)
            {
                angle %= 360.0;
            }
            // 0-360を許容
            if (0 < angle && angle < 360)
            {
                // 角度によってフラグを変える
                this.ViewModel.IsLargeArcFlg = false;
                if (angle >= 180)
                {
                    // 180°を超える(180を含む)場合はフラグをtrue
                    this.ViewModel.IsLargeArcFlg = true;
                }
            }

            // 角度と半径から座標を計算
            double radius = (this.pathArc.Width / 2) - thick;

            pathArc.StrokeThickness = thick;
            pathCircleBackground.StrokeThickness = thick;

            if (angle != 0 && angle != 360)
            {

                angle -= 90;

                double radian = Math.PI * angle / 180.0;
                double x = radius * Math.Cos(radian);
                double y = radius * Math.Sin(radian);
                x = ToRoundDown(x, 3);
                y = ToRoundDown(y, 3);

                // 終点計算
                double endPointX = radius + x + thick;
                double endPointY = radius + y + thick;

                // 図形生成
                PathFigure pfArc = new PathFigure();
                pfArc.StartPoint = new Point(100, thick); // 開始点

                // セグメント生成
                ArcSegment arc = new ArcSegment();
                arc.Point = new Point(endPointX, endPointY); // 終点(計算値)
                arc.Size = new Size(radius, radius); // 半径
                arc.IsLargeArc = this.ViewModel.IsLargeArcFlg;
                arc.SweepDirection = SweepDirection.Clockwise;
                //arc.RotationAngle = Math.PI * -90.0 / 180.0;

                // 図形入れ替え
                pfArc.Segments.Clear();
                pfArc.Segments.Add(arc);

                this.pathGeometryArc.Figures.Clear();
                this.pathGeometryArc.Figures.Add(pfArc);

                // 図形生成(背景)
                PathFigure pfCircle = new PathFigure();
                pfCircle.StartPoint = new Point(100, thick); // 開始点

                // セグメント生成
                ArcSegment circle = new ArcSegment();
                circle.Point = new Point(endPointX, endPointY); // 終点(計算値)
                circle.Size = new Size(radius, radius); // 半径
                circle.IsLargeArc = !this.ViewModel.IsLargeArcFlg;
                circle.SweepDirection = SweepDirection.Counterclockwise;

                // 図形入れ替え
                pfCircle.Segments.Clear();
                pfCircle.Segments.Add(circle);

                this.pathGeometryCircle.Figures.Clear();
                this.pathGeometryCircle.Figures.Add(pfCircle);
            }
            else
            {
                var center = new Point(this.pathArc.Width / 2, this.pathArc.Height / 2);
                var circle = new EllipseGeometry(center, radius, radius);
                var pathgeo = circle.GetOutlinedPathGeometry();

                this.pathGeometryArc.Clear();
                this.pathGeometryCircle.Clear();
                if (angle == 0)
                    this.pathGeometryCircle.Figures = pathgeo.Figures;
                else
                    this.pathGeometryArc.Figures = pathgeo.Figures;
            }
        }