Exemplo n.º 1
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();
                }
            }
        }
Exemplo 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();
                }
            }
        }