示例#1
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 + "]}";
        }
 private double GetOutgoingHalfEdgeAngle(HalfEdge he)
 {
     var points = he.Edge.Points;
     Line line;
     if (he.Start.X == points[0].X && he.Start.Y == points[0].Y)
         line = new Line(new Point(he.Start.X, he.Start.Y), new Point(points[1].X, points[1].Y));
     else
         line = new Line(new Point(he.Start.X, he.Start.Y), new Point(points[points.Count - 2].X, points[points.Count - 2].Y));
     return line.Angle();
 }
 private HalfEdge FindNextHalfEdge(HalfEdge inEdge)
 {
     int nodeKey = GetNodeKey(inEdge.End);
     List<HalfEdge> outgoingEdges = new List<HalfEdge>(NodeHalfEdges[nodeKey]);
     int counterPart = -1;
     for (int i=0; i<outgoingEdges.Count; i++)
         if (outgoingEdges[i].Edge == inEdge.Edge)
             counterPart = i;
     double inAngle = FixAngle(GetHalfEdgeAngle(outgoingEdges[counterPart]));
     outgoingEdges.RemoveAt(counterPart);
     double[] angles = new double[outgoingEdges.Count];
     int greater = -1, smaller = -1;
     for (int i=0; i<angles.Length; i++)
     {
         angles[i] = FixAngle(GetHalfEdgeAngle(outgoingEdges[i]));
         if (angles[i] > inAngle)
             greater = i;
         if (angles[i] < inAngle)
             smaller = i;
     }
     if (greater >= 0)
     {
         for (int i = 0; i<angles.Length; i++)
                 if (angles[i] > inAngle && angles[i] < angles[greater])
                     greater = i;
         return outgoingEdges[greater];
     }
     if (smaller >= 0)
     {
         for (int i = 0; i < angles.Length; i++)
                 if (angles[i] < inAngle && angles[i] < angles[smaller])
                     smaller = i;
         return outgoingEdges[smaller];
     }
     return null;
 }
 private void AddHalfEdge(HalfEdge he)
 {
     HalfEdges.Add(he);
     int key = GetNodeKey(he.Start);
     if (NodeHalfEdges.ContainsKey(key))
         NodeHalfEdges[key].Add(he);
     else
     {
         List<HalfEdge> list = new List<HalfEdge>();
         list.Add(he);
         NodeHalfEdges.Add(key, list);
     }
 }
 public long GetHalfEdgeKey(HalfEdge he)
 {
     return GetHalfEdgeKey(he.Start, he.End);
 }
 public HalfEdge FindNextUnvisitedHalfEdge(HalfEdge halfEdge, Dictionary<long,bool> vistedHalfEdges)
 {
     HalfEdge nextHalfEdge = FindNextHalfEdge(halfEdge);
     if (nextHalfEdge == null)
         return null;
     long nextHalfEdgeKey = GetHalfEdgeKey(nextHalfEdge);
     if (vistedHalfEdges.ContainsKey(nextHalfEdgeKey))
         return null;
     else
         return nextHalfEdge;
 }