From c6ad74da334cf70359f4dd1f56f0392dc524fc21 Mon Sep 17 00:00:00 2001 From: Ashish-coder-gif Date: Wed, 26 Nov 2025 11:50:22 +0530 Subject: [PATCH] Add collision detection algorithm (#12569) --- geometry/collision_detection.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 geometry/collision_detection.py diff --git a/geometry/collision_detection.py b/geometry/collision_detection.py new file mode 100644 index 000000000000..2a310e12e9f7 --- /dev/null +++ b/geometry/collision_detection.py @@ -0,0 +1,11 @@ +def is_colliding(rect1, rect2): + """ + Checks if rect1 and rect2 collide. + rect1, rect2: tuples (x, y, width, height) + Returns: True if colliding, else False + """ + x1, y1, w1, h1 = rect1 + x2, y2, w2, h2 = rect2 + horizontal = (x1 + w1 >= x2) and (x2 + w2 >= x1) + vertical = (y1 + h1 >= y2) and (y2 + h2 >= y1) + return horizontal and vertical