Skip to content

Commit 89c757f

Browse files
committed
Include sensor shapes in result from all Space.query methods. #280
1 parent ff22c47 commit 89c757f

File tree

7 files changed

+48
-19
lines changed

7 files changed

+48
-19
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ TODO: Add note of new collision handler logic!
1010

1111
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 shape.constraints updates can break silently!
1212

13-
Extra thanks for Github user aetle for a number of suggestions and feedback for this Pymunk release!
13+
Extra thanks for Github user aatle for a number of suggestions and feedback for this Pymunk release!
1414

1515

1616
Changes:
1717

1818
Breaking changes
1919

20+
- Unified all Space.query methods to include sensor shapes. Previsouly the nearest methods filtered them out.
2021
- Changed Space.shapes, Space.bodies and Space.constraints to return a KeysView of instead of a list of the items. Note that this means the returned collection is no longer a copy. To get the old behavior, you can convert to list manually, like list(space.shapes).
2122
- At least one of the two bodies attached to constraint/joint must be dynamic.
2223
- Vec2d now supports bool to test if zero. (bool(Vec2d(2,3) == True) Note this is a breaking change.
@@ -46,7 +47,7 @@ Other improvements
4647
- Improved documentation in many places (Vec2d, Poly, Shape and more)
4748
- Internal cleanup of code
4849

49-
Extra thanks for aetle for a number of suggestions for improvements in this pymunk release
50+
Extra thanks for aatle for a number of suggestions for improvements in this Pymunk release
5051

5152

5253

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ authors:
55
given-names: "Victor"
66
title: "Pymunk"
77
abstract: "A easy-to-use pythonic rigid body 2d physics library"
8-
version: 6.11.1
8+
version: 7.0.0
99
date-released: 2025-02-09
1010
url: "https://pymunk.org"

pymunk/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
cp = _chipmunk_cffi.lib
3333
ffi = _chipmunk_cffi.ffi
3434

35-
version = "6.11.1"
35+
version = "7.0.0"
3636

3737
chipmunk_version = "%s-%s" % (
3838
ffi.string(cp.cpVersionString).decode("utf-8"),

pymunk/space.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -762,13 +762,11 @@ def point_query(
762762
the point must be a under a certain depth within a shape to be
763763
considered a match.
764764
765+
Sensor shapes are included in the result.
766+
765767
See :py:class:`ShapeFilter` for details about how the shape_filter
766768
parameter can be used.
767769
768-
.. Note::
769-
Sensor shapes are included in the result (In
770-
:py:meth:`Space.point_query_nearest` they are not)
771-
772770
:param point: Where to check for collision in the Space
773771
:type point: :py:class:`~vec2d.Vec2d` or (float,float)
774772
:param float max_distance: Match only within this distance
@@ -806,8 +804,7 @@ def point_query_nearest(
806804
parameter can be used.
807805
808806
.. Note::
809-
Sensor shapes are not included in the result (In
810-
:py:meth:`Space.point_query` they are)
807+
Sensor shapes are included in the result. (Changed in Pymunk 7.0)
811808
812809
:param point: Where to check for collision in the Space
813810
:type point: :py:class:`~vec2d.Vec2d` or (float,float)
@@ -849,9 +846,7 @@ def segment_query(
849846
See :py:class:`ShapeFilter` for details about how the shape_filter
850847
parameter can be used.
851848
852-
.. Note::
853-
Sensor shapes are included in the result (In
854-
:py:meth:`Space.segment_query_first` they are not)
849+
Sensor shapes are included in the result.
855850
856851
:param start: Starting point
857852
:param end: End point
@@ -892,8 +887,7 @@ def segment_query_first(
892887
collision detection.
893888
894889
.. Note::
895-
Sensor shapes are not included in the result (In
896-
:py:meth:`Space.segment_query` they are)
890+
Sensor shapes are included in the result. (Changed in Pymunk 7.0)
897891
898892
See :py:class:`ShapeFilter` for details about how the shape_filter
899893
parameter can be used.
@@ -923,7 +917,6 @@ def bb_query(self, bb: "BB", shape_filter: ShapeFilter) -> list[Shape]:
923917
The filter is applied to the query and follows the same rules as the
924918
collision detection.
925919
926-
.. Note::
927920
Sensor shapes are included in the result
928921
929922
:param bb: Bounding box
@@ -945,7 +938,6 @@ def bb_query(self, bb: "BB", shape_filter: ShapeFilter) -> list[Shape]:
945938
def shape_query(self, shape: Shape) -> list[ShapeQueryInfo]:
946939
"""Query a space for any shapes overlapping the given shape
947940
948-
.. Note::
949941
Sensor shapes are included in the result
950942
951943
:param shape: Shape to query with

pymunk/tests/test_space.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,42 @@ def testStaticPointQueries(self) -> None:
339339
self.assertEqual(hits[0].shape, c)
340340
self._tearDown()
341341

342+
def testSensorQueries(self) -> None:
343+
s = p.Space()
344+
345+
b1 = p.Body(1, 1)
346+
b1.position = 3, 0
347+
s1 = p.Circle(b1, 1)
348+
s1.sensor = True
349+
s.add(b1, s1)
350+
351+
b2 = p.Body(1, 1)
352+
b2.position = 6, 0
353+
s2 = p.Circle(b2, 1)
354+
s.add(b2, s2)
355+
356+
print()
357+
print("Shapes", s1, s2)
358+
r = s.bb_query(p.BB(0, 0, 10, 10), p.ShapeFilter())
359+
assert len(r), 2
360+
361+
r = s.point_query((0, 0), 10, p.ShapeFilter())
362+
assert len(r), 2
363+
364+
r = s.point_query_nearest((0, 0), 10, p.ShapeFilter())
365+
assert r != None
366+
self.assertEqual(r.shape, s1)
367+
368+
r = s.shape_query(p.Circle(p.Body(body_type=p.Body.KINEMATIC), 10))
369+
assert len(r), 2
370+
371+
r = s.segment_query((0, 0), (10, 0), 1, p.ShapeFilter())
372+
assert len(r), 2
373+
374+
r = s.segment_query_first((0, 0), (10, 0), 1, p.ShapeFilter())
375+
assert r != None
376+
self.assertEqual(r.shape, s1)
377+
342378
def testReindexShape(self) -> None:
343379
s = p.Space()
344380

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
1010

1111
[project]
1212
name = "pymunk"
13-
version = "6.11.1" # remember to change me for new versions!
13+
version = "7.0.0" # remember to change me for new versions!
1414
# Require cffi >1.14.0 since that (and older) has problem with returing structs from functions.
1515
# Require cffi >= 1.17.1 since older cant work with latest setuptools version
1616
dependencies = [

0 commit comments

Comments
 (0)