Skip to content

Commit 2108cbd

Browse files
authored
Merge pull request #62 from Ashtreighlia/main
Added value checks for "rect" and "roundrect"
2 parents 12beb94 + 75c1978 commit 2108cbd

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

adafruit_display_shapes/rect.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def __init__(
5959
outline: Optional[int] = None,
6060
stroke: int = 1,
6161
) -> None:
62+
if width <= 0 or height <= 0:
63+
raise ValueError("Rectangle dimensions must be larger than 0.")
64+
6265
self._bitmap = displayio.Bitmap(width, height, 2)
6366
self._palette = displayio.Palette(2)
6467

adafruit_display_shapes/roundrect.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def __init__(
5252
outline: Optional[int] = None,
5353
stroke: int = 1,
5454
) -> None:
55+
if width <= 0 or height <= 0:
56+
raise ValueError("Rectangle dimensions must be larger than 0.")
57+
if r > width / 2 or r > height / 2:
58+
raise ValueError(
59+
"Radius cannot exceed half of the smaller side (width or height)."
60+
)
61+
5562
self._palette = displayio.Palette(3)
5663
self._palette.make_transparent(0)
5764
self._bitmap = displayio.Bitmap(width, height, 3)

0 commit comments

Comments
 (0)