public void DrawLine(int x1, int y1, int x2, int y2)
{
x1 = scope.X + x1;
y1 = scope.Y + y1;
x2 = scope.X + x2;
y2 = scope.Y + y2;
if (x1 == x2)
{
int yMin = y1 >= y2 ? y2 : y1;
int yMax = y1 >= y2 ? y1 : y2;
for (int y = yMin; y < yMax; y++)
{
if (IsInScope(x1, y))
{
pixels[x1][y].Value = Pen;
}
}
}
else if (y1 == y2)
{
int xMin = x1 >= x2 ? x2 : x1;
int xMax = x1 >= x2 ? x1 : x2;
for (int x = xMin; x < xMax; x++)
{
if (IsInScope(x, y1))
{
pixels[x][y1].Value = Pen;
}
}
return;
}
else
{
double slope = ((double)y2 - y1) / ((double)x2 - x1);
int dx = Math.Abs(x1 - x2);
int dy = Math.Abs(y1 - y2);
if (dy > dx)
{
for (double x = x1; x < x2; x += DrawPrecision)
{
double y = slope + (x - x1) + y1;
int xInt = (int)x;
int yInt = (int)y;
if (IsInScope(xInt, yInt))
{
pixels[xInt][yInt].Value = Pen;
}
}
for (double x = x2; x < x1; x += DrawPrecision)
{
double y = slope + (x - x1) + y1;
int xInt = (int)x;
int yInt = (int)y;
if (IsInScope(xInt, yInt))
{
pixels[xInt][yInt].Value = Pen;
}
}
}
else
{
for (double y = y1; y < y2; y += DrawPrecision)
{
double x = ((y - y1) / slope) + x1;
int xInt = (int)x;
int yInt = (int)y;
if (IsInScope(xInt, yInt))
{
pixels[xInt][yInt].Value = Pen;
}
}
for (double y = y2; y < y1; y += DrawPrecision)
{
double x = ((y - y1) / slope) + x1;
int xInt = (int)x;
int yInt = (int)y;
if (IsInScope(xInt, yInt))
{
pixels[xInt][yInt].Value = Pen;
}
}
}
}
}