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 rotate() / rotate_ip() #2662

Merged
merged 7 commits into from
Feb 25, 2024

Conversation

Co-authored-by: Emc2356 <63981925+emc2356@users.noreply.github.com>
Co-authored-by: NovialRiptide <35881688+novialriptide@users.noreply.github.com>
Co-authored-by: ScriptLineStudios <scriptlinestudios@protonmail.com>
Co-authored-by: Avaxar <44055981+avaxar@users.noreply.github.com>
Co-authored-by: maqa41 <amehebbet41@gmail.com>
@itzpr3d4t0r itzpr3d4t0r added New API This pull request may need extra debate as it adds a new class or function to pygame geometry pygame.geometry labels Jan 7, 2024
@itzpr3d4t0r itzpr3d4t0r requested a review from a team as a code owner January 7, 2024 13:18
@itzpr3d4t0r itzpr3d4t0r mentioned this pull request Jan 7, 2024
87 tasks
Copy link
Member

@Matiiss Matiiss left a comment

Choose a reason for hiding this comment

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

A really minor thing, but also the error messages have inconsistencies in first letter cases, they should all be lowercase, i.e., Invalid -> invalid

buildconfig/stubs/pygame/geometry.pyi Outdated Show resolved Hide resolved
docs/reST/ref/geometry.rst Outdated Show resolved Hide resolved
docs/reST/ref/geometry.rst Outdated Show resolved Hide resolved
src_c/doc/geometry_doc.h Outdated Show resolved Hide resolved
test/geometry_test.py Outdated Show resolved Hide resolved
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.

LGTM 👍 Does what it says, and there is documentation and tests.

I used the following cisual test program to tinker around with it:

import pygame

from pygame import Color
from pygame.geometry import Circle

pygame.init()
screen = pygame.display.set_mode((640, 480), 0)

white_background = pygame.Surface(screen.get_rect().size)
white_background.fill((255, 255, 255))

circle_1 = Circle((50, 50), 30)
circle_col = Color("red")

circle_2 = Circle((250, 250), 30)
circle_2_col = Color("blue")

clock = pygame.time.Clock()

running = True
curr_angle = 2.0
rotate_time = 0.005
rotate_acc = 0.0
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

        if event.type == pygame.MOUSEBUTTONDOWN and event.button == pygame.BUTTON_LEFT:
            circle_1.center = (
                pygame.mouse.get_pos()[0],
                pygame.mouse.get_pos()[1] - 60,
            )

        if event.type == pygame.MOUSEBUTTONDOWN and event.button == pygame.BUTTON_RIGHT:
            circle_2 = circle_2.rotate(90, pygame.mouse.get_pos())

    dt = clock.tick() / 1000.0

    rotate_acc += dt
    if rotate_acc >= rotate_time:
        rotate_acc = 0.0
        circle_1.rotate_ip(curr_angle, pygame.mouse.get_pos())

    if circle_1.collidecircle(circle_2.x, circle_2.y, circle_2.radius):
        circle_col = Color("blue")
        circle_2_col = Color("green")
    else:
        circle_col = Color("red")
        circle_2_col = Color("blue")

    screen.blit(white_background, (0, 0))

    pygame.draw.circle(screen, circle_col, (circle_1.x, circle_1.y), circle_1.r)
    pygame.draw.circle(screen, circle_2_col, (circle_2.x, circle_2.y), circle_2.r)

    pygame.display.flip()


pygame.quit()

I left a couple of minor suggestions on the documentation and spotted one copy and paste typo in the tests.

Co-authored-by: Dan Lawrence <danintheshed@gmail.com>
@MyreMylar
Copy link
Member

You'll need to merge with main again to pick up that CircleCI fix I guess.

Copy link
Member

@Matiiss Matiiss left a comment

Choose a reason for hiding this comment

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

Thanks for the PR 🎉

@Matiiss Matiiss merged commit acb6155 into pygame-community:main Feb 25, 2024
30 checks passed
@ankith26 ankith26 added this to the 2.5.0 milestone Feb 26, 2024
@itzpr3d4t0r itzpr3d4t0r deleted the circle-rotate branch February 27, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geometry pygame.geometry 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.

None yet

4 participants