示例#1
0
 public double GetDistance(Vertex other)
 {
     double xd = Point.X - other.Point.X;
     double yd = Point.Y - other.Point.Y;
     double squared = xd * xd + yd * yd;
     return Math.Sqrt(squared);
 }
 public List<Vertex> ExtractVertices()
 {
     vertices = new List<Vertex>();
     vertexMap = new Dictionary<int, Vertex>();
     foreach (Point p in se.PointExtractor.Points)
     {
         int key = GetVertexKey(p);
         List<Segment> connectedSegments = se.PointSegments[key];
         if (connectedSegments.Count != 2)
         {
             Vertex vertex = new Vertex(p, connectedSegments);
             vertices.Add(vertex);
             vertexMap.Add(key, vertex);
         }
     }
     return vertices;
 }
示例#3
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);
 }
示例#4
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);
 }
示例#5
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);
             }
     }
 }
示例#6
0
 public long GetPathKey(Vertex v1, Vertex v2)
 {
     return SegmentExtractor.GetSegmentKey(v1.Point, v2.Point);
 }
示例#7
0
 public Path(Vertex v1, Vertex v2, List<Point> p)
 {
     V1 = v1; V2 = v2; Points = p;
 }
 public int GetVertexKey(Vertex v)
 {
     return GetVertexKey(v.Point);
 }