public void TestRemoveEdges() { var graph = new GeometricGraph(1, 100); // add and remove edge. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddEdge(0, 1, new uint[] { 10 }, null); Assert.AreEqual(1, graph.RemoveEdges(0)); Assert.AreEqual(0, graph.RemoveEdges(1)); // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(0, edges.Count()); graph = new GeometricGraph(1, 100); // add and remove edges. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddVertex(2, 0, 0); graph.AddEdge(0, 1, new uint[] { 10 }, null); graph.AddEdge(0, 2, new uint[] { 10 }, null); Assert.AreEqual(2, graph.RemoveEdges(0)); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(0, edges.Count()); graph = new GeometricGraph(1, 100); // add and remove edges. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddVertex(2, 0, 0); graph.AddEdge(0, 1, new uint[] { 10 }, null); graph.AddEdge(0, 2, new uint[] { 20 }, null); graph.AddEdge(1, 2, new uint[] { 30 }, null); Assert.AreEqual(2, graph.RemoveEdges(0)); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(0, edges.Count()); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(1, edges.Count()); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); }
public void TestGetShape() { var graph = new GeometricGraph(2, 100); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 0, 1); graph.AddVertex(3, 0, 2); var edge1 = graph.AddEdge(0, 1, new uint[] { 0, 10 }, new Coordinate(0.25f, 0.25f), new Coordinate(0.50f, 0.50f), new Coordinate(0.75f, 0.75f)); var shape = graph.GetShape(graph.GetEdge(edge1)); Assert.IsNotNull(shape); Assert.AreEqual(5, shape.Count); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(0, shape[0].Longitude); Assert.AreEqual(0.25, shape[1].Latitude); Assert.AreEqual(0.25, shape[1].Longitude); Assert.AreEqual(0.5, shape[2].Latitude); Assert.AreEqual(0.5, shape[2].Longitude); Assert.AreEqual(0.75, shape[3].Latitude); Assert.AreEqual(0.75, shape[3].Longitude); Assert.AreEqual(1, shape[4].Latitude); Assert.AreEqual(1, shape[4].Longitude); shape = graph.GetShape(graph.GetEdgeEnumerator(0).First()); Assert.IsNotNull(shape); Assert.AreEqual(5, shape.Count); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(0, shape[0].Longitude); Assert.AreEqual(0.25, shape[1].Latitude); Assert.AreEqual(0.25, shape[1].Longitude); Assert.AreEqual(0.5, shape[2].Latitude); Assert.AreEqual(0.5, shape[2].Longitude); Assert.AreEqual(0.75, shape[3].Latitude); Assert.AreEqual(0.75, shape[3].Longitude); Assert.AreEqual(1, shape[4].Latitude); Assert.AreEqual(1, shape[4].Longitude); shape = graph.GetShape(graph.GetEdgeEnumerator(1).First(x => x.To == 0)); Assert.IsNotNull(shape); Assert.AreEqual(5, shape.Count); Assert.AreEqual(1, shape[0].Latitude); Assert.AreEqual(1, shape[0].Longitude); Assert.AreEqual(0.75, shape[1].Latitude); Assert.AreEqual(0.75, shape[1].Longitude); Assert.AreEqual(0.5, shape[2].Latitude); Assert.AreEqual(0.5, shape[2].Longitude); Assert.AreEqual(0.25, shape[3].Latitude); Assert.AreEqual(0.25, shape[3].Longitude); Assert.AreEqual(0, shape[4].Latitude); Assert.AreEqual(0, shape[4].Longitude); }
/// <summary> /// Searches for an edge that has the exact start- and endpoints given within the given tolerance. /// </summary> public static uint SearchEdgeExact(this GeometricGraph graph, Coordinate location1, Coordinate location2, float tolerance) { var vertex1 = graph.SearchClosest(location1.Latitude, location1.Longitude, 0.01f, 0.01f); if (vertex1 == Constants.NO_VERTEX) { return(Constants.NO_EDGE); } var vertex1Location = graph.GetVertex(vertex1); if (Coordinate.DistanceEstimateInMeter(location1, vertex1Location) > tolerance) { return(Constants.NO_EDGE); } var edgeEnumerator = graph.GetEdgeEnumerator(); var best = float.MaxValue; var bestEdge = Constants.NO_EDGE; while (edgeEnumerator.MoveNext()) { var vertex2Location = graph.GetVertex(edgeEnumerator.To); var dist = Coordinate.DistanceEstimateInMeter(location2, vertex2Location); if (dist < tolerance && dist < best) { best = dist; bestEdge = edgeEnumerator.Id; } } return(bestEdge); }
/// <summary> /// Creates a router point for the given vertex. /// </summary> public static RouterPoint CreateRouterPointForVertex(this GeometricGraph graph, uint vertex, uint neighbour) { float latitude, longitude; if (!graph.GetVertex(vertex, out latitude, out longitude)) { throw new ArgumentException("Vertex doesn't exist, cannot create routerpoint."); } var edges = graph.GetEdgeEnumerator(vertex); while (true) { if (!edges.MoveNext()) { throw new ArgumentException("No edges associated with vertex and it's neigbour, cannot create routerpoint."); } if (edges.To == neighbour) { break; } } if (edges.DataInverted) { return(new RouterPoint(latitude, longitude, edges.Id, ushort.MaxValue)); } return(new RouterPoint(latitude, longitude, edges.Id, 0)); }
public void TestArgumentExcptions() { // create graph with one vertex and start adding 2. var graph = new GeometricGraph(1, 2); // make sure to add 1 and 2. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddEdge(0, 1, new uint[] { 1 }, null); Assert.Catch <ArgumentOutOfRangeException>(() => { graph.GetEdgeEnumerator(2); }); }
public static RouterPoint CreateRouterPointForVertex(this GeometricGraph graph, uint vertex) { float latitude; float longitude; if (!graph.GetVertex(vertex, out latitude, out longitude)) { throw new ArgumentException("Vertex doesn't exist, cannot create routerpoint."); } GeometricGraph.EdgeEnumerator edgeEnumerator = graph.GetEdgeEnumerator(vertex); if (!edgeEnumerator.MoveNext()) { throw new ArgumentException("No edges associated with vertex, cannot create routerpoint."); } if (edgeEnumerator.DataInverted) { return(new RouterPoint(latitude, longitude, edgeEnumerator.Id, ushort.MaxValue)); } return(new RouterPoint(latitude, longitude, edgeEnumerator.Id, (ushort)0)); }
/// <summary> /// Gets all features inside the given bounding box. /// </summary> public static FeatureCollection GetFeaturesIn(this GeometricGraph graph, float minLatitude, float minLongitude, float maxLatitude, float maxLongitude) { var features = new FeatureCollection(); var vertices = Itinero.Algorithms.Search.Hilbert.HilbertExtensions.Search(graph, minLatitude, minLongitude, maxLatitude, maxLongitude); var edges = new HashSet <long>(); var edgeEnumerator = graph.GetEdgeEnumerator(); foreach (var vertex in vertices) { var attributes = new AttributesTable(); attributes.AddAttribute("id", vertex.ToInvariantString()); var vertexLocation = graph.GetVertex(vertex); features.Add(new Feature(new Point(vertexLocation.ToCoordinate()), attributes)); edgeEnumerator.MoveTo(vertex); edgeEnumerator.Reset(); while (edgeEnumerator.MoveNext()) { if (edges.Contains(edgeEnumerator.Id)) { continue; } edges.Add(edgeEnumerator.Id); var geometry = new LineString(graph.GetShape(edgeEnumerator.Current).ToCoordinatesArray()); attributes = new AttributesTable(); attributes.AddAttribute("id", edgeEnumerator.Id.ToInvariantString()); features.Add(new Feature(geometry, attributes)); } } return(features); }
/// <summary> /// Creates a router point for the given vertex. /// </summary> public static RouterPoint CreateRouterPointForVertex(this GeometricGraph graph, uint vertex, Func <GeometricEdge, bool> isAcceptable) { float latitude, longitude; if (!graph.GetVertex(vertex, out latitude, out longitude)) { throw new ArgumentException("Vertex doesn't exist, cannot create routerpoint."); } var edges = graph.GetEdgeEnumerator(vertex); while (edges.MoveNext()) { if (isAcceptable(edges.Current)) { if (edges.DataInverted) { return(new RouterPoint(latitude, longitude, edges.Id, ushort.MaxValue)); } return(new RouterPoint(latitude, longitude, edges.Id, 0)); } } throw new ArgumentException("No edges associated with vertex can be used for all of the given profiles, cannot create routerpoint."); }
public void TestSwitch() { var graph = new GeometricGraph(1, 100); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddEdge(0, 1, new uint[] { 1 }, null); graph.Switch(0, 1); // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().To); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(1, edges.First().Data[0]); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(0, edges.First().To); Assert.AreEqual(1, edges.First().Data[0]); graph = new GeometricGraph(1, 100); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddVertex(2, 0, 0); graph.AddVertex(3, 0, 0); graph.AddVertex(4, 0, 0); graph.AddVertex(5, 0, 0); graph.AddEdge(0, 1, new uint[] { 1 }, null); graph.AddEdge(0, 2, new uint[] { 2 }, null); graph.AddEdge(0, 3, new uint[] { 3 }, null); graph.AddEdge(0, 4, new uint[] { 4 }, null); graph.AddEdge(5, 1, new uint[] { 5 }, null); graph.AddEdge(5, 2, new uint[] { 6 }, null); graph.AddEdge(5, 3, new uint[] { 7 }, null); graph.AddEdge(5, 4, new uint[] { 8 }, null); graph.Switch(0, 1); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(1, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(5, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(4, edges.Count()); Assert.AreEqual(1, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(2, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(3, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(4, edges.First(x => x.To == 4).Data[0]); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(2, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(6, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(3, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(7, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(4); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(4, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(8, edges.First(x => x.To == 5).Data[0]); graph.Switch(0, 1); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(4, edges.Count()); Assert.AreEqual(1, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(2, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(3, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(4, edges.First(x => x.To == 4).Data[0]); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(1, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(5, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(2, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(6, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(3, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(7, edges.First(x => x.To == 5).Data[0]); edges = graph.GetEdgeEnumerator(4); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(4, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(8, edges.First(x => x.To == 5).Data[0]); }
public void TestGetEdgeEnumerator() { var graph = new GeometricGraph(1, 100); // add edges. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 0, 0); graph.AddVertex(2, 0, 0); graph.AddVertex(3, 0, 0); graph.AddVertex(4, 0, 0); graph.AddVertex(5, 0, 0); var edge1 = graph.AddEdge(0, 1, new uint[] { 10 }, null); var edge2 = graph.AddEdge(1, 2, new uint[] { 20 }, null); var edge3 = graph.AddEdge(1, 3, new uint[] { 30 }, null); var edge4 = graph.AddEdge(3, 4, new uint[] { 40 }, null); var edge5 = graph.AddEdge(4, 1, new uint[] { 50 }, null); var edge6 = graph.AddEdge(5, 1, new uint[] { 60 }, null); // get empty edge enumerator. var edges = graph.GetEdgeEnumerator(); Assert.IsFalse(edges.HasData); // move to vertices and test result. Assert.IsTrue(edges.MoveTo(0)); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(1, edges.First().To); Assert.IsTrue(edges.MoveTo(1)); Assert.AreEqual(5, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edge1, edges.First(x => x.To == 0).Id); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edge2, edges.First(x => x.To == 2).Id); Assert.IsTrue(edges.Any(x => x.To == 3)); Assert.AreEqual(30, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(edge3, edges.First(x => x.To == 3).Id); Assert.IsTrue(edges.Any(x => x.To == 4)); Assert.AreEqual(true, edges.First(x => x.To == 4).DataInverted); Assert.AreEqual(50, edges.First(x => x.To == 4).Data[0]); Assert.AreEqual(edge5, edges.First(x => x.To == 4).Id); Assert.IsTrue(edges.Any(x => x.To == 5)); Assert.AreEqual(true, edges.First(x => x.To == 5).DataInverted); Assert.AreEqual(60, edges.First(x => x.To == 5).Data[0]); Assert.AreEqual(edge6, edges.First(x => x.To == 5).Id); Assert.IsTrue(edges.MoveTo(2)); Assert.AreEqual(1, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 1)); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(20, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(edge2, edges.First(x => x.To == 1).Id); Assert.IsTrue(edges.MoveTo(3)); Assert.AreEqual(2, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 1)); Assert.AreEqual(true, edges.First(x => x.To == 1).DataInverted); Assert.AreEqual(30, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(edge3, edges.First(x => x.To == 1).Id); Assert.IsTrue(edges.Any(x => x.To == 4)); Assert.AreEqual(40, edges.First(x => x.To == 4).Data[0]); Assert.AreEqual(edge4, edges.First(x => x.To == 4).Id); Assert.IsTrue(edges.MoveTo(4)); Assert.AreEqual(2, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 3)); Assert.AreEqual(true, edges.First(x => x.To == 3).DataInverted); Assert.AreEqual(40, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(edge4, edges.First(x => x.To == 3).Id); Assert.IsTrue(edges.Any(x => x.To == 1)); Assert.AreEqual(50, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(edge5, edges.First(x => x.To == 1).Id); Assert.IsTrue(edges.MoveTo(5)); Assert.AreEqual(1, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 1)); Assert.AreEqual(60, edges.First(x => x.To == 1).Data[0]); Assert.AreEqual(edge6, edges.First(x => x.To == 1).Id); }
public void TestAddEdge() { var graph = new GeometricGraph(1, 100); // add edge. graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); var edgeId1 = graph.AddEdge(0, 1, new uint[] { 10 }, null); Assert.AreEqual(0, edgeId1); // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(1, edges.First().From); Assert.AreEqual(0, edges.First().To); // add another edge. graph.AddVertex(2, 2, 2); var edgeId2 = graph.AddEdge(1, 2, new uint[] { 20 }, null); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(2, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edgeId1, edges.First(x => x.To == 0).Id); Assert.AreEqual(1, edges.First(x => x.To == 0).From); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edgeId2, edges.First(x => x.To == 2).Id); Assert.AreEqual(1, edges.First(x => x.To == 2).From); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(20, edges.First().Data[0]); Assert.AreEqual(edgeId2, edges.First().Id); Assert.AreEqual(2, edges.First().From); Assert.AreEqual(1, edges.First().To); // add another edge. graph.AddVertex(3, 3, 3); var edgeId3 = graph.AddEdge(1, 3, new uint[] { 30 }, null); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(3, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edgeId1, edges.First(x => x.To == 0).Id); Assert.AreEqual(1, edges.First(x => x.To == 0).From); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edgeId2, edges.First(x => x.To == 2).Id); Assert.AreEqual(1, edges.First(x => x.To == 2).From); Assert.IsTrue(edges.Any(x => x.To == 3)); Assert.AreEqual(30, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 3).Id); Assert.AreEqual(1, edges.First(x => x.To == 3).From); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(edgeId2, edges.First().Id); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(20, edges.First().Data[0]); Assert.AreEqual(2, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(30, edges.First().Data[0]); Assert.AreEqual(edgeId3, edges.First().Id); Assert.AreEqual(3, edges.First().From); Assert.AreEqual(1, edges.First().To); // add another edge but in reverse. var edgeId4 = graph.AddEdge(3, 1, new uint[] { 31 }, null); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(4, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edgeId1, edges.First(x => x.To == 0).Id); Assert.AreEqual(1, edges.First(x => x.To == 0).From); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edgeId2, edges.First(x => x.To == 2).Id); Assert.AreEqual(1, edges.First(x => x.To == 2).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 30)); Assert.AreEqual(false, edges.First(x => x.To == 3 && x.Data[0] == 30).DataInverted); Assert.AreEqual(30, edges.First(x => x.To == 3 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 3 && x.Data[0] == 30).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 30).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 31)); Assert.AreEqual(true, edges.First(x => x.To == 3 && x.Data[0] == 31).DataInverted); Assert.AreEqual(31, edges.First(x => x.To == 3 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 3 && x.Data[0] == 31).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 31).From); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(edgeId2, edges.First().Id); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(20, edges.First().Data[0]); Assert.AreEqual(2, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(30, edges.First(x => x.To == 1 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 1 && x.Data[0] == 30).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 30).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 30).To); Assert.AreEqual(31, edges.First(x => x.To == 1 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 1 && x.Data[0] == 31).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 31).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 31).To); // add another edge and start a new island. uint vertex4 = 4; uint vertex5 = 5; graph.AddVertex(vertex4, 4, 4); graph.AddVertex(vertex5, 5, 5); var edge5Id = graph.AddEdge(vertex4, vertex5, new uint[] { 40 }, null); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(4, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edgeId1, edges.First(x => x.To == 0).Id); Assert.AreEqual(1, edges.First(x => x.To == 0).From); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edgeId2, edges.First(x => x.To == 2).Id); Assert.AreEqual(1, edges.First(x => x.To == 2).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 30)); Assert.AreEqual(false, edges.First(x => x.To == 3 && x.Data[0] == 30).DataInverted); Assert.AreEqual(30, edges.First(x => x.To == 3 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 3 && x.Data[0] == 30).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 30).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 31)); Assert.AreEqual(true, edges.First(x => x.To == 3 && x.Data[0] == 31).DataInverted); Assert.AreEqual(31, edges.First(x => x.To == 3 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 3 && x.Data[0] == 31).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 31).From); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(edgeId2, edges.First().Id); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(20, edges.First().Data[0]); Assert.AreEqual(2, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(2, edges.Count()); Assert.AreEqual(30, edges.First(x => x.To == 1 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 1 && x.Data[0] == 30).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 30).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 30).To); Assert.AreEqual(31, edges.First(x => x.To == 1 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 1 && x.Data[0] == 31).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 31).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 31).To); edges = graph.GetEdgeEnumerator(vertex4); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(40, edges.First().Data[0]); Assert.AreEqual(edge5Id, edges.First().Id); Assert.AreEqual(vertex4, edges.First().From); Assert.AreEqual(vertex5, edges.First().To); edges = graph.GetEdgeEnumerator(vertex5); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(40, edges.First().Data[0]); Assert.AreEqual(edge5Id, edges.First().Id); Assert.AreEqual(vertex5, edges.First().From); Assert.AreEqual(vertex4, edges.First().To); // connect the islands. var edgeId5 = graph.AddEdge(vertex5, 3, new uint[] { 50 }, null); // verify all edges. edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(10, edges.First().Data[0]); Assert.AreEqual(edgeId1, edges.First().Id); Assert.AreEqual(0, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(1); Assert.AreEqual(4, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == 0)); Assert.AreEqual(true, edges.First(x => x.To == 0).DataInverted); Assert.AreEqual(10, edges.First(x => x.To == 0).Data[0]); Assert.AreEqual(edgeId1, edges.First(x => x.To == 0).Id); Assert.AreEqual(1, edges.First(x => x.To == 0).From); Assert.IsTrue(edges.Any(x => x.To == 2)); Assert.AreEqual(20, edges.First(x => x.To == 2).Data[0]); Assert.AreEqual(edgeId2, edges.First(x => x.To == 2).Id); Assert.AreEqual(1, edges.First(x => x.To == 2).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 30)); Assert.AreEqual(false, edges.First(x => x.To == 3 && x.Data[0] == 30).DataInverted); Assert.AreEqual(30, edges.First(x => x.To == 3 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 3 && x.Data[0] == 30).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 30).From); Assert.IsTrue(edges.Any(x => x.To == 3 && x.Data[0] == 31)); Assert.AreEqual(true, edges.First(x => x.To == 3 && x.Data[0] == 31).DataInverted); Assert.AreEqual(31, edges.First(x => x.To == 3 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 3 && x.Data[0] == 31).Id); Assert.AreEqual(1, edges.First(x => x.To == 3 && x.Data[0] == 31).From); edges = graph.GetEdgeEnumerator(2); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(edgeId2, edges.First().Id); Assert.AreEqual(true, edges.First().DataInverted); Assert.AreEqual(20, edges.First().Data[0]); Assert.AreEqual(2, edges.First().From); Assert.AreEqual(1, edges.First().To); edges = graph.GetEdgeEnumerator(3); Assert.AreEqual(3, edges.Count()); Assert.AreEqual(30, edges.First(x => x.To == 1 && x.Data[0] == 30).Data[0]); Assert.AreEqual(edgeId3, edges.First(x => x.To == 1 && x.Data[0] == 30).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 30).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 30).To); Assert.AreEqual(31, edges.First(x => x.To == 1 && x.Data[0] == 31).Data[0]); Assert.AreEqual(edgeId4, edges.First(x => x.To == 1 && x.Data[0] == 31).Id); Assert.AreEqual(3, edges.First(x => x.To == 1 && x.Data[0] == 31).From); Assert.AreEqual(1, edges.First(x => x.To == 1 && x.Data[0] == 31).To); Assert.IsTrue(edges.Any(x => x.To == vertex5)); Assert.AreEqual(true, edges.First(x => x.To == vertex5).DataInverted); Assert.AreEqual(50, edges.First(x => x.To == vertex5).Data[0]); Assert.AreEqual(edgeId5, edges.First(x => x.To == vertex5).Id); Assert.AreEqual(3, edges.First(x => x.To == vertex5).From); edges = graph.GetEdgeEnumerator(vertex4); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(40, edges.First().Data[0]); Assert.AreEqual(edge5Id, edges.First().Id); Assert.AreEqual(vertex4, edges.First().From); Assert.AreEqual(vertex5, edges.First().To); edges = graph.GetEdgeEnumerator(vertex5); Assert.AreEqual(2, edges.Count()); Assert.IsTrue(edges.Any(x => x.To == vertex4)); Assert.AreEqual(true, edges.First(x => x.To == vertex4).DataInverted); Assert.AreEqual(40, edges.First(x => x.To == vertex4).Data[0]); Assert.AreEqual(edge5Id, edges.First(x => x.To == vertex4).Id); Assert.AreEqual(vertex5, edges.First(x => x.To == vertex4).From); Assert.IsTrue(edges.Any(x => x.To == 3)); Assert.AreEqual(50, edges.First(x => x.To == 3).Data[0]); Assert.AreEqual(edgeId5, edges.First(x => x.To == 3).Id); Assert.AreEqual(vertex5, edges.First(x => x.To == 3).From); }
public void TestAddEdgeShape() { var graph = new GeometricGraph(2, 100); graph.AddVertex(0, 0, 0); graph.AddVertex(1, 1, 1); graph.AddVertex(2, 0, 1); graph.AddVertex(3, 0, 2); graph.AddEdge(0, 1, new uint[] { 0, 10 }, new Coordinate(0.25f, 0.25f), new Coordinate(0.5f, 0.5f), new Coordinate(0.75f, 0.75f)); graph.AddEdge(1, 2, new uint[] { 10, 20 }, new Coordinate(0.75f, 1), new Coordinate(0.5f, 1), new Coordinate(0.25f, 1)); graph.AddEdge(2, 3, new uint[] { 20, 30 }, new Coordinate(0, 1.25f), new Coordinate(0, 1.5f), new Coordinate(0, 1.75f)); // verify all edges. var edges = graph.GetEdgeEnumerator(0); Assert.AreEqual(1, edges.Count()); Assert.AreEqual(1, edges.First().To); Assert.IsNotNull(edges.First().Shape); var shape = new List <Coordinate>(edges.First().Shape); Assert.AreEqual(0.25, shape[0].Latitude); Assert.AreEqual(0.25, shape[0].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(0.5, shape[1].Longitude); Assert.AreEqual(0.75, shape[2].Latitude); Assert.AreEqual(0.75, shape[2].Longitude); shape = new List <Coordinate>(edges.First().Shape.Reverse()); Assert.AreEqual(0.25, shape[2].Latitude); Assert.AreEqual(0.25, shape[2].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(0.5, shape[1].Longitude); Assert.AreEqual(0.75, shape[0].Latitude); Assert.AreEqual(0.75, shape[0].Longitude); edges = graph.GetEdgeEnumerator(1); shape = new List <Coordinate>(edges.First(x => x.To == 0).Shape); Assert.AreEqual(0.25, shape[0].Latitude); Assert.AreEqual(0.25, shape[0].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(0.5, shape[1].Longitude); Assert.AreEqual(0.75, shape[2].Latitude); Assert.AreEqual(0.75, shape[2].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 0).Shape.Reverse()); Assert.AreEqual(0.25, shape[2].Latitude); Assert.AreEqual(0.25, shape[2].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(0.5, shape[1].Longitude); Assert.AreEqual(0.75, shape[0].Latitude); Assert.AreEqual(0.75, shape[0].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 2).Shape); Assert.AreEqual(0.75, shape[0].Latitude); Assert.AreEqual(1, shape[0].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(0.25, shape[2].Latitude); Assert.AreEqual(1, shape[2].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 2).Shape.Reverse()); Assert.AreEqual(0.75, shape[2].Latitude); Assert.AreEqual(1, shape[2].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(0.25, shape[0].Latitude); Assert.AreEqual(1, shape[0].Longitude); edges = graph.GetEdgeEnumerator(2); shape = new List <Coordinate>(edges.First(x => x.To == 1).Shape); Assert.AreEqual(0.75, shape[0].Latitude); Assert.AreEqual(1, shape[0].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(0.25, shape[2].Latitude); Assert.AreEqual(1, shape[2].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 1).Shape.Reverse()); Assert.AreEqual(0.75, shape[2].Latitude); Assert.AreEqual(1, shape[2].Longitude); Assert.AreEqual(0.5, shape[1].Latitude); Assert.AreEqual(1, shape[1].Longitude); Assert.AreEqual(0.25, shape[0].Latitude); Assert.AreEqual(1, shape[0].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 3).Shape); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(1.25, shape[0].Longitude); Assert.AreEqual(0, shape[1].Latitude); Assert.AreEqual(1.5, shape[1].Longitude); Assert.AreEqual(0, shape[2].Latitude); Assert.AreEqual(1.75, shape[2].Longitude); shape = new List <Coordinate>(edges.First(x => x.To == 3).Shape.Reverse()); Assert.AreEqual(0, shape[2].Latitude); Assert.AreEqual(1.25, shape[2].Longitude); Assert.AreEqual(0, shape[1].Latitude); Assert.AreEqual(1.5, shape[1].Longitude); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(1.75, shape[0].Longitude); edges = graph.GetEdgeEnumerator(3); shape = new List <Coordinate>(edges.First().Shape); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(1.25, shape[0].Longitude); Assert.AreEqual(0, shape[1].Latitude); Assert.AreEqual(1.5, shape[1].Longitude); Assert.AreEqual(0, shape[2].Latitude); Assert.AreEqual(1.75, shape[2].Longitude); shape = new List <Coordinate>(edges.First().Shape.Reverse()); Assert.AreEqual(0, shape[2].Latitude); Assert.AreEqual(1.25, shape[2].Longitude); Assert.AreEqual(0, shape[1].Latitude); Assert.AreEqual(1.5, shape[1].Longitude); Assert.AreEqual(0, shape[0].Latitude); Assert.AreEqual(1.75, shape[0].Longitude); }
public static List <uint> SearchCloserThan(this GeometricGraph graph, float latitude, float longitude, float offset, float maxDistanceMeter, Func <GeometricEdge, bool> isOk) { HashSet <uint> uintSet1 = new HashSet <uint>(); GeoCoordinate geoCoordinate = new GeoCoordinate((double)latitude, (double)longitude); HashSet <uint> uintSet2 = graph.Search(latitude, longitude, offset); GeometricGraph.EdgeEnumerator edgeEnumerator = graph.GetEdgeEnumerator(); foreach (uint vertex1 in uintSet2) { GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1); if (GeoCoordinate.DistanceEstimateInMeter((double)latitude, (double)longitude, (double)vertex2.Latitude, (double)vertex2.Longitude) < (double)maxDistanceMeter) { edgeEnumerator.MoveTo(vertex1); while (edgeEnumerator.MoveNext()) { if (isOk(edgeEnumerator.Current)) { uintSet1.Add(edgeEnumerator.Id); break; } } } } GeoCoordinateBox geoCoordinateBox = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.SouthEast)); HashSet <uint> uintSet3 = new HashSet <uint>(); foreach (uint vertex1 in uintSet2) { GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1); if (edgeEnumerator.MoveTo(vertex1) && edgeEnumerator.HasData) { while (edgeEnumerator.MoveNext()) { if (!uintSet3.Contains(edgeEnumerator.Id)) { uintSet3.Add(edgeEnumerator.Id); bool flag = isOk == null; ICoordinate coordinate = (ICoordinate)vertex2; ShapeBase shapeBase = edgeEnumerator.Shape; if (shapeBase != null) { if (edgeEnumerator.DataInverted) { shapeBase = shapeBase.Reverse(); } IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator(); enumerator.Reset(); while (enumerator.MoveNext()) { ICoordinate current = enumerator.Current; if (GeoCoordinate.DistanceEstimateInMeter((double)current.Latitude, (double)current.Longitude, (double)latitude, (double)longitude) < (double)maxDistanceMeter) { if (!flag && isOk(edgeEnumerator.Current)) { flag = true; } if (flag) { uintSet1.Add(edgeEnumerator.Id); } } if (geoCoordinateBox.IntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)current.Longitude, (double)current.Latitude)) { PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)current.Latitude, (double)current.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate); if (pointF2D != (PointF2D)null && GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude) < (double)maxDistanceMeter) { if (!flag && isOk(edgeEnumerator.Current)) { flag = true; } if (flag) { uintSet1.Add(edgeEnumerator.Id); } } } coordinate = current; } } ICoordinate vertex3 = (ICoordinate)graph.GetVertex(edgeEnumerator.To); if (geoCoordinateBox.IntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)vertex3.Longitude, (double)vertex3.Latitude)) { PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)vertex3.Latitude, (double)vertex3.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate); if (pointF2D != (PointF2D)null && GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude) < (double)maxDistanceMeter) { if (!flag && isOk(edgeEnumerator.Current)) { flag = true; } if (flag) { uintSet1.Add(edgeEnumerator.Id); } } } } } } } return(new List <uint>((IEnumerable <uint>)uintSet1)); }
public static uint[] SearchClosestEdges(this GeometricGraph graph, float latitude, float longitude, float latitudeOffset, float longitudeOffset, float maxDistanceMeter, Func <GeometricEdge, bool>[] isOks) { GeoCoordinate geoCoordinate = new GeoCoordinate((double)latitude, (double)longitude); HashSet <uint> uintSet1 = graph.Search(latitude - latitudeOffset, longitude - longitudeOffset, latitude + latitudeOffset, longitude + longitudeOffset); uint[] numArray1 = new uint[isOks.Length]; double[] numArray2 = new double[isOks.Length]; for (int index = 0; index < numArray1.Length; ++index) { numArray1[index] = uint.MaxValue; numArray2[index] = (double)maxDistanceMeter; } GeometricGraph.EdgeEnumerator edgeEnumerator = graph.GetEdgeEnumerator(); foreach (uint vertex1 in uintSet1) { GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1); double num = GeoCoordinate.DistanceEstimateInMeter((double)latitude, (double)longitude, (double)vertex2.Latitude, (double)vertex2.Longitude); for (int index = 0; index < isOks.Length; ++index) { if (num < numArray2[index]) { edgeEnumerator.MoveTo(vertex1); while (edgeEnumerator.MoveNext()) { if (isOks[index](edgeEnumerator.Current)) { numArray2[index] = num; numArray1[index] = edgeEnumerator.Id; break; } } } } } GeoCoordinateBox[] boxes = new GeoCoordinateBox[isOks.Length]; for (int index = 0; index < boxes.Length; ++index) { boxes[index] = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)((double)maxDistanceMeter), DirectionEnum.SouthEast)); } HashSet <uint> uintSet2 = new HashSet <uint>(); foreach (uint vertex1 in uintSet1) { GeoCoordinateSimple vertex2 = graph.GetVertex(vertex1); if (edgeEnumerator.MoveTo(vertex1) && edgeEnumerator.HasData) { while (edgeEnumerator.MoveNext()) { if (!uintSet2.Contains(edgeEnumerator.Id)) { uintSet2.Add(edgeEnumerator.Id); bool[] flagArray = new bool[isOks.Length]; for (int index = 0; index < isOks.Length; ++index) { flagArray[index] = isOks[index] == null; } ICoordinate coordinate = (ICoordinate)vertex2; ShapeBase shapeBase = edgeEnumerator.Shape; if (shapeBase != null) { if (edgeEnumerator.DataInverted) { shapeBase = shapeBase.Reverse(); } IEnumerator <ICoordinate> enumerator = shapeBase.GetEnumerator(); enumerator.Reset(); while (enumerator.MoveNext()) { ICoordinate current = enumerator.Current; double num1 = GeoCoordinate.DistanceEstimateInMeter((double)current.Latitude, (double)current.Longitude, (double)latitude, (double)longitude); for (int index = 0; index < numArray1.Length; ++index) { if (num1 < numArray2[index]) { if (!flagArray[index] && isOks[index](edgeEnumerator.Current)) { flagArray[index] = true; } if (flagArray[index]) { numArray2[index] = num1; numArray1[index] = edgeEnumerator.Id; boxes[index] = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast)); } } } if (boxes.AnyIntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)current.Longitude, (double)current.Latitude)) { PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)current.Latitude, (double)current.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate); if (pointF2D != (PointF2D)null) { double num2 = GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude); for (int index = 0; index < numArray1.Length; ++index) { if (num2 < numArray2[index]) { if (!flagArray[index] && isOks[index](edgeEnumerator.Current)) { flagArray[index] = true; } if (flagArray[index]) { numArray2[index] = num2; numArray1[index] = edgeEnumerator.Id; boxes[index] = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast)); } } } } } coordinate = current; } } ICoordinate vertex3 = (ICoordinate)graph.GetVertex(edgeEnumerator.To); if (boxes.AnyIntersectsPotentially((double)coordinate.Longitude, (double)coordinate.Latitude, (double)vertex3.Longitude, (double)vertex3.Latitude)) { PointF2D pointF2D = new GeoCoordinateLine(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude), new GeoCoordinate((double)vertex3.Latitude, (double)vertex3.Longitude), true, true).ProjectOn((PointF2D)geoCoordinate); if (pointF2D != (PointF2D)null) { double num = GeoCoordinate.DistanceEstimateInMeter(pointF2D[1], pointF2D[0], (double)latitude, (double)longitude); for (int index = 0; index < isOks.Length; ++index) { if (num < numArray2[index]) { if (!flagArray[index] && isOks[index](edgeEnumerator.Current)) { flagArray[index] = true; } if (flagArray[index]) { numArray2[index] = num; numArray1[index] = edgeEnumerator.Id; boxes[index] = new GeoCoordinateBox(new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.NorthWest), new GeoCoordinate((double)latitude, (double)longitude).OffsetWithDirection((Meter)numArray2[index], DirectionEnum.SouthEast)); } } } } } } } } } return(numArray1); }
/// <summary> /// Gets an empty edge enumerator. /// </summary> /// <returns></returns> public EdgeEnumerator GetEdgeEnumerator() { return(new EdgeEnumerator(this, _graph.GetEdgeEnumerator())); }