//Bresenham lines public static void SetBHLine(Texture2D texture, Point startPoint, Point endPoint, Color color) { IntDeltaValues deltaValues = new IntDeltaValues(startPoint, endPoint); if (deltaValues.AbsDeltaX > deltaValues.AbsDeltaY) { SetBHLineIncrementingX(texture, startPoint, endPoint, deltaValues, color); } else if (deltaValues.AbsDeltaY > 0) { SetBHLineIncrementingY(texture, startPoint, endPoint, deltaValues, color); } else { SetPixel(texture, (int)startPoint.X, (int)startPoint.Y, color); } }
private static void SwapForYDrawingAsNeeded(ref Point startPoint, ref Point endPoint, ref IntDeltaValues deltaValues) { if (startPoint.Y > endPoint.Y) { SwapStartAndEnd(ref startPoint, ref endPoint); deltaValues = new IntDeltaValues(startPoint, endPoint); } }
private static void SetBHLineIncrementingY(Texture2D texture, Point startPoint, Point endPoint, IntDeltaValues deltaValues, Color color) { SwapForYDrawingAsNeeded(ref startPoint, ref endPoint, ref deltaValues); int slope = 0; int incE = 0; int incNE = 0; int d = 0; SetBHStartValues(deltaValues.AbsDeltaY, deltaValues.DeltaX, deltaValues.AbsDeltaX, ref slope, ref incE, ref incNE, ref d); for (Point currentPos = startPoint; currentPos.Y <= endPoint.Y; currentPos.Y++) { SetPixel(texture, (int)currentPos.X, (int)currentPos.Y, color); if (d <= 0) { d += incE; } else { d += incNE; currentPos.X += slope; } } }