Skip to content

Pymunk7 #285

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
merged 82 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
19ac3e3
WIP require at least one of the two bodies attached to constraint be …
viblo Feb 9, 2025
ad572a9
Merge branch 'master' into pymunk7
viblo Feb 14, 2025
5993754
Update pygame_util to clarify Pygame-CE can be used
viblo Feb 14, 2025
7716e51
Require that at least ony body is alwayd DYNAMIC on constraints
viblo Feb 15, 2025
a24f93e
New method ShapeFilter.rejects_collision() #271
viblo Feb 15, 2025
f772ded
improve docs
viblo Feb 18, 2025
e6be610
Switch Chipmunk2D to Munk2D, part1
viblo Feb 20, 2025
70cb1e4
Comment out update body type test until fixed
viblo Feb 20, 2025
875c3f7
Make most properties use conventional syntax
aatle Feb 21, 2025
cb2853b
Add __bool__ to Vec2d to allow testing if 0
viblo Feb 21, 2025
949a367
Return floats if possible in Vec2d and optimize Vec2d.angle #274
viblo Feb 21, 2025
a7afc5b
Improve docs of Vec2d #274
viblo Feb 21, 2025
b7b298d
Merge pull request #273 from aatle/pymunk7
viblo Feb 22, 2025
ba40182
Add Vec2d.length_squared, deprecated Vec2d.get_length_sqrd #274
viblo Feb 22, 2025
ab9f699
New Vec2d.polar_tuple property #274
viblo Feb 22, 2025
eafa77c
Added Vec2d.get_distance_squared, deprecated get_dist_sqrd #274
viblo Feb 22, 2025
de52ceb
Note about how angle of vec2d is calculated #274
viblo Feb 24, 2025
bc90bf6
Add default CollisionHandler callback functions instead of None to be…
viblo Feb 25, 2025
72bbe3b
Add example in Poly docs of convex hull #257
viblo Feb 25, 2025
c1d222a
Made it required to have mass > 0 on dynamic bodies when stepping #268
viblo Mar 9, 2025
daaaee9
Add test for dynamic 0 mass bodies
viblo Mar 9, 2025
3f549e1
Deprecated matplotlib_util
viblo Mar 9, 2025
df54445
Change Space.shapes internally to behave as Space.bodies
viblo Mar 14, 2025
59a5251
Improve docs for collision_type #277
viblo Mar 16, 2025
df11ae6
Update body weakref to space to ref, and fix issue with del space. #278
viblo Mar 16, 2025
fe322bb
Reverse dependency between shape and body, so shape has the weak ref …
viblo Mar 16, 2025
83ffa01
Add latest changes to changelog
viblo Mar 16, 2025
2d6e031
Fix test of deleted space
viblo Mar 17, 2025
f6bf849
Drop support for Python 3.8
viblo Mar 17, 2025
3473532
Changed Body.constraints to return a KeysView of the constraints atta…
viblo Mar 23, 2025
7e7b63d
Changed Body.Shapes to return a KeysView instead of set #275
viblo Mar 23, 2025
7fda279
Improved and fixed some types
viblo Mar 23, 2025
39f562a
Refactored body.space weakref implementation
viblo Mar 24, 2025
d774940
Removed unused imports
viblo Mar 24, 2025
bd0295a
Minor cleanup
viblo Mar 24, 2025
5e99b08
Refactor how to get a shape from a cp_shape
viblo Mar 25, 2025
e6b4506
Changed Query info shape properties to never have a None. #279
viblo Mar 25, 2025
50984d7
Fix point_query.py example
viblo Mar 25, 2025
143db86
Temp disable building of arm linux wheels
viblo Mar 30, 2025
5650984
Temp disable some os in build
viblo Mar 30, 2025
86e5d04
Temp disable some os in build
viblo Apr 2, 2025
add4fe4
test fix for seg fault
viblo Apr 4, 2025
cbe41d9
re-enable build for all platforms
viblo Apr 4, 2025
e1682c2
Change ContactPointSet.points to tuple #279
viblo Apr 5, 2025
929f95e
New shorthand to get bodies from a Arbiter. #279
viblo Apr 5, 2025
9b8076a
Update showcase articles
viblo Apr 5, 2025
e1a9c51
Update cibuildwheel
viblo Apr 5, 2025
e6bc763
Changed Space.shapes/bodies/constraints to return a KeysView #275
viblo Apr 6, 2025
e7fe4f5
Use Munk2D 1.0
viblo Apr 8, 2025
e431bda
wip readme
viblo Apr 8, 2025
eba1674
fix space docs
viblo Apr 10, 2025
a6a7c4c
minor adjustments to changelog and docs
viblo Apr 19, 2025
b0d747f
Fix strange None assert in callbacks, and callback changelog #280
viblo Apr 19, 2025
dfb716b
Fix pickle of default callback funcs #280
viblo Apr 19, 2025
23fff81
Update license spec in pyproject.toml to new format
viblo Apr 20, 2025
d9f6de8
Reworked collision handlers wip #280
viblo May 8, 2025
498a57f
Fix cpArbiter mem issue
viblo May 9, 2025
feb6dd0
Use list/tuple instead of typing.Tuple etc
viblo May 9, 2025
b557366
Use type instead of typing.Type etc
viblo May 9, 2025
b052012
skip building for PyPy 3.9
viblo May 9, 2025
df66852
Minor type cleanup
viblo May 9, 2025
ff22c47
Fix in MANIFEST
viblo May 13, 2025
89c757f
Include sensor shapes in result from all Space.query methods. #280
viblo May 18, 2025
cf198b9
wip collision handler rework
viblo May 18, 2025
fe6393f
WIP fixing collision handler order
viblo May 18, 2025
2306192
fix tests
viblo May 18, 2025
36fed33
Fix processCollision
viblo May 21, 2025
aa5a7c0
fix processCollision in cpHastySpace
viblo May 21, 2025
3686ff6
internal refactor - use lib instead of cp for cffi
viblo May 22, 2025
1b4b88e
WIP Removed data from coll callbacks, made CollisionHandler private
viblo May 22, 2025
3591517
Readd data to collision callbacks, fix tests
viblo May 24, 2025
b16b4c4
Renamed coll callback to on_collision, moved do_nothing to Pymunk.emp…
viblo May 25, 2025
5395577
fix tests
viblo May 25, 2025
030328e
Minor type fixes
viblo May 25, 2025
6471d3d
fix tutorial, changelog
viblo May 25, 2025
b4a0690
Minor fixes to docs of new features
viblo May 25, 2025
ef9e787
Dont allow on_collision(None, 1). Better assert for non-inf mass.
viblo May 26, 2025
a675cfc
Assert body.moment > 0 when added to space
viblo May 26, 2025
ee6fce4
minor doc fixes
viblo May 26, 2025
abdaab3
fix callback benchmark
viblo May 26, 2025
6af8524
fix broken test
viblo May 27, 2025
92f6e5c
Prep 7.0.0
viblo May 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
os:
[ubuntu-latest, ubuntu-24.04-arm, windows-latest, macos-13, macos-14]

