Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b1b23a

Browse files
committed
replace Path.get_extents instead of adding new API
1 parent b8008ac commit 0b1b23a

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

lib/matplotlib/path.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -587,38 +587,26 @@ def contains_path(self, path, transform=None):
587587
transform = transform.frozen()
588588
return _path.path_in_path(self, None, path, transform)
589589

590-
def get_extents(self, transform=None):
591-
"""
592-
Return the extents (*xmin*, *ymin*, *xmax*, *ymax*) of the path.
593-
594-
Unlike computing the extents on the *vertices* alone, this
595-
algorithm will take into account the curves and deal with
596-
control points appropriately.
597-
"""
598-
from .transforms import Bbox
599-
path = self
600-
if transform is not None:
601-
transform = transform.frozen()
602-
if not transform.is_affine:
603-
path = self.transformed(transform)
604-
transform = None
605-
return Bbox(_path.get_path_extents(path, transform))
606-
607-
def get_exact_extents(self, **kwargs):
590+
def get_extents(self, transform=None, **kwargs):
608591
"""Get size of Bbox of curve (instead of Bbox of control points).
609592
610593
Parameters
611594
----------
595+
transform : matplotlib.transforms.Transform, optional
596+
Transform to apply to path before computing extents, if any.
612597
kwargs : Dict[str, object]
613598
Forwarded to self.iter_bezier.
614599
615600
Returns
616601
-------
617-
extents : (4,) float, array_like
618-
The extents of the path (xmin, ymin, xmax, ymax).
602+
bbox : matplotlib.transforms.Bbox
603+
The extents of the path Bbox([[xmin, ymin], [xmax, ymax]])
619604
"""
605+
from .transforms import Bbox
606+
if transform is not None:
607+
self = transform.transform_path(self)
620608
maxi = 2 # [xmin, ymin, *xmax, ymax]
621-
# return value for empty paths to match _path.h
609+
# return value for empty paths to match what used to be done in _path.h
622610
extents = np.array([np.inf, np.inf, -np.inf, -np.inf])
623611
for curve, code in self.iter_bezier(**kwargs):
624612
# start and endpoints can be extrema of the curve
@@ -628,10 +616,10 @@ def get_exact_extents(self, **kwargs):
628616
_, dzeros = curve.axis_aligned_extrema
629617
if len(dzeros) == 0:
630618
continue
631-
for zero in dzeros:
632-
potential_extrema = curve.point_at_t(zero)
619+
for ti in dzeros:
620+
potential_extrema = curve.point_at_t(ti)
633621
_update_extents(extents, potential_extrema)
634-
return extents
622+
return Bbox.from_extents(extents)
635623

636624
def intersects_path(self, other, filled=True):
637625
"""

lib/matplotlib/tests/test_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_contains_points_negative_radius():
5252
def test_exact_extents_cubic():
5353
hard_curve = Path([[0, 0], [1, 0], [1, 1], [0, 1]],
5454
[Path.MOVETO, Path.CURVE4, Path.CURVE4, Path.CURVE4])
55-
np.testing.assert_equal(hard_curve.get_exact_extents(), [0., 0., 0.75, 1.])
55+
assert(hard_curve.get_extents().bounds == (0., 0., 0.75, 1.))
5656

5757

5858
def test_point_in_path_nan():

0 commit comments

Comments
 (0)