Given a hatch specifier, *hatchpattern*, generates Path to render the hatch in a unit square. *density* is the number of lines per unit square.
(hatchpattern, density=6)
| 186 | |
| 187 | |
| 188 | def get_path(hatchpattern, density=6): |
| 189 | """ |
| 190 | Given a hatch specifier, *hatchpattern*, generates Path to render |
| 191 | the hatch in a unit square. *density* is the number of lines per |
| 192 | unit square. |
| 193 | """ |
| 194 | density = int(density) |
| 195 | |
| 196 | patterns = [hatch_type(hatchpattern, density) |
| 197 | for hatch_type in _hatch_types] |
| 198 | num_vertices = sum([pattern.num_vertices for pattern in patterns]) |
| 199 | |
| 200 | if num_vertices == 0: |
| 201 | return Path(np.empty((0, 2))) |
| 202 | |
| 203 | vertices = np.empty((num_vertices, 2)) |
| 204 | codes = np.empty((num_vertices,), np.uint8) |
| 205 | |
| 206 | cursor = 0 |
| 207 | for pattern in patterns: |
| 208 | if pattern.num_vertices != 0: |
| 209 | vertices_chunk = vertices[cursor:cursor + pattern.num_vertices] |
| 210 | codes_chunk = codes[cursor:cursor + pattern.num_vertices] |
| 211 | pattern.set_vertices_and_codes(vertices_chunk, codes_chunk) |
| 212 | cursor += pattern.num_vertices |
| 213 | |
| 214 | return Path(vertices, codes) |
no test coverage detected