Skip to content

Simplify use of Path._fast_from_codes_and_verts. #12868

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 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 23 additions & 27 deletions lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,32 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
self._readonly = False

@classmethod
def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
"""
Creates a Path instance without the expense of calling the constructor
Creates a Path instance without the expense of calling the constructor.

Parameters
----------
verts : numpy array
codes : numpy array
internals : dict or None
The attributes that the resulting path should have. Allowed keys
are ``readonly``, ``should_simplify``, ``simplify_threshold``, and
``interpolation_steps``.

internals_from : Path or None
If not None, another `Path` from which the attributes
``should_simplify``, ``simplify_threshold``, and
``interpolation_steps`` will be copied. Note that ``readonly`` is
never copied, and always set to ``False`` by this constructor.
"""
internals = internals or {}
pth = cls.__new__(cls)
pth._vertices = _to_unmasked_float_array(verts)
pth._codes = codes
pth._readonly = internals.pop('readonly', False)
pth.should_simplify = internals.pop('should_simplify', True)
pth.simplify_threshold = (
internals.pop('simplify_threshold',
rcParams['path.simplify_threshold'])
)
pth._interpolation_steps = internals.pop('interpolation_steps', 1)
if internals:
raise ValueError('Unexpected internals provided to '
'_fast_from_codes_and_verts: '
'{0}'.format('\n *'.join(internals)))
pth._readonly = False
if internals_from is not None:
pth._should_simplify = internals_from._should_simplify
pth._simplify_threshold = internals_from._simplify_threshold
pth._interpolation_steps = internals_from._interpolation_steps
else:
pth._should_simplify = True
pth._simplify_threshold = rcParams['path.simplify_threshold']
pth._interpolation_steps = 1
return pth

def _update_values(self):
Expand Down Expand Up @@ -436,14 +433,13 @@ def cleaned(self, transform=None, remove_nans=False, clip=None,
-------
Path instance with cleaned up vertices and codes.
"""
vertices, codes = _path.cleanup_path(self, transform,
remove_nans, clip,
snap, stroke_width,
simplify, curves, sketch)
internals = {'should_simplify': self.should_simplify and not simplify,
'simplify_threshold': self.simplify_threshold,
'interpolation_steps': self._interpolation_steps}
return Path._fast_from_codes_and_verts(vertices, codes, internals)
vertices, codes = _path.cleanup_path(
self, transform, remove_nans, clip, snap, stroke_width, simplify,
curves, sketch)
pth = Path._fast_from_codes_and_verts(vertices, codes, self)
if not simplify:
pth._should_simplify = False
return pth

def transformed(self, transform):
"""
Expand Down
12 changes: 3 additions & 9 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1552,9 +1552,7 @@ def transform_path_non_affine(self, path):
``transform_path_affine(transform_path_non_affine(values))``.
"""
x = self.transform_non_affine(path.vertices)
return Path._fast_from_codes_and_verts(x, path.codes,
{'interpolation_steps': path._interpolation_steps,
'should_simplify': path.should_simplify})
return Path._fast_from_codes_and_verts(x, path.codes, path)

def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
"""
Expand Down Expand Up @@ -2762,9 +2760,7 @@ def _revalidate(self):
self._transformed_points = \
Path._fast_from_codes_and_verts(
self._transform.transform_non_affine(self._path.vertices),
None,
{'interpolation_steps': self._path._interpolation_steps,
'should_simplify': self._path.should_simplify})
None, self._path)
self._invalid = 0

def get_transformed_points_and_affine(self):
Expand Down Expand Up @@ -2832,9 +2828,7 @@ def _revalidate(self):
self._transformed_points = \
Path._fast_from_codes_and_verts(
self._transform.transform_non_affine(patch_path.vertices),
None,
{'interpolation_steps': patch_path._interpolation_steps,
'should_simplify': patch_path.should_simplify})
None, patch_path)
self._invalid = 0


Expand Down