Skip to content

Commit 566350d

Browse files
committed
fix(dda): fix docstring
1 parent ae68a78 commit 566350d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

graphics/digital_differential_analyzer_line.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@ 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) algorithm.
9+
10+
The DDA algorithm works by computing the differences in x and y (dx, dy),
11+
determining the dominant axis (the one with the larger absolute difference),
12+
and incrementing along it in small uniform steps. The other coordinate is
13+
updated by a proportional fractional amount at each iteration, producing a
14+
sequence of intermediate points that approximate a straight line.
15+
16+
While simple and widely used for teaching computer graphics, the algorithm
17+
relies on floating-point arithmetic and rounding at each step. This makes it
18+
less efficient and less precise than the integer-only Bresenham line algorithm,
19+
which is commonly preferred in performance-critical rasterization tasks.
920
1021
Args:
11-
- p1: Coordinates of the starting point.
12-
- p2: Coordinates of the ending point.
22+
p1: Coordinates of the starting point.
23+
p2: Coordinates of the ending point.
24+
1325
Returns:
14-
- List of coordinate points that form the line.
26+
List of coordinate points that form the line.
1527
1628
>>> digital_differential_analyzer_line((1, 1), (4, 4))
1729
[(2, 2), (3, 3), (4, 4)]
30+
31+
For more information, see:
32+
https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
1833
"""
1934
x1, y1 = p1
2035
x2, y2 = p2

0 commit comments

Comments
 (0)