Skip to content

Commit 4a6642a

Browse files
committed
better coding style
1 parent 77ebcc4 commit 4a6642a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

fractals/hilbert_curve.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,20 @@
1212
- numpy
1313
"""
1414

15+
import doctest
16+
1517
import matplotlib.pyplot as plt
1618

1719

18-
def hilbert_curve(order, x0=0, y0=0, xi=1, xj=0, yi=0, yj=1):
20+
def hilbert_curve(
21+
order: int,
22+
x0: float = 0,
23+
y0: float = 0,
24+
xi: float = 1,
25+
xj: float = 0,
26+
yi: float = 0,
27+
yj: float = 1,
28+
) -> list[tuple[float, float]]:
1929
"""
2030
Generates the points for the Hilbert curve of the specified order.
2131
@@ -28,6 +38,9 @@ def hilbert_curve(order, x0=0, y0=0, xi=1, xj=0, yi=0, yj=1):
2838
- xi, xj: the transformation matrix for x coordinates
2939
- yi, yj: the transformation matrix for y coordinates
3040
41+
Returns:
42+
- A list of (x, y) coordinates representing the Hilbert curve.
43+
3144
>>> len(hilbert_curve(1))
3245
5
3346
>>> len(hilbert_curve(2))
@@ -65,9 +78,15 @@ def hilbert_curve(order, x0=0, y0=0, xi=1, xj=0, yi=0, yj=1):
6578
return points
6679

6780

68-
def plot_hilbert_curve(points):
81+
def plot_hilbert_curve(points: list[tuple[float, float]]) -> None:
6982
"""
7083
Plots the Hilbert curve using matplotlib.
84+
85+
Parameters:
86+
- points: A list of (x, y) coordinates representing the Hilbert curve.
87+
88+
Returns:
89+
- None
7190
"""
7291
x, y = zip(*points)
7392
plt.plot(x, y)
@@ -77,6 +96,8 @@ def plot_hilbert_curve(points):
7796

7897

7998
if __name__ == "__main__":
99+
doctest.testmod()
100+
80101
order = 5 # Order of the Hilbert curve
81102
curve_points = hilbert_curve(order)
82103
plot_hilbert_curve(curve_points)

0 commit comments

Comments
 (0)