@@ -7121,9 +7121,73 @@ def test_arc__invalid_color_formats(self):
71217121 with self .assertRaises (TypeError ):
71227122 bounds_rect = self .draw_arc (** kwargs )
71237123
7124- def todo_test_arc (self ):
7124+ def test_arc__correct_drawing (self ):
71257125 """Ensure draw arc works correctly."""
7126- self .fail ()
7126+ surfw , surfh = 500 , 500
7127+ surface = pygame .Surface ((surfw , surfh ))
7128+ surface_color = pygame .Color ("black" )
7129+ surface .fill (surface_color )
7130+ arc_color = pygame .Color ("white" )
7131+ rectangles = [
7132+ pygame .Rect ((200 , 200 ), (300 + i , 200 + i )) for i in range (- 100 , 50 , 30 )
7133+ ] # Test on different bounding rectangles
7134+ angle_pairs = [
7135+ (0 , 2 ),
7136+ (0 , 3.14 ),
7137+ (1 , 4 ),
7138+ (2 , 5.5 ),
7139+ (0 , 6.28 ),
7140+ ] # Test a variety of start and stop angles
7141+ widths = [
7142+ - 10 ,
7143+ - 5 ,
7144+ - 1 ,
7145+ 0 ,
7146+ 1 ,
7147+ 2 ,
7148+ 5 ,
7149+ 10 ,
7150+ 20 ,
7151+ 50 ,
7152+ 100 ,
7153+ ] # Test a wider range of stroke width
7154+
7155+ for rect in rectangles :
7156+ for start , stop in angle_pairs :
7157+ for width in widths :
7158+ # A tolerance value that adapt to the width
7159+ tolerance_radius = min (max (0 , width // 10 ), 1 )
7160+ kwargs = {
7161+ "surface" : surface ,
7162+ "color" : arc_color ,
7163+ "rect" : rect ,
7164+ "start_angle" : start ,
7165+ "stop_angle" : stop ,
7166+ "width" : width ,
7167+ }
7168+
7169+ pygame .draw .arc (** kwargs )
7170+
7171+ a , b = rect .width / 2 , rect .height / 2
7172+ number_of_valid_arc_points = 0
7173+ number_of_invalid_arc_points = 0
7174+ # Define a threshold for comparison
7175+ eps = 0.01
7176+ center_x = rect .centerx
7177+ center_y = rect .centery
7178+
7179+ for x in range (surfw ):
7180+ for y in range (surfh ):
7181+ # Check whether the point on the arc belongs to the ellipse defined by the bounding rectangle
7182+ if (surface .get_at ((x , y )) == arc_color ) and abs (
7183+ ((x - center_x ) / a ) ** 2 + ((y - center_y ) / b ) ** 2 - 1
7184+ ) <= eps + tolerance_radius :
7185+ number_of_valid_arc_points += 1
7186+ elif surface .get_at ((x , y )) == arc_color :
7187+ number_of_invalid_arc_points += 1
7188+ surface .fill (surface_color ) # Clear for the next test
7189+
7190+ self .assertEqual (number_of_invalid_arc_points , 0 )
71277191
71287192 def test_arc__bounding_rect (self ):
71297193 """Ensures draw arc returns the correct bounding rect.
0 commit comments