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)
| 215 | |
| 216 | |
| 217 | def get_path(hatchpattern, density=6): |
| 218 | """ |
| 219 | Given a hatch specifier, *hatchpattern*, generates Path to render |
| 220 | the hatch in a unit square. *density* is the number of lines per |
| 221 | unit square. |
| 222 | """ |
| 223 | density = int(density) |
| 224 | |
| 225 | patterns = [hatch_type(hatchpattern, density) |
| 226 | for hatch_type in _hatch_types] |
| 227 | num_vertices = sum([pattern.num_vertices for pattern in patterns]) |
| 228 | |
| 229 | if num_vertices == 0: |
| 230 | return Path(np.empty((0, 2))) |
| 231 | |
| 232 | vertices = np.empty((num_vertices, 2)) |
| 233 | codes = np.empty(num_vertices, Path.code_type) |
| 234 | |
| 235 | cursor = 0 |
| 236 | for pattern in patterns: |
| 237 | if pattern.num_vertices != 0: |
| 238 | vertices_chunk = vertices[cursor:cursor + pattern.num_vertices] |
| 239 | codes_chunk = codes[cursor:cursor + pattern.num_vertices] |
| 240 | pattern.set_vertices_and_codes(vertices_chunk, codes_chunk) |
| 241 | cursor += pattern.num_vertices |
| 242 | |
| 243 | return Path(vertices, codes) |
no test coverage detected
searching dependent graphs…