Skip to content

Commit 3a34f44

Browse files
authored
Merge pull request #1 from radarhere/imagedraw_circle
Added test
2 parents 8db5fbe + cac1a04 commit 3a34f44

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

Tests/test_imagedraw.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import contextlib
44
import os.path
5+
from typing import Sequence
56

67
import pytest
78

@@ -265,6 +266,21 @@ def test_chord_too_fat() -> None:
265266
assert_image_equal_tofile(im, "Tests/images/imagedraw_chord_too_fat.png")
266267

267268

269+
@pytest.mark.parametrize("mode", ("RGB", "L"))
270+
@pytest.mark.parametrize("xy", ((W / 2, H / 2), [W / 2, H / 2]))
271+
def test_circle(mode: str, xy: Sequence[float]) -> None:
272+
# Arrange
273+
im = Image.new(mode, (W, H))
274+
draw = ImageDraw.Draw(im)
275+
expected = f"Tests/images/imagedraw_ellipse_{mode}.png"
276+
277+
# Act
278+
draw.circle(xy, 25, fill="green", outline="blue")
279+
280+
# Assert
281+
assert_image_similar_tofile(im, expected, 1)
282+
283+
268284
@pytest.mark.parametrize("mode", ("RGB", "L"))
269285
@pytest.mark.parametrize("bbox", BBOX)
270286
def test_ellipse(mode: str, bbox: Coords) -> None:

docs/reference/ImageDraw.rst

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ Methods
227227

228228
.. versionadded:: 5.3.0
229229

230+
.. py:method:: ImageDraw.circle(xy, radius, fill=None, outline=None, width=1)
231+
232+
Draws a circle with a given radius centering on a point.
233+
234+
.. versionadded:: 10.4.0
235+
236+
:param xy: The point for the center of the circle, e.g. ``(x, y)``.
237+
:param radius: Radius of the circle.
238+
:param outline: Color to use for the outline.
239+
:param fill: Color to use for the fill.
240+
:param width: The line width, in pixels.
241+
230242
.. py:method:: ImageDraw.ellipse(xy, fill=None, outline=None, width=1)
231243
232244
Draws an ellipse inside the given bounding box.
@@ -240,19 +252,6 @@ Methods
240252

241253
.. versionadded:: 5.3.0
242254

243-
.. py:method:: ImageDraw.circle(xy, radius, fill=None, outline=None, width=1)
244-
245-
Draws a circle given the center coordinates and a radius.
246-
247-
.. versionadded:: 10.4.0
248-
249-
:param xy: One point to define the circle center. Sequence:
250-
``[x, y]``
251-
:param radius: Radius of the circle
252-
:param outline: Color to use for the outline.
253-
:param fill: Color to use for the fill.
254-
:param width: The line width, in pixels.
255-
256255
.. py:method:: ImageDraw.line(xy, fill=None, width=0, joint=None)
257256
258257
Draws a line between the coordinates in the ``xy`` list.

docs/releasenotes/10.4.0.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ TODO
4545
API Additions
4646
=============
4747

48-
Added PIL.ImageDraw.circle()
49-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
50-
Given the circle center coordinate pair and a radius, plots a circle using PIL.ImageDraw.ellipse()
48+
ImageDraw.circle
49+
^^^^^^^^^^^^^^^^
50+
51+
Added :py:meth:`~PIL.ImageDraw.ImageDraw.circle`. It provides the same functionality as
52+
:py:meth:`~PIL.ImageDraw.ImageDraw.ellipse`, but instead of taking a bounding box, it
53+
takes a center point and radius.
5154

5255
TODO
5356
^^^^

0 commit comments

Comments
 (0)