Exemplo n.º 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 showPointsForLine(Point begin, Point end)
        {
            IEnumerable <Point> myLine = BresenhamLine.RenderLine(begin, end);

            Log.Debug("<<START>>: " + begin.ToString() + " *\t");
            showPoints(myLine);
            Log.Debug("\t* <<FINISH>>: " + end.ToString() + " *" + Environment.NewLine);
        }
Exemplo n.º 2
0
        public static List <Point> GetBresenhamLine(Point startPoint, Point endPoint)
        {
            IEnumerable <Point> originalLine;                        // Represent an enumerable line
            List <Point>        translatedLine = new List <Point>(); // Represent an enumerable line

            int origX1 = startPoint.X;
            int origY1 = startPoint.Y;

            int origX2 = endPoint.X;
            int origY2 = endPoint.Y;

            // calculate how far the original point is away from the origin
            int originXDisplacement;
            int originYDisplacement;

            if (origX1 >= 0)
            {
                originXDisplacement = -origX1;
            }
            else
            {
                originXDisplacement = origX1;
            }

            if (origY1 >= 0)
            {
                originYDisplacement = -origY1;
            }
            else
            {
                originYDisplacement = origY1;
            }

            // use 0,0 as first point and then translate second point over
            int transX2 = origX2 + originXDisplacement;
            int transY2 = origY2 + originYDisplacement;

            // the bresenham algorithm seems to only work in cartesian quadrant I, so we
            // need to flip the negative axes over to do perform the point calculations
            // they will be flipped back afterwards
            const int NO_AXIS_FLIP = 1;
            const int AXIS_FLIP    = -1;

            int flipXAxis;
            int flipYAxis;

            if (transX2 < 0)
            {
                transX2   = transX2 * AXIS_FLIP;
                flipXAxis = AXIS_FLIP;
            }
            else
            {
                flipXAxis = NO_AXIS_FLIP;
            }

            if (transY2 < 0)
            {
                transY2   = transY2 * AXIS_FLIP;
                flipYAxis = AXIS_FLIP;
            }
            else
            {
                flipYAxis = NO_AXIS_FLIP;
            }

            originalLine = BresenhamLine.RenderLine(new Point(0, 0), new Point(transX2, transY2));

            int   newX;
            int   newY;
            Point newPoint;

            foreach (Point myPoint in originalLine)
            {
                newX = (myPoint.X * flipXAxis) - originXDisplacement;
                newY = (myPoint.Y * flipYAxis) - originYDisplacement;

                newPoint = new Point(newX, newY);
                translatedLine.Add(newPoint);
            }

            Point translatedPoint;

            for (int x = 0; x < translatedLine.Count; x++)
            {
                translatedPoint = translatedLine[x];
            }

            return(translatedLine);
        }