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 bezier from gfxdraw module to draw module #3009

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

bilhox
Copy link
Contributor

@bilhox bilhox commented Jul 21, 2024

Hello, as part of #3005 plan, this PR moves pygame.gfxdraw.bezier to pygame.draw.bezier.

@bilhox bilhox requested a review from a team as a code owner July 21, 2024 10:58
@mzivic7 mzivic7 mentioned this pull request Jul 21, 2024
19 tasks
@damusss
Copy link
Contributor

damusss commented Jul 21, 2024

This note is outdated.

docs/reST/ref/gfxdraw.rst Outdated Show resolved Hide resolved
@damusss damusss added New API This pull request may need extra debate as it adds a new class or function to pygame draw pygame.draw labels Jul 22, 2024
@bilhox bilhox changed the title Port bezier from gfxdraw to draw + bring the same support like every draw function Add bezier from gfxdraw module to draw module Aug 21, 2024
Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

OK, LGTM. Bezier works as expected under the draw module instead of gfxdraw in my testing. the tests all pass locally as well.

Test program:

import pygame

pygame.init()

sf = pygame.display.set_mode((640, 480))

font = pygame.font.Font(size=36)

points = []

STEPS = 3

print("Click on the screen to put points.")

while 1:
    for event in pygame.event.get():
        if event.type == pygame.MOUSEBUTTONDOWN:
            points.append(event.pos)
    sf.fill((0, 0, 0))

    for p in points:
        pygame.draw.circle(sf, (255, 0, 0), p, 5)

    if len(points) > 2:
        pygame.draw.lines(sf, (255, 0, 0), False, points)
        pygame.draw.bezier(sf, points, STEPS, (255, 255, 255))

    test = f"Points: {len(points)}\nSteps: {STEPS}"
    text_sf = font.render(test, True, (255, 255, 255))
    sf.blit(text_sf, (10, 400))

    pygame.display.update()

@bilhox
Copy link
Contributor Author

bilhox commented Sep 3, 2024

I would like to know your opinion about the step argument before potentially merging it. I think personally the docs are not clear at all about step argument, and when I tested it with different values, I couldn't really figure out how it was used. Furthermore the code is not that great to read (I first look the variable names are not understandable), which is why I support the idea of a new implementation of Bézier curves so I can also document the terrible code.

@MyreMylar
Copy link
Member

I would like to know your opinion about the step argument before potentially merging it. I think personally the docs are not clear at all about step argument, and when I tested it with different values, I couldn't really figure out how it was used. Furthermore the code is not that great to read (I first look the variable names are not understandable), which is why I support the idea of a new implementation of Bézier curves so I can also document the terrible code.

My main feeling is that we should try and get this merged so we can shim & steadily get rid of gfxdraw from docs and examples and the like.

However, if you think the step argument is the least reliable argument in a future implementation of bezier line drawing then what I would do is move it to the end of the function signature instead of before the color argument, and make sure it has a default value specified so it is optional. You could also make it a keyword argument only parameter too.

That way in the future it will be much easier to remove or alter the step argument while still allowing us to handle it as it is right now and make a convenient gfxdraw shim for it.

So, to be clear the function signature (in python) would be something like:

def bezier(Surface surface, Sequence[Point] points, ColorLike color, *,  int step=3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
draw pygame.draw New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants