Skip to content

feat: add draw.rounded_rectangle primitive#176

Merged
wkentaro merged 2 commits into
mainfrom
feat/draw-rounded-rectangle
Jun 10, 2026
Merged

feat: add draw.rounded_rectangle primitive#176
wkentaro merged 2 commits into
mainfrom
feat/draw-rounded-rectangle

Conversation

@wkentaro

Copy link
Copy Markdown
Owner

Summary

  • Add imgviz.draw.rounded_rectangle(image, yx1, yx2, radius, fill=None, outline=None, width=0) and its in-place pair rounded_rectangle_, for arc-cornered rectangles.
  • Thin wrapper over PIL's native ImageDraw.rounded_rectangle, mirroring the existing draw.rectangle / rectangle_ pair exactly: same yx1/yx2 (min/max vertex) convention with the yxxy swap, same Ink / get_pil_ink / require_fill_or_outline handling, same width=0 default (kept for sibling consistency rather than diverging a single primitive).
  • PIL's per-corner corners kwarg is intentionally not exposed — the issue spec is (yx1, yx2, radius) and no caller needs selective rounding yet; it can be added when one does.

Test plan

  • tests added: tests/unit/draw/_rounded_rectangle_test.py (rendered outline, the fill/outline guard, corner-clipping pixel check, in-place mutation)
  • uv run pytest tests/unit/draw/ — 33 passed
  • uv run ruff check / uv run ruff format --check / uv run ty check clean on touched files

Closes #154

@wkentaro wkentaro self-assigned this Jun 10, 2026
@wkentaro wkentaro force-pushed the feat/draw-rounded-rectangle branch from d5d368c to fae803e Compare June 10, 2026 14:56
@wkentaro wkentaro marked this pull request as ready for review June 10, 2026 15:04
@wkentaro

Copy link
Copy Markdown
Owner Author

Added examples/rounded_rectangle.py (and refreshed the README table) so the rendering is reviewable. It draws three boxes with radius=0 (sharp), radius=40 (rounded), and radius=100 (pill) on lena:

rounded_rectangle

Regenerate with uv run python examples/rounded_rectangle.py --save.

@wkentaro wkentaro added this to the v2.2.0 milestone Jun 10, 2026
@wkentaro wkentaro merged commit 93b5996 into main Jun 10, 2026
7 checks passed
@wkentaro wkentaro deleted the feat/draw-rounded-rectangle branch June 10, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

draw.rounded_rectangle primitive

1 participant