Ejemplo n.º 1
0
 public void CopyData_NullPointsTypes_ThrowsNullReferenceException(PointF[] points, byte[] types)
 {
     using (GraphicsPath gp = new GraphicsPath())
         using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
         {
             Assert.Throws <NullReferenceException>(() => gpi.CopyData(ref points, ref types, 0, 1));
         }
 }
Ejemplo n.º 2
0
 public void CopyData_PointsTypesMismatch_ThrowsArgumentException(PointF[] points, byte[] types)
 {
     using (GraphicsPath gp = new GraphicsPath())
         using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
         {
             AssertExtensions.Throws <ArgumentException>(null, () => gpi.CopyData(ref points, ref types, 0, points.Length));
         }
 }
Ejemplo n.º 3
0
        public void CopyData_StartEndIndexesOutOfRange_ReturnsExpected(PointF[] points, byte[] types, int startIndex, int endIndex)
        {
            PointF[] resultPoints = new PointF[points.Length];
            byte[]   resultTypes  = new byte[points.Length];

            using (GraphicsPath gp = new GraphicsPath(points, types))
                using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
                {
                    Assert.Equal(0, gpi.CopyData(ref resultPoints, ref resultTypes, startIndex, endIndex));
                }
        }
Ejemplo n.º 4
0
        public void CopyData_StartEndIndexesOutOfRange_ThrowsArgumentException(int startIndex, int endIndex)
        {
            PointF[] resultPoints = new PointF[0];
            byte[]   resultTypes  = new byte[0];

            using (GraphicsPath gp = new GraphicsPath())
                using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
                {
                    AssertExtensions.Throws <ArgumentException>(null, () => gpi.CopyData(ref resultPoints, ref resultTypes, startIndex, endIndex));
                }
        }
Ejemplo n.º 5
0
 public void CopyData_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.CopyData(ref points, ref types, 0, 1));
         }
     }
 }
Ejemplo n.º 6
0
 public void CopyData_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.CopyData(ref points, ref types, 0, 1));
         }
     }
 }
Ejemplo n.º 7
0
 public void CopyData_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.AreEqual(0, gpi.CopyData(ref points, ref types, 0, 1));
         }
     }
 }
Ejemplo n.º 8
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]);
            }
        }
Ejemplo n.º 9
0
        public void CopyData_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[3];
            byte[]   actualTypes  = new byte[3];

            using (GraphicsPath gp = new GraphicsPath(points, types))
                using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
                {
                    Assert.Equal(3, gpi.CopyData(ref actualPoints, ref actualTypes, 0, 2));
                }
        }
Ejemplo n.º 10
0
        public void CopyData_EqualStartEndIndexes_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[1];
            byte[]   actualTypes  = new byte[1];

            using (GraphicsPath gp = new GraphicsPath(points, types))
                using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
                {
                    Assert.Equal(1, gpi.CopyData(ref actualPoints, ref actualTypes, 0, 0));
                    Assert.Equal(gp.PathPoints[0], actualPoints[0]);
                    Assert.Equal(gp.PathTypes[0], actualTypes[0]);
                }
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        ///


        // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.CopyData(System.Drawing.PointF[]@,System.Byte[]@,System.Int32,System.Int32)
        // <snippet1>
        public void CopyDataExample(PaintEventArgs e)
        {
            // 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++)
            {
                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 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;
                e.Graphics.DrawString(
                    "Point: " + copiedStartIndex.ToString() +
                    ", Value: " + points[i].ToString() +
                    ", Type: " + types[i].ToString(),
                    myFont,
                    myBrush,
                    200,
                    j);
                j += 20;
            }
        }