public void Enumerate_PointsTypesMismatch_ThrowsArgumentException(PointF[] points, byte[] types) { using (GraphicsPath gp = new GraphicsPath()) using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { AssertExtensions.Throws <ArgumentException>(null, () => gpi.Enumerate(ref points, ref types)); } }
public void Enumerate_NullPointsTypes_ThrowsNullReferenceException(PointF[] points, byte[] types) { using (GraphicsPath gp = new GraphicsPath()) using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { Assert.Throws <NullReferenceException>(() => gpi.Enumerate(ref points, ref types)); } }
public void Enumerate_DifferentSize() { using (GraphicsPath gp = new GraphicsPath()) { gp.AddLines(pts_2f); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { PointF [] points = new PointF [1]; byte [] types = new byte [2]; Assert.Throws <ArgumentException> (() => gpi.Enumerate(ref points, ref types)); } } }
public void Enumerate_NullTypes() { using (GraphicsPath gp = new GraphicsPath()) { gp.AddLines(pts_2f); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { PointF [] points = new PointF [1]; byte [] types = null; Assert.Throws <NullReferenceException> (() => gpi.Enumerate(ref points, ref types)); } } }
public void Enumerate_DifferentSize() { using (GraphicsPath gp = new GraphicsPath()) { gp.AddLines(pts_2f); using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { PointF [] points = new PointF [1]; byte [] types = new byte [2]; Assert.AreEqual(0, gpi.Enumerate(ref points, ref types)); } } }
public void Enumerate_ZeroPoints_ReturnsExpected() { PointF[] points = new PointF[0]; byte[] types = new byte[0]; using (GraphicsPath gp = new GraphicsPath()) using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { Assert.Equal(0, gpi.Enumerate(ref points, ref types)); Assert.Equal(0, points.Length); Assert.Equal(0, types.Length); } }
public void Enumerate_ReturnsExpected() { PointF[] points = new PointF[] { new PointF(1f, 1f), new PointF(2f, 2f), new PointF(3f, 3f), new PointF(4f, 4f) }; byte[] types = new byte[] { 0, 3, 3, 3 }; PointF[] actualPoints = new PointF[4]; byte[] actualTypes = new byte[4]; using (GraphicsPath gp = new GraphicsPath(points, types)) using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp)) { Assert.Equal(4, gpi.Enumerate(ref actualPoints, ref actualTypes)); Assert.Equal(gp.PathPoints, actualPoints); Assert.Equal(gp.PathTypes, actualTypes); } }
public virtual void Enumerate() { 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.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.AddLine(new Point(400, 400), new Point(400, 10)); path.Reverse(); GraphicsPathIterator iterator = new GraphicsPathIterator(path); PointF [] actualPoints = new PointF [14]; byte [] actualTypes = new byte [14]; iterator.Enumerate(ref actualPoints, ref actualTypes); PointF [] expectedPoints = new PointF [] { new PointF(400f, 10f), new PointF(400f, 400f), new PointF(10f, 420f), new PointF(310f, 420f), new PointF(310f, 20f), new PointF(10f, 20f), new PointF(200f, 280f), new PointF(100f, 5f), new PointF(50f, 250f), new PointF(10f, 10f), new PointF(10f, 100f), new PointF(400f, 200f), new PointF(400f, 100f), new PointF(100f, 100f) }; 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.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)(PathPointType.Line | PathPointType.CloseSubpath), (byte)PathPointType.Start, (byte)PathPointType.Bezier3, (byte)PathPointType.Bezier3, (byte)PathPointType.Bezier3, (byte)PathPointType.Start, (byte)PathPointType.Line, (byte)PathPointType.Line, (byte)PathPointType.Line }; for (int i = 0; i < expectedTypes.Length; i++) { Assert.AreEqual(expectedTypes [i], actualTypes [i]); } }
// </snippet1> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.Enumerate(System.Drawing.PointF[]@,System.Byte[]@) // <snippet2> public void EnumerateExample(PaintEventArgs e) { GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); myPath.AddLines(myPoints); myPath.AddRectangle(myRect); 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. e.Graphics.DrawString("Original Data", myFont, myBrush, 20, j); j += 20; for (i = 0; i < myPathPointCount; i++) { e.Graphics.DrawString(myPathPoints[i].X.ToString() + ", " + myPathPoints[i].Y.ToString() + ", " + myPathTypes[i].ToString(), myFont, myBrush, 20, j); j += 20; } // Create a GraphicsPathIterator for myPath. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); myPathIterator.Rewind(); PointF[] points = new PointF[myPathIterator.Count]; byte[] types = new byte[myPathIterator.Count]; int numPoints = myPathIterator.Enumerate(ref points, ref types); // Draw the set of copied points and types to the screen. j = 20; e.Graphics.DrawString("Copied Data", myFont, myBrush, 200, j); j += 20; for (i = 0; i < points.Length; i++) { e.Graphics.DrawString("Point: " + i + ", " + "Value: " + points[i].ToString() + ", " + "Type: " + types[i].ToString(), myFont, myBrush, 200, j); j += 20; } }