UIElement DrawConnection(PopulationCentreConnection connection, bool highway) { var line = new Line(); line.X1 = connection.Position1.x; line.Y1 = connection.Position1.y; line.X2 = connection.Position2.x; line.Y2 = connection.Position2.y; float thickness; Brush brush; if (highway) { thickness = 2; brush = new SolidColorBrush(Color.FromRgb(255, 0, 255)); } else { thickness = 1; brush = new SolidColorBrush(Color.FromRgb(128, 128, 128)); } line.Stroke = brush; line.StrokeThickness = thickness; return(line); }
private static IEnumerable <PopulationCentreConnection> getPopCenterConnections(List <PopulationCentre> popCentres) { SortedList <float, PopulationCentreConnection> links = new SortedList <float, PopulationCentreConnection>((popCentres.Count * (popCentres.Count - 1)) / 2); for (int i = 0; i < popCentres.Count - 1; i++) { for (int j = i + 1; j < popCentres.Count; j++) { var connection = new PopulationCentreConnection(popCentres[i], popCentres[j]); try { links.Add(connection.weight, connection); } catch (ArgumentException a) { } } } return(links.Values.Reverse()); }
List <PopulationCentreConnection> getNearestNeighbourConnections(List <PopulationCentre> pops, RoadType roadType, List <PopulationCentreConnection> connections = null) { var geometry = new TriangleNet.Geometry.Polygon(); //Dictionary<Vertex, PopulationCentre> popDictionary = new Dictionary<Vertex, PopulationCentre>(); var connectionList = new List <PopulationCentreConnection>(); foreach (var pop in pops) { var vertex = new Vertex(pop.Position.x, pop.Position.y); //popDictionary.Add(vertex, pop); geometry.Add(vertex); } var mesh = geometry.Triangulate(); int org, dest; ITriangle neighbor; int nid; foreach (var tri in mesh.Triangles) { for (int i = 0; i < 3; i++) { // The neighbor opposite of vertex i. GetNeighbor(tri, i, out neighbor, out nid); // Consider each edge only once. if ((tri.ID < nid) || (nid < 0)) { // Get the edge endpoints. org = tri.GetVertexID((i + 1) % 3); dest = tri.GetVertexID((i + 2) % 3); var pop1 = pops[org]; var pop2 = pops[dest]; var connection = new PopulationCentreConnection(pop1, pop2); connection.roadType = roadType; if (connections == null || !connections.Any(x => x.Equal(connection))) { connectionList.Add(connection); } } } } return(connectionList); }