Beispiel #1
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (draggedRect)
            {
                draggedRect = false;
                dragged     = null;
            }

            ShowPic();
            if (Math.Abs(stX - e.X) < 20 || Math.Abs(stY - e.Y) < 10)
            {
                return;
            }

            int         x  = Math.Max(0, myRound(Math.Min(e.X, stX)));
            int         y  = Math.Max(0, myRound(Math.Min(e.Y, stY)));
            MyRectangle mr = new MyRectangle
            {
                X         = x,
                Y         = y,
                Width     = Math.Min(pictureBox1.Width - x, myRound(Math.Abs(stX - e.X))),
                Height    = Math.Min(pictureBox1.Height - y, myRound(Math.Abs(stY - e.Y))),
                FillColor = Color.Black
            };

            borderRects.Add(mr);
            if (checkRectCross())
            {
                MessageBox.Show("Пересечение границ");
                borderRects.Remove(mr);
            }
            ShowPic();
        }
Beispiel #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            InputRect inputRect = new InputRect(pictureBox1.Width, pictureBox1.Height);

            if (inputRect.ShowDialog() == DialogResult.OK)
            {
                MyRectangle newRect = new MyRectangle
                {
                    X         = inputRect.x,
                    Y         = inputRect.y,
                    Width     = inputRect.w,
                    Height    = inputRect.h,
                    FillColor = Color.Black
                };

                borderRects.Add(newRect);

                if (checkRectCross())
                {
                    MessageBox.Show("Пересечение!");
                    borderRects.Remove(newRect);
                }
            }
            ShowPic();
        }
Beispiel #3
0
        /// <summary>
        /// Слияние прямоугольников в нужное
        /// </summary>
        void calcRectangles()
        {
            bool has_changes = true;

            // double h = (double)pictureBox1.Width;

            resultRects.Clear();
            foreach (var rect in startRects)
            {
                resultRects.Add(rect.Copy());
            }

            while (has_changes)
            {
                has_changes = false;
                resultRects.Sort((mr1, mr2) => mr1.getM() > mr2.getM() ? -1 : mr1.getM() == mr2.getM() ? 0 : 1);

                for (int i = 0; i < resultRects.Count - 1; i++)
                {
                    MyRectangle mri = resultRects[i];

                    Dictionary <double, List <MyRectangle> > nearests = new Dictionary <double, List <MyRectangle> >();

                    for (int j = 0; j < resultRects.Count; j++)
                    {
                        if (i != j && mri.isNearest(resultRects[j]))
                        {
                            double O      = 0;
                            double h      = (double)(pictureBox1.Height);
                            double lambda = (mri.Width + resultRects[j].Width) / h;
                            O = (mri.getM() + resultRects[j].getM()) / lambda;
                            if (!nearests.ContainsKey(O))
                            {
                                nearests.Add(O, new List <MyRectangle>());
                            }
                            nearests[O].Add(resultRects[j]);
                        }
                    }

                    if (nearests.Count > 0)
                    {
                        MyRectangle near = nearests.Last().Value.First();

                        resultRects[i] += near;
                        resultRects.Remove(near);
                        has_changes = true;
                        i--;
                    }
                }
            }
        }
Beispiel #4
0
        private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
        {
            if (resultRects.Any(rect => rect.IsIn(e.Location)))
            {
                MyRectangle rect = resultRects.Find(rect1 => rect1.IsIn(e.Location));
                toolTip1.ToolTipTitle = "result rect " + rect.ToString();
                toolTip1.Tag          = rect;
            }

            if (borderRects.Any(rect => rect.IsIn(e.Location)))
            {
                MyRectangle rect = borderRects.Find(rect1 => rect1.IsIn(e.Location));
                toolTip1.ToolTipTitle = "border rect " + rect.ToString();
                toolTip1.Tag          = rect;
            }
        }
Beispiel #5
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            stX = e.X;
            stY = e.Y;

            foreach (var borRect in borderRects)
            {
                borRect.Selected = false;
            }


            draggedRect = borderRects.Any(bord => bord.IsIn(e.Location));
            if (draggedRect)
            {
                dragged          = borderRects.Find(bord => bord.IsIn(e.Location));
                dragged.Selected = true;
            }
        }
Beispiel #6
0
        private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (borderRects.Any(bord => bord.IsIn(e.Location)))
            {
                MyRectangle clicked   = borderRects.Find(rect => rect.IsIn(e.Location));
                InputRect   inputRect = new InputRect(pictureBox1.Width, pictureBox1.Height,
                                                      clicked.X, clicked.Y,
                                                      clicked.Width, clicked.Height);
                if (inputRect.ShowDialog() == DialogResult.OK)
                {
                    clicked.X      = inputRect.x;
                    clicked.Y      = inputRect.y;
                    clicked.Width  = inputRect.w;
                    clicked.Height = inputRect.h;
                }
            }

            ShowPic();
        }
Beispiel #7
0
        /// <summary>
        /// Находим все прямоугольники, на которые запретные разбивают экран
        /// </summary>
        void getAllRectangles()
        {
            startRects = new List <MyRectangle>();
            for (int i = 0; i < boredrrsX.Count - 1; i++)
            {
                for (int j = 0; j < boredresY.Count - 1; j++)
                {
                    MyRectangle mr = new MyRectangle();
                    mr.X         = boredrrsX[i];
                    mr.Y         = boredresY[j];
                    mr.Width     = boredrrsX[i + 1] - boredrrsX[i];
                    mr.Height    = boredresY[j + 1] - boredresY[j];
                    mr.FillColor = getRandColor();



                    if (!borderRects.Any(border => border.isPart(mr)))
                    {
                        startRects.Add(mr);
                    }
                }
            }
        }