Skip to content

Commit

Permalink
Merge pull request #7132 from radarhere/regular_polygon_width
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed May 3, 2023
2 parents 74a8519 + 3fc446c commit 9636a2a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Binary file added Tests/images/imagedraw_triangle_width.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 10 additions & 10 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,20 +1347,20 @@ def test_same_color_outline():


@pytest.mark.parametrize(
"n_sides, rotation, polygon_name",
[(4, 0, "square"), (8, 0, "regular_octagon"), (4, 45, "square")],
"n_sides, polygon_name, args",
[
(4, "square", {}),
(8, "regular_octagon", {}),
(4, "square_rotate_45", {"rotation": 45}),
(3, "triangle_width", {"width": 5, "outline": "yellow"}),
],
)
def test_draw_regular_polygon(n_sides, rotation, polygon_name):
def test_draw_regular_polygon(n_sides, polygon_name, args):
im = Image.new("RGBA", size=(W, H), color=(255, 0, 0, 0))
filename_base = f"Tests/images/imagedraw_{polygon_name}"
filename = (
f"{filename_base}.png"
if rotation == 0
else f"{filename_base}_rotate_{rotation}.png"
)
filename = f"Tests/images/imagedraw_{polygon_name}.png"
draw = ImageDraw.Draw(im)
bounding_circle = ((W // 2, H // 2), 25)
draw.regular_polygon(bounding_circle, n_sides, rotation=rotation, fill="red")
draw.regular_polygon(bounding_circle, n_sides, fill="red", **args)
assert_image_equal_tofile(im, filename)


Expand Down
3 changes: 2 additions & 1 deletion docs/reference/ImageDraw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Methods
:param width: The line width, in pixels.


.. py:method:: ImageDraw.regular_polygon(bounding_circle, n_sides, rotation=0, fill=None, outline=None)
.. py:method:: ImageDraw.regular_polygon(bounding_circle, n_sides, rotation=0, fill=None, outline=None, width=1)
Draws a regular polygon inscribed in ``bounding_circle``,
with ``n_sides``, and rotation of ``rotation`` degrees.
Expand All @@ -311,6 +311,7 @@ Methods
(e.g. ``rotation=90``, applies a 90 degree rotation).
:param fill: Color to use for the fill.
:param outline: Color to use for the outline.
:param width: The line width, in pixels.


.. py:method:: ImageDraw.rectangle(xy, fill=None, outline=None, width=1)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ def polygon(self, xy, fill=None, outline=None, width=1):
self.im.paste(im.im, (0, 0) + im.size, mask.im)

def regular_polygon(
self, bounding_circle, n_sides, rotation=0, fill=None, outline=None
self, bounding_circle, n_sides, rotation=0, fill=None, outline=None, width=1
):
"""Draw a regular polygon."""
xy = _compute_regular_polygon_vertices(bounding_circle, n_sides, rotation)
self.polygon(xy, fill, outline)
self.polygon(xy, fill, outline, width)

def rectangle(self, xy, fill=None, outline=None, width=1):
"""Draw a rectangle."""
Expand Down

0 comments on commit 9636a2a

Please sign in to comment.