Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9ccfe60

Browse files
committed
Ignore STOP and CLOSPOLY codes when calculating path extents
1 parent7a0d656 commit9ccfe60

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
ifself.codesisNone:
622622
xys=self.vertices
623623
eliflen(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
forcurve,codeinself.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
assertnp.all(path.get_extents().extents==extents)
103103

104104

105+
@pytest.mark.parametrize('ignored_code', [Path.CLOSEPOLY,Path.STOP])
106+
deftest_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+
assertnp.all(path.get_extents().extents== (0.,0.,1.,1.))
113+
114+
105115
deftest_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)

[8]ページ先頭

©2009-2025 Movatter.jp