Skip to content
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

Added value checks for "rect" and "roundrect" #62

Merged
merged 4 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
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
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