public void removeConnection(Node n) { int x = connections.IndexOf(n); if(x != -1) { weights.Remove(weights[x]); connections.Remove(n); } }
public double distanceTo(Node n){ int index = connections.IndexOf(n); try { return weights[index]; } catch(Exception e) { return -20; } }
public void addNode(double x, double y, double z) { Node n = getNodeReference(x, y, z); if(n == null) { int num = 0; if(nodes.Count > 0) num = nodes[nodes.Count - 1].Number + 1; Node node = new Node(name, x, y, z, num); //Assumes nodes are in numerical order nodes.Add(node); } }
public void addConnection(Node a) { connections.Add(a); weights.Add(Math.Sqrt(Math.Pow(a.x - x, 2) + Math.Pow(a.y - y, 2))); }
public void loadFile() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Room| *.rm"; ofd.FilterIndex = 1; ofd.Title = "Open Room"; if(ofd.ShowDialog() == DialogResult.OK) { clearRoom(); System.IO.StreamReader save = new System.IO.StreamReader(ofd.OpenFile()); location = ofd.FileName; List<int> nodeNums = new List<int>(); while(save.Peek() >= 0) { String line = save.ReadLine(); String[] items = line.Split(' '); if(line.Contains("L")) { PointF pt1 = new PointF(Convert.ToInt32(items[1]), Convert.ToInt32(items[2])); PointF pt2 = new PointF(Convert.ToInt32(items[3]), Convert.ToInt32(items[4])); PointF[] a = { pt1, pt2 }; lines.Add(a); } else if(line.Contains("N")) { Node n = new Node(name, Convert.ToDouble(items[2]), Convert.ToDouble(items[3]), Convert.ToDouble(items[4]), Convert.ToInt32(items[1])); int maxValue = items.Length; if(items[items.Length - 2].Equals("C")) { n.Comment = items[items.Length - 1]; maxValue = items.Length - 3; } for(int k = 5;k < maxValue;k++) { if(!items[k].Equals("") && nodeNums.Contains(Convert.ToInt32(items[k]))) { n.addConnection(nodes[Convert.ToInt32(items[k])]); nodes[Convert.ToInt32(items[k])].addConnection(n); } } nodeNums.Add(n.Number);//used for adding connections nodes.Add(n); } } save.Close(); } }