Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draw.aapolygon #3126

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions buildconfig/stubs/pygame/draw.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def polygon(
points: SequenceLike[Coordinate],
width: int = 0,
) -> Rect: ...
def aapolygon(
surface: Surface,
color: ColorLike,
points: SequenceLike[Coordinate],
filled: bool = True,
) -> Rect: ...
def circle(
surface: Surface,
color: ColorLike,
Expand Down
Binary file modified docs/reST/ref/code_examples/draw_module_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion docs/reST/ref/code_examples/draw_module_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,16 @@
# Draw an solid ellipse, using a rectangle as the outside boundaries
pygame.draw.ellipse(screen, "red", [300, 10, 50, 20])

# This draws a triangle using the polygon command
# Draw a triangle using the polygon command
pygame.draw.polygon(screen, "black", [[100, 100], [0, 200], [200, 200]], 5)

# Draw an antialiased polygon
pygame.draw.aapolygon(
screen,
"black",
[[100, 40], [150, 75], [110, 60], [70, 70]]
)

# Draw an arc as part of an ellipse.
# Use radians to determine what angle to draw.
pygame.draw.arc(screen, "black", [210, 75, 150, 125], 0, pi / 2, 2)
Expand Down
40 changes: 40 additions & 0 deletions docs/reST/ref/draw.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,46 @@ object around the draw calls (see :func:`pygame.Surface.lock` and

.. ## pygame.draw.polygon ##

.. function:: aapolygon

| :sl:`draw an antialiased polygon`
| :sg:`aapolygon(surface, color, points) -> Rect`
| :sg:`aapolygon(surface, color, points, filled=True) -> Rect`

Draws an antialiased polygon on the given surface.

:param Surface surface: surface to draw on
:param color: color to draw with, the alpha value is optional if using a
tuple ``(RGB[A])``
:type color: Color or string (for :doc:`color_list`) or int or tuple(int, int, int, [int])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it would be interesting to refer to ColorLike from pygame.typing, using a link to its paragraph in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to add this to all functions in docs at once, in one separate PR. Like just one find-and-replace.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it should be in a different PR when it concerns directly aapolygon ?

:param points: a sequence of 3 or more (x, y) coordinates that make up the
bilhox marked this conversation as resolved.
Show resolved Hide resolved
vertices of the polygon, each *coordinate* in the sequence must be a
tuple/list/:class:`pygame.math.Vector2` of 2 ints/floats,
e.g. ``[(x1, y1), (x2, y2), (x3, y3)]``
:type points: tuple(coordinate) or list(coordinate)
:param int filled: (optional) used to indicate that the polygon is to be filled

| if filled == True, (default) fill the polygon
| if filled == False, don't fill the polygon
|

:returns: a rect bounding the changed pixels, if nothing is drawn the
bounding rect's position will be the position of the first point in the
``points`` parameter (float values will be truncated) and its width and
height will be 0
:rtype: Rect

:raises ValueError: if ``len(points) < 3`` (must have at least 3 points)
damusss marked this conversation as resolved.
Show resolved Hide resolved
:raises TypeError: if ``points`` is not a sequence or ``points`` does not
contain number pairs

.. note::
For an aapolygon, use :func:`aalines()` with ``closed=True``.
mzivic7 marked this conversation as resolved.
Show resolved Hide resolved

.. versionadded:: 2.6.0

.. ## pygame.draw.aapolygon ##

.. function:: circle

| :sl:`draw a circle`
Expand Down
1 change: 1 addition & 0 deletions src_c/doc/draw_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DOC_DRAW "pygame module for drawing shapes"
#define DOC_DRAW_RECT "rect(surface, color, rect) -> Rect\nrect(surface, color, rect, width=0, border_radius=0, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1, border_bottom_right_radius=-1) -> Rect\ndraw a rectangle"
#define DOC_DRAW_POLYGON "polygon(surface, color, points) -> Rect\npolygon(surface, color, points, width=0) -> Rect\ndraw a polygon"
#define DOC_DRAW_AAPOLYGON "aapolygon(surface, color, points) -> Rect\naapolygon(surface, color, points, filled=True) -> Rect\ndraw an antialiased polygon"
#define DOC_DRAW_CIRCLE "circle(surface, color, center, radius) -> Rect\ncircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect\ndraw a circle"
#define DOC_DRAW_AACIRCLE "aacircle(surface, color, center, radius) -> Rect\naacircle(surface, color, center, radius, width=0, draw_top_right=None, draw_top_left=None, draw_bottom_left=None, draw_bottom_right=None) -> Rect\ndraw an antialiased circle"
#define DOC_DRAW_ELLIPSE "ellipse(surface, color, rect) -> Rect\nellipse(surface, color, rect, width=0) -> Rect\ndraw an ellipse"
Expand Down
Loading
Loading