Skip to content

Fixes collisions(#1183). #1666

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

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Changes from all commits
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
13 changes: 7 additions & 6 deletions arcade/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@ def are_polygons_intersecting(poly_a: PointList, poly_b: PointList) -> bool:
normal = (projection_2[1] - projection_1[1],
projection_1[0] - projection_2[0])

min_a, max_a, min_b, max_b = (None,) * 4
min_a, min_b = (float("inf"),) * 2
max_a, max_b = (-float("inf"),) * 2

for poly in poly_a:
projected = normal[0] * poly[0] + normal[1] * poly[1]

if min_a is None or projected < min_a:
if projected < min_a:
min_a = projected
if max_a is None or projected > max_a:
if projected > max_a:
max_a = projected

for poly in poly_b:
projected = normal[0] * poly[0] + normal[1] * poly[1]

if min_b is None or projected < min_b:
if projected < min_b:
min_b = projected
if max_b is None or projected > max_b:
if projected > max_b:
max_b = projected

# Avoid typing.cast() because this is a very hot path
Expand Down Expand Up @@ -193,4 +194,4 @@ def is_point_in_polygon(x: float, y: float, polygon: PointList) -> bool:

# Return true if count is odd, false otherwise
return count % 2 == 1