private void btnTry_Click(object sender, EventArgs e)
        {
            showPicture form2 = new showPicture();

            form2.Show();

            List <int> record = new List <int>();
            Rectangle  rec    = new Rectangle()
            {
                Width = 3000, Height = 1500
            };

            foreach (var item in record)
            {
                rictxt.AppendText(item + " ");
            }
        }
Beispiel #2
0
        private void btnTry_Click(object sender, EventArgs e)
        {
            showPicture form2 = new showPicture();

            form2.Show();

            List <int> record = new List <int>();
            Rectangle  rec    = new Rectangle()
            {
                Width = 3000, Height = 1500
            };

            cut();
            foreach (var item in record)
            {
                rictxt.AppendText(item + " ");
            }
            void cut()
            {
                if (rec.Width >= p1.width && rec.Height >= p1.height)
                {
                    List <int> cnt = new List <int>()
                    {
                        1000, 1000, 1000, 1000
                    };
                    for (int i = 0; i < 4; i++)
                    {
                        cnt[i] = 10000;
                    }
                    if (rec.Width >= p1.width && rec.Height >= p1.height)
                    {
                        cnt[0] = (rec.Width % p1.width) * p1.height;  //hh
                        cnt[2] = (rec.Height % p1.height) * p1.width; //sh
                    }
                    if (rec.Width >= p1.height && rec.Height >= p1.width)
                    {
                        cnt[1] = (rec.Width % p1.height) * p1.width;  //hs
                        cnt[3] = (rec.Height % p1.width) * p1.height; //ss
                    }
                    int num = cnt.IndexOf(cnt.Min());
                    switch (num)
                    {
                    case 0:
                        rec.Height -= p1.height;
                        break;

                    case 1:
                        rec.Height -= p1.width;
                        break;

                    case 2:
                        rec.Width -= p1.width;
                        break;

                    case 3:
                        rec.Width -= p1.height;
                        break;

                    default:
                        break;
                    }
                    record.Add(num);
                    cut();
                }
                else
                {
                    return;
                }
            }

            void randomCut()
            {
                if (rec.Width >= p1.width && rec.Height >= p1.height)
                {
                    List <int> cnt = new List <int>()
                    {
                        1000, 1000, 1000, 1000
                    };
                    for (int i = 0; i < 4; i++)
                    {
                        cnt[i] = 10000;
                    }
                    if (rec.Width >= p1.width && rec.Height >= p1.height)
                    {
                        cnt[0] = (rec.Width % p1.width) * p1.height;  //hh
                        cnt[2] = (rec.Height % p1.height) * p1.width; //sh
                    }
                    if (rec.Width >= p1.height && rec.Height >= p1.width)
                    {
                        cnt[1] = (rec.Width % p1.height) * p1.width;  //hs
                        cnt[3] = (rec.Height % p1.width) * p1.height; //ss
                    }
                    int num = cnt.IndexOf(cnt.Min());
                    switch (num)
                    {
                    case 0:
                        rec.Height -= p1.height;
                        break;

                    case 1:
                        rec.Height -= p1.width;
                        break;

                    case 2:
                        rec.Width -= p1.width;
                        break;

                    case 3:
                        rec.Width -= p1.height;
                        break;

                    default:
                        break;
                    }
                    record.Add(num);
                    cut();
                }
                else
                {
                    return;
                }
            }
        }