Skip to content

feat: add draw.arrow primitive#193

Draft
wkentaro wants to merge 2 commits into
mainfrom
feat/draw-arrow
Draft

feat: add draw.arrow primitive#193
wkentaro wants to merge 2 commits into
mainfrom
feat/draw-arrow

Conversation

@wkentaro

Copy link
Copy Markdown
Owner

Summary

  • Add imgviz.draw.arrow(image, yx1, yx2, fill, width=1, head_length_ratio=0.1, head_angle=30.0) and its in-place pair arrow_, drawing a shaft from yx1 (tail) to yx2 (tip) with an arrowhead at the tip.
  • The arrowhead is an open V of two barbs computed by rotating the shaft unit vector by ±head_angle, so the geometry stays correct for any direction (the "not trivially composable" justification per ADR 0002).
  • head_length_ratio sizes the head as a fraction of the shaft length (cv2 arrowedLine's tipLength convention), so it stays sensible at any image scale; head_angle is the head half-angle in degrees.
  • Single fill stroke color like draw.line; yx1/yx2 accept tuples/lists/arrays (ArrayLike) and are shape-validated, matching draw.line.

Test plan

  • tests added: tests/unit/draw/_arrow_test.py — happy path, head-adds-over-plain-line, head-at-tip for horizontal and diagonal arrows, head_length_ratio scaling, zero-length skips head, in-place mutation, non-PIL and bad-shape guards
  • uv run pytest tests/unit/draw/ — 47 passed
  • uv run ruff check / uv run ruff format --check / uv run ty check clean on touched files

Closes #152

@wkentaro wkentaro self-assigned this Jun 10, 2026
@wkentaro wkentaro added the needs-author-action PR is awaiting action from the contributor: code changes or more info label Jun 11, 2026
@wkentaro

Copy link
Copy Markdown
Owner Author

lint is failing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-author-action PR is awaiting action from the contributor: code changes or more info

Projects

None yet

Development

Successfully merging this pull request may close these issues.

draw.arrow primitive

1 participant