Skip to content

Commit 19ac3e3

Browse files
committed
WIP require at least one of the two bodies attached to constraint be dynamic
1 parent f67fcb3 commit 19ac3e3

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
=========
22
Changelog
33
=========
4+
.. Pymunk 7.0.0
5+
Breaking: At least one of the two bodies attached to constraint/join must be dynamic.
6+
47
58
.. Pymunk 6.12?????
69
Changes....

TODO.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ v6.x
5454
- Remove support for pyglet 1.5 in debug draw. Should be fine now that 2.x has been out for a long time.
5555
- Think about if Pymunk should assert things that Chipmunk already asserts, like if a body can sleep when calling Body.sleep()?
5656

57+
v7
58+
---
59+
- Require at least one body on constraint to be dynamic.
60+
5761
v7+ (all potentially breaking changes)
5862
---
5963
- Think about split between pymunk.util and pymunk modules

pymunk/body.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ def is_sleeping(self) -> bool:
619619
return bool(lib.cpBodyIsSleeping(self._body))
620620

621621
def _set_type(self, body_type: _BodyType) -> None:
622+
if body_type != Body.DYNAMIC:
623+
for c in self.constraints:
624+
assert (c.a != self and c.b.body_type == Body.DYNAMIC) or (
625+
c.b != self and c.a.body_type == Body.DYNAMIC
626+
), "Cannot set a non-dynamic body type when Body is connected to a constraint {c} with a non-dynamic other body."
627+
622628
lib.cpBodySetType(self._body, body_type)
623629

624630
def _get_type(self) -> _BodyType:

pymunk/space.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ def spacefree(cp_space: ffi.CData) -> None:
138138

139139
self._space = ffi.gc(cp_space, spacefree)
140140

141-
self._handlers: Dict[
142-
Any, CollisionHandler
143-
] = {} # To prevent the gc to collect the callbacks.
141+
self._handlers: Dict[Any, CollisionHandler] = (
142+
{}
143+
) # To prevent the gc to collect the callbacks.
144144

145145
self._post_step_callbacks: Dict[Any, Callable[["Space"], None]] = {}
146146
self._removed_shapes: Dict[int, Shape] = {}
@@ -450,6 +450,11 @@ def _add_constraint(self, constraint: "Constraint") -> None:
450450
"""Adds a constraint to the space"""
451451
assert constraint not in self._constraints, "Constraint already added to space."
452452

453+
assert (
454+
constraint.a.body_type == Body.DYNAMIC
455+
or constraint.b.body_type == Body.DYNAMIC
456+
), "At leasts one of a constraint's bodies must be DYNAMIC."
457+
453458
self._constraints[constraint] = None
454459
cp.cpSpaceAddConstraint(self._space, constraint._constraint)
455460

0 commit comments

Comments
 (0)