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 Circle.intersect() #235

Merged
merged 7 commits into from
Jul 25, 2024
Merged

Add Circle.intersect() #235

merged 7 commits into from
Jul 25, 2024

Conversation

itzpr3d4t0r
Copy link
Member

@itzpr3d4t0r itzpr3d4t0r commented Jul 12, 2024

Part of #169. This PR adds the .intersect() method to the Circle class. It returns a list of points of intersection if there are any, or an empty list otherwise. This is inteded to be further expanded to support all geometry shapes (Line and Polygon) as well pygame's Rect and Frect.
image

This is a ltl test program that demos the functionality:

from geometry import Circle
import pygame

sw, sh = 600, 600
swh, shh = sw / 2, sh / 2
c = Circle((swh, shh), 100)

pygame.init()
screen = pygame.display.set_mode((sw, sh))
clock = pygame.time.Clock()
keep = True

c2 = Circle((swh + 50, shh + 50), 100)

angle = 1

while keep:
    dt = clock.tick_busy_loop(165) / 16

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keep = False

    screen.fill((0, 0, 0))

    c2.center = pygame.mouse.get_pos()

    pygame.draw.circle(screen, (255, 255, 255), c.center, c.r, 1)
    pygame.draw.circle(screen, (255, 255, 255), c2.center, c2.r, 1)

    for center in c.intersect(c2):
        pygame.draw.circle(screen, (255, 0, 0), center, 5)

    pygame.display.flip()


pygame.quit()

@itzpr3d4t0r itzpr3d4t0r added type:new_api Adds new functionalities to the project submodule:circle labels Jul 12, 2024
@itzpr3d4t0r itzpr3d4t0r merged commit f984c3c into main Jul 25, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
submodule:circle type:new_api Adds new functionalities to the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant