This one's got me really confused, but hopefully y'all will see something I can't for lack of experience and expertise. The following segment of code is part of a larger function that performs a Hough Transform on a series of coordinates to find lines described by the points. I'm looking for a line of a particular length, so this snippet is meant to find all of the coordinates that fall on the line and remove them from the list of coordinates, keeping track of the two endpoints. In the future I will probably be worrying about adjacency, but it's not an issue right now. The problem that I am running into is with the one printf statement that is in the code. If I take it out, the execution will never enter the if statement, even though I can confirm that it satisfies the condition. It doesn't matter what the text I'm printing is, it just has to be there and be at least one character long.
hits is a linked list that holds the coordinates being processed. Each element of the list has an x term and a y term, each with its own function to return it as a double. bestTheta and bestP are values describing the line found earlier in the function, which is at angle bestTheta in degrees from the positive x-axis and shortest distance bestP from the origin. Both variables are doubles. iterations simply keeps track of where in the linked list we are. (x_min, y_min) and (x_max, y_max) are the coordinates of the endpoints of the line. The odd lines that use the integer casting are used to round the values of the coordinates to the resolution of the Hough map. I think that's all you need to know, but let me know if more information would be helpful.
// Handle the case for a vertical line
if (bestTheta == 0)
{
// Find all points on the line
iterations = hits.count();
index = 0;
x_min = bestP;
x_max = bestP;
for (int hitIndex = 0; hitIndex<iterations; hitIndex++)
{
hit[0] = hits.getx(index);
hit[1] = hits.gety(index);
x = (static_cast<int> (hit[0]/distRes)) * distRes;
y = (static_cast<int> (hit[1]/distRes)) * distRes;
printf(" ");
if (x == bestP)
{
if (y > y_max)
{
y_max = y;
}
if (y < y_min)
{
y_min = y;
}
hits.del(hit[0], hit[1]);
}
else
{
index++;
}
}
}
So again, when that printf(" ");
statement is there, everything works as expected. But if it is taken out, nothing ever gets removed from the linked list. Anyone have a clue?