Skip to content

Commit

Permalink
Merge branch 'main' into circle_collidelist_all
Browse files Browse the repository at this point in the history
  • Loading branch information
itzpr3d4t0r authored May 8, 2024
2 parents 0f3c5ff + eff0b26 commit 937786e
Show file tree
Hide file tree
Showing 12 changed files with 327 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: psf/black@stable
2 changes: 1 addition & 1 deletion .github/workflows/cppcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install deps
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/macos_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install Python
run: |
# Add the deadsnakes PPA to install python
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install packages
run: |
py -${{ matrix.python-version }} -m pip install --upgrade pip
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See below to see how to build pygame_geometry from source. If you need help, tal
2. Install [Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/community/) or [Visual Studio Build Tools 2017](https://aka.ms/vs/15/release/vs_buildtools.exe) and make sure you mark `MSVC v140 - VS 2015 C++ build tools (v14.00)` with the installation
3. Run `python -m pip install setuptools -U`
4. Install the latest version of [git](https://gitforwindows.org/)
5. Run `git clone https://github.com/novialriptide/pygame_geometry.git`
5. Run `git clone https://github.com/pygame-community/pygame_geometry.git`
6. Run `cd pygame_geometry; python -m pip install .`

**If you are having trouble re-compiling, try deleting the `build` folder from the root directory if it exists**
Expand All @@ -32,7 +32,7 @@ See below to see how to build pygame_geometry from source. If you need help, tal
brew install sdl2 sdl2_image sdl2_mixer sdl2_ttf pkg-config
```
4. Run `python3 -m pip install setuptools -U`
5. Run `git clone https://github.com/novialriptide/pygame_geometry.git`
5. Run `git clone https://github.com/pygame-community/pygame_geometry.git`
6. Run `cd pygame_geometry; python3 -m pip install .`

## Linux (Debian-based Distributions)
Expand All @@ -43,5 +43,5 @@ sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev
```
3. Install git by `sudo apt install git -y`
4. Run `python3 -m pip install setuptools -U`
5. Run `git clone https://github.com/novialriptide/pygame_geometry.git`
5. Run `git clone https://github.com/pygame-community/pygame_geometry.git`
6. Run `cd pygame_geometry; python3 -m pip install .`
23 changes: 23 additions & 0 deletions docs/circle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,29 @@ Circle Methods

.. ## Circle.contains ##
.. method:: rotate
| :sl:`rotates the circle`
| :sg:`rotate(angle, rotation_point=Circle.center) -> None`
Returns a new `Circle` that is rotated by the specified angle around a point.
A positive angle rotates the circle clockwise, while a negative angle rotates it counter-clockwise.
The rotation point can be a `tuple`, `list`, or `Vector2`.
If no rotation point is given, the circle will be rotated around its center.

.. ## Circle.rotate ##
.. method:: rotate_ip
| :sl:`rotates the circle in place`
| :sg:`rotate_ip(angle, rotation_point=Circle.center) -> None`
This method rotates the circle by a specified angle around a point.
A positive angle rotates the circle clockwise, while a negative angle rotates it counter-clockwise.
The rotation point can be a `tuple`, `list`, or `Vector2`.

If no rotation point is given, the circle will be rotated around its center.

.. ## Circle.rotate_ip ##
.. method:: copy

| :sl:`returns a copy of the circle`
Expand Down
4 changes: 4 additions & 0 deletions docs/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ performing transformations and checking for collisions with other objects.

contains: Checks if the circle fully contains the given object.

rotate: Rotates the circle by the given amount.

rotate_ip: Rotates the circle by the given amount in place.

as_rect: Returns the smallest rectangle that contains the circle.

Additionally to these, the circle shape can also be used as a collider for the ``geometry.raycast`` function.
Expand Down
2 changes: 1 addition & 1 deletion examples/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Contributing Guidelines

1. See [Contributing Guidelines](https://github.com/novialriptide/pygame_geometry/blob/main/CONTRIBUTING.md) for general contributing guidelines.
1. See [Contributing Guidelines](https://github.com/pygame-community/pygame_geometry/blob/main/CONTRIBUTING.md) for general contributing guidelines.
2. Use this boilerplate to get started

```python
Expand Down
6 changes: 6 additions & 0 deletions geometry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ class Circle:
) -> bool: ...
@overload
def collidepolygon(self, *coords, only_edges: bool = False) -> bool: ...
def rotate(
self, angle: float, rotation_point: Coordinate = Circle.center
) -> Circle: ...
def rotate_ip(
self, angle: float, rotation_point: Coordinate = Circle.center
) -> None: ...

class Polygon:
vertices: List[Coordinate]
Expand Down
96 changes: 96 additions & 0 deletions src_c/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,100 @@ pg_circle_collidelistall(pgCircleObject *self, PyObject *arg)
}

return ret;

}

static void
_pg_rotate_circle_helper(pgCircleBase *circle, double angle, double rx,
double ry)
{
if (angle == 0.0 || fmod(angle, 360.0) == 0.0) {
return;
}

double x = circle->x - rx;
double y = circle->y - ry;

const double angle_rad = DEG_TO_RAD(angle);

double cos_theta = cos(angle_rad);
double sin_theta = sin(angle_rad);

circle->x = rx + x * cos_theta - y * sin_theta;
circle->y = ry + x * sin_theta + y * cos_theta;
}

static PyObject *
pg_circle_rotate(pgCircleObject *self, PyObject *const *args, Py_ssize_t nargs)
{
if (!nargs || nargs > 2) {
return RAISE(PyExc_TypeError, "rotate requires 1 or 2 arguments");
}

pgCircleBase *circle = &self->circle;
double angle, rx, ry;

rx = circle->x;
ry = circle->y;

if (!pg_DoubleFromObj(args[0], &angle)) {
return RAISE(PyExc_TypeError,
"Invalid angle argument, must be numeric");
}

if (nargs != 2) {
return _pg_circle_subtype_new(Py_TYPE(self), circle);
}

if (!pg_TwoDoublesFromObj(args[1], &rx, &ry)) {
return RAISE(PyExc_TypeError,
"Invalid rotation point argument, must be a sequence of "
"2 numbers");
}

PyObject *circle_obj = _pg_circle_subtype_new(Py_TYPE(self), circle);
if (!circle_obj) {
return NULL;
}

_pg_rotate_circle_helper(&pgCircle_AsCircle(circle_obj), angle, rx, ry);

return circle_obj;
}

static PyObject *
pg_circle_rotate_ip(pgCircleObject *self, PyObject *const *args,
Py_ssize_t nargs)
{
if (!nargs || nargs > 2) {
return RAISE(PyExc_TypeError, "rotate requires 1 or 2 arguments");
}

pgCircleBase *circle = &self->circle;
double angle, rx, ry;

rx = circle->x;
ry = circle->y;

if (!pg_DoubleFromObj(args[0], &angle)) {
return RAISE(PyExc_TypeError,
"Invalid angle argument, must be numeric");
}

if (nargs != 2) {
/* just return None */
Py_RETURN_NONE;
}

if (!pg_TwoDoublesFromObj(args[1], &rx, &ry)) {
return RAISE(PyExc_TypeError,
"Invalid rotation point argument, must be a sequence "
"of 2 numbers");
}

_pg_rotate_circle_helper(circle, angle, rx, ry);

Py_RETURN_NONE;
}

static struct PyMethodDef pg_circle_methods[] = {
Expand All @@ -657,6 +751,8 @@ static struct PyMethodDef pg_circle_methods[] = {
{"contains", (PyCFunction)pg_circle_contains, METH_O, NULL},
{"__copy__", (PyCFunction)pg_circle_copy, METH_NOARGS, NULL},
{"copy", (PyCFunction)pg_circle_copy, METH_NOARGS, NULL},
{"rotate", (PyCFunction)pg_circle_rotate, METH_FASTCALL, NULL},
{"rotate_ip", (PyCFunction)pg_circle_rotate_ip, METH_FASTCALL, NULL},
{NULL, NULL, 0, NULL}};

/* numeric functions */
Expand Down
Loading

0 comments on commit 937786e

Please sign in to comment.