Skip to content

Commit 905633e

Browse files
committed
Added one more check for roundrect
1 parent 5b0c84a commit 905633e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

adafruit_display_shapes/rect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ def __init__(
5959
outline: Optional[int] = None,
6060
stroke: int = 1,
6161
) -> None:
62-
self._bitmap = displayio.Bitmap(width, height, 2)
63-
self._palette = displayio.Palette(2)
64-
6562
if width <= 0 or height <= 0:
6663
raise ValueError("Width and height must be greater than 0")
6764

65+
self._bitmap = displayio.Bitmap(width, height, 2)
66+
self._palette = displayio.Palette(2)
67+
6868
if outline is not None:
6969
self._palette[1] = outline
7070
for w in range(width):

adafruit_display_shapes/roundrect.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def __init__(
5252
outline: Optional[int] = None,
5353
stroke: int = 1,
5454
) -> None:
55+
if r > width / 2 or r > height / 2:
56+
raise ValueError("Radius too large for given dimensions")
57+
if width <= 0 or height <= 0:
58+
raise ValueError("Width and height must be greater than 0")
59+
5560
self._palette = displayio.Palette(3)
5661
self._palette.make_transparent(0)
5762
self._bitmap = displayio.Bitmap(width, height, 3)
@@ -68,9 +73,6 @@ def __init__(
6873
y_offset=height - 2 * r - 1,
6974
)
7075

71-
if width <= 0 or height <= 0:
72-
raise ValueError("Width and height must be greater than 0")
73-
7476
if fill is not None:
7577
self._palette[2] = fill
7678
self._palette.make_opaque(2)

0 commit comments

Comments
 (0)