steps:
- uses: actions/checkout@v4
Expand All @@ -21,10 +22,10 @@ jobs:
python3 -c "import pathlib,glob;pathlib.Path('GITHUB_ENV').write_text('SDIST_PATH' + glob.glob('dist/*.tar.gz')[0])"

- name: Build wheels
uses: pypa/cibuildwheel@v2.22.0
uses: pypa/cibuildwheel@v2.23.1
env:
CIBW_BUILD:
"cp38-* cp39-* cp310-* cp311-* cp312-* cp313-* pp39-* pp310-*"
"cp39-* cp310-* cp311-* cp312-* cp313-* pp310-* pp311-*"
# "cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
CIBW_TEST_COMMAND: "python -m pymunk.tests"
# CIBW_BUILD_VERBOSITY: 3
Expand Down Expand Up @@ -56,7 +57,7 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: pypa/cibuildwheel@v2.22.0
- uses: pypa/cibuildwheel@v2.23.2
env:
CIBW_PLATFORM: pyodide
PYMUNK_BUILD_SLIM: 1
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "Chipmunk2D"]
path = Chipmunk2D
url = git@github.com:viblo/Chipmunk2D.git
[submodule "Munk2D"]
path = Munk2D
url = git@github.com:viblo/Munk2D.git
10 changes: 5 additions & 5 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ build:

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/src/conf.py
configuration: docs/src/conf.py

