Skip to content

Commit b8422c7

Browse files
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
1 parent 2c15b8c commit b8422c7

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

graphics/digital_differential_analyzer_line.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,27 @@ def digital_differential_analyzer_line(
55
p1: tuple[int, int], p2: tuple[int, int]
66
) -> list[tuple[int, int]]:
77
"""
8-
Draws a line between two points using the DDA algorithm.
8+
9+
Digital Differential Analyzer (DDA) Line Drawing Algorithm.
10+
11+
This algorithm draws a straight line between two points by calculating
12+
the difference in x (dx) and y (dy) coordinates and incrementally stepping
13+
through the dominant axis while updating the other axis using fractional
14+
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.
23+
24+
For more details, see:
25+
https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
26+
27+
28+
929
1030
Args:
1131
- p1: Coordinates of the starting point.

0 commit comments

Comments
 (0)