Exemplo n.º 1
0
 public List<Segment> ExtractSegments()
 {
     Dictionary<int, Point> pointMap = pe.BuildPointMap();
     segments = new List<Segment>();
     segmentMap = new Dictionary<long, Segment>();
     pointSegments = new Dictionary<int, List<Segment>>();
     foreach (Point p1 in pe.Points)
     {
         int p1Key = pe.GetPointKey(p1);
         List<Segment> connectedSegments = new List<Segment>();
         foreach (Point n in neighbors)
         {
             Point p2 = new Point(p1.X + n.X, p1.Y + n.Y);
             int p2Key = pe.GetPointKey(p2);
             if (pointMap.ContainsKey(p2Key))
             {
                 long segmentKey = GetSegmentKey(p1, p2);
                 if (!segmentMap.ContainsKey(segmentKey))
                 {
                     Segment segment = new Segment(p1, p2);
                     segments.Add(segment);
                     segmentMap.Add(segmentKey, segment);
                     connectedSegments.Add(segment);
                 }
                 else connectedSegments.Add(segmentMap[segmentKey]);
             }
         }
         pointSegments.Add(p1Key, connectedSegments);
     }
     return segments;
 }
Exemplo n.º 2
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);
             }
     }
 }
Exemplo n.º 3
0
 public long GetSegmentKey(Segment s)
 {
     return GetSegmentKey(s.P1, s.P2);
 }