Skip to content

rename 'collideswith' to 'collide' #229

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions benchmarks/GEOMETRY_circle_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,16 @@
]

collideswith_tests = [
("C rect", "c1.collideswith(r1)"),
("NC rect", "c1.collideswith(r2)"),
("C circle", "c1.collideswith(c2)"),
("NC circle", "c1.collideswith(c2)"),
("C point int", "c1.collideswith(p1)"),
("NC point int", "c1.collideswith(p2)"),
("C point float", "c1.collideswith(p3)"),
("NC point float", "c1.collideswith(p4)"),
("C line", "c1.collideswith(l1)"),
("NC line", "c1.collideswith(l2)"),
("C rect", "c1.collide(r1)"),
("NC rect", "c1.collide(r2)"),
("C circle", "c1.collide(c2)"),
("NC circle", "c1.collide(c2)"),
("C point int", "c1.collide(p1)"),
("NC point int", "c1.collide(p2)"),
("C point float", "c1.collide(p3)"),
("NC point float", "c1.collide(p4)"),
("C line", "c1.collide(l1)"),
("NC line", "c1.collide(l2)"),
]

contains_tests = [
Expand Down
16 changes: 8 additions & 8 deletions docs/circle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,17 @@ Circle Methods

.. ## Circle.collidepolygon ##

.. method:: collideswith
.. method:: collide

| :sl:`test if a shape or point and the circle collide`
| :sg:`collideswith(Line) -> bool`
| :sg:`collideswith(Circle) -> bool`
| :sg:`collideswith(Rect) -> bool`
| :sg:`collideswith(Polygon) -> bool`
| :sg:`collideswith((x, y)) -> bool`
| :sg:`collide(Line) -> bool`
| :sg:`collide(Circle) -> bool`
| :sg:`collide(Rect) -> bool`
| :sg:`collide(Polygon) -> bool`
| :sg:`collide((x, y)) -> bool`
| :sg:`contains(Vector2) -> bool`

The `collideswith` method tests whether a given shape or point collides (overlaps)
The `collide` method tests whether a given shape or point collides (overlaps)
with a `Circle` object. The function takes in a single argument, which can be a
`Line`, `Circle`, `Rect`, `Polygon`, tuple or list containing the x and y coordinates
of a point, or a `Vector2` object. The function returns a boolean value of `True`
Expand All @@ -296,7 +296,7 @@ Circle Methods
Collisions with a `Polygon` object are evaluated the same way the :meth:`collidepolygon`
method does by default, meaning with only_edges set to `False`.

.. ## Circle.collideswith ##
.. ## Circle.collide ##

.. method:: collidelist

Expand Down
4 changes: 2 additions & 2 deletions docs/geometry.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ performing transformations and checking for collisions with other objects.

collidepolygon: Checks if the circle collides with the given polygon.

collideswith: Checks if the circle collides with the given object.
collide: Checks if the circle collides with the given object.

collidelist: Checks if the circle collides with any of the given objects.

Expand Down Expand Up @@ -136,7 +136,7 @@ other objects.

collidepolygon: Checks if the line collides with the given polygon.

collideswith: Checks if the line collides with the given object.
collide: Checks if the line collides with the given object.

as_circle: Returns a circle which fully encloses the line.

Expand Down
14 changes: 7 additions & 7 deletions docs/line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -344,14 +344,14 @@ Line Methods
.. ## Line.collidepolygon ##


.. method:: collideswith
.. method:: collide

| :sl:`test if a shape or point and the line collide`
| :sg:`collideswith(Line) -> bool`
| :sg:`collideswith(Circle) -> bool`
| :sg:`collideswith(Rect) -> bool`
| :sg:`collideswith(Polygon) -> bool`
| :sg:`collideswith((x, y)) -> bool`
| :sg:`collide(Line) -> bool`
| :sg:`collide(Circle) -> bool`
| :sg:`collide(Rect) -> bool`
| :sg:`collide(Polygon) -> bool`
| :sg:`collide((x, y)) -> bool`
| :sg:`contains(Vector2) -> bool`

Returns `True` if any portion of the shape or point overlaps with the Line,
Expand All @@ -369,7 +369,7 @@ Line Methods
Collisions with a `Polygon` object are evaluated the same way the :meth:`collidepolygon`
method does by default, meaning with only_edges set to `False`.

.. ## Line.collideswith ##
.. ## Line.collide ##


.. method:: as_circle
Expand Down
2 changes: 1 addition & 1 deletion examples/circle_collision_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_new_circle_surf(
is_circle = isinstance(shape, Circle)
is_rect = isinstance(shape, pygame.Rect)

if feed_active and mouse_circle.collideswith(shape):
if feed_active and mouse_circle.collide(shape):
if is_circle:
shape.r += 0.2
draw_circle(screen, coll_color, shape.center, shape.r, 3)
Expand Down
4 changes: 2 additions & 2 deletions geometry.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class Line(Sequence[float]):
def update(self, a: Coordinate, b: Coordinate) -> None: ...
@overload
def update(self, single_arg: LineValue) -> None: ...
def collideswith(self, other: _CanBeCollided) -> bool: ...
def collide(self, other: _CanBeCollided) -> bool: ...
@overload
def collidepoint(self, x: float, y: float) -> bool: ...
@overload
Expand Down Expand Up @@ -175,7 +175,7 @@ class Circle:
def colliderect(self, rect: Rect) -> bool: ...
@overload
def colliderect(self, x: int, y: int, w: int, h: int) -> bool: ...
def collideswith(self, other: _CanBeCollided) -> bool: ...
def collide(self, other: _CanBeCollided) -> bool: ...
def collidelist(self, colliders: Sequence[_CanBeCollided]) -> int: ...
def collidelistall(self, colliders: Sequence[_CanBeCollided]) -> List[int]: ...
def __copy__(self) -> Circle: ...
Expand Down
2 changes: 1 addition & 1 deletion src_c/circle.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ static struct PyMethodDef pg_circle_methods[] = {
{"collideline", (PyCFunction)pg_circle_collideline, METH_FASTCALL, NULL},
{"collidepoint", (PyCFunction)pg_circle_collidepoint, METH_FASTCALL, NULL},
{"colliderect", (PyCFunction)pg_circle_colliderect, METH_FASTCALL, NULL},
{"collideswith", (PyCFunction)pg_circle_collideswith, METH_O, NULL},
{"collide", (PyCFunction)pg_circle_collideswith, METH_O, NULL},
{"collidepolygon", (PyCFunction)pg_circle_collidepolygon, METH_FASTCALL,
NULL},
{"collidelist", (PyCFunction)pg_circle_collidelist, METH_O, NULL},
Expand Down
2 changes: 1 addition & 1 deletion src_c/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ static struct PyMethodDef pg_line_methods[] = {
{"collidepoint", (PyCFunction)pg_line_collidepoint, METH_FASTCALL, NULL},
{"collidecircle", (PyCFunction)pg_line_collidecircle, METH_FASTCALL, NULL},
{"colliderect", (PyCFunction)pg_line_colliderect, METH_FASTCALL, NULL},
{"collideswith", (PyCFunction)pg_line_collideswith, METH_O, NULL},
{"collide", (PyCFunction)pg_line_collideswith, METH_O, NULL},
{"collidepolygon", (PyCFunction)pg_line_collidepolygon, METH_FASTCALL,
NULL},
{"as_rect", (PyCFunction)pg_line_as_rect, METH_NOARGS, NULL},
Expand Down
34 changes: 17 additions & 17 deletions test/test_circle.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,64 +657,64 @@ def test_colliderect(self):
# barely colliding single
self.assertTrue(c.colliderect(0, 4.9999999999999, 4, 4), msgt)

def test_collideswith_argtype(self):
def test_collide_argtype(self):
"""tests if the function correctly handles incorrect types as parameters"""
invalid_types = (None, [], "1", (1,), Vector3(1, 1, 1), 1)

c = Circle(10, 10, 4)

for value in invalid_types:
with self.assertRaises(TypeError):
c.collideswith(value)
c.collide(value)

def test_collideswith_argnum(self):
def test_collide_argnum(self):
c = Circle(10, 10, 4)
args = [tuple(range(x)) for x in range(2, 4)]

# no params
with self.assertRaises(TypeError):
c.collideswith()
c.collide()

# too many params
for arg in args:
with self.assertRaises(TypeError):
c.collideswith(*arg)
c.collide(*arg)

def test_collideswith(self):
"""Ensures the collideswith function correctly registers collisions with circles, lines, rects and points"""
def test_collide(self):
"""Ensures the collide function correctly registers collisions with circles, lines, rects and points"""
c = Circle(0, 0, 5)

# circle
c2 = Circle(0, 10, 15)
c3 = Circle(100, 100, 1)
self.assertTrue(c.collideswith(c2), E_T + "circles should collide here")
self.assertFalse(c.collideswith(c3), E_F + "circles should not collide here")
self.assertTrue(c.collide(c2), E_T + "circles should collide here")
self.assertFalse(c.collide(c3), E_F + "circles should not collide here")

# line
l = Line(0, 0, 10, 10)
l2 = Line(50, 0, 50, 10)
self.assertTrue(c.collideswith(l), E_T + "line should collide here")
self.assertFalse(c.collideswith(l2), E_F + "line should not collide here")
self.assertTrue(c.collide(l), E_T + "line should collide here")
self.assertFalse(c.collide(l2), E_F + "line should not collide here")

# rect
r = Rect(0, 0, 10, 10)
r2 = Rect(50, 0, 10, 10)
self.assertTrue(c.collideswith(r), E_T + "rect should collide here")
self.assertFalse(c.collideswith(r2), E_F + "rect should not collide here")
self.assertTrue(c.collide(r), E_T + "rect should collide here")
self.assertFalse(c.collide(r2), E_F + "rect should not collide here")

# point
p = (0, 0)
p2 = (50, 0)
self.assertTrue(c.collideswith(p), E_T + "point should collide here")
self.assertFalse(c.collideswith(p2), E_F + "point should not collide here")
self.assertTrue(c.collide(p), E_T + "point should collide here")
self.assertFalse(c.collide(p2), E_F + "point should not collide here")

# polygon
c4 = Circle(0, 0, 15)
po1 = Polygon([(-5, 0), (5, 0), (0, 5)])
po2 = Polygon([(100, 150), (200, 225), (150, 200)])

self.assertTrue(c.collideswith(po1), E_T + "polygon should collide here")
self.assertFalse(c.collideswith(po2), E_F + "polygon should not collide here")
self.assertTrue(c.collide(po1), E_T + "polygon should collide here")
self.assertFalse(c.collide(po2), E_F + "polygon should not collide here")

def test_as_rect_invalid_args(self):
c = Circle(0, 0, 10)
Expand Down
40 changes: 20 additions & 20 deletions test/test_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,57 +505,57 @@ def test_attrib_centery(self):
with self.assertRaises(AttributeError):
del line.centery

def test_collideswith_argtype(self):
def test_collide_argtype(self):
"""tests if the function correctly handles incorrect types as parameters"""
invalid_types = (None, [], "1", (1,), Vector3(1, 1, 1), 1)

l = Line(10, 10, 60, 60)

for value in invalid_types:
with self.assertRaises(TypeError):
l.collideswith(value)
l.collide(value)

def test_collideswith_argnum(self):
def test_collide_argnum(self):
l = Line(10, 10, 4, 4)
args = [tuple(range(x)) for x in range(2, 4)]

# no params
with self.assertRaises(TypeError):
l.collideswith()
l.collide()

# too many params
for arg in args:
with self.assertRaises(TypeError):
l.collideswith(*arg)
l.collide(*arg)

def test_collideswith(self):
"""Ensures the collideswith function correctly registers collisions with circles, lines, rects and points"""
def test_collide(self):
"""Ensures the collide function correctly registers collisions with circles, lines, rects and points"""
l = Line(10, 10, 200, 200)

# line
l2 = Line(400, 300, 10, 100)
l3 = Line(400, 300, 10, 200)

self.assertTrue(l.collideswith(l2), E_T + "lines should collide here")
self.assertFalse(l.collideswith(l3), E_F + "lines should not collide here")
self.assertTrue(l.collide(l2), E_T + "lines should collide here")
self.assertFalse(l.collide(l3), E_F + "lines should not collide here")

# circle
c = Circle(10, 10, 10)
c2 = Circle(50, 10, 10)
self.assertTrue(l.collideswith(c), E_T + "circle should collide here")
self.assertFalse(l.collideswith(c2), E_F + "circle should not collide here")
self.assertTrue(l.collide(c), E_T + "circle should collide here")
self.assertFalse(l.collide(c2), E_F + "circle should not collide here")

# rect
r = Rect(10, 10, 10, 10)
r2 = Rect(50, 10, 10, 10)
self.assertTrue(l.collideswith(r), E_T + "rect should collide here")
self.assertFalse(l.collideswith(r2), E_F + "rect should not collide here")
self.assertTrue(l.collide(r), E_T + "rect should collide here")
self.assertFalse(l.collide(r2), E_F + "rect should not collide here")

# point
p = (11, 11)
p2 = (60, 80)
self.assertTrue(c.collideswith(p), E_T + "point should collide here")
self.assertFalse(c.collideswith(p2), E_F + "point should not collide here")
self.assertTrue(c.collide(p), E_T + "point should collide here")
self.assertFalse(c.collide(p2), E_F + "point should not collide here")

# polygon
l4 = Line(0, 0, 10, 10)
Expand All @@ -565,11 +565,11 @@ def test_collideswith(self):
po4 = Polygon((5, 5), (5, 10), (0, 10), (2.5, 2.5))
po5 = Polygon((0, 0), (0, 10), (-5, 10), (-5, 0))

self.assertTrue(l4.collideswith(po1))
self.assertFalse(l4.collideswith(po2))
self.assertTrue(l4.collideswith(po3))
self.assertTrue(l4.collideswith(po4))
self.assertTrue(l4.collideswith(po5))
self.assertTrue(l4.collide(po1))
self.assertFalse(l4.collide(po2))
self.assertTrue(l4.collide(po3))
self.assertTrue(l4.collide(po4))
self.assertTrue(l4.collide(po5))

def test_meth_copy(self):
line = Line(1, 2, 3, 4)
Expand Down
Loading