using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Microsoft.Msagl.Core.Geometry; using Microsoft.Msagl.Core.Geometry.Curves; using Microsoft.Msagl.Routing.ConstrainedDelaunayTriangulation; namespace Microsoft.Msagl.Routing { /// /// [DebuggerDisplay("{Point}")] #if TEST_MSAGL [Serializable] #endif public class CdtSite { /// /// Object to which this site refers to. /// public object Owner { get; set; } /// /// public Point Point; /// /// each CdtSite points to the edges for which it is the upper virtex ( for horizontal edges it is the left point) /// public List Edges; internal List InEdges; /// /// /// public CdtSite(Point isolatedSite) { Point = isolatedSite; } internal void AddEdgeToSite(CdtEdge edge) { if (Edges == null) Edges = new List(); Edges.Add(edge); } #if DEBUG && TEST_MSAGL /// /// Returns a that represents the current . /// /// /// A that represents the current . /// /// 2 public override string ToString() { return Point.ToString(); } #endif internal CdtEdge EdgeBetweenUpperSiteAndLowerSite(CdtSite b) { Debug.Assert(Cdt.Above(this, b) > 0); if (Edges != null) foreach (var edge in Edges) if (edge.lowerSite == b) return edge; return null; } internal void AddInEdge(CdtEdge e) { if (InEdges == null) InEdges = new List(); InEdges.Add(e); } /// /// enumerates over all site triangles /// internal IEnumerable Triangles { // this function might not work correctly if InEdges are not set get { CdtEdge edge; if (Edges != null && Edges.Count>0) edge = Edges[0]; else if (InEdges != null && InEdges.Count>0) edge = InEdges[0]; else yield break; //going counterclockwise around the site var e = edge; do { var t = e.upperSite == this ? e.CcwTriangle : e.CwTriangle; if (t == null) { e = null; break; } yield return t; e = t.Edges[t.Edges.Index(e) + 2]; } while (e != edge);//full circle if (e != edge) { //we have not done the full circle, starting again with edge but now going clockwise around the site e = edge; do { var t = e.upperSite == this ? e.CwTriangle : e.CcwTriangle; if (t == null) { break; } yield return t; e = t.Edges[t.Edges.Index(e) + 1]; } while (true); // we will hit a null triangle for the convex hull border edge } } } } }