pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/matplotlib/matplotlib/commit/9ccfe60ad071bc6ff3918973c13e08c3f7de12ee

css" /> Ignore STOP and CLOSPOLY codes when calculating path extents · matplotlib/matplotlib@9ccfe60 · GitHub
Skip to content

Commit 9ccfe60

Browse files
committed
Ignore STOP and CLOSPOLY codes when calculating path extents
1 parent 7a0d656 commit 9ccfe60

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/matplotlib/path.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,12 @@ def get_extents(self, transform=None, **kwargs):
621621
if self.codes is None:
622622
xys = self.vertices
623623
elif len(np.intersect1d(self.codes, [Path.CURVE3, Path.CURVE4])) == 0:
624-
xys = self.vertices[self.codes != Path.CLOSEPOLY]
624+
# Optimization for the straight line case.
625+
# Instead of iterating through each curve, consider
626+
# each line segment's end-points
627+
# (recall that STOP and CLOSEPOLY vertices are ignored)
628+
xys = self.vertices[np.isin(self.codes,
629+
[Path.MOVETO, Path.LINETO])]
625630
else:
626631
xys = []
627632
for curve, code in self.iter_bezier(**kwargs):

lib/matplotlib/tests/test_path.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,16 @@ def test_exact_extents(path, extents):
102102
assert np.all(path.get_extents().extents == extents)
103103

104104

105+
@pytest.mark.parametrize('ignored_code', [Path.CLOSEPOLY, Path.STOP])
106+
def test_extents_with_ignored_codes(ignored_code):
107+
# Check that STOP and CLOSEPOLY points are ignored when calculating extents
108+
# of a path with only straight lines
109+
path = Path([[0, 0],
110+
[1, 1],
111+
[2, 2]], [Path.MOVETO, Path.MOVETO, ignored_code])
112+
assert np.all(path.get_extents().extents == (0., 0., 1., 1.))
113+
114+
105115
def test_point_in_path_nan():
106116
box = np.array([[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
107117
p = Path(box)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy