Beispiel #1
0
        // </snippet2>


        // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.HasCurve
        // <snippet3>
        private void HasCurveExample(PaintEventArgs e)
        {
            // Create a path and add three lines,
            // a rectangle and an ellipse.
            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);

            // Create a GraphicsPathIterator for myPath.
            GraphicsPathIterator myPathIterator = new
                                                  GraphicsPathIterator(myPath);

            // Test for a curve.
            bool myHasCurve = myPathIterator.HasCurve();

            // Show the test result.
            MessageBox.Show(myHasCurve.ToString());
        }
Beispiel #2
0
        public virtual void HasCurve()
        {
            GraphicsPath path = new GraphicsPath();

            GraphicsPathIterator iterator = new GraphicsPathIterator(path);

            Assert.IsFalse(iterator.HasCurve());

            path.AddLine(new Point(100, 100), new Point(400, 100));
            path.AddLine(new Point(400, 200), new Point(10, 100));

            iterator = new GraphicsPathIterator(path);
            Assert.IsFalse(iterator.HasCurve());

            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));

            iterator = new GraphicsPathIterator(path);
            Assert.IsTrue(iterator.HasCurve());
        }
        public void HasCurve_ReturnsExpected()
        {
            Point[] points = new Point[] { new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(4, 4) };
            byte[]  types  = new byte[] { 0, 3, 3, 3 };

            using (GraphicsPath gp = new GraphicsPath(points, types))
                using (GraphicsPath gpEmpty = new GraphicsPath())
                    using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
                        using (GraphicsPathIterator gpiEmpty = new GraphicsPathIterator(gpEmpty))
                            using (GraphicsPathIterator gpiNull = new GraphicsPathIterator(null))
                            {
                                Assert.True(gpi.HasCurve());
                                Assert.False(gpiEmpty.HasCurve());
                                Assert.False(gpiNull.HasCurve());
                            }
        }
Beispiel #4
0
        ///<summary>
        /// Extracts the points of the paths in a flat {@link PathIterator} into
        /// a list of Coordinate arrays.
        ///</summary>
        /// <param name="pathIt">A path iterator</param>
        /// <returns>A list of coordinate arrays</returns>
        /// <exception cref="ArgumentException">If a non-linear segment type is encountered</exception>
        public static IList <Coordinate[]> ToCoordinates(GraphicsPathIterator pathIt)
        {
            if (pathIt.HasCurve())
            {
                throw new ArgumentException("Path must not have non-linear segments");
            }

            var  coordArrays = new List <Coordinate[]>();
            int  startIndex, endIndex;
            bool isClosed;

            while (pathIt.NextSubpath(out startIndex, out endIndex, out isClosed) > 0)
            {
                Coordinate[] pts = NextCoordinateArray(pathIt, startIndex, endIndex, isClosed);
                coordArrays.Add(pts);
                if (endIndex == pathIt.Count - 1)
                {
                    break;
                }
            }
            return(coordArrays);
        }