-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Create collision_between_rectangles.py #7831
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 2 commits
585f631
fd14a82
ad9f14b
c03713b
7acd1ba
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 check_collision(rect1, rect2) -> bool: | ||
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 type hint for the parameter: Please provide type hint for the parameter: 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 type hint for the parameter: Please provide type hint for the parameter: |
||
""" | ||
Check if two rectangle are colliding/overlaping | ||
|
||
>>> check_collision(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. Test variables should go inside the doctest, not outside |
||
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.
These are not used within the actual code, so it should go within the
if __name__ == "__main__"
as test variables