Example #1
0
        private void ReadFromFile(string filename)
        {
            StreamReader sr = new StreamReader(filename);

            strip_vector = new Vector2d();

            string[] s = sr.ReadLine().Split(' ');
            strip_vector.X = double.Parse(s[0]);
            strip_vector.Y = double.Parse(s[1]);

            polygons = new PolygonWithMinMax[int.Parse(sr.ReadLine())];
            for (int i = 0; i < polygons.Length; i++)
            {
                polygons[i] = new PolygonWithMinMax();

                s = sr.ReadLine().Split(' ');
                polygons[i].Pole.X = double.Parse(s[0]);
                polygons[i].Pole.Y = double.Parse(s[1]);

                for (int j = 2; j < s.Length; j += 2)
                    polygons[i].Add(new Point2d() { X = double.Parse(s[j]), Y = double.Parse(s[j + 1]) });

                polygons[i].Check();
            }

            sr.Close();
        }
Example #2
0
        public PlacingOpt(PolygonWithMinMax[] polygons, Vector2d strip_vector)
        {
            this.polygons = polygons;
            this.strip_vector = strip_vector;

            int n = polygons.Length;
            X = new double[2 * n + 1];
            Gs = new double[4 * n + n * (n - 1) / 2][];
            for (int i = 0; i < Gs.Length; i++)
                Gs[i] = new double[10];

            index_strip = 2 * n;
        }
Example #3
0
        public FormMain()
        {
            InitializeComponent();

            random = new Random();

            filename = "example_input_data.txt";

            ReadFromFile(filename);

            polygon = null;

            placing = new PlacingOpt(polygons, strip_vector);
            placing.FillPoint();

            Text = "Размещение многоугольников (" + filename + ")";

            thread = null;
            thread_start = new ParameterizedThreadStart(MethodInThread);

            settings = new FormSettings.SettingsClass();
        }
Example #4
0
        private void pictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
                location_old = e.Location;

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                double d = double.PositiveInfinity;
                int k = 0;
                for (int i = 0; i < polygons.Length; i++)
                {
                    double x = e.X - polygons[i].CenterX;
                    double y = pictureBox.ClientSize.Height / 2 + strip_vector.Y / 2 - e.Y - polygons[i].CenterY;
                    double dd = Math.Sqrt(x * x + y * y);
                    if (d > dd)
                    {
                        d = dd;
                        k = i;
                    }
                }
                if (d < 25)
                    polygon = polygons[k];
                else
                    polygon = null;

                pictureBox.Invalidate();
            }
        }