private int Dodai(GuiLocation a, GuiLocation b) { double x1 = a.X, y1 = a.Y; double x2 = b.X, y2 = b.Y; double distance = Math.Sqrt(Math.Pow(x2 - x1, 2.0) + Math.Pow(y2 - y1, 2.0)); return((int)distance); }
private void pnlView_MouseDown(object sender, MouseEventArgs e) { if (_addLoc) { if (getGuiLocationAtPoint(e.X, e.Y) == null) { GuiLocation _guiLocation = new GuiLocation(); _guiLocation.Identifier = _guiLocations.Count().ToString(); _guiLocation.X = e.X; _guiLocation.Y = e.Y; _guiLocations.Add(_guiLocation); cmbLocations.Items.Add(_guiLocation); } } else { GuiLocation _guiLocation = getGuiLocationAtPoint(e.X, e.Y); if (_guiLocation != null) { if (_selectedGuiLocation != null) { int weight = 0; if (chkRandom.Checked) { Random random = new Random(); weight = random.Next(1, 25); } else if (chkOxy.Checked) { weight = Dodai(_selectedGuiLocation, _guiLocation); } else { weight = int.Parse(txtweight.Text); } Connection connection = new Connection(_selectedGuiLocation, _guiLocation, weight); _connections.Add(connection); _selectedGuiLocation.Selected = false; _selectedGuiLocation = null; } else { _guiLocation.Selected = true; _selectedGuiLocation = _guiLocation; } } } PaintGui(); }
private void pnlView_MouseDown(object sender, MouseEventArgs e) { if (_addLoc) { if (getGuiLocationAtPoint(e.X, e.Y) == null) { GuiLocation _guiLocation = new GuiLocation(); _guiLocation.Identifier = _guiLocations.Count().ToString(); _guiLocation.X = e.X; _guiLocation.Y = e.Y; _guiLocations.Add(_guiLocation); cmbLocations.Items.Add(_guiLocation); } } else { GuiLocation _guiLocation = getGuiLocationAtPoint(e.X, e.Y); if (_guiLocation != null) { if (_selectedGuiLocation != null) { int weight = 0; if (chkRandom.Checked) { Random random=new Random(); weight = random.Next(1, 25); } else { weight = int.Parse(txtweight.Text); } Connection connection = new Connection(_selectedGuiLocation, _guiLocation, weight); _connections.Add(connection); _selectedGuiLocation.Selected = false; _selectedGuiLocation = null; } else { _guiLocation.Selected = true; _selectedGuiLocation = _guiLocation; } } } PaintGui(); }