12
12
- numpy
13
13
"""
14
14
15
+ import doctest
16
+
15
17
import matplotlib .pyplot as plt
16
18
17
19
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 ]]:
19
29
"""
20
30
Generates the points for the Hilbert curve of the specified order.
21
31
@@ -28,6 +38,9 @@ def hilbert_curve(order, x0=0, y0=0, xi=1, xj=0, yi=0, yj=1):
28
38
- xi, xj: the transformation matrix for x coordinates
29
39
- yi, yj: the transformation matrix for y coordinates
30
40
41
+ Returns:
42
+ - A list of (x, y) coordinates representing the Hilbert curve.
43
+
31
44
>>> len(hilbert_curve(1))
32
45
5
33
46
>>> len(hilbert_curve(2))
@@ -65,9 +78,15 @@ def hilbert_curve(order, x0=0, y0=0, xi=1, xj=0, yi=0, yj=1):
65
78
return points
66
79
67
80
68
- def plot_hilbert_curve (points ) :
81
+ def plot_hilbert_curve (points : list [ tuple [ float , float ]]) -> None :
69
82
"""
70
83
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
71
90
"""
72
91
x , y = zip (* points )
73
92
plt .plot (x , y )
@@ -77,6 +96,8 @@ def plot_hilbert_curve(points):
77
96
78
97
79
98
if __name__ == "__main__" :
99
+ doctest .testmod ()
100
+
80
101
order = 5 # Order of the Hilbert curve
81
102
curve_points = hilbert_curve (order )
82
103
plot_hilbert_curve (curve_points )
0 commit comments