예제 #1
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]);
            }
        }
예제 #2
0
        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]);
            }
        }
예제 #3
0
        public virtual void NextSubpath_GraphicsPath_Bool()
        {
            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.CloseFigure();
            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);
            GraphicsPath         path2    = new GraphicsPath();

            bool isClosed;

            int count = iterator.NextSubpath(path2, out isClosed);

            Assert.AreEqual(4, count);
            Assert.IsFalse(isClosed);

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

            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(4, count);
            Assert.IsTrue(isClosed);

            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.CloseSubpath | PathPointType.PathMarker) };

            for (int i = 0; i < expectedTypes.Length; i++)
            {
                Assert.AreEqual(expectedTypes [i], actualTypes [i]);
            }

            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(4, count);
            Assert.IsTrue(isClosed);

            actualPoints = path2.PathPoints;
            actualTypes  = path2.PathTypes;

            expectedPoints = new PointF [] { new PointF(10f, 20f),
                                             new PointF(310f, 20f),
                                             new PointF(310f, 420f),
                                             new PointF(10f, 420f) };

            for (int i = 0; i < expectedPoints.Length; i++)
            {
                DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]);
            }

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

            for (int i = 0; i < expectedTypes.Length; i++)
            {
                Assert.AreEqual(expectedTypes [i], actualTypes [i]);
            }

            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(2, count);
            Assert.IsFalse(isClosed);

            actualPoints = path2.PathPoints;
            actualTypes  = path2.PathTypes;

            expectedPoints = new PointF [] { new PointF(400f, 400f),
                                             new PointF(400f, 10f) };

            for (int i = 0; i < expectedPoints.Length; i++)
            {
                DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]);
            }

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

            for (int i = 0; i < expectedTypes.Length; i++)
            {
                Assert.AreEqual(expectedTypes [i], actualTypes [i]);
            }

            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(0, count);

            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(0, count);
            Assert.IsTrue(isClosed);
            Assert.AreEqual(2, path2.PointCount);

            actualPoints = path2.PathPoints;
            actualTypes  = path2.PathTypes;

            expectedPoints = new PointF [] { new PointF(400f, 400f),
                                             new PointF(400f, 10f) };

            for (int i = 0; i < expectedPoints.Length; i++)
            {
                DrawingTest.AssertAlmostEqual(expectedPoints [i], actualPoints [i]);
            }

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

            for (int i = 0; i < expectedTypes.Length; i++)
            {
                Assert.AreEqual(expectedTypes [i], actualTypes [i]);
            }

            path = new GraphicsPath();
            path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280);
            iterator = new GraphicsPathIterator(path);

            path2 = new GraphicsPath();
            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(4, count);
            Assert.IsFalse(isClosed);

            path2 = new GraphicsPath();
            count = iterator.NextSubpath(path2, out isClosed);
            Assert.AreEqual(0, count);
            Assert.IsTrue(isClosed);
        }
예제 #4
0
        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]);
            }
        }