-
-
Notifications
You must be signed in to change notification settings - Fork 186
geometry
module, Circle
base
#2268
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
Merged
MyreMylar
merged 14 commits into
pygame-community:main
from
itzpr3d4t0r:add_circle_object
Oct 8, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d1ef11f
added geometry/circle base
itzpr3d4t0r e6c80fe
fixes, refactors and docs
itzpr3d4t0r fe0777e
addressed reviews, hid docs, made docs much closer to the original in…
itzpr3d4t0r d1f5cf3
added geometry to android setup
itzpr3d4t0r d50a2d9
added geometry to emscripten
itzpr3d4t0r 579cabb
addressed reviews
itzpr3d4t0r 4a9d162
fix1
itzpr3d4t0r 4777745
added missing slots code
itzpr3d4t0r a083ae7
simplification
itzpr3d4t0r 9c6c57a
a couple docs corrections
itzpr3d4t0r 4fca2b6
Merge branch 'main' into add_circle_object
itzpr3d4t0r cc5d787
Merge branch 'main' into add_circle_object
itzpr3d4t0r e19c582
Merge branch 'main' into add_circle_object
MyreMylar e8ba16f
Update test/geometry_test.py
itzpr3d4t0r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from typing import ( | ||
Sequence, | ||
overload, | ||
) | ||
|
||
class Circle: | ||
x: float | ||
y: float | ||
r: float | ||
|
||
@overload | ||
def __init__(self, x: float, y: float, r: float) -> None: ... | ||
@overload | ||
def __init__(self, pos: Sequence[float], r: float) -> None: ... | ||
@overload | ||
def __init__(self, circle: Circle) -> None: ... | ||
@overload | ||
def __init__(self, obj_with_circle_attr) -> None: ... | ||
def __copy__(self) -> Circle: ... | ||
copy = __copy__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,7 @@ def lowercase_name(d): | |
"music", | ||
"pygame", | ||
"Rect", | ||
"geometry", | ||
"Surface", | ||
"sprite", | ||
"time", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
.. include:: common.txt | ||
|
||
:mod:`pygame.geometry` | ||
====================== | ||
itzpr3d4t0r marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. module:: pygame.geometry | ||
:synopsis: pygame geometry module | ||
|
||
.. warning:: | ||
**Experimental Module** | ||
|
||
**This module is a work in progress. Refrain from relying on any features provided by | ||
this module, as they are subject to change or removal without prior notice.** | ||
|
||
| :sl:`pygame module for the Circle, Line, and Polygon objects` | ||
|
||
.. currentmodule:: pygame | ||
|
||
.. class:: Circle | ||
|
||
| :sl:`pygame object for representing a circle` | ||
| :sg:`Circle((x, y), radius) -> Circle` | ||
| :sg:`Circle(x, y, radius) -> Circle` | ||
|
||
The `Circle` class provides many useful methods for collision / transform and intersection. | ||
A `Circle` can be created from a combination of a pair of coordinates that represent | ||
the center of the circle and a radius. Circles can also be created from python objects that | ||
are already a `Circle` or have an attribute named "circle". | ||
|
||
Specifically, to construct a circle you can pass the x, y, and radius values as separate | ||
arguments or inside a sequence(list or tuple). | ||
|
||
Functions that require a `Circle` argument may also accept these values as Circles: | ||
|
||
:: | ||
|
||
((x, y), radius) | ||
(x, y, radius) | ||
|
||
It is important to note that you cannot create degenerate circles, which are circles with | ||
a radius of 0 or less. If you try to create such a circle, the `Circle` object will not be | ||
created and an error will be raised. This is because a circle with a radius of 0 or | ||
less is not a valid geometric object. | ||
|
||
The `Circle` class has both virtual and non-virtual attributes. Non-virtual attributes | ||
are attributes that are stored in the `Circle` object itself. Virtual attributes are the | ||
result of calculations that utilize the Circle's non-virtual attributes. | ||
|
||
Here is the list of all the attributes and methods of the Circle class: | ||
|
||
**Circle Attributes** | ||
|
||
---- | ||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This strategy is unconventional versus the rest of the docs, gave me a pause when looking at the generated copy. |
||
|
||
.. attribute:: x | ||
|
||
| :sl:`center x coordinate of the circle` | ||
| :sg:`x -> float` | ||
|
||
The `x` coordinate of the center of the circle. It can be reassigned to move the circle. | ||
Reassigning the `x` attribute will move the circle to the new `x` coordinate. | ||
The `y` and `r` attributes will not be affected. | ||
|
||
.. ## Circle.x ## | ||
|
||
.. attribute:: y | ||
|
||
| :sl:`center y coordinate of the circle` | ||
| :sg:`y -> float` | ||
|
||
The `y` coordinate of the center of the circle. It can be reassigned to move the circle. | ||
Reassigning the `y` attribute will move the circle to the new `y` coordinate. | ||
The `x` and `r` attributes will not be affected. | ||
|
||
.. ## Circle.y ## | ||
|
||
.. attribute:: r | ||
|
||
| :sl:`radius of the circle` | ||
| :sg:`r -> float` | ||
|
||
It is not possible to set the radius to a negative value. It can be reassigned. | ||
If reassigned it will only change the radius of the circle. | ||
The circle will not be moved from its original position. | ||
|
||
.. ## Circle.r ## | ||
|
||
**Circle Methods** | ||
|
||
---- | ||
|
||
.. method:: copy | ||
|
||
| :sl:`returns a copy of the circle` | ||
| :sg:`copy() -> Circle` | ||
|
||
The `copy` method returns a new `Circle` object having the same position and radius | ||
as the original `Circle` object. The function takes no arguments and returns the | ||
new `Circle` object. | ||
|
||
.. ## Circle.copy ## | ||
|
||
.. ## pygame.Circle ## |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.