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

Lines drawn with aaline() and aalines() contain gaps or aren't drawn #512

Closed
amosbastian opened this issue Aug 28, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@amosbastian
Copy link
Contributor

commented Aug 28, 2018

Using draw.aaline(s) to draw lines sometimes doesn't work at all (when close to the border of the surface) or contains gaps.

What's left to do:

  • Example showing error
  • Write a unit test in test/draw_test.py
  • Create a fix in src_c/draw.c

For some reason draw.aaline does not draw anything when it's on the border of a surface (not sure if it's intended).

import pygame
from pygame.locals import QUIT
pygame.init()
surface = pygame.display.set_mode((50, 50))
pygame.draw.aaline(surface, (0, 0, 255), (0, 0), (50, 50))

print(surface.get_at((0, 0)))
going = True
while going:
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == QUIT:
            going = False

gives the following image:

image

Same thing happens when drawing lines around the border with aalines(). Even when drawing it just inside the border of the surface it gives lines that contain gaps, as seen below:

pygame.draw.aalines(surface, (0, 0, 255), True, [(1, 1), (48, 1), (48, 48), (1, 48)])

image

Even this

pygame.draw.aalines(surface, (0, 0, 255), True, [(1, 1), (49, 0), (49, 49), (0, 49)])

only draws 1 pixel at (1, 1).

amosbastian added a commit to amosbastian/pygame that referenced this issue Aug 28, 2018

Refactor unit tests and docstrings
Merges some of the unit tests into one unit test and moves
some of the functions closer to the relevant tests for better
readability. Also improves the way the surfaces are created for
testing as it now includes the depth.

See: pygame#512
@e1000

This comment has been minimized.

Copy link

commented Aug 29, 2018

Your first code snippet seems to have a little error : replace draw.line with draw.aaline ; said that, it is also strange, that the last two bottom pixel lines stay black...

@illume

This comment has been minimized.

Copy link
Member

commented Aug 29, 2018

Very nice issue report @amosbastian Yeah, it definitely seems to be a bug to me.

I updated the aaline in the code example. Thanks @e1000

@amosbastian

This comment has been minimized.

Copy link
Contributor Author

commented Aug 29, 2018

@e1000 I just zoomed in and took a picture of the top left corner (the bottom right pixels do stay black, but this isn't shown in the picture since it's cut off).

@e1000

This comment has been minimized.

Copy link

commented Aug 29, 2018

in src_c/draw.c , around lines 710 - 735,

For line clipping, the function clip_and_draw_aaline cuts off explicitly one pixel more than clip_and_draw_line , which seems strange too me.

But then, this seems there is another problem : the gaps shown by @amosbastian also appear if we draw a much smaller square . Maybe several issues, but related since clipaaline modifies pts (startpoint and endpoint)

@e1000

This comment has been minimized.

Copy link

commented Aug 29, 2018

Here is another strange thing :

import pygame
pygame.init()


surface = pygame.display.set_mode((50, 50))

# one green rectangle
pygame.draw.rect(surface, (0, 255, 100), (5, 5, 40, 40), 0)

# one magenta multi-line
pygame.draw.aalines(surface, (255, 0, 255), False,
        [(10, 20), (10, 10), (30, 30), (20, 40)])
pygame.image.save(surface, 'this-is-the-result.bmp')

results in :
screen08-29-14h18

I do not understand the black pixels created by aalines ;

also I'm not sure how blend=1 is to be interpreted, but the dark-magenta seems buggy to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.