//static Mesh<TVertex, TEdge, TFace> MakeMonotone(Mesh<TVertex, TEdge, TFace> mesh) //{ // var partitioner = new YMonotonePartitioner<TVertex, TEdge, TFace>(mesh); // // return partitioner.Result; // return mesh; //} // TODO: Temporary public constructor taking a polygon during debugging public YMonotonePartitioner(CircularLinkedList <TVertex> polygon) { //source = planar_subdivision; //target = (Mesh<TVertex, TEdge, TFace>) source.Clone(); vertices = polygon; // 1. Construct a priority queue Q on the vertices P, using their y-coordinates // as priority. If two points have the same y-coordinate, the one with the smaller // x-coordinate has the higher priority yxComparer = new HighYLowXComparer(); queue = new PriorityQueue <Point2D, TVertex>(yxComparer); foreach (TVertex vertex in polygon) { queue.Enqueue(vertex.Position, vertex); } // TODO Need right comparer here helpers = new SplayDictionary <TVertex, TVertex>(edgeComparer); while (queue.Count != 0) { TVertex vertex = queue.Dequeue(); VertexType type = GetVertexType(vertex); switch (type) { case VertexType.Start: HandleStartVertex(vertex); break; case VertexType.Split: HandleSplitVertex(vertex); break; case VertexType.End: HandleEndVertex(vertex); break; case VertexType.Merge: HandleMergeVertex(vertex); break; case VertexType.Regular: HandleRegularVertex(vertex); break; case VertexType.Collinear: HandleCollinearVertex(vertex); break; default: throw new ArgumentOutOfRangeException(); } } }
/// <summary> /// Create the partitioner. New diagonals will be inserted into the result mesh by calls to /// the provided DiagonalInserterDelegate which accepts the mesh and from and to vertices for the /// new edge. /// </summary> /// <param name="mesh">The mesh to be partitioned.</param> /// <param name="DiagonalInserterDelegate">An action for inserting edges into the mesh between the specificed vertices</param> public MonotoneYPartitioner(Mesh <TVertex, TEdge, TFace> mesh, Action <Mesh <TVertex, TEdge, TFace>, TVertex, TVertex> DiagonalInserterDelegate) { // TODO: We should copy the mesh here, but no copy-constructor yet! //this.mesh = new Mesh<TVertex, TEdge, TFace>(mesh); this.mesh = mesh; // The comparer used for ordering vertices in the queue - controlling // the order in which the sweep line sweeps over vertices HighYLowXComparer yxComparer = new HighYLowXComparer(); meshUtilities = new MonotoneMeshUtilities <TVertex>(yxComparer); queueDictionary = new PriorityQueueDictionary <Point2D, TVertex>(yxComparer); xEdgeComparer = new LeftToRightEdgeComparer(); sweeplineUtilities = new SweeplineUtilities(xEdgeComparer); helpers = new SplayDictionary <EdgeBase, TVertex>(xEdgeComparer); this.DiagonalInserterDelegate = DiagonalInserterDelegate; }