# Optionally build your docs in additional formats such as PDF
formats:
- pdf
- pdf

# Optionally set the version of Python and requirements required to build your docs
python:
install:
- requirements: docs/requirements.txt
install:
- requirements: docs/requirements.txt

# Do not include the Chipmunk2D submodule. It it not needed for docs.
submodules:
exclude: all
exclude: all
106 changes: 104 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,106 @@
Changelog
=========

Pymunk 7.0.0 (2025-05-28)
-------------------------

**Many improvements and breaking changes!**

This is a big cleanup release with several breaking changes. If you upgrade
from an older version, make sure to pay attention, especially the
``Space.bodies``, ``Space.shapes`` and ``Space.constraints`` updates can break silently!

Extra thanks for Github user aatle for a number of suggestions and feedback
for this Pymunk release!


The biggest changes relates to collision handlers:

- The ``begin``, ``pre_step`` and ``separate`` methods will now always be
called. ``post_solve`` will continue to only be called if the collision were
actually processed.
- You no longer return a ``bool`` from ``begin`` or ``pre_step`` to control if the
collision should be processed. Instead, there is a property on the ``Arbiter``,
``process_collision``, that can be set to ``False``.
- The ``process_collision`` property is stable but updatable, e.g if set to
``False`` in a ``begin`` callback it will be ``False`` in the ``pre_step``,
which in turn can toggle it back to ``True``.
- The ``CollisionHandler`` class itself is no longer public. The ``Space`` has
a new ``on_collision()`` method that takes the callbacks as arguments without
returning anything.

In addition to the above (which will be easy to spot), there is also a more
subtle change:

- ``Space.shapes``, ``Space.bodies`` and ``Space.constraints`` now return a
``KeysView``. That means that the returned collection is no longer a copy,
instead if you hold a ref to it and if you for example add an object to the
``Space`` it will update. To get the old behavior, you can convert to a list
manually, e.g ``list(Space.shapes)``.

Additional breaking changes:

