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

Fix infinite loop for connectionstyle + add some tests #11323

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
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions 5 lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def get_intersection(cx1, cy1, cos_t1, sin_t1,
c, d = sin_t2, -cos_t2

ad_bc = a * d - b * c
if ad_bc == 0.:
raise ValueError("Given lines do not intersect")
if np.abs(ad_bc) < 1.0e-12:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between

  • np.abs(ad_bc) < 1.0e-12
  • np.isclose([0], [ad_bc], atol=1.0e-12)

Why would I prefer the longer over the shorter?

raise ValueError("Given lines do not intersect. Please verify that "
"the angles are not equal or differ by 180 degrees.")

# rhs_inverse
a_, b_ = d, -b
Expand Down
10 changes: 5 additions & 5 deletions 10 lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -2789,8 +2789,8 @@ class Angle3(_Base):
"""
Creates a simple quadratic Bezier curve between two
points. The middle control points is placed at the
intersecting point of two lines which crosses the start (or
end) point and has a angle of angleA (or angleB).
intersecting point of two lines which cross the start and
end point, and have a slope of angleA and angleB, respectively.
"""

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

def __init__(self, angleA=90, angleB=0, rad=0.):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions 32 lib/matplotlib/tests/test_arrow_patches.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
import matplotlib.pyplot as plt
from matplotlib.testing.decorators import image_comparison
import matplotlib.patches as mpatches
Expand Down Expand Up @@ -133,3 +134,34 @@ def test_arrow_styles():
arrowstyle=stylename,
mutation_scale=25)
ax.add_patch(patch)


@image_comparison(baseline_images=['connection_styles'], extensions=['png'],
style='mpl20', remove_text=True)
def test_connection_styles():
styles = mpatches.ConnectionStyle.get_styles()

n = len(styles)
fig, ax = plt.subplots(figsize=(6, 10))
ax.set_xlim(0, 1)
ax.set_ylim(-1, n)

for i, stylename in enumerate(sorted(styles)):
patch = mpatches.FancyArrowPatch((0.1, i), (0.8, i + 0.5),
arrowstyle="->",
connectionstyle=stylename,
mutation_scale=25)
ax.add_patch(patch)


def test_invalid_intersection():
conn_style_1 = mpatches.ConnectionStyle.Angle3(angleA=20, angleB=200)
p1 = mpatches.FancyArrowPatch((.2, .2), (.5, .5),
connectionstyle=conn_style_1)
with pytest.raises(ValueError):
plt.gca().add_patch(p1)

conn_style_2 = mpatches.ConnectionStyle.Angle3(angleA=20, angleB=199.9)
p2 = mpatches.FancyArrowPatch((.2, .2), (.5, .5),
connectionstyle=conn_style_2)
plt.gca().add_patch(p2)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.