Example #1
0
 void FireStructureChangedUnder(RowVM row)
 {
     if (row == null)               // roots changed
     // Reestablish dependencies from model to ViewModel
     {
         _tree.Roots.DependentSentry.OnGet();
         StructureChanged(this, new TreePathEventArgs());
     }
     else
     {
         // Reestablish dependencies from model to ViewModel
         row.Children.DependentSentry.OnGet();
         TreePath path;
         if (row.Model.Parent == null)
         {
             path = new TreePath(row);
         }
         else
         {
             var list = new DList <RowVM>();
             for (; row != null; row = row.Parent)
             {
                 list.PushFirst(row);
             }
             path = new TreePath(list.ToArray());
         }
         StructureChanged(this, new TreePathEventArgs(path));
     }
 }
            // Puts contents of a #splice into NodeQueue and returns the first item of the splice.
            public LNode EnqueueSplice(VList <LNode> spliced, int maxExpansionsInner, int maxExpansions)
            {
                //Debug.Assert(!IsTarget); should be true except that IsTarget may not have been set yet
                MaybeCreateNodeQueue(maxExpansions, ref NodeQueue);

                // Enqueue spliced items
                foreach (var item in spliced.ToFVList())
                {
                    NodeQueue.PushFirst(Pair.Create(item, maxExpansionsInner));
                }

                return(NodeQueue.PopFirst().A);
            }
Example #3
0
        public static IListSource <Point> ComputeConvexHull(List <Point> points, bool sortInPlace)
        {
            if (points.Count < 2)
            {
                return(new DList <Point>((IReadOnlyList <Point>)points));
            }
            if (!sortInPlace)
            {
                points = new List <Point>(points);
            }
            points.Sort((a, b) =>
                        a.X == b.X ? a.Y.CompareTo(b.Y) : a.X > b.X ? 1 : -1);

            // Importantly, DList provides O(1) insertion at beginning and end
            DList <Point> hull = new DList <Point>();
            int           L = 0, U = 0;   // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                // right turn (clockwise) => negative cross product (for Y-up coords)
                Point p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count - 2]).Cross(p.Sub(p1)) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0)                 // when U == 0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
                Debug.Assert(U + L == hull.Count + 1);
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull);
        }
        public static PointF[] ComputeConvexHull(List<PointF> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
                points = new List<PointF>(points);
            points.Sort((a, b) =>
              a.X == b.X ? a.Y.CompareTo(b.Y) : (a.X > b.X ? 1 : -1));

            DList<PointF> hull = new DList<PointF>();
            int L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                PointF p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && cross((p1 = hull.Last),hull[hull.Count - 2], points[i]) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && cross((p1 = hull.First), (hull[1]), points[i]) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                    hull.PushFirst(p);
                U++;
            }

            try {

                hull.RemoveAt(hull.Count - 1);

            } catch (System.Exception) {

            }

            return hull.ToArray();
        }
 // Converts the list of remaining nodes from an implicit sublist of
 // OldAndRemainingNodes into an explicit queue, if it wasn't done yet.
 public void MaybeCreateNodeQueue(int maxExpansions, ref DList <Pair <LNode, int> > nodeQueue)
 {
     //Debug.Assert(!IsTarget); should be true except that IsTarget may not have been set yet
     if (nodeQueue == null)
     {
         // Transfer OldAndRemainingNodes into NodeQueue
         nodeQueue = new DList <Pair <LNode, int> >();
         if (!DropRemainingNodesIfRequested())
         {
             for (int left = OldAndRemainingNodes.Count - (CurrentNodeIndex + 1); left > 0; left--)
             {
                 nodeQueue.PushFirst(Pair.Create(OldAndRemainingNodes.Pop(), maxExpansions));
             }
         }
         OldAndRemainingNodes = LNode.List();
         _remainingNodes      = null;
     }
 }
