Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Add TransformedPatchPath for clipping. #4920

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 30, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
TST: Add tests for Transformed(Patch)Path.
  • Loading branch information
QuLogic committed Oct 19, 2015
commit c2877b38f6aa6939fa48f506ed5b200ef20af0e1
44 changes: 43 additions & 1 deletion 44 lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import numpy.testing as np_test
from numpy.testing import assert_almost_equal, assert_array_equal
from numpy.testing import assert_array_almost_equal
from matplotlib.transforms import Affine2D, BlendedGenericTransform, Bbox
from matplotlib.transforms import (Affine2D, BlendedGenericTransform, Bbox,
TransformedPath, TransformedPatchPath)
from matplotlib.path import Path
from matplotlib.scale import LogScale
from matplotlib.testing.decorators import cleanup, image_comparison
Expand Down Expand Up @@ -576,6 +577,47 @@ def test_invalid_arguments():
assert_raises(RuntimeError, t.transform, [[1, 2, 3]])


def test_transformed_path():
points = [(0, 0), (1, 0), (1, 1), (0, 1)]
codes = [Path.MOVETO, Path.LINETO, Path.LINETO, Path.CLOSEPOLY]
path = Path(points, codes)

trans = mtrans.Affine2D()
trans_path = TransformedPath(path, trans)
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
points)

# Changing the transform should change the result.
r2 = 1 / np.sqrt(2)
trans.rotate(np.pi / 4)
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])

# Changing the path does not change the result (it's cached).
path.points = [(0, 0)] * 4
assert np.allclose(trans_path.get_fully_transformed_path().vertices,
[(0, 0), (r2, r2), (0, 2 * r2), (-r2, r2)])


def test_transformed_patch_path():
trans = mtrans.Affine2D()
patch = mpatches.Wedge((0, 0), 1, 45, 135, transform=trans)

tpatch = TransformedPatchPath(patch)
points = tpatch.get_fully_transformed_path().vertices

# Changing the transform should change the result.
trans.scale(2)
assert np.allclose(tpatch.get_fully_transformed_path().vertices,
points * 2)

# Changing the path should change the result (and cancel out the scaling
# from the transform).
patch.set_radius(0.5)
assert np.allclose(tpatch.get_fully_transformed_path().vertices,
points)


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.