Skip to content

Fixed bug in fill_triangle for flat topped triangles #22

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

Merged
merged 2 commits into from
Jul 26, 2021

Conversation

lucashadfield
Copy link
Contributor

Fix for this bug: #2

If y0 was equal to y1, the loop on line 283 was being skipped meaning y was 0 when getting to the loop on line 293, resulting in a much bigger triangle being drawn starting from y = 0.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt tannewt merged commit 52838f3 into adafruit:main Jul 26, 2021
peter-l5 added a commit to peter-l5/Adafruit_CircuitPython_GFX-fix-for-33 that referenced this pull request May 5, 2023
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()
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants