Skip to content

Commit e3a0a84

Browse files
author
deepshekhardas
committed
docs: improve DDA algorithm docstring
Expand the docstring for digital_differential_analyzer_line with principle explanation, floating-point disadvantage, Bresenham comparison, and Wikipedia reference as requested. Fixes #13905
1 parent f5988cc commit e3a0a84

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

graphics/digital_differential_analyzer_line.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@ 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+
Draws a line between two points using the Digital Differential Analyzer (DDA)
9+
algorithm.
10+
11+
The DDA algorithm works by calculating dx and dy and then iteratively stepping
12+
along the dominant axis while incrementing the other axis by a fractional
13+
amount, rounding at each step to determine the next pixel.
14+
15+
This approach relies on floating-point arithmetic and rounding at every step,
16+
which can be slower and less accurate than integer-only methods. In practice
17+
it is generally outperformed by the Bresenham line algorithm, which uses
18+
only integer arithmetic.
19+
20+
More details: https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
921
1022
Args:
1123
- p1: Coordinates of the starting point.

0 commit comments

Comments
 (0)