-
Notifications
You must be signed in to change notification settings - Fork 13
Possible bug in fill_triangle() method #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This fix for issue adafruit#33 replaces the for loop at lines 283 to 291 with a while loop so that the y variable is properly incremented between the loops to fill the top and bottom parts of the triangle. This avoids screen row at y0 being drawn twice, and corrects the shape of the triangle. The changes to lines 278 to 282 (as numbered after the fix) initiate the two loops in a way that addresses issue adafruit#22 where a triangle with a flat bottom edge was not drawn correctly. This fix has been implemented in the derived repository [framebuf2](https://github.com/peter-l5/framebuf2) which applies the algorithm here and has been tested with the following code. (Note that `f=True` parameter draws a filled triangle in this implementation.) ``` for z in range(3,123+1,20): for x in range(10,120+1,20): for y in range(0,128): display.fill(0) display.triangle(x,y,30,z,90,63,c=1,f=True) display.show() ```
Hi, I submitted some code to fix this under #34, however this failed the automated workflow testing before getting to a stage where it could be reviewed. I'm afraid I don't know how to resolve this issue in order that the test would be passed. |
Hello @peter-l5 :), you could use pre-commit, it would reformat the files for the CI to pass. You could follow the instructions here If you have any further questions, we could discuss in the Adafruit discord server :). |
Thanks! @jposada202020, I will take a look and try that out, might be a few days before I can pick this up again - just to be aware. |
No worries :) take your time |
The fill_triangle method seems to be drawing triangles incorrectly around the middle vertex (in the vertical direction). This appears to be related to the method drawing a horizontal line with the same y co-ordinate twice at the level of the middle vertex. The behaviour happens because the final value of the loop variable y in the loop used to fill the top part of the triangle is repeated for the first line used to fill the bottom part of the triangle. The code from the two loops is below for reference.
The images below illustrate the issue around the middle vertex.
I have developed and tested a fix for this employed in the repository framebuf2 and will post it here as a pull request separately in the next day or two. While I realise that this library is due to be deprecated soon, I figure it may still be worthwhile to fix it.
The text was updated successfully, but these errors were encountered: