diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index 27a8e80ac..10c351102 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -64,8 +64,14 @@ terminal from inside the top level of the arcade directory: .. code-block:: shell + # For Unix-like shells (Linux, macOS) pip install -e '.[dev]' +.. code-block:: shell + + # For Windows + pip install -e .[dev] + If you get an error like the one below, you probably need to update your pip version: .. code-block:: text diff --git a/arcade/geometry.py b/arcade/geometry.py index b04f16cd9..778fe20f8 100644 --- a/arcade/geometry.py +++ b/arcade/geometry.py @@ -8,6 +8,7 @@ from __future__ import annotations from arcade.types import Point, PointList +from sys import maxsize as sys_int_maxsize def are_polygons_intersecting(poly_a: PointList, poly_b: PointList) -> bool: @@ -18,18 +19,19 @@ def are_polygons_intersecting(poly_a: PointList, poly_b: PointList) -> bool: :param poly_b: List of points that define the second polygon. :Returns: True or false depending if polygons intersect """ - #if either are [], they don't intersect + # if either are [], they don't intersect if not poly_a or not poly_b: return False for polygon in (poly_a, poly_b): - for i1 in range(len(polygon)): i2 = (i1 + 1) % len(polygon) projection_1 = polygon[i1] projection_2 = polygon[i2] - normal = (projection_2[1] - projection_1[1], - projection_1[0] - projection_2[0]) + normal = ( + projection_2[1] - projection_1[1], + projection_1[0] - projection_2[0], + ) min_a, min_b = (float("inf"),) * 2 max_a, max_b = (-float("inf"),) * 2 @@ -56,6 +58,7 @@ def are_polygons_intersecting(poly_a: PointList, poly_b: PointList) -> bool: return True + def is_point_in_box(p: Point, q: Point, r: Point) -> bool: """ Return True if point q is inside the box defined by p and r. @@ -157,7 +160,7 @@ def is_point_in_polygon(x: float, y: float, polygon: PointList) -> bool: # Create a point for line segment # from p to infinite - extreme = (10000, p[1]) + extreme = (sys_int_maxsize, p[1]) # To count number of points in polygon # whose y-coordinate is equal to @@ -198,4 +201,3 @@ def is_point_in_polygon(x: float, y: float, polygon: PointList) -> bool: # Return true if count is odd, false otherwise return count % 2 == 1 - diff --git a/benchmarks/collisions/bench.py b/benchmarks/collisions/bench.py index cfd5a6d4e..947142de1 100644 --- a/benchmarks/collisions/bench.py +++ b/benchmarks/collisions/bench.py @@ -2,7 +2,6 @@ import arcade import pyglet import random -import time SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 diff --git a/tests/unit/test_geometry.py b/tests/unit/test_geometry.py index ce55d1578..fbbf855d1 100644 --- a/tests/unit/test_geometry.py +++ b/tests/unit/test_geometry.py @@ -35,10 +35,11 @@ def test_point_not_in_empty_polygon(): assert result is False -def test_are_polygons_intersecting(): - poly_a = [(0, 0), (0, 50), (50, 50), (50, 0)] - poly_b = [(25, 25), (25, 75), (75, 75), (75, 25)] - assert are_polygons_intersecting(poly_a, poly_b) is True +def test_point_in_extreme_polygon(): + # Cf : https://github.com/pythonarcade/arcade/issues/1906 + polygon = [(9984.0, 2112.0), (10048.0, 2112.0), (10048.0, 2048.0), (9984.0, 2048.0)] + + assert is_point_in_polygon(10016.0, 2080.0, polygon) def test_are_polygons_intersecting(): @@ -48,12 +49,13 @@ def test_are_polygons_intersecting(): def test_are_empty_polygons_breaking(): - poly_a = [] + poly_a = [] poly_b = [] assert are_polygons_intersecting(poly_a, poly_b) is False + def test_are_mismatched_polygons_breaking(): - poly_a = [(0, 0), (0, 50), (50, 50), (50, 0)] + poly_a = [(0, 0), (0, 50), (50, 50), (50, 0)] poly_b = [] assert are_polygons_intersecting(poly_a, poly_b) is False @@ -74,7 +76,7 @@ def test_are_lines_intersecting(): line_b = [(0, 0), (50, 50)] assert are_lines_intersecting(*line_a, *line_b) is True - #--------- + # --------- # Two lines clearly intersecting line_a = [(0, 0), (50, 50)] line_b = [(0, 50), (50, 0)]