8000 FEATURE: Path.get_stroked_extents · matplotlib/matplotlib@0a92c2f · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a92c2f

Browse files
committed
FEATURE: Path.get_stroked_extents
1 parent e841b51 commit 0a92c2f

File tree

7 files changed

+713
-4
lines changed

7 files changed

+713
-4
lines changed

doc/users/next_whats_new/2020-03-31-path-size-methods.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@ Historically, `~.path.Path.get_extents` has always simply returned the Bbox of
2525
a curve's control points, instead of the Bbox of the curve itself. While this is
2626
a correct upper bound for the path's extents, it can differ dramatically from
2727
the Path's actual extents for non-linear Bezier curves.
28+
29+
New function to get Path's *stroked* Bbox
30+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
32+
A Path is typically drawn by stroking it (with some ``markeredgewidth``), an
33+
operation which changes its bounding box in a nontrivial way, depending on the
34+
Path's joinstyle, capstyle, miterlimit, and shape.
35+
36+
`~.path.Path.get_stroked_extents` was added to allow computation of the final
37+
bounding box in pixel/points coordinates of the line, after it has been drawn
38+
(and accounting for the joinstyle, capstyle, and miterlimit).

lib/matplotlib/bezier.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,20 @@ def degree(self):
234234
"""Degree of the polynomial. One less the number of control points."""
235235
return self._N - 1
236236

237+
@property
238+
def tan_in(self):
239+
if self._N < 2:
240+
raise ValueError("Need at least two control points to get tangent "
241+
"vector!")
242+
return self.control_points[1] - self.control_points[0]
243+
244+
@property
245+
def tan_out(self):
246+
if self._N < 2:
247+
raise ValueError("Need at least two control points to get tangent "
248+
"vector!")
249+
return self.control_points[-1] - self.control_points[-2]
250+
237251
@property
238252
def polynomial_coefficients(self):
239253
r"""

0 commit comments

Comments
 (0)
0