|
| 1 | +from matplotlib.backend_bases import RendererBase |
| 2 | +import matplotlib.transforms as transforms |
| 3 | +import matplotlib.path as path |
| 4 | +import numpy as np |
| 5 | + |
| 6 | + |
| 7 | +def test_uses_per_path(): |
| 8 | + id = transforms.Affine2D() |
| 9 | + paths = [path.Path.unit_regular_polygon(i) for i in range(3, 7)] |
| 10 | + tforms = [id.rotate(i) for i in range(1, 5)] |
| 11 | + offsets = np.arange(20).reshape((10, 2)) |
| 12 | + facecolors = ['red', 'green'] |
| 13 | + edgecolors = ['red', 'green'] |
| 14 | + |
| 15 | + def check(master_transform, paths, all_transforms, |
| 16 | + offsets, facecolors, edgecolors): |
| 17 | + rb = RendererBase() |
| 18 | + raw_paths = list(rb._iter_collection_raw_paths(master_transform, |
| 19 | + paths, all_transforms)) |
| 20 | + gc = rb.new_gc() |
| 21 | + ids = [path_id for xo, yo, path_id, gc0, rgbFace in |
| 22 | + rb._iter_collection(gc, master_transform, all_transforms, |
| 23 | + range(len(raw_paths)), offsets, |
| 24 | + transforms.IdentityTransform(), |
| 25 | + facecolors, edgecolors, [], [], [False], |
| 26 | + [], 'data')] |
| 27 | + uses = rb._iter_collection_uses_per_path( |
| 28 | + paths, all_transforms, offsets, facecolors, edgecolors) |
| 29 | + seen = [0] * len(raw_paths) |
| 30 | + for i in ids: |
| 31 | + seen[i] += 1 |
| 32 | + for n in seen: |
| 33 | + assert n in (uses-1, uses) |
| 34 | + |
| 35 | + check(id, paths, tforms, offsets, facecolors, edgecolors) |
| 36 | + check(id, paths[0:1], tforms, offsets, facecolors, edgecolors) |
| 37 | + check(id, [], tforms, offsets, facecolors, edgecolors) |
| 38 | + check(id, paths, tforms[0:1], offsets, facecolors, edgecolors) |
| 39 | + check(id, paths, [], offsets, facecolors, edgecolors) |
| 40 | + for n in range(0, offsets.shape[0]): |
| 41 | + check(id, paths, tforms, offsets[0:n, :], facecolors, edgecolors) |
| 42 | + check(id, paths, tforms, offsets, [], edgecolors) |
| 43 | + check(id, paths, tforms, offsets, facecolors, []) |
| 44 | + check(id, paths, tforms, offsets, [], []) |
| 45 | + check(id, paths, tforms, offsets, facecolors[0:1], edgecolors) |
0 commit comments