コード例 #1
0
 private void MergePaths(Path p1, Path p2, Vertex sharedVertex, Vertex start, Vertex end)
 {
     List<Point> points = new List<Point>();
     if (p1.Points[0] != start.Point)
         p1.Points.Reverse();
     points.AddRange(p1.Points);
     if (p2.Points[p2.Points.Count - 1] != end.Point)
         p2.Points.Reverse();
     points.AddRange(p2.Points);
     Path newPath = new Path(start, end, points);
     long key = GetPathKey(newPath);
     paths.Add(newPath);
     pathMap.Add(key, newPath);
     InsertVertexPath(start, newPath);
     InsertVertexPath(end, newPath);
     RemovePath(p1);
     RemovePath(p2);
 }
コード例 #2
0
 private void InsertVertexPath(Vertex vertex, Path path)
 {
     int key = VertexExtractor.GetVertexKey(vertex);
     List<Path> paths;
     if (vertexPaths.ContainsKey(key))
         paths = vertexPaths[key];
     else
     {
         paths = new List<Path>();
         vertexPaths.Add(key, paths);
     }
     paths.Add(path);
 }
コード例 #3
0
 public void RemovePath(Path path)
 {
     long key = GetPathKey(path);
     paths.Remove(path);
     pathMap.Remove(key);
     int v1Key = VertexExtractor.GetVertexKey(path.V1);
     int v2Key = VertexExtractor.GetVertexKey(path.V2);
     vertexPaths[v1Key].Remove(path);
     if (vertexPaths[v1Key].Count == 0)
     {
         ve.Vertices.Remove(path.V1);
         ve.VertexMap.Remove(v1Key);
         vertexPaths.Remove(v1Key);
     }
     vertexPaths[v2Key].Remove(path);
     if (vertexPaths[v2Key].Count == 0)
     {
         ve.Vertices.Remove(path.V2);
         ve.VertexMap.Remove(v2Key);
         vertexPaths.Remove(v2Key);
     }
 }
コード例 #4
0
 private void FindEndVertex(Vertex startVertex, Point fromPoint, Segment nextSegment, List<Point> pointList)
 {
     Point nextPoint = (nextSegment.P2 == fromPoint) ? nextSegment.P1 : nextSegment.P2;
     int nextPointKey = PointExtractor.GetPointKey(nextPoint);
     if (ve.VertexMap.ContainsKey(nextPointKey))
     {
         Vertex endVertex = ve.VertexMap[nextPointKey];
         long pathKey = GetPathKey(startVertex, endVertex);
         if (!pathMap.ContainsKey(pathKey))
         {
             pointList.Add(nextPoint);
             Path path = new Path(startVertex, endVertex, pointList);
             paths.Add(path);
             pathMap.Add(pathKey, path);
             InsertVertexPath(startVertex, path);
             InsertVertexPath(endVertex, path);
         }
     }
     else
     {
         List<Segment> toCheck = SegmentExtractor.PointSegments[nextPointKey];
         foreach (Segment s in toCheck)
             if (s != nextSegment && (s.P1 == nextPoint || s.P2 == nextPoint))
             {
                 pointList.Add(nextPoint);
                 FindEndVertex(startVertex, nextPoint, s, pointList);
             }
     }
 }
コード例 #5
0
 public long GetPathKey(Path p)
 {
     return GetPathKey(p.V1, p.V2);
 }