From 3e364cd547bc77120de7777467449da3a5f5b7fc Mon Sep 17 00:00:00 2001 From: Houda222 Date: Tue, 26 Dec 2023 18:38:03 +0100 Subject: [PATCH 1/3] added todo_test_arc --- test/draw_test.py | 50 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/test/draw_test.py b/test/draw_test.py index 4429740b28..4c08f9dd3e 100644 --- a/test/draw_test.py +++ b/test/draw_test.py @@ -6160,9 +6160,55 @@ def test_arc__invalid_color_formats(self): with self.assertRaises(TypeError): bounds_rect = self.draw_arc(**kwargs) - def todo_test_arc(self): + def test_arc__correct_drawing(self): """Ensure draw arc works correctly.""" - self.fail() + surfw, surfh = 500, 500 + surface = pygame.Surface((surfw, surfh)) + surface_color = pygame.Color("black") + surface.fill(surface_color) + arc_color = pygame.Color("white") + rectangles = [ + pygame.Rect((200, 200), (300 + i, 200 + i)) for i in range(-100, 50, 30) + ] # Test on different bounding rectangles + start = 0 + stop = 2 + + for rect in rectangles: + kwargs = { + "surface": surface, + "color": arc_color, + "rect": rect, + "start_angle": start, + "stop_angle": stop, + "width": 1, + } + + pygame.draw.arc(**kwargs) + + a, b = rect.width / 2, rect.height / 2 + number_of_valid_arc_points = 0 + number_of_invalid_arc_points = 0 + # Define a threshold for comparison + eps = 0.1 + center_x = rect.centerx + center_y = rect.centery + + for x in range(surfw): + for y in range(surfh): + # Check whether the point on the arc belongs to the ellipse defined by the bounding rectangle + if (surface.get_at((x, y)) == arc_color) and abs( + ((x - center_x) / a) ** 2 + ((y - center_y) / b) ** 2 - 1 + ) <= eps: + number_of_valid_arc_points += 1 + elif surface.get_at((x, y)) == arc_color: + number_of_invalid_arc_points += 1 + + surface.fill(surface_color) # Clear for the next test + + self.assertEqual( + number_of_valid_arc_points, + number_of_invalid_arc_points + number_of_valid_arc_points, + ) def test_arc__bounding_rect(self): """Ensures draw arc returns the correct bounding rect. From 409c679ea6841befef48714f539e077f886c9f6c Mon Sep 17 00:00:00 2001 From: Dan Lawrence Date: Mon, 12 Feb 2024 15:12:41 +0000 Subject: [PATCH 2/3] adjust test assertion on test review feedback. --- test/draw_test.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/draw_test.py b/test/draw_test.py index 4c08f9dd3e..7a048267b0 100644 --- a/test/draw_test.py +++ b/test/draw_test.py @@ -6205,10 +6205,7 @@ def test_arc__correct_drawing(self): surface.fill(surface_color) # Clear for the next test - self.assertEqual( - number_of_valid_arc_points, - number_of_invalid_arc_points + number_of_valid_arc_points, - ) + self.assertEqual(number_of_invalid_arc_points, 0) def test_arc__bounding_rect(self): """Ensures draw arc returns the correct bounding rect. From 9c90cd71619ead4f608a48d2f03e22a40f5c5887 Mon Sep 17 00:00:00 2001 From: Alexia Date: Wed, 20 Nov 2024 11:26:47 +0100 Subject: [PATCH 3/3] enhancing test for pygame.draw.arc --- test/draw_test.py | 65 +++++++++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/test/draw_test.py b/test/draw_test.py index 8c57834de9..478191d854 100644 --- a/test/draw_test.py +++ b/test/draw_test.py @@ -6204,39 +6204,60 @@ def test_arc__correct_drawing(self): rectangles = [ pygame.Rect((200, 200), (300 + i, 200 + i)) for i in range(-100, 50, 30) ] # Test on different bounding rectangles - start = 0 - stop = 2 + angle_pairs = [ + (0, 2), + (0, 3.14), + (1, 4), + (2, 5.5), + (0, 6.28), + ] # Test a variety of start and stop angles + widths = [ + -10, + -5, + -1, + 0, + 1, + 2, + 5, + 10, + 20, + 50, + 100, + ] # Test a wider range of stroke width for rect in rectangles: - kwargs = { - "surface": surface, - "color": arc_color, - "rect": rect, - "start_angle": start, - "stop_angle": stop, - "width": 1, - } - - pygame.draw.arc(**kwargs) - - a, b = rect.width / 2, rect.height / 2 - number_of_valid_arc_points = 0 - number_of_invalid_arc_points = 0 - # Define a threshold for comparison - eps = 0.1 - center_x = rect.centerx - center_y = rect.centery + for start, stop in angle_pairs: + for width in widths: + # A tolerance value that adapt to the width + tolerance_radius = min(max(0, width // 10), 1) + kwargs = { + "surface": surface, + "color": arc_color, + "rect": rect, + "start_angle": start, + "stop_angle": stop, + "width": width, + } + + pygame.draw.arc(**kwargs) + + a, b = rect.width / 2, rect.height / 2 + number_of_valid_arc_points = 0 + number_of_invalid_arc_points = 0 + # Define a threshold for comparison + eps = 0.01 + center_x = rect.centerx + center_y = rect.centery for x in range(surfw): for y in range(surfh): # Check whether the point on the arc belongs to the ellipse defined by the bounding rectangle if (surface.get_at((x, y)) == arc_color) and abs( ((x - center_x) / a) ** 2 + ((y - center_y) / b) ** 2 - 1 - ) <= eps: + ) <= eps + tolerance_radius: number_of_valid_arc_points += 1 elif surface.get_at((x, y)) == arc_color: number_of_invalid_arc_points += 1 - surface.fill(surface_color) # Clear for the next test self.assertEqual(number_of_invalid_arc_points, 0)