Skip to content

Commit 9c90cd7

Browse files
author
Alexia
committed
enhancing test for pygame.draw.arc
1 parent cd88289 commit 9c90cd7

File tree

1 file changed

+43
-22
lines changed

1 file changed

+43
-22
lines changed

test/draw_test.py

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6204,39 +6204,60 @@ def test_arc__correct_drawing(self):
62046204
rectangles = [
62056205
pygame.Rect((200, 200), (300 + i, 200 + i)) for i in range(-100, 50, 30)
62066206
] # Test on different bounding rectangles
6207-
start = 0
6208-
stop = 2
6207+
angle_pairs = [
6208+
(0, 2),
6209+
(0, 3.14),
6210+
(1, 4),
6211+
(2, 5.5),
6212+
(0, 6.28),
6213+
] # Test a variety of start and stop angles
6214+
widths = [
6215+
-10,
6216+
-5,
6217+
-1,
6218+
0,
6219+
1,
6220+
2,
6221+
5,
6222+
10,
6223+
20,
6224+
50,
6225+
100,
6226+
] # Test a wider range of stroke width
62096227

62106228
for rect in rectangles:
6211-
kwargs = {
6212-
"surface": surface,
6213-
"color": arc_color,
6214-
"rect": rect,
6215-
"start_angle": start,
6216-
"stop_angle": stop,
6217-
"width": 1,
6218-
}
6219-
6220-
pygame.draw.arc(**kwargs)
6221-
6222-
a, b = rect.width / 2, rect.height / 2
6223-
number_of_valid_arc_points = 0
6224-
number_of_invalid_arc_points = 0
6225-
# Define a threshold for comparison
6226-
eps = 0.1
6227-
center_x = rect.centerx
6228-
center_y = rect.centery
6229+
for start, stop in angle_pairs:
6230+
for width in widths:
6231+
# A tolerance value that adapt to the width
6232+
tolerance_radius = min(max(0, width // 10), 1)
6233+
kwargs = {
6234+
"surface": surface,
6235+
"color": arc_color,
6236+
"rect": rect,
6237+
"start_angle": start,
6238+
"stop_angle": stop,
6239+
"width": width,
6240+
}
6241+
6242+
pygame.draw.arc(**kwargs)
6243+
6244+
a, b = rect.width / 2, rect.height / 2
6245+
number_of_valid_arc_points = 0
6246+
number_of_invalid_arc_points = 0
6247+
# Define a threshold for comparison
6248+
eps = 0.01
6249+
center_x = rect.centerx
6250+
center_y = rect.centery
62296251

62306252
for x in range(surfw):
62316253
for y in range(surfh):
62326254
# Check whether the point on the arc belongs to the ellipse defined by the bounding rectangle
62336255
if (surface.get_at((x, y)) == arc_color) and abs(
62346256
((x - center_x) / a) ** 2 + ((y - center_y) / b) ** 2 - 1
6235-
) <= eps:
6257+
) <= eps + tolerance_radius:
62366258
number_of_valid_arc_points += 1
62376259
elif surface.get_at((x, y)) == arc_color:
62386260
number_of_invalid_arc_points += 1
6239-
62406261
surface.fill(surface_color) # Clear for the next test
62416262

62426263
self.assertEqual(number_of_invalid_arc_points, 0)

0 commit comments

Comments
 (0)