Skip to content

Commit f7febf5

Browse files
authored
Added doctest to function
1 parent c6043fc commit f7febf5

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

‎maths/line_intersection.py‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def determinant(a: float, b: float, c: float, d: float) -> float:
1818
# Function to compute the line equation coefficients from two points
1919
def line_coefficients(p1: list[float] | tuple, p2: list[float] | tuple) -> tuple:
2020
"""
21-
Computes the coefficients A, B, C of the line equation Ax + By + C = 0
21+
Computes the coefficients A, B, C of the line equation Ax + By + C = 0
2222
from two points.
2323
2424
Args:
@@ -27,7 +27,25 @@ def line_coefficients(p1: list[float] | tuple, p2: list[float] | tuple) -> tuple
2727
2828
Returns:
2929
tuple: Coefficients (A, B, C) of the line equation.
30+
31+
Examples:
32+
# Vertical line (x = constant)
33+
>>> line_coefficients([1, 0], [1, 2])
34+
(1, 0, 1)
35+
36+
# Horizontal line (y = constant)
37+
>>> line_coefficients([0, 1], [2, 1])
38+
(0.0, -1, 1)
39+
40+
# Diagonal line (positive slope)
41+
>>> line_coefficients([0, 0], [1, 1])
42+
(1.0, -1, 0)
43+
44+
# Diagonal line (negative slope)
45+
>>> line_coefficients([0, 1], [1, 0])
46+
(-1.0, -1, 1)
3047
"""
48+
3149
if p1[0] == p2[0]: # Vertical line
3250
return 1, 0, p1[0]
3351
else: # Non-vertical line

0 commit comments

Comments
 (0)