Skip to content

fix fill_triangle bug issue #33 #34

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
May 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions adafruit_gfx/gfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_GFX.git"


# pylint: disable=invalid-name
class GFX:
# pylint: disable=too-many-instance-attributes
Expand All @@ -49,6 +50,7 @@ class GFX:
:param font: An optional input to augment the default text method with a new font.
The input should be a properly formatted dict.
"""

# pylint: disable=too-many-arguments
def __init__(
self,
Expand Down Expand Up @@ -247,7 +249,6 @@ def fill_triangle(self, x0, y0, x1, y1, x2, y2, *args, **kwargs):
x0, x1 = x1, x0
a = 0
b = 0
y = 0
last = 0
if y0 == y2:
a = x0
Expand Down Expand Up @@ -276,18 +277,20 @@ def fill_triangle(self, x0, y0, x1, y1, x2, y2, *args, **kwargs):
dy12 = 1
sa = 0
sb = 0
if y1 == y2 or y0 == y1: # pylint: disable=consider-using-in
last = y1
else:
y = y0
if y0 == y1:
last = y1 - 1
for y in range(y0, last + 1):
else:
last = y1
while y <= last:
a = x0 + sa // dy01
b = x0 + sb // dy02
sa += dx01
sb += dx02
if a > b:
a, b = b, a
self.hline(a, y, b - a + 1, *args, **kwargs)
y += 1
sa = dx12 * (y - y1)
sb = dx02 * (y - y0)
while y <= y2:
Expand All @@ -303,7 +306,8 @@ def fill_triangle(self, x0, y0, x1, y1, x2, y2, *args, **kwargs):
def round_rect(self, x0, y0, width, height, radius, *args, **kwargs):
"""Rectangle with rounded corners drawing function.
This works like a regular rect though! if radius = 0
Will draw the outline of a rectangle with rounded corners with (x0,y0) at the top left"""
Will draw the outline of a rectangle with rounded corners with (x0,y0) at the top left
"""
# shift to correct for start point location
x0 += radius
y0 += radius
Expand Down