Versions of the Bresenham line plot code written in C#. It includes one variation that plots in order from start to finish.
The original code was intended to plot lines on early printers. It has other uses.
Wikipedia does a good job of explaining the
Bresenham line algorithm
The language is C# but I have used the XNA version of the 'Point' structure. It would be trivial to use a different point structure in the code.
It includes methods to validate the results.
The one thing that I think is important from a game coding perspective is that the results do NOT include every grid square that a line could pass through. It was originally intended to produce a result that looked like a line. It is no use in a game if you
want accurate collision detection along that line!
I implemented this for use to calculate view occlusion for my XNA game,
Diabolical: The Shooter