Adding the 45deg angle was a small addition to Part 1.
public void MarkLine(Point A, Point B)
{
if (A.X == B.X)
{
if (A.Y > B.Y)
{
for (int i = A.Y; i >= B.Y; i--)
{
_matrix[A.X, i]++;
if (_matrix[A.X, i] == 2) { IntersectionCount++; }
}
}
else
{
for (int i = A.Y; i <= B.Y; i++)
{
_matrix[A.X, i]++;
if (_matrix[A.X, i] == 2) { IntersectionCount++; }
}
}
}
else if (A.Y == B.Y)
{
if (A.X > B.X)
{
for (int i = A.X; i >= B.X; i--)
{
_matrix[i, A.Y]++;
if (_matrix[i, A.Y] == 2) { IntersectionCount++; }
}
}
else
{
for (int i = A.X; i <= B.X; i++)
{
_matrix[i, A.Y]++;
if (_matrix[i, A.Y] == 2) { IntersectionCount++; }
}
}
}
if (_HorizontalVerticalOnly) { return; }
//Assume 45deg angle
if (A.X != B.X
&& A.Y != B.Y)
{
int unit = Math.Abs(A.X - B.X);
int xd = A.X;
int yd = A.Y;
for (int i = 0; i <= unit; i++)
{
_matrix[xd, yd]++;
if (_matrix[xd, yd] == 2) { IntersectionCount++; }
xd += A.X > B.X ? -1 : 1;
yd += A.Y > B.Y ? -1 : 1;
}
}
}