Example #1
0
 private string CreatePolygonString(Polygon p)
 {
     List<string> edgeStrings = new List<string>();
     foreach (HalfEdge he in p.HalfEdges)
         edgeStrings.Add(CreateHalfEdgeString(he, p));
     return "{\"id\": " + p.Id + ", \"edges\": [" + String.Join(",", edgeStrings) + "]}";
 }
 public void AddPolygon(Polygon polygon)
 {
     polygons.Add(polygon);
     foreach (Edge e in polygon.Edges)
     {
         long edgeKey = GetEdgeKey(e);
         if (!EdgePolygons.ContainsKey(edgeKey))
             EdgePolygons.Add(edgeKey, new List<Polygon>());
         EdgePolygons[edgeKey].Add(polygon);
     }
 }
Example #3
0
        private string CreateHalfEdgeString(HalfEdge he, Polygon p)
        {
            long edgeKey = pe.GetEdgeKey(he.Edge);
            Polygon neighbor = null;
            foreach (Polygon candidate in pe.EdgePolygons[edgeKey])
                if (candidate != p)
                    neighbor = candidate;
            string neighborStr = (neighbor != null) ? neighbor.Id.ToString() : "-1";

            List<string> xp = new List<string>();
            List<string> yp = new List<string>();
            Point[] points = he.GetPoints();
            foreach (Point op in points)
            {
                PointF cp = ConvertPoint(op);
                xp.Add(cp.X.ToString(CultureInfo.InvariantCulture));
                yp.Add(cp.Y.ToString(CultureInfo.InvariantCulture));
            }
            string xPoints = String.Join(",", xp);
            string yPoints = String.Join(",", yp);
            return "{\"neighbor\": " + neighborStr + ", \"xpoints\": [" + xPoints + "], \"ypoints\": [" + yPoints + "]}";
        }
 public List<Polygon> ExtractPolygons()
 {
     Dictionary<long,bool> vistedHalfEdges = new Dictionary<long,bool>();
     polygons = new List<Polygon>();
     foreach (Node n in Nodes)
     {
         int nodeKey = GetNodeKey(n);
         foreach (HalfEdge he in NodeHalfEdges[nodeKey])
         {
             long halfEdgeKey = GetHalfEdgeKey(he);
             if (!vistedHalfEdges.ContainsKey(halfEdgeKey))
             {
                 List<HalfEdge> edgesList = new List<HalfEdge>();
                 HalfEdge currentHalfEdge = he;
                 long currentKey = GetHalfEdgeKey(currentHalfEdge);
                 edgesList.Add(currentHalfEdge);
                 vistedHalfEdges.Add(currentKey, true);
                 bool deadEnd = false;
                 while (currentHalfEdge.End != n && !deadEnd)
                 {
                     currentHalfEdge = FindNextUnvisitedHalfEdge(currentHalfEdge, vistedHalfEdges);
                     if (currentHalfEdge == null)
                     {
                         deadEnd = true;
                         break;
                     }
                     currentKey = GetHalfEdgeKey(currentHalfEdge);
                     edgesList.Add(currentHalfEdge);
                     vistedHalfEdges.Add(currentKey, true);
                 }
                 Polygon polygon = new Polygon(edgesList, polygons.Count);
                 if (!deadEnd && polygon.IsClockWise())
                     AddPolygon(polygon);
                 else
                 {
                     foreach (HalfEdge used in edgesList)
                     {
                         long key = GetHalfEdgeKey(used);
                         vistedHalfEdges.Remove(key);
                     }
                 }
             }
         }
     }
     CreateNeighborLists();
     return polygons;
 }