Open mzivic7 opened 1 month ago
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
I added same warning, docs and tests to draw.rect
and draw.arc
Sure, here it comes.
Did some testing,
I still think the most straightforward way to fix this is normalize the rect arguments when they come in. (https://pyga.me/docs/ref/rect.html#pygame.Rect.normalize)
Why is normalizing input rects bad:
So I will remove warning and only disable drawing if rect width/height is negative.
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 todraw.aaellipse
in #3016 Closes #2727Sample code
```py 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() ```