Skip to content

Commit 89343fd

Browse files
tanishka-sonawanepre-commit-ci[bot]cclauss
authored
improve docstring for DDA algorithm (#14029)
* improve docstring for DDA algorithm Fixes #13905 Improves the DDA algorithm docstring by adding: - explanation of how the algorithm works - its main disadvantage - comparison with Bresenham algorithm - reference link for further reading * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * improve docstring for DDA algorithm Fixes #13905 Improves the DDA algorithm docstring by adding: - explanation of how the algorithm works - its main disadvantage - comparison with Bresenham algorithm - reference link for further reading * Refactor docstring for digital_differential_analyzer_line Updated the docstring to clarify the DDA algorithm description and removed redundant references. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 86af3bd commit 89343fd

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

graphics/digital_differential_analyzer_line.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
# https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
2+
13
import matplotlib.pyplot as plt
24

35

46
def digital_differential_analyzer_line(
57
p1: tuple[int, int], p2: tuple[int, int]
68
) -> list[tuple[int, int]]:
79
"""
8-
Draws a line between two points using the DDA algorithm.
10+
Digital Differential Analyzer (DDA) Line Drawing Algorithm.
11+
12+
Draw a straight line between two points by calculating the difference in
13+
x (dx) and y (dy) coordinates and incrementally stepping through the
14+
dominant axis while updating the other axis using fractional increments.
15+
16+
One of the main disadvantages of the DDA algorithm is its reliance on
17+
floating-point arithmetic, which can introduce rounding errors at each step.
18+
Because of this, it is generally slower and less accurate than the
19+
Bresenham line drawing algorithm, which uses only integer arithmetic.
20+
21+
Despite this, DDA is useful for educational purposes as it is simple
22+
to understand and demonstrates the basic idea of incremental line generation.
923
1024
Args:
11-
- p1: Coordinates of the starting point.
12-
- p2: Coordinates of the ending point.
25+
- p1: Coordinates of the starting point.
26+
- p2: Coordinates of the ending point.
1327
Returns:
14-
- List of coordinate points that form the line.
28+
- List of coordinate points that form the line.
1529
1630
>>> digital_differential_analyzer_line((1, 1), (4, 4))
1731
[(2, 2), (3, 3), (4, 4)]

0 commit comments

Comments
 (0)