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 warning when using negative rect dimensions in draw module #3158

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

Conversation

mzivic7
Copy link
Contributor

@mzivic7 mzivic7 commented Oct 9, 2024

Using negative rect dimension values have some undesirable results as shown in #2727.
This PR adds deprecation warning to these draw functions: draw.rect, draw.ellipse, draw.arc when using negative value for rect width and height.
And prevents anything from being drawn at wrong position.
Warnings are also added to docs and tests.
This warning will also be added to draw.aaellipse in #3016

Sample code
import pygame
pygame.init()
screen = pygame.display.set_mode((300, 300))
clock = pygame.time.Clock()
run = True
while run:
  for event in pygame.event.get():
      if event.type == pygame.QUIT:
          run = False
  screen.fill((0, 0, 0))
  pygame.draw.rect(screen, "white", (150, 150, -50, 30), 0)
  pygame.draw.ellipse(screen, "white", (150, 150, -50, 30), 0)
  pygame.draw.arc(screen, "white", (150, 150, -50, 30), 0, 180, 0)
  pygame.display.flip()
  clock.tick(60)
pygame.quit()

Added warning in docs
Added test for this warning
@mzivic7 mzivic7 requested a review from a team as a code owner October 9, 2024 23:28
src_c/draw.c Outdated Show resolved Hide resolved
@yunline yunline added Code quality/robustness Code quality and resilience to changes draw pygame.draw labels Oct 10, 2024
Copy link
Contributor

@bilhox bilhox left a comment

Choose a reason for hiding this comment

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

It seems fair to me, LGTM !

@ankith26
Copy link
Member

while thinking about this, I realised that some other draw API also takes in rect style arguments. How are negative dims handled everywhere else. Whatever fix we do, we should try to be consistent with the approach everywhere

@mzivic7 mzivic7 changed the title Add warning when using negative dimensions in draw.ellipse Add warning when using negative rect dimensions in draw module Oct 12, 2024
@mzivic7
Copy link
Contributor Author

mzivic7 commented Oct 12, 2024

I added same warning, docs and tests to draw.rect and draw.arc

@bilhox bilhox added this to the 2.5.3 milestone Oct 13, 2024
@mzivic7 mzivic7 mentioned this pull request Oct 8, 2024
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code quality/robustness Code quality and resilience to changes draw pygame.draw
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants