public List<Vector2> GetWorldIndexPointsAlongLine(Vector2 point1, Vector2 point2)
{
// this is using Bresenham's Line Algorithm (http://en.wikipedia.org/wiki/Bresenham's_line_algorithm)
List<Vector2> points = new List<Vector2>();
int x0 = (int)point1.X;
int x1 = (int)point2.X;
int y0 = (int)point1.Y;
int y1 = (int)point2.Y;
bool steep = Math.Abs(y1 - y0) > Math.Abs(x1 - x0);
if (steep)
{
int temp = y0;
y0 = x0;
x0 = temp;
temp = y1;
y1 = x1;
x1 = temp;
}
if (x0 > x1)
{
int temp = x1;
x1 = x0;
x0 = temp;
temp = y1;
y1 = y0;
y0 = temp;
}
int deltax = x1 - x0;
int deltay = Math.Abs(y1 - y0);
int error = deltax / 2;
int ystep;
int y = y0;
if (y0 < y1)
ystep = 1;
else
ystep = -1;
for (int x = x0; x <= x1; x++)
{
if (steep)
points.Add(new Vector2(y, x));
else
points.Add(new Vector2(x, y));
error = error - deltay;
if (error < 0)
{
y = y + ystep;
error = error + deltax;
}
}
return points;
}