Skip to content

Commit 1e2fea7

Browse files
anntzertimhoffm
authored andcommitted
Simplify use of Path._fast_from_codes_and_verts. (#12868)
All uses of Path._fast_from_codes_and_verts create the internals dict by copying the attribute from another Path. Instead of having the caller create that dict, just let him pass a Path from which to copy the attributes. Note that this means that the copying will now also use the simplify_threshold from the previous Path; however I think it is clear that the previous behavior of not copying it was an oversight (compounded by the fact that simplify_threshold is rarely, if ever, overwritten on a per-Path basis).
1 parent 61dec52 commit 1e2fea7

File tree

2 files changed

+26
-36
lines changed

2 files changed

+26
-36
lines changed

lib/matplotlib/path.py

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -157,35 +157,32 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,
157157
self._readonly = False
158158

159159
@classmethod
160-
def _fast_from_codes_and_verts(cls, verts, codes, internals=None):
160+
def _fast_from_codes_and_verts(cls, verts, codes, internals_from=None):
161161
"""
162-
Creates a Path instance without the expense of calling the constructor
162+
Creates a Path instance without the expense of calling the constructor.
163163
164164
Parameters
165165
----------
166166
verts : numpy array
167167
codes : numpy array
168-
internals : dict or None
169-
The attributes that the resulting path should have. Allowed keys
170-
are ``readonly``, ``should_simplify``, ``simplify_threshold``, and
171-
``interpolation_steps``.
172-
168+
internals_from : Path or None
169+
If not None, another `Path` from which the attributes
170+
``should_simplify``, ``simplify_threshold``, and
171+
``interpolation_steps`` will be copied. Note that ``readonly`` is
172+
never copied, and always set to ``False`` by this constructor.
173173
"""
174-
internals = internals or {}
175174
pth = cls.__new__(cls)
176175
pth._vertices = _to_unmasked_float_array(verts)
177176
pth._codes = codes
178-
pth._readonly = internals.pop('readonly', False)
179-
pth.should_simplify = internals.pop('should_simplify', True)
180-
pth.simplify_threshold = (
181-
internals.pop('simplify_threshold',
182-
rcParams['path.simplify_threshold'])
183-
)
184-
pth._interpolation_steps = internals.pop('interpolation_steps', 1)
185-
if internals:
186-
raise ValueError('Unexpected internals provided to '
187-
'_fast_from_codes_and_verts: '
188-
'{0}'.format('\n *'.join(internals)))
177+
pth._readonly = False
178+
if internals_from is not None:
179+
pth._should_simplify = internals_from._should_simplify
180+
pth._simplify_threshold = internals_from._simplify_threshold
181+
pth._interpolation_steps = internals_from._interpolation_steps
182+
else:
183+
pth._should_simplify = True
184+
pth._simplify_threshold = rcParams['path.simplify_threshold']
185+
pth._interpolation_steps = 1
189186
return pth
190187

191188
def _update_values(self):
@@ -436,14 +433,13 @@ def cleaned(self, transform=None, remove_nans=False, clip=None,
436433
-------
437434
Path instance with cleaned up vertices and codes.
438435
"""
439-
vertices, codes = _path.cleanup_path(self, transform,
440-
remove_nans, clip,
441-
snap, stroke_width,
442-
simplify, curves, sketch)
443-
internals = {'should_simplify': self.should_simplify and not simplify,
444-
'simplify_threshold': self.simplify_threshold,
445-
'interpolation_steps': self._interpolation_steps}
446-
return Path._fast_from_codes_and_verts(vertices, codes, internals)
436+
vertices, codes = _path.cleanup_path(
437+
self, transform, remove_nans, clip, snap, stroke_width, simplify,
438+
curves, sketch)
439+
pth = Path._fast_from_codes_and_verts(vertices, codes, self)
440+
if not simplify:
441+
pth._should_simplify = False
442+
return pth
447443

448444
def transformed(self, transform):
449445
"""

lib/matplotlib/transforms.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,9 +1552,7 @@ def transform_path_non_affine(self, path):
15521552
``transform_path_affine(transform_path_non_affine(values))``.
15531553
"""
15541554
x = self.transform_non_affine(path.vertices)
1555-
return Path._fast_from_codes_and_verts(x, path.codes,
1556-
{'interpolation_steps': path._interpolation_steps,
1557-
'should_simplify': path.should_simplify})
1555+
return Path._fast_from_codes_and_verts(x, path.codes, path)
15581556

15591557
def transform_angles(self, angles, pts, radians=False, pushoff=1e-5):
15601558
"""
@@ -2762,9 +2760,7 @@ def _revalidate(self):
27622760
self._transformed_points = \
27632761
Path._fast_from_codes_and_verts(
27642762
self._transform.transform_non_affine(self._path.vertices),
2765-
None,
2766-
{'interpolation_steps': self._path._interpolation_steps,
2767-
'should_simplify': self._path.should_simplify})
2763+
None, self._path)
27682764
self._invalid = 0
27692765

27702766
def get_transformed_points_and_affine(self):
@@ -2832,9 +2828,7 @@ def _revalidate(self):
28322828
self._transformed_points = \
28332829
Path._fast_from_codes_and_verts(
28342830
self._transform.transform_non_affine(patch_path.vertices),
2835-
None,
2836-
{'interpolation_steps': patch_path._interpolation_steps,
2837-
'should_simplify': patch_path.should_simplify})
2831+
None, patch_path)
28382832
self._invalid = 0
28392833

28402834

0 commit comments

Comments
 (0)