Skip to content

Commit

Permalink
Merge pull request #62 from Ashtreighlia/main
Browse files Browse the repository at this point in the history
Added value checks for "rect" and "roundrect"
  • Loading branch information
FoamyGuy committed Aug 23, 2023
2 parents 12beb94 + 75c1978 commit 2108cbd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions adafruit_display_shapes/rect.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def __init__(
outline: Optional[int] = None,
stroke: int = 1,
) -> None:
if width <= 0 or height <= 0:
raise ValueError("Rectangle dimensions must be larger than 0.")

self._bitmap = displayio.Bitmap(width, height, 2)
self._palette = displayio.Palette(2)

Expand Down
7 changes: 7 additions & 0 deletions adafruit_display_shapes/roundrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def __init__(
outline: Optional[int] = None,
stroke: int = 1,
) -> None:
if width <= 0 or height <= 0:
raise ValueError("Rectangle dimensions must be larger than 0.")
if r > width / 2 or r > height / 2:
raise ValueError(
"Radius cannot exceed half of the smaller side (width or height)."
)

self._palette = displayio.Palette(3)
self._palette.make_transparent(0)
self._bitmap = displayio.Bitmap(width, height, 3)
Expand Down

0 comments on commit 2108cbd

Please sign in to comment.