Skip to content

Inline _calc_extents_from_path. #29831

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
Apr 2, 2025
Merged
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: 9 additions & 41 deletions lib/matplotlib/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,53 +867,16 @@ def update_from_path(self, path, ignore=None, updatex=True, updatey=True):
if ignore is None:
ignore = self._ignore

if path.vertices.size == 0:
if path.vertices.size == 0 or not (updatex or updatey):
return

points, minpos, changed = self._calc_extents_from_path(path, ignore,
updatex, updatey)

if changed:
self.invalidate()
if updatex:
self._points[:, 0] = points[:, 0]
self._minpos[0] = minpos[0]
if updatey:
self._points[:, 1] = points[:, 1]
self._minpos[1] = minpos[1]

def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True):
"""
Calculate the new bounds and minimum positive values for a `Bbox` from
the path.

Parameters
----------
path : `~matplotlib.path.Path`
ignore : bool
- When ``True``, ignore the existing bounds of the `Bbox`.
- When ``False``, include the existing bounds of the `Bbox`.
updatex : bool
When ``True``, update the x-values.
updatey : bool
When ``True``, update the y-values.

Returns
-------
points : (2, 2) array
minpos : (2,) array
changed : bool
"""
if ignore:
points = np.array([[np.inf, np.inf], [-np.inf, -np.inf]])
minpos = np.array([np.inf, np.inf])
else:
points = self._points.copy()
minpos = self._minpos.copy()

if not (updatex or updatey):
return points, minpos, False

valid_points = (np.isfinite(path.vertices[..., 0])
& np.isfinite(path.vertices[..., 1]))

Expand All @@ -928,9 +891,14 @@ def _calc_extents_from_path(self, path, ignore, updatex=True, updatey=True):
points[1, 1] = max(points[1, 1], np.max(y, initial=-np.inf))
minpos[1] = min(minpos[1], np.min(y[y > 0], initial=np.inf))

changed = np.any(points != self._points) or np.any(minpos != self._minpos)

return points, minpos, changed
if np.any(points != self._points) or np.any(minpos != self._minpos):
self.invalidate()
if updatex:
self._points[:, 0] = points[:, 0]
self._minpos[0] = minpos[0]
if updatey:
self._points[:, 1] = points[:, 1]
self._minpos[1] = minpos[1]

def update_from_data_x(self, x, ignore=None):
"""
Expand Down
Loading