public void NextMarker_Null () { using (GraphicsPath gp = new GraphicsPath ()) { gp.AddLines (pts_2f); using (GraphicsPathIterator gpi = new GraphicsPathIterator (gp)) { Assert.AreEqual (0, gpi.NextMarker (null)); } } }
public virtual void Rewind() { 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.AddBezier( 10, 10, 50, 250, 100, 5, 200, 280); 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 iterator = new GraphicsPathIterator (path); int i; int j; iterator.NextMarker (out i, out j); iterator.NextMarker (out i, out j); iterator.Rewind (); iterator.NextMarker (out i, out j); Assert.AreEqual (0, i); Assert.AreEqual (3, j); }
public virtual void NextMarker_GraphicsPath() { 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.AddBezier( 10, 10, 50, 250, 100, 5, 200, 280); 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)); GraphicsPath path2 = new GraphicsPath (); path.AddLine (new Point (150, 150), new Point (450, 150)); path.AddLine (new Point (450, 250), new Point (50, 150)); GraphicsPathIterator iterator = new GraphicsPathIterator (path); iterator.NextMarker (null); iterator.NextMarker (path2); Assert.AreEqual (4, path2.PointCount); PointF [] actualPoints = path2.PathPoints; byte [] actualTypes = path2.PathTypes; PointF [] expectedPoints = new PointF [] { new PointF(100f, 100f), new PointF(400f, 100f), new PointF(400f, 200f), new PointF(10f, 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.Line, (byte) (PathPointType.Line | PathPointType.PathMarker)}; for (int i=0; i < expectedTypes.Length; i++) { Assert.AreEqual (expectedTypes [i], actualTypes [i]); } iterator.NextMarker (null); iterator.NextMarker (null); iterator.NextMarker (null); iterator.NextMarker (path2); Assert.AreEqual (4, path2.PointCount); actualPoints = path2.PathPoints; actualTypes = path2.PathTypes; expectedPoints = new PointF [] {new PointF(10f, 10f), new PointF(50f, 250f), new PointF(100f, 5f), new PointF(200f, 280f)}; for(int i = 0; i < expectedPoints.Length; i++) { DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]); } expectedTypes = new byte [] { (byte) PathPointType.Start, (byte) PathPointType.Bezier3, (byte) PathPointType.Bezier3, (byte) (PathPointType.Bezier3 | PathPointType.PathMarker)}; for (int i=0; i < expectedTypes.Length; i++) { Assert.AreEqual (expectedTypes [i], actualTypes [i]); } }
public void NextSubpath_NextMarker() { GraphicsPath path = new GraphicsPath(); path.AddLine (10, 10, 50, 50); // figure #1 path.AddLine (50, 50, 80, 80); path.AddLine (90, 90, 100, 100); path.SetMarkers (); // marker #1 path.AddLine (150, 150, 180, 180); path.SetMarkers (); // marker #2 path.StartFigure (); // figure #2 path.SetMarkers (); // marker #3 is actually marker #2 path.AddRectangle (new Rectangle (200, 200, 200, 200)); path.SetMarkers (); // marker #4 path.AddLine (150, 150, 180, 180); path.StartFigure (); // figure #3 path.AddBezier (400, 400, 500, 500, 600, 600, 700, 700); path.AddBezier (450, 450, 550, 550, 650, 650, 750, 750); GraphicsPathIterator iterator = new GraphicsPathIterator (path); int start; int end; bool isClosed; int count = iterator.NextMarker (out start,out end); // marker #1 Assert.AreEqual (5, count); Assert.AreEqual (0, start); Assert.AreEqual (4, end); count = iterator.NextSubpath (out start,out end,out isClosed); // figure #1 Assert.AreEqual (7, count); Assert.AreEqual (0, start); Assert.AreEqual (6, end); Assert.AreEqual (false, isClosed); count = iterator.NextMarker (out start,out end); // marker #2 (and #3) Assert.AreEqual (2, count); Assert.AreEqual (5, start); Assert.AreEqual (6, end); count = iterator.NextSubpath (out start,out end,out isClosed); // figure #2 Assert.AreEqual (4, count); Assert.AreEqual (7, start); Assert.AreEqual (10, end); Assert.AreEqual (true, isClosed); count = iterator.NextSubpath (out start,out end,out isClosed); // figure #3 Assert.AreEqual (2, count); Assert.AreEqual (11, start); Assert.AreEqual (12, end); Assert.AreEqual (false, isClosed); count = iterator.NextMarker (out start,out end); // marker #5 (end) Assert.AreEqual (4, count); Assert.AreEqual (7, start); Assert.AreEqual (10, end); count = iterator.NextMarker (out start,out end); // marker #5 (end) Assert.AreEqual (10, count); Assert.AreEqual (11, start); Assert.AreEqual (20, end); // we dont want to be bug compliant with .net /* count = iterator.NextMarker (out start,out end); // no more markers Assert.AreEqual (0, count); Assert.AreEqual (11, start); Assert.AreEqual (20, end); */ count = iterator.NextSubpath (out start,out end,out isClosed); // figure #4 Assert.AreEqual (8, count); Assert.AreEqual (13, start); Assert.AreEqual (20, end); Assert.AreEqual (false, isClosed); // we dont want to be bug compliant with .net /* count = iterator.NextMarker (out start,out end); // no more markers Assert.AreEqual (0, count); Assert.AreEqual (13, start); Assert.AreEqual (20, end); */ count = iterator.NextSubpath (out start,out end,out isClosed); // no more figures Assert.AreEqual (0, count); Assert.AreEqual (0, start); Assert.AreEqual (0, end); Assert.AreEqual (true, isClosed); count = iterator.NextMarker (out start,out end); // no more markers Assert.AreEqual (0, count); Assert.AreEqual (0, start); Assert.AreEqual (0, end); }
public virtual void NextMarker_Int32_Int32() { 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.AddBezier( 10, 10, 50, 250, 100, 5, 200, 280); 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 iterator = new GraphicsPathIterator (path); int start; int end; int count = iterator.NextMarker (out start, out end); Assert.AreEqual (4, count); Assert.AreEqual (0, start); Assert.AreEqual (3, end); count = iterator.NextMarker (out start, out end); Assert.AreEqual (4, count); Assert.AreEqual (4, start); Assert.AreEqual (7, end); count = iterator.NextMarker (out start, out end); Assert.AreEqual (4, count); Assert.AreEqual (8, start); Assert.AreEqual (11, end); count = iterator.NextMarker (out start, out end); Assert.AreEqual (2, count); Assert.AreEqual (12, start); Assert.AreEqual (13, end); // FIXME - should return all 0'z? /* count = iterator.NextMarker (out start, out end); Assert.AreEqual (0, count); Assert.AreEqual (12, start); Assert.AreEqual (13, end); */ }
public void PathIterator5(Graphics g) { // Create a graphics path. GraphicsPath myPath = new GraphicsPath(); // Set up primitives to add to myPath. 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); // Add 3 lines, a rectangle, an ellipse, and 2 markers. 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 the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for listing all the values of the path's // points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // List the values for all of path points 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. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the iterator. myPathIterator.Rewind(); // Create a GraphicsPath to receive a section of myPath. GraphicsPath myPathSection = new GraphicsPath(); // Retrieve and list the number of points contained in // the first marker to the right side of the screen. int markerPoints; markerPoints = myPathIterator.NextMarker(myPathSection); g.DrawString("Marker: 1" + " Num Points: " + markerPoints.ToString(), myFont, myBrush, 200, 20); }
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 void PathIterator6(Graphics g) { // Create the GraphicsPath. 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); // Add 3 lines, a rectangle, an ellipse, and 2 markers. 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 the arrays of the points and types. int myPathPointCount = myPath.PointCount; PointF[] myPathPoints = myPath.PathPoints; byte[] myPathTypes = myPath.PathTypes; // Set up variables for drawing the array // of points to the screen. int i; float j = 20; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); // Draw the set of path points and types to 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. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); int myStartIndex; int myEndIndex; // Rewind the Iterator. myPathIterator.Rewind(); // Draw the Markers and their start and end points // to the screen. j=20; for(i=0;i<3;i++) { myPathIterator.NextMarker(out myStartIndex, out myEndIndex); g.DrawString("Marker " + i.ToString() + ": Start: " + myStartIndex.ToString()+ " End: " + myEndIndex.ToString(), myFont, myBrush, 200, j); j += 20; } // Draw the total number of points to the screen. j += 20; int myPathTotalPoints = myPathIterator.Count; g.DrawString("Total Points = " + myPathTotalPoints.ToString(), myFont, myBrush, 200, j); }
public void Clone() { path = new GraphicsPath (); path.AddEllipse (0, 0, 100, 200); path.SetMarkers (); path.AddLine (new Point (100, 100), new Point (200, 100)); Rectangle rect = new Rectangle (200, 0, 100, 200); path.AddRectangle (rect); path.SetMarkers (); path.AddLine (new Point (250, 200), new Point (250, 300)); path.SetMarkers (); GraphicsPath cloned = (GraphicsPath) path.Clone (); Assert.AreEqual (path.PointCount, cloned.PointCount); for ( int i = 0; i < path.PointCount; i++) { DrawingTest.AssertAlmostEqual(path.PathPoints [i], cloned.PathPoints [i]); Assert.AreEqual (path.PathTypes [i], cloned.PathTypes [i]); } GraphicsPathIterator pathIterator = new GraphicsPathIterator(path); pathIterator.Rewind (); GraphicsPathIterator clonedIterator = new GraphicsPathIterator(cloned); clonedIterator.Rewind (); for (int i=0; i < 4; i ++) { Assert.AreEqual (pathIterator.NextMarker (path), clonedIterator.NextMarker (cloned)); } //t.AssertCompare (); }
public void ClearMarkers() { path = new GraphicsPath (); path.AddEllipse (0, 0, 100, 200); path.SetMarkers (); path.AddLine (new Point (100, 100), new Point (200, 100)); Rectangle rect = new Rectangle (200, 0, 100, 200); path.AddRectangle (rect); path.SetMarkers (); path.AddLine (new Point (250, 200), new Point (250, 300)); path.SetMarkers (); path.ClearMarkers(); GraphicsPathIterator pathIterator = new GraphicsPathIterator(path); pathIterator.Rewind (); int [] pointsNumber = new int [] {21, 0, 0, 0}; for (int i=0; i < 4; i ++) { Assert.AreEqual (pointsNumber [i], pathIterator.NextMarker (path)); } //t.AssertCompare (); }
/// <summary> /// This is used to get the image area at the specified point (if any) /// </summary> /// <returns>The image area index if the point is in an image area or negative one (-1) if it is not in /// any of the image areas.</returns> private int ImageAreaAtPoint(Point pt) { int idx; if(pt.X > this.ImageMapWidth || pt.Y > this.ImageMapHeight) return -1; // Set the image area paths if they need recalculating if(pathData.PointCount == 0) this.SetImageAreaPaths(); using(GraphicsPath p = new GraphicsPath()) using(GraphicsPathIterator i = new GraphicsPathIterator(pathData)) { i.Rewind(); for(idx = 0; idx < i.SubpathCount; idx++) { i.NextMarker(p); if(p.IsVisible(pt, gPanel) && this.Areas[idx].Enabled) break; } return (idx < i.SubpathCount) ? idx : -1; } }