private void novoPoligono(Poligono p)
 {
     if (p.getPontos().Count > 2)
     {
         p.desenha(imagemBmp);
         poligonos.Add(p);
         pictureBox.Image = imagemBmp;
         DataRow dr = dsPoligonos.Tables["tbPoligonos"].NewRow();
         dr["Poligono"]       = p;
         dr["PosicaoInicial"] = p.getPosicaoInicial();
         dsPoligonos.Tables["tbPoligonos"].Rows.Add(dr);
     }
 }
 private void dgvPoligonos_RowEnter(object sender, DataGridViewCellEventArgs e)
 {
     if (poligonos.Count > e.RowIndex)
     {
         DataSet dsPts = Util.criaTablePontos();
         dgvPontos.DataSource = dsPts;
         dgvPontos.DataMember = "tbPontos";
         Poligono p = poligonos[e.RowIndex];
         if (p != null)
         {
             List <Point> pts = p.getPontos();
             foreach (Point pt in pts)
             {
                 DataRow dr = dsPts.Tables["tbPontos"].NewRow();
                 dr["Ponto"] = new Point(pt.X, pt.Y);
                 dsPts.Tables["tbPontos"].Rows.Add(dr);
             }
         }
     }
 }
        public static unsafe void scanLine(int xclick, int yclick, Bitmap img, Color c, Poligono poligono)
        {
            int        H       = img.Height;
            int        W       = img.Width;
            BitmapData bmpData = img.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            int        padding = bmpData.Stride - (W * 3);
            byte *     ptrIni  = (byte *)bmpData.Scan0.ToPointer();

            List <List <Aresta> > ET  = new List <List <Aresta> >();
            List <Aresta>         AET = new List <Aresta>();

            for (int i = 0; i < Principal.getHTela(); i++)
            {
                ET.Add(new List <Aresta>());
            }

            List <Point> polPoint = poligono.getPontos();

            for (int i = 0; i < polPoint.Count; i++)
            {
                Aresta aresta = new Aresta(polPoint[i % polPoint.Count], polPoint[(i + 1) % polPoint.Count]);
                ET[aresta.getYmin()].Add(aresta);
            }
            int y = 0, x;

            while (ET[y].Count == 0)
            {
                y++;
            }

            //primeiro Y
            foreach (Aresta a in ET[y])
            {
                AET.Add(a);
            }

            while (AET.Count > 0)
            {
                for (int i = 0; i < AET.Count; i++)
                {
                    if (AET[i].getYmax() == y)
                    {
                        AET.Remove(AET[i--]);
                    }
                }
                //AET.Sort();
                heap(AET);
                for (int i = 0; i < AET.Count; i += 2)
                {
                    Aresta a = AET[i];
                    Aresta b = AET[i + 1];
                    for (x = (int)Math.Floor(a.getXmin()); x < Math.Ceiling(b.getXmin()); x++)
                    {
                        Util.setPixel(ptrIni, x, y, W, padding, c);
                    }
                    a.setXmin(a.getXmin() + a.getIncX());
                    b.setXmin(b.getXmin() + b.getIncX());
                }
                y++;
                foreach (Aresta a in ET[y])
                {
                    AET.Add(a);
                }
            }
            img.UnlockBits(bmpData);
        }