Skip to content

Commit 3e364cd

Browse files
committed
added todo_test_arc
1 parent 06572ce commit 3e364cd

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

test/draw_test.py

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6160,9 +6160,55 @@ def test_arc__invalid_color_formats(self):
61606160
with self.assertRaises(TypeError):
61616161
bounds_rect = self.draw_arc(**kwargs)
61626162

6163-
def todo_test_arc(self):
6163+
def test_arc__correct_drawing(self):
61646164
"""Ensure draw arc works correctly."""
6165-
self.fail()
6165+
surfw, surfh = 500, 500
6166+
surface = pygame.Surface((surfw, surfh))
6167+
surface_color = pygame.Color("black")
6168+
surface.fill(surface_color)
6169+
arc_color = pygame.Color("white")
6170+
rectangles = [
6171+
pygame.Rect((200, 200), (300 + i, 200 + i)) for i in range(-100, 50, 30)
6172+
] # Test on different bounding rectangles
6173+
start = 0
6174+
stop = 2
6175+
6176+
for rect in rectangles:
6177+
kwargs = {
6178+
"surface": surface,
6179+
"color": arc_color,
6180+
"rect": rect,
6181+
"start_angle": start,
6182+
"stop_angle": stop,
6183+
"width": 1,
6184+
}
6185+
6186+
pygame.draw.arc(**kwargs)
6187+
6188+
a, b = rect.width / 2, rect.height / 2
6189+
number_of_valid_arc_points = 0
6190+
number_of_invalid_arc_points = 0
6191+
# Define a threshold for comparison
6192+
eps = 0.1
6193+
center_x = rect.centerx
6194+
center_y = rect.centery
6195+
6196+
for x in range(surfw):
6197+
for y in range(surfh):
6198+
# Check whether the point on the arc belongs to the ellipse defined by the bounding rectangle
6199+
if (surface.get_at((x, y)) == arc_color) and abs(
6200+
((x - center_x) / a) ** 2 + ((y - center_y) / b) ** 2 - 1
6201+
) <= eps:
6202+
number_of_valid_arc_points += 1
6203+
elif surface.get_at((x, y)) == arc_color:
6204+
number_of_invalid_arc_points += 1
6205+
6206+
surface.fill(surface_color) # Clear for the next test
6207+
6208+
self.assertEqual(
6209+
number_of_valid_arc_points,
6210+
number_of_invalid_arc_points + number_of_valid_arc_points,
6211+
)
61666212

61676213
def test_arc__bounding_rect(self):
61686214
"""Ensures draw arc returns the correct bounding rect.

0 commit comments

Comments
 (0)