Skip to content

Commit 928a189

Browse files
committed
docs(graphics): improve DDA algorithm docstring explanation
1 parent 678dedb commit 928a189

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

graphics/digital_differential_analyzer_line.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@ 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+
Draw a line between two points using the Digital Differential Analyzer (DDA) algorithm.
99
10-
Args:
11-
- p1: Coordinates of the starting point.
12-
- p2: Coordinates of the ending point.
13-
Returns:
14-
- List of coordinate points that form the line.
10+
The DDA algorithm works by calculating dx and dy and incrementally stepping
11+
along the dominant axis while updating the other axis using fractional values.
1512
16-
>>> digital_differential_analyzer_line((1, 1), (4, 4))
17-
[(2, 2), (3, 3), (4, 4)]
13+
Advantages:
14+
- Simple and easy to understand implementation.
15+
16+
Disadvantages:
17+
- Uses floating-point arithmetic, which can introduce rounding errors.
18+
- Generally slower and less efficient than Bresenham's line algorithm,
19+
which relies only on integer calculations.
20+
21+
Reference:
22+
https://en.wikipedia.org/wiki/Digital_differential_analyzer_(graphics_algorithm)
1823
"""
1924
x1, y1 = p1
2025
x2, y2 = p2

0 commit comments

Comments
 (0)