Skip to content

Commit c6ad74d

Browse files
Add collision detection algorithm (#12569)
1 parent a051ab5 commit c6ad74d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

geometry/collision_detection.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def is_colliding(rect1, rect2):
2+
"""
3+
Checks if rect1 and rect2 collide.
4+
rect1, rect2: tuples (x, y, width, height)
5+
Returns: True if colliding, else False
6+
"""
7+
x1, y1, w1, h1 = rect1
8+
x2, y2, w2, h2 = rect2
9+
horizontal = (x1 + w1 >= x2) and (x2 + w2 >= x1)
10+
vertical = (y1 + h1 >= y2) and (y2 + h2 >= y1)
11+
return horizontal and vertical

0 commit comments

Comments
 (0)