Esempio n. 1
0
        private void DrawPolygon(PolygonBase polygon, Graphics graphs)
        {
            if (polygon.Vertices.Count < 2)
                return;

            var path = new GraphicsPath();
            if (polygon.IsClosedFigure) path.StartFigure();
            path.AddLines(polygon.Vertices.ToPoints());
            if (polygon.IsClosedFigure) path.CloseFigure();

            using (var b = new SolidBrush(polygon.FillColor))
            using (var p = new Pen(polygon.OutlineColor, polygon.OutlineWidth))
            {
                p.DashStyle = polygon.OutlineDash;
                if (polygon.GetShapeType() != ShapeType.FreePencil) graphs.FillPath(b, path);
                //_filler.FillByScanline(graphs, polygon, polygon.FillColor);
                graphs.DrawPath(p, path);
            }
        }
Esempio n. 2
0
        public void ScanLineFillPolygon(Graphics graph, PolygonBase shape, Color color)
        {
            if (shape.Vertices.Count < 3)
                return;

            if (shape.GetShapeType() == ShapeType.FreePencil)
                return;

            var rec = new Rectangle(Point.Round(shape.Location), Size.Round(shape.Size));
            if (rec.Location.Equals(Point.Empty))
                return;

            rec.X -= 1;
            rec.Y -= 1;
            rec.Width += 2;
            rec.Height += 2;

            //var h = rec.Y + 1;
            var h = rec.Y + rec.Height;
            var et = new SortedDoublyLinkedList<CActiveEdge>[h];
            var active = new SortedDoublyLinkedList<CActiveEdge>();

            for (int i = 0; i < h; i++)
                et[i] = new SortedDoublyLinkedList<CActiveEdge>();

            BuildEdgeList(shape.Vertices.ToList(), ref et);

            //for (int i = rec.Y - rec.Height; i < rec.Y; i++)
            for (int i = rec.Y; i < rec.Y + rec.Height; i++)
            {
                buildActiveList(ref active, ref et[i]);
                if (active.Count != 0)
                {
                    using (var p = new Pen(color, 1F))
                        FillScan(i, ref active, graph, p);
                    updateEdgeList(i, ref active);
                    active.Sort();
                }
            }
        }