Skip to content

Create collision_between_rectangles.py #7827

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

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions maths/collision_between_rectangles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
rect1 = {
"x": 10,
"y": 10,
"height": 30,
"width": 50
}

rect2 = {
"x": 20,
"y": 30,
"height": 40,
"width": 30
}

def checkCollision(rect1, rect2):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: checkCollision. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: checkCollision

Please provide type hint for the parameter: rect1

Please provide type hint for the parameter: rect2

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: checkCollision. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: checkCollision

Please provide type hint for the parameter: rect1

Please provide type hint for the parameter: rect2

"""
Check if two rectangle are colliding/overlaping

>>> checkCollision(rect1, rect2)
True
"""
x_bound = rect1["x"] < rect2["x"] + rect1["width"] and rect1["x"] + rect2["width"] > rect2["x"]
y_bound = rect1["y"] < rect2["y"] + rect1["height"] and rect1["height"] + rect1["y"] > rect2["y"]
return x_bound and y_bound

if __name__ == "__main__":
import doctest

doctest.testmod()