public EdgeReorderer (List<Edge> origEdges, VertexOrSite criterion)
		{
			_edges = new List<Edge> ();
			_edgeOrientations = new List<Side> ();
			if (origEdges.Count > 0) {
				_edges = ReorderEdges (origEdges, criterion);
			}
		}
 public EdgeReorderer(List <Edge> origEdges, VertexOrSite criterion)
 {
     _edges            = new List <Edge> ();
     _edgeOrientations = new List <Side> ();
     if (origEdges.Count > 0)
     {
         _edges = ReorderEdges(origEdges, criterion);
     }
 }
        private List <Edge> ReorderEdges(List <Edge> origEdges, VertexOrSite criterion)
        {
            int  i;
            int  n = origEdges.Count;
            Edge edge;

            // we're going to reorder the edges in order of traversal
            bool[] done  = new bool[n];
            int    nDone = 0;

            for (int j = 0; j < n; j++)
            {
                done [j] = false;
            }
            List <Edge> newEdges = new List <Edge> ();           // TODO: Switch to Deque if performance is a concern

            i    = 0;
            edge = origEdges [i];
            newEdges.Add(edge);
            _edgeOrientations.Add(Side.LEFT);
            ICoord firstPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
            ICoord lastPoint  = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;

            if (firstPoint == Vertex.VERTEX_AT_INFINITY || lastPoint == Vertex.VERTEX_AT_INFINITY)
            {
                return(new List <Edge> ());
            }

            done [i] = true;
            ++nDone;

            while (nDone < n)
            {
                for (i = 1; i < n; ++i)
                {
                    if (done [i])
                    {
                        continue;
                    }
                    edge = origEdges [i];
                    ICoord leftPoint  = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
                    ICoord rightPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;
                    if (leftPoint == Vertex.VERTEX_AT_INFINITY || rightPoint == Vertex.VERTEX_AT_INFINITY)
                    {
                        return(new List <Edge> ());
                    }
                    if (leftPoint == lastPoint)
                    {
                        lastPoint = rightPoint;
                        _edgeOrientations.Add(Side.LEFT);
                        newEdges.Add(edge);
                        done [i] = true;
                    }
                    else if (rightPoint == firstPoint)
                    {
                        firstPoint = leftPoint;
                        _edgeOrientations.Insert(0, Side.LEFT);                          // TODO: Change datastructure if this is slow
                        newEdges.Insert(0, edge);
                        done [i] = true;
                    }
                    else if (leftPoint == firstPoint)
                    {
                        firstPoint = rightPoint;
                        _edgeOrientations.Insert(0, Side.RIGHT);
                        newEdges.Insert(0, edge);
                        done [i] = true;
                    }
                    else if (rightPoint == lastPoint)
                    {
                        lastPoint = leftPoint;
                        _edgeOrientations.Add(Side.RIGHT);
                        newEdges.Add(edge);
                        done [i] = true;
                    }
                    if (done [i])
                    {
                        ++nDone;
                    }
                }
            }

            return(newEdges);
        }
		private List<Edge> ReorderEdges (List<Edge> origEdges, VertexOrSite criterion)
		{
			int i;
			int n = origEdges.Count;
			Edge edge;
			// we're going to reorder the edges in order of traversal
			bool[] done = new bool[n];
			int nDone = 0;
			for (int j=0; j<n; j++) {
				done [j] = false;
			}
			List<Edge> newEdges = new List<Edge> (); // TODO: Switch to Deque if performance is a concern
			
			i = 0;
			edge = origEdges [i];
			newEdges.Add (edge);
			_edgeOrientations.Add (Side.LEFT);
			ICoord firstPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
			ICoord lastPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;
			
			if (firstPoint == Vertex.VERTEX_AT_INFINITY || lastPoint == Vertex.VERTEX_AT_INFINITY) {
				return new List<Edge> ();
			}
			
			done [i] = true;
			++nDone;
			
			while (nDone < n) {
				for (i = 1; i < n; ++i) {
					if (done [i]) {
						continue;
					}
					edge = origEdges [i];
					ICoord leftPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.leftVertex : (ICoord)edge.leftSite;
					ICoord rightPoint = (criterion == VertexOrSite.VERTEX) ? (ICoord)edge.rightVertex : (ICoord)edge.rightSite;
					if (leftPoint == Vertex.VERTEX_AT_INFINITY || rightPoint == Vertex.VERTEX_AT_INFINITY) {
						return new List<Edge> ();
					}
					if (leftPoint == lastPoint) {
						lastPoint = rightPoint;
						_edgeOrientations.Add (Side.LEFT);
						newEdges.Add (edge);
						done [i] = true;
					} else if (rightPoint == firstPoint) {
						firstPoint = leftPoint;
						_edgeOrientations.Insert (0, Side.LEFT); // TODO: Change datastructure if this is slow
						newEdges.Insert (0, edge);
						done [i] = true;
					} else if (leftPoint == firstPoint) {
						firstPoint = rightPoint;
						_edgeOrientations.Insert (0, Side.RIGHT);
						newEdges.Insert (0, edge);
						done [i] = true;
					} else if (rightPoint == lastPoint) {
						lastPoint = leftPoint;
						_edgeOrientations.Add (Side.RIGHT);
						newEdges.Add (edge);
						done [i] = true;
					}
					if (done [i]) {
						++nDone;
					}
				}
			}
			
			return newEdges;
		}
