Exemple #1
0
        /// <summary>
        /// This function puts a BEGIN and END tag around a list of points from a line
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        private static void printPointsForLine(Point begin, Point end)
        {
            IEnumerable <Point> myLine = BresLine.RenderLine(begin, end);

            Console.Write("* BEGIN: " + begin.ToString() + " *\t");
            printPoints(myLine);
            Console.Write("\t* END: " + end.ToString() + " *" + Environment.NewLine);
        }
Exemple #2
0
        /// <summary>
        /// This function iterates over the points in some gigantic lines
        /// that you wouldn't want to be storing in memory.
        /// </summary>
        public static void LineExamples()
        {
            // print out details for Bresenham lines in 8 directions and a single point 'line'
            testLineCases();

            IEnumerable <Point> longLine; // Represent an enumerable line

            // This is an example of why I am using the iterative approach
            // We'll draw a line from 0,0 to 5000000,900000--
            longLine = BresLine.RenderLine(new Point(0, 0), new Point(5000000, 900000));
            // Now iterate over the line and perform some operation
            foreach (Point myPoint in longLine)
            {
                double dummyVar = myPoint.X * Math.Sin(myPoint.X / 90);
                // Eventually our X will exceed the boundary value of 12345 in some direction
                if (Math.Abs(dummyVar) > 12345)
                {
                    break;
                }
            }

            // Now output some strings
            StringBuilder sb          = new StringBuilder();
            string        totalString = longLine.Aggregate(sb, (acc, x) => sb.Append(x.ToString())).ToString();

            // totalString is something like 98 million characters long at this point

            if (totalString.Length < 1000)
            {
                // We could print the 98 million character string...
                // but you could expect an OutOfMemoryException
                Console.WriteLine(totalString);
            }

            // Accumulate the SIN of all y values for no reason in particular
            Console.WriteLine("SIN(Y) aggregate: " + longLine.Aggregate(0d, (acc, pointN) => acc += Math.Sin(pointN.Y)));
        }