Skip to content

feat: add draw.rotated_rectangle primitive#184

Merged
wkentaro merged 4 commits into
mainfrom
feat/draw-rotated-rectangle
Jun 11, 2026
Merged

feat: add draw.rotated_rectangle primitive#184
wkentaro merged 4 commits into
mainfrom
feat/draw-rotated-rectangle

Conversation

@wkentaro

@wkentaro wkentaro commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add imgviz.draw.rotated_rectangle(image, center, size, angle, fill=None, outline=None, width=1) and its in-place pair rotated_rectangle_, for oriented bounding boxes.
  • center is (cy, cx), size is (height, width) before rotation, angle is in degrees (positive rotates clockwise, since the image y-axis points down).
  • Computes the four rotated corners with a rotation matrix and delegates drawing to the existing draw.polygon_, so fill/outline/width semantics and validation live in one place. Calls require_fill_or_outline at its own entry, matching the other _ primitives.
  • width defaults to 1 (not 0 like rectangle/rounded_rectangle): it wraps polygon_, where PIL treats width=0 as a no-op outline, so 1 is the meaningful default here.

Test plan

  • tests added: tests/unit/draw/_rotated_rectangle_test.py — axis-aligned at angle=0, extent-swap at angle=90, clockwise rotation-direction check, area preservation under rotation, outline-only path, fill+outline together, the fill/outline guard, and in-place mutation
  • uv run pytest tests/unit/draw/
  • uv run ruff check / uv run ruff format --check / uv run ty check clean on touched files

Closes #153

@wkentaro wkentaro self-assigned this Jun 10, 2026
@wkentaro wkentaro force-pushed the feat/draw-rotated-rectangle branch from 859acd7 to f9c2853 Compare June 10, 2026 15:04
@wkentaro wkentaro marked this pull request as ready for review June 10, 2026 15:04
@wkentaro wkentaro added this to the v2.2.0 milestone Jun 10, 2026
@wkentaro wkentaro force-pushed the feat/draw-rotated-rectangle branch from f9c2853 to 3828c8d Compare June 11, 2026 11:35
wkentaro added 2 commits June 11, 2026 21:33
Match the rectangle and rounded_rectangle signatures, which already accept
tuple[float, float] | NDArray[np.floating].
@wkentaro wkentaro added the ready-for-merger PR is accepted by maintainer label Jun 11, 2026
@wkentaro wkentaro merged commit fbc1293 into main Jun 11, 2026
7 checks passed
@wkentaro wkentaro deleted the feat/draw-rotated-rectangle branch June 11, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merger PR is accepted by maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

draw.rotated_rectangle primitive

1 participant