Closed owendelong closed 11 years ago
I've narrowed this down a little bit more.
The problem seems to occur when (after sorting the coordinate pairs such that y0<=y1<=y2, you are left with a case where x0<x2<x1.
It does not seem to matter whether or not any of the x values are equal or whether or not any of the y values are equal.
I'm continuing to work on figuring out a fix.
Resolved...
Here's the deal... Sometimes the algorithm passes to drawHorizontalLine a value where x1>x2. This results in a line width being passed to drawHorizontalLine which is a negative signed long int. drawHorizontalLine expects an unsigned 16 bit integer.
Solution: reorder the arguments to drawHorizontalLine and reverse the computation for the width of the line when necessary.
Essentially replace occurrences of:
drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
With:
if (sx2 < sx1)
{
drawHorizontalLine(sx2/1000, sy, (sx1-sx2)/1000, color);
}
else
{
drawHorizontalLine(sx1/1000, sy, (sx2-sx1)/1000, color);
}
Hopefully when you guys merge this into the library, you can also merge in my improvements to drawChar.
There are still occasionally odd results with some triangles. It's working well enough in my application that I probably won't have time to track it down, but at least the above code changes result in consistent results and no screen-filling errors.
Resolved in one of the interim commits since this was originally posted.
This code demonstrates the problem:
You can also refer to my more complete description of the problem in the adafruit forums where it seems the solution offered by adafruit to any request is merely to ask the poster to go do something else.
http://forums.adafruit.com/viewtopic.php?f=47&t=26204