Skip to content

Commit

Permalink
Fixes collisions(#1183). (#1666)
Browse files Browse the repository at this point in the history
* Fixes collisions. 

Before, if min_a, min_b, max_a, max_b weren't changed by the code, it would break(make odd collisions) as #1183 notes. Now, it always creates the collisions

* Update geometry.py
  • Loading branch information
gran4 committed Apr 1, 2023
1 parent 1757f6b commit ab6655c
Showing 1 changed file with 7 additions and 6 deletions.
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


0 comments on commit ab6655c

Please sign in to comment.