Exemplo n.º 1
0
		public void CopyData_NullPoints ()
		{
			using (GraphicsPath gp = new GraphicsPath ()) {
				gp.AddLines (pts_2f);
				using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) {
					PointF [] points = null;
					byte [] types = new byte [1];
					Assert.AreEqual (0, gpi.CopyData (ref points, ref types, 0, 1));
				}
			}
		}
Exemplo n.º 2
0
        public virtual void CopyData() 
		{
            GraphicsPath path = new GraphicsPath ();
			path.AddLine (new Point (100, 100), new Point (400, 100));
			path.AddLine (new Point (400, 200), new Point (10, 100));
			path.StartFigure ();
			path.SetMarkers ();
			path.AddRectangle (new Rectangle (10, 20, 300, 400));
			path.StartFigure ();
			path.SetMarkers ();
			path.AddLine (new Point (400, 400), new Point (400, 10));

			GraphicsPathIterator pathIterator = new GraphicsPathIterator(path);
			pathIterator.Rewind ();
			PointF [] actualPoints = new PointF [10];
			byte [] actualTypes = new byte [10];
			pathIterator.CopyData (ref actualPoints, ref actualTypes, 0, 9);

			PointF [] expectedPoints = new PointF [] {	new PointF(100f, 100f), 
														new PointF(400f, 100f), 
														new PointF(400f, 200f), 
														new PointF(10f, 100f), 
														new PointF(10f, 20f), 
														new PointF(310f, 20f), 
														new PointF(310f, 420f), 
														new PointF(10f, 420f), 
														new PointF(400f, 400f), 
														new PointF(400f, 10f)};
			
			for(int i = 0; i < expectedPoints.Length; i++) {
				DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]);
			}

			byte [] expectedTypes = new byte [] {	(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.PathMarker), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line, 
													(byte) PathPointType.Line, 
													(byte) (PathPointType.Line | PathPointType.CloseSubpath | PathPointType.PathMarker), 
													(byte) PathPointType.Start, 
													(byte) PathPointType.Line};

			for (int i=0; i < expectedTypes.Length; i++) {
				Assert.AreEqual (expectedTypes [i], actualTypes [i]);
			}	
        }
Exemplo n.º 3
0
        public void PathIterator1(Graphics g)
        {
            // Create a graphics path.
            GraphicsPath myPath = new GraphicsPath ();

            // Set up a points array.
            Point[] myPoints = {
                new Point(20, 20),
                new Point(120, 120),
                new Point(20, 120),
                new Point(20, 20)
            };

            // Create a rectangle.
            Rectangle myRect = new Rectangle(120, 120, 100, 100);

            // Add the points, rectangle, and an ellipse to the path.
            myPath.AddLines(myPoints);
            myPath.SetMarkers();
            myPath.AddRectangle(myRect);
            myPath.SetMarkers();
            myPath.AddEllipse(220, 220, 100, 100);

            // Get the total number of points for the path, and arrays of
            // the  points and types.
            int myPathPointCount = myPath.PointCount;
            PointF[] myPathPoints = myPath.PathPoints;
            byte[] myPathTypes = myPath.PathTypes;

            // Set up variables for listing the array of points on the left
            // side of the screen.
            int i;
            float j = 20;
            Font myFont = new Font("Arial", 8);
            SolidBrush myBrush = new SolidBrush(Color.Black);

            // List the set of points and types and types to the left side
            // of the screen.
            for(i=0; i<myPathPointCount; i++)
            {
                g.DrawString(myPathPoints[i].X.ToString()+
                                      ", " + myPathPoints[i].Y.ToString() + ", " +
                                      myPathTypes[i].ToString(),
                                      myFont,
                                      myBrush,
                                      20,
                                      j);
                j+=20;
            }

            // Create a GraphicsPathIterator for myPath and rewind it.
            GraphicsPathIterator myPathIterator =
                new GraphicsPathIterator(myPath);
            myPathIterator.Rewind();

            // Set up the arrays to receive the copied data.
            PointF[] points = new PointF[myPathIterator.Count];
            byte[] types = new byte[myPathIterator.Count];
            int myStartIndex;
            int myEndIndex;

            // Increment the starting index to the second marker in the
            // path.
            myPathIterator.NextMarker(out myStartIndex, out myEndIndex);
            myPathIterator.NextMarker(out myStartIndex, out myEndIndex);

            // Copy all the points and types from the starting index to the
            // ending index to the points array and the types array
            // respectively.
            int numPointsCopied = myPathIterator.CopyData(
                ref points,
                ref types,
                myStartIndex,
                myEndIndex);

            // List the copied points to the right side of the screen.
            j = 20;
            int copiedStartIndex = 0;
            for(i=0; i<numPointsCopied; i++)
            {
                copiedStartIndex = myStartIndex + i;
                g.DrawString(
                    "Point: " + copiedStartIndex.ToString() +
                    ", Value: " + points[i].ToString() +
                    ", Type: " + types[i].ToString(),
                    myFont,
                    myBrush,
                    200,
                    j);
                j+=20;
            }
        }
        private static Coordinate[] NextCoordinateArray(GraphicsPathIterator pathIt, int start, int end, bool isClosed)
        {
            var num = end - start + 1;
            var points = new PointF[num];
            var types = new byte[num];
            pathIt.CopyData(ref points, ref types, start, end);

            var ret = new Coordinate[num + (isClosed ? 1 : 0)];
            for (var i = 0; i < num; i++)
                ret[i] = new Coordinate(points[i].X, points[i].Y);
            if (isClosed)
                ret[ret.Length - 1] = new Coordinate(points[0].X, points[0].Y);

            return ret;
        }