コード例 #1
0
ファイル: JsonExport.cs プロジェクト: SteviePonder/FactionMap
 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) + "]}";
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
ファイル: JsonExport.cs プロジェクト: SteviePonder/FactionMap
        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 + "]}";
        }
コード例 #4
0
 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;
 }