Skip to content

Commit 255d82a

Browse files
committed
Cleanup dolphin example.
- Use NUM_VERTICES_PER_CODE table already present in lib. - I think the new version of `vertices.extend` is easier to read ("start at index i+1 and take npoints"). - vertices is already a float array.
1 parent 9a24fb7 commit 255d82a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

examples/shapes_and_collections/dolphin.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,19 @@
7575
parts = dolphin.split()
7676
i = 0
7777
code_map = {
78-
'M': (Path.MOVETO, 1),
79-
'C': (Path.CURVE4, 3),
80-
'L': (Path.LINETO, 1)}
78+
'M': Path.MOVETO,
79+
'C': Path.CURVE4,
80+
'L': Path.LINETO,
81+
}
8182

8283
while i < len(parts):
83-
code = parts[i]
84-
path_code, npoints = code_map[code]
84+
path_code = code_map[parts[i]]
85+
npoints = Path.NUM_VERTICES_FOR_CODE[path_code]
8586
codes.extend([path_code] * npoints)
86-
vertices.extend([[float(x) for x in y.split(',')] for y in
87-
parts[i + 1:i + npoints + 1]])
87+
vertices.extend([[*map(float, y.split(','))]
88+
for y in parts[i + 1:][:npoints]])
8889
i += npoints + 1
89-
vertices = np.array(vertices, float)
90+
vertices = np.array(vertices)
9091
vertices[:, 1] -= 160
9192

9293
dolphin_path = Path(vertices, codes)

0 commit comments

Comments
 (0)