Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2877b3

Browse files
committed
TST: Add tests for Transformed(Patch)Path.
1 parent 8357131 commit c2877b3

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lib/matplotlib/tests/test_transforms.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import numpy.testing as np_test
1111
from numpy.testing import assert_almost_equal, assert_array_equal
1212
from numpy.testing import assert_array_almost_equal
13-
from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox
13+
from matplotlib.transforms import (Affine2D, BlendedGenericTransform, Bbox,
14+
TransformedPath, TransformedPatchPath)
1415
from matplotlib.path import Path
1516
from matplotlib.scale import LogScale
1617
from matplotlib.testing.decorators import cleanup, image_comparison
@@ -576,6 +577,47 @@ def test_invalid_arguments():
576577
assert_raises(RuntimeError, t.transform, [[1, 2, 3]])
577578

578579

580+
def test_transformed_path():
581+
points = [(0, 0), (1, 0), (1, 1), (0, 1)]
582+
codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
583+
path = Path(points, codes)
584+
585+
trans = mtrans.Affine2D()
586+
trans_path = TransformedPath(path, trans)
587+
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
588+
points)
589+
590+
# Changing the transform should change the result.
591+
r2 = 1 / np.sqrt(2)
592+
trans.rotate(np.pi / 4)
593+
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
594+
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])
595+
596+
# Changing the path does not change the result (it's cached).
597+
path.points = [(0, 0)] * 4
598+
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
599+
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])
600+
601+
602+
def test_transformed_patch_path():
603+
trans = mtrans.Affine2D()
604+
patch = mpatches.Wedge((0, 0), 1, 45, 135, transform=trans)
605+
606+
tpatch = TransformedPatchPath(patch)
607+
points = tpatch.get_fully_transformed_path().vertices
608+
609+
# Changing the transform should change the result.
610+
trans.scale(2)
611+
assert np.allclose(tpatch.get_fully_transformed_path().vertices,
612+
points * 2)
613+
614+
# Changing the path should change the result (and cancel out the scaling
615+
# from the transform).
616+
patch.set_radius(0.5)
617+
assert np.allclose(tpatch.get_fully_transformed_path().vertices,
618+
points)
619+
620+
579621
if __name__ == '__main__':
580622
import nose
581623
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)