From d059c70867bfe78da23efbfac9678203d669dc22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeanne=20Boussonni=C3=A8re?= Date: Mon, 21 Sep 2026 23:29:44 +0200 Subject: [PATCH] Docs: Improve docstring for DDA algorithm (#13906) * Docs: Improve docstring for DDA algorithm * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestion from @cclauss * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix typo in DDA algorithm description Corrected a typo in the comment regarding the DDA algorithm. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss --- graphics/digital_differential_analyzer_line.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/graphics/digital_differential_analyzer_line.py b/graphics/digital_differential_analyzer_line.py index b8d15ca38..ee5f50585 100644 --- a/graphics/digital_differential_analyzer_line.py +++ b/graphics/digital_differential_analyzer_line.py @@ -21,6 +21,15 @@ def digital_differential_analyzer_line( Despite this, DDA is useful for educational purposes as it is simple to understand and demonstrates the basic idea of incremental line generation. + This algorithm works by calculating the dx (change in x) and dy (change in y) and + then iteratively steps along the dominant axis, incrementing the other axis by a + fractional amount (the slope). + It is notable for its simplicity but also for its main disadvantage: + * it relies on floating-point arithmetic at every step, which is computationally + slow. + * it is generally outperformed by Bresenham's algorithm, which achieves the same + result using only integer-based math. + Args: - p1: Coordinates of the starting point. - p2: Coordinates of the ending point.