Ejemplo n.º 5
0
        private List <Edge> ReorderEdges(List <Edge> origEdges, VertexOrSite criterion)
        {
            int count = origEdges.Count;

            bool[] array = new bool[count];
            int    num   = 0;

            for (int i = 0; i < count; i++)
            {
                array[i] = false;
            }
            List <Edge> list = new List <Edge>();
            int         num2 = 0;
            Edge        edge = origEdges[num2];

            list.Add(edge);
            _edgeOrientations.Add(Side.LEFT);
            object obj;

            if (criterion == VertexOrSite.VERTEX)
            {
                ICoord leftVertex = edge.leftVertex;
                obj = leftVertex;
            }
            else
            {
                obj = edge.leftSite;
            }
            ICoord coord = (ICoord)obj;
            object obj2;

            if (criterion == VertexOrSite.VERTEX)
            {
                ICoord leftVertex = edge.rightVertex;
                obj2 = leftVertex;
            }
            else
            {
                obj2 = edge.rightSite;
            }
            ICoord coord2 = (ICoord)obj2;

            if (coord == Vertex.VERTEX_AT_INFINITY || coord2 == Vertex.VERTEX_AT_INFINITY)
            {
                return(new List <Edge>());
            }
            array[num2] = true;
            num++;
            while (num < count)
            {
                for (num2 = 1; num2 < count; num2++)
                {
                    if (!array[num2])
                    {
                        edge = origEdges[num2];
                        object obj3;
                        if (criterion == VertexOrSite.VERTEX)
                        {
                            ICoord leftVertex = edge.leftVertex;
                            obj3 = leftVertex;
                        }
                        else
                        {
                            obj3 = edge.leftSite;
                        }
                        ICoord coord3 = (ICoord)obj3;
                        object obj4;
                        if (criterion == VertexOrSite.VERTEX)
                        {
                            ICoord leftVertex = edge.rightVertex;
                            obj4 = leftVertex;
                        }
                        else
                        {
                            obj4 = edge.rightSite;
                        }
                        ICoord coord4 = (ICoord)obj4;
                        if (coord3 == Vertex.VERTEX_AT_INFINITY || coord4 == Vertex.VERTEX_AT_INFINITY)
                        {
                            return(new List <Edge>());
                        }
                        if (coord3 == coord2)
                        {
                            coord2 = coord4;
                            _edgeOrientations.Add(Side.LEFT);
                            list.Add(edge);
                            array[num2] = true;
                        }
                        else if (coord4 == coord)
                        {
                            coord = coord3;
                            _edgeOrientations.Insert(0, Side.LEFT);
                            list.Insert(0, edge);
                            array[num2] = true;
                        }
                        else if (coord3 == coord)
                        {
                            coord = coord4;
                            _edgeOrientations.Insert(0, Side.RIGHT);
                            list.Insert(0, edge);
                            array[num2] = true;
                        }
                        else if (coord4 == coord2)
                        {
                            coord2 = coord3;
                            _edgeOrientations.Add(Side.RIGHT);
                            list.Add(edge);
                            array[num2] = true;
                        }
                        if (array[num2])
                        {
                            num++;
                        }
                    }
                }
            }
            return(list);
        }
Ejemplo n.º 6
0
        private List <Edge> ReorderEdges(List <Edge> origEdges, VertexOrSite criterion)
        {
            var n = origEdges.Count;
            // we're going to reorder the edges in order of traversal
            var done  = new bool[n];
            var nDone = 0;

            for (var j = 0; j < n; j++)
            {
                done[j] = false;
            }
            var newEdges = new List <Edge>(); // TODO: Switch to Deque if performance is a concern

            var i    = 0;
            var edge = origEdges[i];

            newEdges.Add(edge);
            EdgeOrientations.Add(Side.Left);
            var firstPoint = criterion == VertexOrSite.Vertex ? edge.LeftVertex : (ICoord)edge.LeftSite;
            var lastPoint  = criterion == VertexOrSite.Vertex ? edge.RightVertex : (ICoord)edge.RightSite;

            if (firstPoint == Vertex.VertexAtInfinity || lastPoint == Vertex.VertexAtInfinity)
            {
                return(new List <Edge>());
            }

            done[i] = true;
            ++nDone;

            while (nDone < n)
            {
                for (i = 1; i < n; ++i)
                {
                    if (done[i])
                    {
                        continue;
                    }
                    edge = origEdges[i];
                    var leftPoint  = criterion == VertexOrSite.Vertex ? edge.LeftVertex : (ICoord)edge.LeftSite;
                    var rightPoint = criterion == VertexOrSite.Vertex ? edge.RightVertex : (ICoord)edge.RightSite;
                    if (leftPoint == Vertex.VertexAtInfinity || rightPoint == Vertex.VertexAtInfinity)
                    {
                        return(new List <Edge>());
                    }
                    if (leftPoint == lastPoint)
                    {
                        lastPoint = rightPoint;
                        EdgeOrientations.Add(Side.Left);
                        newEdges.Add(edge);
                        done[i] = true;
                    }
                    else if (rightPoint == firstPoint)
                    {
                        firstPoint = leftPoint;
                        EdgeOrientations.Insert(0, Side.Left); // TODO: Change datastructure if this is slow
                        newEdges.Insert(0, edge);
                        done[i] = true;
                    }
                    else if (leftPoint == firstPoint)
                    {
                        firstPoint = rightPoint;
                        EdgeOrientations.Insert(0, Side.Right);
                        newEdges.Insert(0, edge);
                        done[i] = true;
                    }
                    else if (rightPoint == lastPoint)
                    {
                        lastPoint = leftPoint;
                        EdgeOrientations.Add(Side.Right);
                        newEdges.Add(edge);
                        done[i] = true;
                    }
                    if (done[i])
                    {
                        ++nDone;
                    }
                }
            }

            return(newEdges);
        }