From 575bf3bd17bfc9788b8837698da4762a92f17ca5 Mon Sep 17 00:00:00 2001 From: Maic Siemering Date: Wed, 28 Feb 2024 23:23:54 +0100 Subject: [PATCH] Fix #1999 --- arcade/gui/widgets/__init__.py | 2 +- tests/unit/gui/test_rect.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arcade/gui/widgets/__init__.py b/arcade/gui/widgets/__init__.py index 34d05c80b9..55156cd81b 100644 --- a/arcade/gui/widgets/__init__.py +++ b/arcade/gui/widgets/__init__.py @@ -59,7 +59,7 @@ def move(self, dx: float = 0, dy: float = 0): def collide_with_point(self, x, y): left, bottom, width, height = self - return left < x < left + width and bottom < y < bottom + height + return left <= x <= left + width and bottom <= y <= bottom + height def scale(self, scale: float) -> "Rect": """Returns a new rect with scale applied""" diff --git a/tests/unit/gui/test_rect.py b/tests/unit/gui/test_rect.py index 53add5e070..68ec78578b 100644 --- a/tests/unit/gui/test_rect.py +++ b/tests/unit/gui/test_rect.py @@ -166,3 +166,12 @@ def test_rect_union(): # THEN assert new_rect == (0, 0, 20, 10) + + +def test_collide_with_point(): + rect = Rect(0, 0, 100, 100) + + assert rect.collide_with_point(0, 0) + assert rect.collide_with_point(50, 50) + assert rect.collide_with_point(100, 100) + assert not rect.collide_with_point(150, 150)