diff --git a/buildconfig/stubs/pygame/draw.pyi b/buildconfig/stubs/pygame/draw.pyi index 68ad3ace5b..b6d057f879 100644 --- a/buildconfig/stubs/pygame/draw.pyi +++ b/buildconfig/stubs/pygame/draw.pyi @@ -82,7 +82,6 @@ def aaline( color: ColorLike, start_pos: Point, end_pos: Point, - width: int = 1, ) -> Rect: ... def aalines( surface: Surface, diff --git a/docs/reST/ref/code_examples/draw_module_example.png b/docs/reST/ref/code_examples/draw_module_example.png index 6e3e6af13c..67234a985b 100644 Binary files a/docs/reST/ref/code_examples/draw_module_example.png and b/docs/reST/ref/code_examples/draw_module_example.png differ diff --git a/docs/reST/ref/draw.rst b/docs/reST/ref/draw.rst index 44ac398a3c..e9a6b76f5d 100644 --- a/docs/reST/ref/draw.rst +++ b/docs/reST/ref/draw.rst @@ -451,10 +451,8 @@ object around the draw calls (see :func:`pygame.Surface.lock` and | :sl:`draw a straight antialiased line` | :sg:`aaline(surface, color, start_pos, end_pos) -> Rect` - :sg:`aaline(surface, color, start_pos, end_pos, width=1) -> Rect` Draws a straight antialiased line on the given surface. There are no endcaps. - For thick lines the ends are squared off. .. note:: Regarding float values for coordinates, a point with coordinate @@ -476,11 +474,6 @@ object around the draw calls (see :func:`pygame.Surface.lock` and :param end_pos: end position of the line, (x, y) :type end_pos: tuple(int or float, int or float) or list(int or float, int or float) or Vector2(int or float, int or float) - :param int width: (optional) used for line thickness - - | if width >= 1, used for line thickness (default is 1) - | if width < 1, nothing will be drawn - | :returns: a rect bounding the changed pixels, if nothing is drawn the bounding rect's position will be the ``start_pos`` parameter value (float @@ -493,7 +486,6 @@ object around the draw calls (see :func:`pygame.Surface.lock` and .. versionchangedold:: 2.0.0 Added support for keyword arguments. .. versionchanged:: 2.4.0 Removed deprecated 'blend' argument .. versionchanged:: 2.5.0 ``blend`` argument readded for backcompat, but will always raise a deprecation exception when used - .. versionchanged:: 2.5.2 Added line width .. ## pygame.draw.aaline ## diff --git a/src_c/doc/draw_doc.h b/src_c/doc/draw_doc.h index 384936e90c..b47ac37250 100644 --- a/src_c/doc/draw_doc.h +++ b/src_c/doc/draw_doc.h @@ -8,5 +8,5 @@ #define DOC_DRAW_ARC "arc(surface, color, rect, start_angle, stop_angle) -> Rect\narc(surface, color, rect, start_angle, stop_angle, width=1) -> Rect\ndraw an elliptical arc" #define DOC_DRAW_LINE "line(surface, color, start_pos, end_pos) -> Rect\nline(surface, color, start_pos, end_pos, width=1) -> Rect\ndraw a straight line" #define DOC_DRAW_LINES "lines(surface, color, closed, points) -> Rect\nlines(surface, color, closed, points, width=1) -> Rect\ndraw multiple contiguous straight line segments" -#define DOC_DRAW_AALINE "aaline(surface, color, start_pos, end_pos) -> Rect\naaline(surface, color, start_pos, end_pos, width=1) -> Rect\ndraw a straight antialiased line" +#define DOC_DRAW_AALINE "aaline(surface, color, start_pos, end_pos) -> Rect\ndraw a straight antialiased line" #define DOC_DRAW_AALINES "aalines(surface, color, closed, points) -> Rect\ndraw multiple contiguous straight antialiased line segments" diff --git a/src_c/draw.c b/src_c/draw.c index 0d6b9fc8a8..d463380a63 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -124,12 +124,12 @@ aaline(PyObject *self, PyObject *arg, PyObject *kwargs) int drawn_area[4] = {INT_MAX, INT_MAX, INT_MIN, INT_MIN}; /* Used to store bounding box values */ Uint32 color; - static char *keywords[] = {"surface", "color", "start_pos", "end_pos", - "width", "blend", NULL}; + static char *keywords[] = {"surface", "color", "start_pos", + "end_pos", "blend", NULL}; - if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OOO|iO", keywords, + if (!PyArg_ParseTupleAndKeywords(arg, kwargs, "O!OOO|O", keywords, &pgSurface_Type, &surfobj, &colorobj, - &start, &end, &width, &blend)) { + &start, &end, &blend)) { return NULL; /* Exception already set. */ } diff --git a/test/draw_test.py b/test/draw_test.py index 872e72ee58..b68a1756b8 100644 --- a/test/draw_test.py +++ b/test/draw_test.py @@ -2455,7 +2455,7 @@ def test_aaline__blend_warning(self): warnings.simplefilter("always") # Trigger DeprecationWarning. self.draw_aaline( - pygame.Surface((2, 2)), (0, 0, 0, 50), (0, 0), (2, 2), 1, blend + pygame.Surface((2, 2)), (0, 0, 0, 50), (0, 0), (2, 2), blend ) # Check if there is only one warning and is a DeprecationWarning. self.assertEqual(len(w), count + 1) @@ -2467,14 +2467,12 @@ def test_aaline__kwargs(self): color = pygame.Color("yellow") start_pos = (1, 1) end_pos = (2, 2) - width = 2 kwargs_list = [ { "surface": surface, "color": color, "start_pos": start_pos, "end_pos": end_pos, - "width": width, }, ] @@ -2487,7 +2485,6 @@ def test_aaline__kwargs_order_independent(self): """Ensures draw aaline's kwargs are not order dependent.""" bounds_rect = self.draw_aaline( start_pos=(1, 2), - width=2, end_pos=(2, 1), color=(10, 20, 30), surface=pygame.Surface((3, 2)), @@ -2519,7 +2516,6 @@ def test_aaline__kwargs_missing(self): "color": pygame.Color("red"), "start_pos": (2, 1), "end_pos": (2, 2), - "width": 2, } for name in ("end_pos", "start_pos", "color", "surface"): @@ -2558,42 +2554,30 @@ def test_aaline__kwarg_invalid_types(self): color = pygame.Color("green") start_pos = (1, 0) end_pos = (2, 0) - width = 1 kwargs_list = [ { "surface": pygame.Surface, # Invalid surface. "color": color, "start_pos": start_pos, "end_pos": end_pos, - "width": width, }, { "surface": surface, "color": 2.3, # Invalid color. "start_pos": start_pos, "end_pos": end_pos, - "width": width, }, { "surface": surface, "color": color, "start_pos": (0, 0, 0), # Invalid start_pos. "end_pos": end_pos, - "width": width, }, { "surface": surface, "color": color, "start_pos": start_pos, "end_pos": (0,), # Invalid end_pos. - "width": width, - }, - { - "surface": surface, - "color": color, - "start_pos": start_pos, - "end_pos": (0,), - "width": 1.2, # Invalid width. }, ] @@ -2607,14 +2591,12 @@ def test_aaline__kwarg_invalid_name(self): color = pygame.Color("cyan") start_pos = (1, 1) end_pos = (2, 0) - width = 1 kwargs_list = [ { "surface": surface, "color": color, "start_pos": start_pos, "end_pos": end_pos, - "width": width, "invalid": 1, }, { @@ -2636,16 +2618,14 @@ def test_aaline__args_and_kwargs(self): color = (255, 255, 0, 0) start_pos = (0, 1) end_pos = (1, 2) - width = 1 kwargs = { "surface": surface, "color": color, "start_pos": start_pos, "end_pos": end_pos, - "width": width, } - for name in ("surface", "color", "start_pos", "end_pos", "width"): + for name in ("surface", "color", "start_pos", "end_pos"): kwargs.pop(name) if "surface" == name: @@ -2665,30 +2645,6 @@ def test_aaline__args_and_kwargs(self): self.assertIsInstance(bounds_rect, pygame.Rect) - def test_aaline__valid_width_values(self): - """Ensures draw aaline accepts different width values.""" - line_color = pygame.Color("yellow") - surface_color = pygame.Color("white") - surface = pygame.Surface((3, 4)) - pos = (2, 1) - kwargs = { - "surface": surface, - "color": line_color, - "start_pos": pos, - "end_pos": (2, 2), - "width": None, - } - - for width in (-100, -10, -1, 0, 1, 10, 100): - surface.fill(surface_color) # Clear for each test. - kwargs["width"] = width - expected_color = line_color if width > 0 else surface_color - - bounds_rect = self.draw_aaline(**kwargs) - - self.assertEqual(surface.get_at(pos), expected_color) - self.assertIsInstance(bounds_rect, pygame.Rect) - def test_aaline__valid_start_pos_formats(self): """Ensures draw aaline accepts different start_pos formats.""" expected_color = pygame.Color("red") @@ -2699,7 +2655,6 @@ def test_aaline__valid_start_pos_formats(self): "color": expected_color, "start_pos": None, "end_pos": (2, 2), - "width": 2, } x, y = 2, 1 # start position positions = ((x, y), (x + 0.01, y), (x, y + 0.01), (x + 0.01, y + 0.01)) @@ -2728,7 +2683,6 @@ def test_aaline__valid_end_pos_formats(self): "color": expected_color, "start_pos": (2, 1), "end_pos": None, - "width": 2, } x, y = 2, 2 # end position positions = ((x, y), (x + 0.02, y), (x, y + 0.02), (x + 0.02, y + 0.02)) @@ -2754,7 +2708,6 @@ def test_aaline__invalid_start_pos_formats(self): "color": pygame.Color("red"), "start_pos": None, "end_pos": (2, 2), - "width": 2, } start_pos_fmts = ( @@ -2778,7 +2731,6 @@ def test_aaline__invalid_end_pos_formats(self): "color": pygame.Color("red"), "start_pos": (2, 2), "end_pos": None, - "width": 2, } end_pos_fmts = ( @@ -2806,7 +2758,6 @@ def test_aaline__valid_color_formats(self): "color": None, "start_pos": pos, "end_pos": (2, 1), - "width": 2, } greens = ( (0, 255, 0), @@ -2836,7 +2787,6 @@ def test_aaline__invalid_color_formats(self): "color": None, "start_pos": (1, 1), "end_pos": (2, 1), - "width": 2, } for expected_color in (2.3, self): @@ -2854,17 +2804,6 @@ def test_aaline__color(self): self.assertEqual(surface.get_at(pos), expected_color, f"pos={pos}") - def test_aaline__color_with_thickness(self): - """Ensures a thick aaline is drawn using the correct color.""" - from_x = 5 - to_x = 10 - y = 5 - for surface in self._create_surfaces(): - for expected_color in self.COLORS: - self.draw_aaline(surface, expected_color, (from_x, y), (to_x, y), 5) - for pos in ((x, y + i) for i in (-2, 0, 2) for x in (from_x, to_x)): - self.assertEqual(surface.get_at(pos), expected_color, f"pos={pos}") - def test_aaline__gaps(self): """Tests if the aaline drawn contains any gaps. @@ -2879,26 +2818,10 @@ def test_aaline__gaps(self): pos = (x, 0) self.assertEqual(surface.get_at(pos), expected_color, f"pos={pos}") - def test_line__gaps_with_thickness(self): - """Ensures a thick aaline is drawn without any gaps.""" - expected_color = (255, 255, 255) - thickness = 5 - for surface in self._create_surfaces(): - width = surface.get_width() - 1 - h = width // 5 - w = h * 5 - self.draw_aaline(surface, expected_color, (0, 5), (w, 5 + h), thickness) - - for x in range(w + 1): - for y in range(3, 8): - pos = (x, y + ((x + 2) // 5)) - self.assertEqual(surface.get_at(pos), expected_color, f"pos={pos}") - def test_aaline__bounding_rect(self): """Ensures draw aaline returns the correct bounding rect. - Test lines with endpoints on and off the surface and a range of - width/thickness values. + Test lines with endpoints on and off the surface. """ line_color = pygame.Color("red") @@ -2918,32 +2841,20 @@ def test_aaline__bounding_rect(self): for pos in rect_corners_mids_and_center(surf_rect): helper_rect.center = pos - # Draw using different thicknesses. - for thickness in range(-1, 5): - for start, end in self._rect_lines(helper_rect): - surface.fill(surf_color) # Clear for each test. + for start, end in self._rect_lines(helper_rect): + surface.fill(surf_color) # Clear for each test. - bounding_rect = self.draw_aaline( - surface, line_color, start, end, thickness - ) + bounding_rect = self.draw_aaline(surface, line_color, start, end) - if 0 < thickness: - # Calculating the expected_rect after the line is - # drawn (it uses what is actually drawn). - expected_rect = create_bounding_rect( - surface, surf_color, start - ) - else: - # Nothing drawn. - expected_rect = pygame.Rect(start, (0, 0)) + # Calculating the expected_rect after the line is + # drawn (it uses what is actually drawn). + expected_rect = create_bounding_rect(surface, surf_color, start) - self.assertEqual( - bounding_rect, - expected_rect, - "start={}, end={}, size={}, thickness={}".format( - start, end, size, thickness - ), - ) + self.assertEqual( + bounding_rect, + expected_rect, + "start={}, end={}, size={}".format(start, end, size), + ) def test_aaline__surface_clip(self): """Ensures draw aaline respects a surface's clip area.""" @@ -2957,52 +2868,47 @@ def test_aaline__surface_clip(self): clip_rect.center = surface.get_rect().center pos_rect = clip_rect.copy() # Manages the aaline's pos. - for thickness in (1, 3): # Test different line widths. - # Test centering the pos_rect along the clip rect's edge to allow for - # drawing the aaline over the clip_rect's bounds. - for center in rect_corners_mids_and_center(clip_rect): - pos_rect.center = center + # Test centering the pos_rect along the clip rect's edge to allow for + # drawing the aaline over the clip_rect's bounds. + for center in rect_corners_mids_and_center(clip_rect): + pos_rect.center = center - # Get the expected points by drawing the aaline without the - # clip area set. - surface.set_clip(None) - surface.fill(surface_color) - self.draw_aaline( - surface, - aaline_color, - pos_rect.midtop, - pos_rect.midbottom, - thickness, - ) + # Get the expected points by drawing the aaline without the + # clip area set. + surface.set_clip(None) + surface.fill(surface_color) + self.draw_aaline( + surface, + aaline_color, + pos_rect.midtop, + pos_rect.midbottom, + ) - expected_pts = get_color_points( - surface, surface_color, clip_rect, False - ) + expected_pts = get_color_points(surface, surface_color, clip_rect, False) - # Clear the surface and set the clip area. Redraw the aaline - # and check that only the clip area is modified. - surface.fill(surface_color) - surface.set_clip(clip_rect) + # Clear the surface and set the clip area. Redraw the aaline + # and check that only the clip area is modified. + surface.fill(surface_color) + surface.set_clip(clip_rect) - self.draw_aaline( - surface, - aaline_color, - pos_rect.midtop, - pos_rect.midbottom, - thickness, - ) + self.draw_aaline( + surface, + aaline_color, + pos_rect.midtop, + pos_rect.midbottom, + ) - surface.lock() # For possible speed up. + surface.lock() # For possible speed up. - # Check all the surface points to ensure the expected_pts - # are not surface_color. - for pt in ((x, y) for x in range(surfw) for y in range(surfh)): - if pt in expected_pts: - self.assertNotEqual(surface.get_at(pt), surface_color, pt) - else: - self.assertEqual(surface.get_at(pt), surface_color, pt) + # Check all the surface points to ensure the expected_pts + # are not surface_color. + for pt in ((x, y) for x in range(surfw) for y in range(surfh)): + if pt in expected_pts: + self.assertNotEqual(surface.get_at(pt), surface_color, pt) + else: + self.assertEqual(surface.get_at(pt), surface_color, pt) - surface.unlock() + surface.unlock() class DrawAALineTest(AALineMixin, DrawTestCase):