-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
rect1 = {"x": 10, "y": 10, "height": 30, "width": 50} | ||
|
||
rect2 = {"x": 20, "y": 30, "height": 40, "width": 30} | ||
|
||
|
||
def checkCollision(rect1, rect2): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide return type hint for the function: Variable and function names should follow the Please provide type hint for the parameter: Please provide type hint for the parameter: |
||
""" | ||
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() |
There was a problem hiding this comment.
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