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

Appearance settings

Commit 4cea630

Browse filesBrowse files
Fix infinite loop for connectionstyle + add some tests
1 parent ec66f36 commit 4cea630
Copy full SHA for 4cea630

File tree

Expand file treeCollapse file tree

4 files changed

+40
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+40
-7
lines changed

‎lib/matplotlib/bezier.py

Copy file name to clipboardExpand all lines: lib/matplotlib/bezier.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def get_intersection(cx1, cy1, cos_t1, sin_t1,
3131
c, d = sin_t2, -cos_t2
3232

3333
ad_bc = a * d - b * c
34-
if ad_bc == 0.:
35-
raise ValueError("Given lines do not intersect")
34+
if np.abs(ad_bc) < 1.0e-12:
35+
raise ValueError("Given lines do not intersect. Please verify that "
36+
"the angles are not equal or differ by 180 degrees.")
3637

3738
# rhs_inverse
3839
a_, b_ = d, -b

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,8 +2789,8 @@ class Angle3(_Base):
27892789
"""
27902790
Creates a simple quadratic Bezier curve between two
27912791
points. The middle control points is placed at the
2792-
intersecting point of two lines which crosses the start (or
2793-
end) point and has a angle of angleA (or angleB).
2792+
intersecting point of two lines which cross the start and
2793+
end point, and have a slope of angleA and angleB, respectively.
27942794
"""
27952795

27962796
def __init__(self, angleA=90, angleB=0):
@@ -2827,9 +2827,9 @@ class Angle(_Base):
28272827
"""
28282828
Creates a piecewise continuous quadratic Bezier path between
28292829
two points. The path has a one passing-through point placed at
2830-
the intersecting point of two lines which crosses the start
2831-
(or end) point and has a angle of angleA (or angleB). The
2832-
connecting edges are rounded with *rad*.
2830+
the intersecting point of two lines which cross the start
2831+
and end point, and have a slope of angleA and angleB, respectively.
2832+
The connecting edges are rounded with *rad*.
28332833
"""
28342834

28352835
def __init__(self, angleA=90, angleB=0, rad=0.):
Loading

‎lib/matplotlib/tests/test_arrow_patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_arrow_patches.py
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
import matplotlib.pyplot as plt
23
from matplotlib.testing.decorators import image_comparison
34
import matplotlib.patches as mpatches
@@ -133,3 +134,34 @@ def test_arrow_styles():
133134
arrowstyle=stylename,
134135
mutation_scale=25)
135136
ax.add_patch(patch)
137+
138+
139+
@image_comparison(baseline_images=['connection_styles'], extensions=['png'],
140+
style='mpl20', remove_text=True)
141+
def test_connection_styles():
142+
styles = mpatches.ConnectionStyle.get_styles()
143+
144+
n = len(styles)
145+
fig, ax = plt.subplots(figsize=(6, 10))
146+
ax.set_xlim(0, 1)
147+
ax.set_ylim(-1, n)
148+
149+
for i, stylename in enumerate(sorted(styles)):
150+
patch = mpatches.FancyArrowPatch((0.1, i), (0.8, i + 0.5),
151+
arrowstyle="->",
152+
connectionstyle=stylename,
153+
mutation_scale=25)
154+
ax.add_patch(patch)
155+
156+
157+
def test_invalid_intersection():
158+
conn_style_1 = mpatches.ConnectionStyle.Angle3(angleA=20, angleB=200)
159+
p1 = mpatches.FancyArrowPatch((.2, .2), (.5, .5),
160+
connectionstyle=conn_style_1)
161+
with pytest.raises(ValueError):
162+
plt.gca().add_patch(p1)
163+
164+
conn_style_2 = mpatches.ConnectionStyle.Angle3(angleA=20, angleB=199.9)
165+
p2 = mpatches.FancyArrowPatch((.2, .2), (.5, .5),
166+
connectionstyle=conn_style_2)
167+
plt.gca().add_patch(p2)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.