- Unified all ``Space.query`` methods to include sensor shapes. Previously
the nearest methods filtered them out.
- At least one of the two bodies attached to a constraint/joint must be
dynamic.
- ``Vec2d`` now supports ``bool`` to test if zero. (
``bool(Vec2d(2,3) == True``).
- Added ``Vec2d.length_squared``, and deprecated ``Vec2d.get_length_sqrd()``
- Added ``Vec2d.get_distance_squared()``, and deprecated
``Vec2d.get_dist_sqrd()``
- A dynamic body must have non-zero mass when calling ``Space.step()`` (either
from ``Body.mass``, or by setting ``mass`` or ``density`` on a Shape
attached to the ``Body``). It is not valid to set ``mass`` to ``0`` on a
dynamic body attached to a ``Space``.
- Deprecated ``matplotlib_util``. If you think this is a useful module, and
you use it, please create an issue on the Pymunk issue tracker at
https://github.com/viblo/pymunk/issues
- Dropped support for Python 3.8
- Changed ``Body.constraints`` to return a ``KeysView`` of the Constraints
attached to the ``Body``. Note that its still weak references to the
Constraints.
- Reversed the dependency between bodies and shapes. Now the ``Body`` owns the
connection, and the ``Shape`` only keeps a weak ref to the ``Body``. That
means that if you remove a ``Body``, then any shapes not referenced
anywhere else will also be removed.
- Changed ``Body.shapes`` to return a ``KeysView`` instead of a set of the shapes.
- Changed ``Shape.segment_query`` to return None in case the query did not
hit the shape.
- Changed ``ContactPointSet.points`` to be a ``tuple`` and not ``list`` to
make it clear its length is fixed.
- Added default ``empty_callback``, that can be used to efficiently reset
any callback to default.

New non-breaking features:

- Switched from using Chipmunk to the new Munk2D fork of Chipmunk (see
https://github.com/viblo/Munk2D for details).
- Added ``Arbiter.bodies`` shorthand to get the shapes' bodies in the ``Arbiter``.
- New method ``ShapeFilter.rejects_collision()`` that checks if the filter
would reject a collision with another filter.
- New method ``Vec2d.polar_tuple`` that return the vector as polar coordinates
- Changed type of ``PointQueryInfo.shape``, ``SegmentQueryInfo.shape`` and
``ShapeQueryInfo.shape`` to not be ``Optional``, they will always have a shape.
- Build and publish wheels for Linux ARM and Pypy 3.11


Other improvements:

- Optimized ``Vec2d.angle`` and ``Vec2d.angle_degrees``. Note that the
optimized versions treat ``0`` length vectors with ``x`` and/or ``y`` equal
to ``-0`` slightly differently.
- Fixed issue with accessing ``Body.space`` after the ``space`` is deleted and
GCed.
- Improved documentation in many places (``Vec2d``, ``Poly``, ``Shape`` and
more)
- Improved assert for ``body.mass`` sanity check (``0 < mass < math.inf``) for
dynamic bodies added to a space.
- Improved assert for ``body.moment`` sanity check (``0 < moment``) for dynamic
bodies added to a space.
- Internal cleanup of code


Pymunk 6.11.1 (2025-02-09)
--------------------------

Expand All @@ -11,6 +111,7 @@ This is a patch update to Pymunk that removes debug logging. This should an
issue with GC on Python 3.13.

Changes:

- Remove debug logging


Expand All @@ -25,8 +126,9 @@ does not work anymore. The release also adds back pre-built wheels for Pypy
with a workaround until Pypy make a new release.

Changes:
- Support Pyglet 2.1.x (this means Pyglet 2.0.x wont work)
- Readded Pypy pre-built wheels

- Support Pyglet 2.1.x (this means Pyglet 2.0.x wont work)
- Readded Pypy pre-built wheels


Pymunk 6.10.0 (2024-12-22)
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ authors:
given-names: "Victor"
title: "Pymunk"
abstract: "A easy-to-use pythonic rigid body 2d physics library"
version: 6.11.1
date-released: 2025-02-09
version: 7.0.0
date-released: 2025-05-28
url: "https://pymunk.org"
1 change: 0 additions & 1 deletion Chipmunk2D
Submodule Chipmunk2D deleted from 7f091a
6 changes: 3 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ prune additional_examples/dist
recursive-include pymunk/examples *.png
recursive-include pymunk/examples *.wav
#chipmunk src
recursive-include Chipmunk2D/src *
recursive-include Chipmunk2D/include/chipmunk *
include Chipmunk2D/*.txt
recursive-include Munk2D/src *
recursive-include Munk2D/include/chipmunk *
include Munk2D/*.txt
recursive-include pymunk_cffi *
#tools
recursive-include tools *.py
Expand Down
1 change: 1 addition & 0 deletions Munk2D
Submodule Munk2D added at 5ef749
11 changes: 6 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Pymunk

Pymunk is an easy-to-use pythonic 2D physics library that can be used whenever
you need 2D rigid body physics from Python. Perfect when you need 2D physics
in your game, demo or simulation! It is built on top of the very
capable 2D physics library `Chipmunk2D <http://chipmunk-physics.net>`_.
in your game, demo or simulation! It is built on top of Munk2D, a fork of the
very capable 2D physics library `Chipmunk2D <http://chipmunk-physics.net>`_.

The first version was released in 2007 and Pymunk is still actively developed
and maintained today, more than 15 years of active development!
Expand All @@ -18,8 +18,8 @@ the Pymunk webpage for some examples.

2007 - 2025, Victor Blomqvist - vb@viblo.se, MIT License

This release is based on the latest Pymunk release (6.11.1),
using Chipmunk2D 7 rev dfc2fb8ca023ce6376fa2cf4a7f91c92ee08a970.
This release is based on the latest Pymunk release (7.0.0),
using Munk2D 2.0 rev 5ef7498946f0e956f294cb3fea283626921e4128.


Installation
Expand Down Expand Up @@ -152,7 +152,8 @@ Older Pythons

- Support for Python 2 (and Python 3.0 - 3.5) was dropped with Pymunk 6.0.
- Support for Python 3.6 was dropped with Pymunk 6.5.2.
- Support for Python 3.7 was dropped with Pymunk 6.9.0
- Support for Python 3.7 was dropped with Pymunk 6.9.0.
- Support for Python 3.8 was dropped with Pymunk 7.0.0.

If you use any of these legacy versions of Python, please use an older
Pymunk version. (It might work on newer Pymunks as well, but it's not tested,
Expand Down
5 changes: 4 additions & 1 deletion TODO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ v6.x
- Add Canvas util module (after pyodide)
- Use https://diataxis.fr/ method of organizing docs (tutorials, how-to, explanation, reference)
- Make sure cffi extensions included in wheel and zip!
- Catch error when NaN in debugdraw, suggest doublecheck mass=0. https://github.com/viblo/pymunk/issues/226 and https://github.com/viblo/pymunk/issues/267
- Make benchmark between pymunk and pybullet. 2d bullet inspiration: https://github.com/bulletphysics/bullet3/blob/2.83/examples/Planar2D/Planar2D.cpp
- After a couple of versions / time passed, re-evaluate if batch api should be separate or merged in to space.
- Think about the copyright notice in some files. Keep / put everywere / remove?
Expand All @@ -54,6 +53,10 @@ v6.x
- Remove support for pyglet 1.5 in debug draw. Should be fine now that 2.x has been out for a long time.
- Think about if Pymunk should assert things that Chipmunk already asserts, like if a body can sleep when calling Body.sleep()?

v7
---
- Require at least one body on constraint to be dynamic.

v7+ (all potentially breaking changes)
---
- Think about split between pymunk.util and pymunk modules
Expand Down
3 changes: 1 addition & 2 deletions benchmarks/pymunk-collision-callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
b = pymunk.Body(1,10)
c = pymunk.Circle(b, 5)
s.add(b, c)
h = s.add_default_collision_handler()
def f(arb, s, data):
return False
h.pre_solve = f
s.on_collision(pre_solve=f)
"""

print(min(timeit.repeat("s.step(0.01)", setup=s, repeat=10)))
8 changes: 8 additions & 0 deletions docs/src/showcase.rst
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ List of papers which has used or mentioned Pymunk:

.. (list made using "Chicago" style citation)

#. Liu, Li, Qiang-hong Zhang, Meng-zi Li, Rui-tong Li, Zhiming He, Arnaud Dechesne, Barth F. Smets, and Guo-ping Sheng.
"Single-cell analysis reveals antibiotic affects conjugative transfer by modulating bacterial growth rather than conjugation efficiency."
Environment International (2025): 109385.

#. Davison, Andrew.
"Simulating Mechanical Curve Drawing using Pymunk."
(2025).

#. Liu, Daochang, Junyu Zhang, Anh-Dung Dinh, Eunbyung Park, Shichao Zhang, and Chang Xu.
"Generative Physical AI in Vision: A Survey."
arXiv preprint arXiv:2501.10928 (2025).
Expand Down
Loading
Loading