Beispiel #1
0
        private void DrawPartitionArea()
        {
            GDB      p = new GDB(ptbGrid.Width, ptbGrid.Height);
            Graphics g = p.Store();

            g.Clear(ptbGrid.BackColor);
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            if (tree.Root != null)
            {
                tree.DrawPartitionArea(tree.Root, g, ptbGrid.Width, ptbGrid.Height);
                if (tree.IsRangeSearch == true)
                {
                    //Lấy giá trị tọa độ lớn nhất hiện tại trên cây
                    double maxCoordinate = tree.GetXValMax(tree.Root);
                    if (maxCoordinate < tree.GetYValMax(tree.Root))
                    {
                        maxCoordinate = tree.GetYValMax(tree.Root);
                    }
                    double xScale     = (ptbGrid.Width - (ptbGrid.Width - (ptbGrid.Height - 20))) / maxCoordinate; //Bằng ptbGrid.Height - 20
                    double yScale     = (ptbGrid.Height - 20) / maxCoordinate;
                    Point  realCentre = new Point(Convert.ToInt32(centre.X * xScale), Convert.ToInt32(centre.Y * yScale));
                    //Ước lượng tỷ lệ tương đối cho realRadius (Không chính xác lắm)
                    int   realRadius = Convert.ToInt32(radius * ((xScale + yScale) / 2));
                    Pen   myPen      = new Pen(Color.Green, 2);
                    Brush myBrush    = new SolidBrush(Color.Green);
                    g.DrawEllipse(myPen, realCentre.X - realRadius, ptbGrid.Height - realCentre.Y - realRadius, realRadius * 2, realRadius * 2);
                    g.FillEllipse(myBrush, realCentre.X - 5, ptbGrid.Height - realCentre.Y - 5, 10, 10);
                    g.DrawLine(myPen, realCentre.X, ptbGrid.Height - realCentre.Y, realCentre.X + realRadius, ptbGrid.Height - realCentre.Y);
                    g.DrawString(String.Format("O({0}, {1})", centre.X, centre.Y), new Font("Arial", 8), myBrush, realCentre.X - 30, ptbGrid.Height - realCentre.Y + 5);
                    g.DrawString(String.Format("R={0}", radius), new Font("Arial", 8), myBrush, (realCentre.X + realCentre.X + realRadius) / 2 - 15, ptbGrid.Height - realCentre.Y - 14);
                }
                p.Paint(ptbGrid);
                p.Dispone();
            }
        }
Beispiel #2
0
 //Vẽ lại cây trong 2 PictureBox (chưa hoạt động được với ptbTree)
 private void ReDrawTree()
 {
     if (ptbTree.Width != 0 && ptbTree.Height != 0 && ptbGrid.Width != 0 && ptbGrid.Height != 0)
     {
         GDB      p = new GDB(ptbTree.Width, ptbTree.Height);
         Graphics g = p.Store();
         g.Clear(ptbTree.BackColor);
         DrawTree(g, tree, XPIXEL, YPIXEL, doDoiX, doDoiY);
         p.Paint(ptbTree);
         p.Dispone();
         DrawPartitionArea();
         //ptbTree.Invalidate();
         this.Invalidate();
     }
 }
Beispiel #3
0
 private void ptbTree_MouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Point diemHT = new Point(e.X, e.Y);
         doDoiXHT = doDoiX + (diemHT.X - diemBD.X);
         doDoiYHT = doDoiY + (diemHT.Y - diemBD.Y);
         GDB      p = new GDB(ptbTree.Width, ptbTree.Height);
         Graphics g = p.Store();
         g.Clear(ptbTree.BackColor);
         DrawTree(g, tree, XPIXEL, YPIXEL, doDoiXHT, doDoiYHT);
         p.Paint(ptbTree);
         p.Dispone();
     }
 }