Example #6
0
        public static IListSource <double[]> ComputeConvexHull(List <double[]> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
            {
                points = new List <double[]>(points);
            }
            points.Sort((a, b) =>
                        a[0] == b[0] ? a[1].CompareTo(b[1]) : (a[0] > b[0] ? 1 : -1));

            // Importantly, DList provides O(1) insertion at beginning and end
            DList <double[]> hull = new DList <double[]>();
            int L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                double[] p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count - 2]).Cross(p.Sub(p1)) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
                Debug.Assert(U + L == hull.Count + 1);
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull);
        }
        public static PointF[] ComputeConvexHull(List <PointF> points, bool sortInPlace = false)
        {
            if (!sortInPlace)
            {
                points = new List <PointF>(points);
            }
            points.Sort((a, b) =>
                        a.X == b.X ? a.Y.CompareTo(b.Y) : (a.X > b.X ? 1 : -1));

            DList <PointF> hull = new DList <PointF>();
            int            L = 0, U = 0; // size of lower and upper hulls

            // Builds a hull such that the output polygon starts at the leftmost point.
            for (int i = points.Count - 1; i >= 0; i--)
            {
                PointF p = points[i], p1;

                // build lower hull (at end of output list)
                while (L >= 2 && cross((p1 = hull.Last), hull[hull.Count - 2], points[i]) >= 0)
                {
                    hull.RemoveAt(hull.Count - 1);
                    L--;
                }
                hull.PushLast(p);
                L++;

                // build upper hull (at beginning of output list)
                while (U >= 2 && cross((p1 = hull.First), (hull[1]), points[i]) <= 0)
                {
                    hull.RemoveAt(0);
                    U--;
                }
                if (U != 0) // when U=0, share the point added above
                {
                    hull.PushFirst(p);
                }
                U++;
            }
            hull.RemoveAt(hull.Count - 1);
            return(hull.ToArray());
        }
Example #8
0
		void FireStructureChangedUnder(RowVM row)
		{
			if (row == null) { // roots changed
				// Reestablish dependencies from model to ViewModel
				_tree.Roots.DependentSentry.OnGet();
				StructureChanged(this, new TreePathEventArgs());
			} else {
				// Reestablish dependencies from model to ViewModel
				row.Children.DependentSentry.OnGet();
				TreePath path;
				if (row.Model.Parent == null)
					path = new TreePath(row);
				else {
					var list = new DList<RowVM>();
					for (; row != null; row = row.Parent)
						list.PushFirst(row);
					path = new TreePath(list.ToArray());
				}
				StructureChanged(this, new TreePathEventArgs(path));
			}
		}
Example #9
0
		public static IListSource<Point> ComputeConvexHull(List<Point> points, bool sortInPlace)
		{
			if (!sortInPlace)
				points = new List<Point>(points);
			points.Sort((a, b) => 
				a.X == b.X ? a.Y.CompareTo(b.Y) : a.X > b.X ? 1 : -1);

			// Importantly, DList provides O(1) insertion at beginning and end
			DList<Point> hull = new DList<Point>();
			int L = 0, U = 0; // size of lower and upper hulls

			// Builds a hull such that the output polygon starts at the leftmost point.
			for (int i = points.Count - 1; i >= 0 ; i--)
			{
				// right turn (clockwise) => negative cross product (for Y-up coords)
				Point p = points[i], p1;

				// build lower hull (at end of output list)
				while (L >= 2 && (p1 = hull.Last).Sub(hull[hull.Count-2]).Cross(p.Sub(p1)) >= 0) {
					hull.RemoveAt(hull.Count-1);
					L--;
				}
				hull.PushLast(p);
				L++;

				// build upper hull (at beginning of output list)
				while (U >= 2 && (p1 = hull.First).Sub(hull[1]).Cross(p.Sub(p1)) <= 0) {
					hull.RemoveAt(0);
					U--;
				}
				if (U != 0) // when U == 0, share the point added above
					hull.PushFirst(p);
				U++;
				Debug.Assert(U + L == hull.Count + 1);
			}
			hull.RemoveAt(hull.Count - 1);
			return hull;
		}